Skip to content

Commit

Permalink
feat: allow for using SIGINT to clear input (#14)
Browse files Browse the repository at this point in the history
  • Loading branch information
reugn authored Apr 6, 2024
1 parent 1fe104f commit 66a75fc
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions cli/chat.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand All @@ -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))
Expand All @@ -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
Expand Down

0 comments on commit 66a75fc

Please sign in to comment.