Explorar o código

fix multi line input in `ollama run`

Jeffrey Morgan hai 1 ano
pai
achega
e20362e0d5
Modificáronse 1 ficheiros con 10 adicións e 6 borrados
  1. 10 6
      cmd/cmd.go

+ 10 - 6
cmd/cmd.go

@@ -32,11 +32,13 @@ import (
 	"github.com/jmorganca/ollama/version"
 )
 
-type Painter struct{}
+type Painter struct {
+	HideHint bool
+}
 
-func (p Painter) Paint(line []rune, l int) []rune {
+func (p Painter) Paint(line []rune, _ int) []rune {
 	termType := os.Getenv("TERM")
-	if termType == "xterm-256color" && len(line) == 0 {
+	if termType == "xterm-256color" && len(line) == 0 && !p.HideHint {
 		prompt := "Send a message (/? for help)"
 		return []rune(fmt.Sprintf("\033[38;5;245m%s\033[%dD\033[0m", prompt, len(prompt)))
 	}
@@ -538,8 +540,10 @@ func generateInteractive(cmd *cobra.Command, model string) error {
 		fmt.Fprintln(os.Stderr, completer.Tree("  "))
 	}
 
+	var painter Painter
+
 	config := readline.Config{
-		Painter:      Painter{},
+		Painter:      &painter,
 		Prompt:       ">>> ",
 		HistoryFile:  filepath.Join(home, ".ollama", "history"),
 		AutoComplete: completer,
@@ -575,11 +579,10 @@ func generateInteractive(cmd *cobra.Command, model string) error {
 		case isMultiLine:
 			if strings.HasSuffix(line, `"""`) {
 				isMultiLine = false
+				painter.HideHint = false
 				multiLineBuffer += strings.TrimSuffix(line, `"""`)
-				line = multiLineBuffer
 				multiLineBuffer = ""
 				scanner.SetPrompt(">>> ")
-				continue
 			} else {
 				multiLineBuffer += line + " "
 				continue
@@ -588,6 +591,7 @@ func generateInteractive(cmd *cobra.Command, model string) error {
 			isMultiLine = true
 			multiLineBuffer = strings.TrimPrefix(line, `"""`) + " "
 			scanner.SetPrompt("... ")
+			painter.HideHint = true
 			continue
 		case strings.HasPrefix(line, "/list"):
 			args := strings.Fields(line)