Skip to content

Commit

Permalink
fix: error handling in multi-line mode (#20)
Browse files Browse the repository at this point in the history
  • Loading branch information
reugn authored Jul 27, 2024
1 parent 66a75fc commit ff8e5a9
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 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(input, err)
return c.handleReadError(len(input), err)
}
return validateInput(input)
}
Expand All @@ -79,7 +79,8 @@ func (c *Chat) readMultiLine() (string, bool) {
for {
input, err := c.reader.Readline()
if err != nil {
return c.handleReadError(input, err)
c.reader.SetPrompt(c.prompt.user)
return c.handleReadError(builder.Len()+len(input), err)
}
if strings.HasSuffix(input, term) {
builder.WriteString(strings.TrimSuffix(input, term))
Expand All @@ -101,9 +102,9 @@ func (c *Chat) parseCommand(message string) command {
return newGeminiCommand(c)
}

func (c *Chat) handleReadError(input string, err error) (string, bool) {
func (c *Chat) handleReadError(inputLen int, err error) (string, bool) {
if errors.Is(err, readline.ErrInterrupt) {
if len(input) == 0 {
if inputLen == 0 {
return systemCmdQuit, true
}
return "", false
Expand Down

0 comments on commit ff8e5a9

Please sign in to comment.