diff --git a/internal/handler/input_mode_command.go b/internal/handler/input_mode_command.go index 8b5484a..71969ad 100644 --- a/internal/handler/input_mode_command.go +++ b/internal/handler/input_mode_command.go @@ -40,6 +40,7 @@ func (h *InputModeCommand) Handle(_ string) (Response, bool) { } h.terminal.Config.Multiline = multiline + h.terminal.SetUserPrompt() if h.terminal.Config.Multiline { // disable history for multi-line messages since it is // unusable for future requests diff --git a/internal/terminal/io.go b/internal/terminal/io.go index 8f22bdb..3c82342 100644 --- a/internal/terminal/io.go +++ b/internal/terminal/io.go @@ -77,7 +77,7 @@ func (io *IO) readLine() string { } func (io *IO) readMultiLine() string { - defer io.Reader.SetPrompt(io.Prompt.User) + defer io.SetUserPrompt() var builder strings.Builder for { input, err := io.Reader.Readline() @@ -92,7 +92,7 @@ func (io *IO) readMultiLine() string { } if builder.Len() == 0 { - io.Reader.SetPrompt(io.Prompt.UserNext) + io.Reader.SetPrompt(io.Prompt.UserMultilineNext) } builder.WriteString(input) @@ -112,3 +112,12 @@ func (io *IO) handleReadError(err error, inputLen int) string { } return "" } + +// SetUserPrompt sets the terminal prompt according to the current input mode. +func (io *IO) SetUserPrompt() { + if io.Config.Multiline { + io.Reader.SetPrompt(io.Prompt.UserMultiline) + } else { + io.Reader.SetPrompt(io.Prompt.User) + } +} diff --git a/internal/terminal/prompt.go b/internal/terminal/prompt.go index e4c0337..db342d0 100644 --- a/internal/terminal/prompt.go +++ b/internal/terminal/prompt.go @@ -14,10 +14,11 @@ const ( ) type Prompt struct { - User string - UserNext string - Gemini string - Cli string + User string + UserMultiline string + UserMultilineNext string + Gemini string + Cli string } type promptColor struct { @@ -45,16 +46,17 @@ func NewPrompt(currentUser string) *Prompt { maxLength := maxLength(currentUser, geminiUser, cliUser) pc := newPromptColor() return &Prompt{ - User: pc.user(buildPrompt(currentUser, maxLength)), - UserNext: pc.user(buildPrompt(strings.Repeat(" ", len(currentUser)), maxLength)), - Gemini: pc.gemini(buildPrompt(geminiUser, maxLength)), - Cli: pc.cli(buildPrompt(cliUser, maxLength)), + User: pc.user(buildPrompt(currentUser, '>', maxLength)), + UserMultiline: pc.user(buildPrompt(currentUser, '#', maxLength)), + UserMultilineNext: pc.user(buildPrompt(strings.Repeat(" ", len(currentUser)), '>', maxLength)), + Gemini: pc.gemini(buildPrompt(geminiUser, '>', maxLength)), + Cli: pc.cli(buildPrompt(cliUser, '>', maxLength)), } } -func maxLength(str ...string) int { +func maxLength(strings ...string) int { var maxLength int - for _, s := range str { + for _, s := range strings { length := len(s) if maxLength < length { maxLength = length @@ -63,6 +65,6 @@ func maxLength(str ...string) int { return maxLength } -func buildPrompt(user string, length int) string { - return fmt.Sprintf("%s>%s", user, strings.Repeat(" ", length-len(user)+1)) +func buildPrompt(user string, p byte, length int) string { + return fmt.Sprintf("%s%c%s", user, p, strings.Repeat(" ", length-len(user)+1)) }