From 4a89a2bdbbc4a9952e6d6b529d2aa5951b146bdb Mon Sep 17 00:00:00 2001 From: Stuart Douglas Date: Thu, 3 Oct 2024 14:51:44 +1000 Subject: [PATCH] fix: readline exit behaviour Send SIGINT so all processess in the group also shut down fixes: #2970 --- internal/terminal/interactive.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/internal/terminal/interactive.go b/internal/terminal/interactive.go index 5839ad9d0e..b1c983e35d 100644 --- a/internal/terminal/interactive.go +++ b/internal/terminal/interactive.go @@ -7,6 +7,7 @@ import ( "io" "os" "strings" + "syscall" "github.com/alecthomas/kong" "github.com/chzyer/readline" @@ -33,7 +34,7 @@ func RunInteractiveConsole(ctx context.Context, k *kong.Kong, binder KongContext InterruptPrompt: "^C", AutoComplete: &FTLCompletion{app: k, ctx: ctx, client: client}, Listener: &ExitListener{cancel: func() { - os.Exit(0) + _ = syscall.Kill(-syscall.Getpid(), syscall.SIGINT) //nolint:forcetypeassert,errcheck // best effort }}, }) sm := FromContext(ctx) @@ -71,6 +72,7 @@ func RunInteractiveConsole(ctx context.Context, k *kong.Kong, binder KongContext for { line, err := l.Readline() if errors.Is(err, readline.ErrInterrupt) { + if len(line) == 0 { break }