Skip to content

Commit

Permalink
Tweak answer colors
Browse files Browse the repository at this point in the history
  • Loading branch information
bakks committed Jan 5, 2024
1 parent bd9496c commit d6d6e34
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 7 deletions.
3 changes: 2 additions & 1 deletion butterfish/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -613,12 +613,13 @@ func (this *ButterfishCtx) Prompt(cmd *promptCommand) (*util.CompletionResponse,

if !cmd.NoColor {
color := styleToEscape(this.Config.Styles.Answer.GetForeground())
highlight := styleToEscape(this.Config.Styles.Highlight.GetForeground())
this.Out.Write([]byte(color))

termWidth, _, _ := term.GetSize(int(os.Stdout.Fd()))

if termWidth > 0 {
writer = util.NewStyleCodeblocksWriter(this.Out, termWidth, color)
writer = util.NewStyleCodeblocksWriter(this.Out, termWidth, color, highlight)
}
} else if cmd.NoBackticks {
// this is an else because the code blocks writer will strip out backticks
Expand Down
9 changes: 6 additions & 3 deletions butterfish/shell.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ var DarkShellColorScheme = &ShellColorScheme{
PromptGoalUnsafe: "\x1b[38;5;9m",
Command: "\x1b[0m",
Autosuggest: "\x1b[38;5;241m",
Answer: "\x1b[38;5;178m",
Answer: "\x1b[38;5;221m",
AnswerHighlight: "\x1b[38;5;204m",
GoalMode: "\x1b[38;5;51m",
Error: "\x1b[38;5;196m",
}
Expand All @@ -63,7 +64,8 @@ var LightShellColorScheme = &ShellColorScheme{
PromptGoalUnsafe: "\x1b[38;5;9m",
Command: "\x1b[0m",
Autosuggest: "\x1b[38;5;241m",
Answer: "\x1b[38;5;178m",
Answer: "\x1b[38;5;221m",
AnswerHighlight: "\x1b[38;5;204m",
GoalMode: "\x1b[38;5;18m",
Error: "\x1b[38;5;196m",
}
Expand Down Expand Up @@ -341,6 +343,7 @@ type ShellColorScheme struct {
Command string
Autosuggest string
Answer string
AnswerHighlight string
GoalMode string
}

Expand Down Expand Up @@ -587,7 +590,7 @@ func (this *ButterfishCtx) ShellMultiplexer(

carriageReturnWriter := util.NewReplaceWriter(parentOut, "\n", "\r\n")
styleCodeblocksWriter := util.NewStyleCodeblocksWriter(carriageReturnWriter,
termWidth, colorScheme.Answer)
termWidth, colorScheme.Answer, colorScheme.AnswerHighlight)

sigwinch := make(chan os.Signal, 1)
signal.Notify(sigwinch, syscall.SIGWINCH)
Expand Down
9 changes: 7 additions & 2 deletions util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,12 @@ type StyleCodeblocksWriter struct {
blockBuffer *bytes.Buffer
}

func NewStyleCodeblocksWriter(writer io.Writer, terminalWidth int, normalColor string) *StyleCodeblocksWriter {
func NewStyleCodeblocksWriter(
writer io.Writer,
terminalWidth int,
normalColor string,
highlightColor string,
) *StyleCodeblocksWriter {
if terminalWidth == 0 {
panic("terminal width must be > 0")
}
Expand All @@ -270,7 +275,7 @@ func NewStyleCodeblocksWriter(writer io.Writer, terminalWidth int, normalColor s
Writer: writer,
state: STATE_NEWLINE,
normalColor: normalColor,
inlineColor: "\x1b[93m", // bright yellow
inlineColor: highlightColor,
terminalWidth: terminalWidth,
}
}
Expand Down
2 changes: 1 addition & 1 deletion util/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (

func TestStyleCodeblocksWriter(t *testing.T) {
buffer := new(bytes.Buffer)
writer := NewStyleCodeblocksWriter(buffer, 80, "")
writer := NewStyleCodeblocksWriter(buffer, 80, "", "")

writer.Write([]byte("Hello\n"))
writer.Write([]byte("```javascript\n"))
Expand Down

0 comments on commit d6d6e34

Please sign in to comment.