From 2601b2736ab99408be041f07704edba9b2a12369 Mon Sep 17 00:00:00 2001 From: reugn Date: Sat, 6 Apr 2024 14:37:36 +0300 Subject: [PATCH] feat: allow for using SIGINT to clear input --- cli/chat.go | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/cli/chat.go b/cli/chat.go index f151934..739adb8 100644 --- a/cli/chat.go +++ b/cli/chat.go @@ -68,7 +68,7 @@ func (c *Chat) read() (string, bool) { func (c *Chat) readLine() (string, bool) { input, err := c.reader.Readline() if err != nil { - return c.handleReadError(err) + return c.handleReadError(input, err) } return validateInput(input) } @@ -79,7 +79,7 @@ func (c *Chat) readMultiLine() (string, bool) { for { input, err := c.reader.Readline() if err != nil { - return c.handleReadError(err) + return c.handleReadError(input, err) } if strings.HasSuffix(input, term) { builder.WriteString(strings.TrimSuffix(input, term)) @@ -101,9 +101,12 @@ func (c *Chat) parseCommand(message string) command { return newGeminiCommand(c) } -func (c *Chat) handleReadError(err error) (string, bool) { +func (c *Chat) handleReadError(input string, err error) (string, bool) { if errors.Is(err, readline.ErrInterrupt) { - return systemCmdQuit, true + if len(input) == 0 { + return systemCmdQuit, true + } + return "", false } fmt.Printf("%s%s\n", c.prompt.cli, err) return "", false