This commit is contained in:
Patrick Devine 2026-01-04 23:38:21 +01:00 committed by GitHub
commit a63438ee69
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 22 additions and 5 deletions

View File

@ -29,6 +29,11 @@ const (
MultilineSystem
)
const (
scannerPrompt = ">>> "
scannerAltPrompt = "... "
)
func generateInteractive(cmd *cobra.Command, opts runOptions) error {
usage := func() {
fmt.Fprintln(os.Stderr, "Available Commands:")
@ -112,8 +117,8 @@ func generateInteractive(cmd *cobra.Command, opts runOptions) error {
}
scanner, err := readline.New(readline.Prompt{
Prompt: ">>> ",
AltPrompt: "... ",
Prompt: scannerPrompt,
AltPrompt: scannerAltPrompt,
Placeholder: "Send a message (/? for help)",
AltPlaceholder: `Use """ to end multi-line input`,
})
@ -146,6 +151,11 @@ func generateInteractive(cmd *cobra.Command, opts runOptions) error {
scanner.Prompt.UseAlt = false
sb.Reset()
continue
case errors.Is(err, readline.ErrNewLineDetected):
sb.WriteString(line)
fmt.Fprintln(&sb)
scanner.Prompt.Prompt = scannerAltPrompt
continue
case err != nil:
return err
@ -171,7 +181,7 @@ func generateInteractive(cmd *cobra.Command, opts runOptions) error {
multiline = MultilineNone
scanner.Prompt.UseAlt = false
case strings.HasPrefix(line, `"""`):
case strings.HasPrefix(line, `"""`) && !scanner.Pasting:
line := strings.TrimPrefix(line, `"""`)
line, ok := strings.CutSuffix(line, `"""`)
sb.WriteString(line)
@ -482,7 +492,7 @@ func generateInteractive(cmd *cobra.Command, opts runOptions) error {
sb.WriteString(line)
}
if sb.Len() > 0 && multiline == MultilineNone {
if sb.Len() > 0 && strings.TrimSpace(sb.String()) != "" && multiline == MultilineNone {
newMessage := api.Message{Role: "user", Content: sb.String()}
if opts.MultiModal {
@ -512,6 +522,7 @@ func generateInteractive(cmd *cobra.Command, opts runOptions) error {
}
sb.Reset()
scanner.Prompt.Prompt = scannerPrompt
}
}
}

View File

@ -4,7 +4,10 @@ import (
"errors"
)
var ErrInterrupt = errors.New("Interrupt")
var (
ErrInterrupt = errors.New("Interrupt")
ErrNewLineDetected = errors.New("new line detected")
)
type InterruptError struct {
Line []rune

View File

@ -219,6 +219,9 @@ func (i *Instance) Readline() (string, error) {
buf.MoveToEnd()
fmt.Println()
if r == CharCtrlJ {
return output, ErrNewLineDetected
}
return output, nil
default:
if metaDel {