From 3603a74dd4561380651f542d87178096fc465b8e Mon Sep 17 00:00:00 2001 From: Kujtim Hoxha Date: Thu, 19 Jun 2025 12:33:39 +0200 Subject: [PATCH] chore: small ui fixes - fixed the tool call header - fixed the status error style - other small things --- go.mod | 2 +- .../tui/components/chat/messages/renderer.go | 11 ++++--- internal/tui/components/core/status/status.go | 33 ++++++++++++++----- internal/tui/keys.go | 4 +-- internal/tui/styles/crush.go | 2 ++ internal/tui/styles/theme.go | 6 ++-- internal/tui/tui.go | 8 +---- 7 files changed, 41 insertions(+), 25 deletions(-) diff --git a/go.mod b/go.mod index f5b9b0ef945822cf386f62767ead9079787524ea..ca66162d0d9efe6316b4d28b31ab92797c569925 100644 --- a/go.mod +++ b/go.mod @@ -32,7 +32,6 @@ require ( github.com/pressly/goose/v3 v3.24.2 github.com/sabhiram/go-gitignore v0.0.0-20210923224102-525f6e181f06 github.com/sahilm/fuzzy v0.1.1 - github.com/sergi/go-diff v1.3.2-0.20230802210424-5b0b94c5c0d3 github.com/spf13/cobra v1.9.1 github.com/spf13/viper v1.20.0 github.com/srwiley/oksvg v0.0.0-20221011165216-be6e8873101c @@ -105,6 +104,7 @@ require ( github.com/rivo/uniseg v0.4.7 github.com/rogpeppe/go-internal v1.14.1 // indirect github.com/sagikazarmark/locafero v0.7.0 // indirect + github.com/sergi/go-diff v1.3.2-0.20230802210424-5b0b94c5c0d3 // indirect github.com/sethvargo/go-retry v0.3.0 // indirect github.com/sourcegraph/conc v0.3.0 // indirect github.com/spf13/afero v1.12.0 // indirect diff --git a/internal/tui/components/chat/messages/renderer.go b/internal/tui/components/chat/messages/renderer.go index 56a42c0f93a3f558218cfac080a6b355b00297bd..71cd7288f5c364b5dd0d5c5a4e80c8d4fa465a5e 100644 --- a/internal/tui/components/chat/messages/renderer.go +++ b/internal/tui/components/chat/messages/renderer.go @@ -125,7 +125,7 @@ func (br baseRenderer) makeHeader(v *toolCallCmp, tool string, width int, params icon = t.S().Muted.Render(styles.ToolPending) } tool = t.S().Base.Foreground(t.Blue).Render(tool) - prefix := fmt.Sprintf("%s %s: ", icon, tool) + prefix := fmt.Sprintf("%s %s ", icon, tool) return prefix + renderParamList(width-lipgloss.Width(prefix), params...) } @@ -517,6 +517,7 @@ func (tr agentRenderer) Render(v *toolCallCmp) string { // renderParamList renders params, params[0] (params[1]=params[2] ....) func renderParamList(paramsWidth int, params ...string) string { + t := styles.CurrentTheme() if len(params) == 0 { return "" } @@ -526,7 +527,7 @@ func renderParamList(paramsWidth int, params ...string) string { } if len(params) == 1 { - return mainParam + return t.S().Subtle.Render(mainParam) } otherParams := params[1:] // create pairs of key/value @@ -548,14 +549,14 @@ func renderParamList(paramsWidth int, params ...string) string { remainingWidth := paramsWidth - lipgloss.Width(partsRendered) - 3 // count for " ()" if remainingWidth < 30 { // No space for the params, just show the main - return mainParam + return t.S().Subtle.Render(mainParam) } if len(parts) > 0 { mainParam = fmt.Sprintf("%s (%s)", mainParam, strings.Join(parts, ", ")) } - return ansi.Truncate(mainParam, paramsWidth, "...") + return t.S().Subtle.Render(ansi.Truncate(mainParam, paramsWidth, "...")) } // earlyState returns immediately‑rendered error/cancelled/ongoing states. @@ -580,7 +581,7 @@ func earlyState(header string, v *toolCallCmp) (string, bool) { func joinHeaderBody(header, body string) string { t := styles.CurrentTheme() body = t.S().Base.PaddingLeft(2).Render(body) - return lipgloss.JoinVertical(lipgloss.Left, header, body, "") + return lipgloss.JoinVertical(lipgloss.Left, header, "", body, "") } func renderPlainContent(v *toolCallCmp, content string) string { diff --git a/internal/tui/components/core/status/status.go b/internal/tui/components/core/status/status.go index 7b91c186f7ab9e572685de3e346204873d8cede2..a5caa538b26b83e6f2388d2419f95f0047df151d 100644 --- a/internal/tui/components/core/status/status.go +++ b/internal/tui/components/core/status/status.go @@ -1,6 +1,7 @@ package status import ( + "strings" "time" "github.com/charmbracelet/bubbles/v2/help" @@ -10,6 +11,8 @@ import ( "github.com/charmbracelet/crush/internal/session" "github.com/charmbracelet/crush/internal/tui/styles" "github.com/charmbracelet/crush/internal/tui/util" + "github.com/charmbracelet/lipgloss/v2" + "github.com/charmbracelet/x/ansi" ) type StatusCmp interface { @@ -94,18 +97,32 @@ func (m *statusCmp) View() tea.View { t := styles.CurrentTheme() status := t.S().Base.Padding(0, 1, 1, 1).Render(m.help.View(m.keyMap)) if m.info.Msg != "" { - switch m.info.Type { - case util.InfoTypeError: - status = t.S().Base.Background(t.Error).Padding(0, 1).Width(m.width).Render(m.info.Msg) - case util.InfoTypeWarn: - status = t.S().Base.Background(t.Warning).Padding(0, 1).Width(m.width).Render(m.info.Msg) - default: - status = t.S().Base.Background(t.Info).Padding(0, 1).Width(m.width).Render(m.info.Msg) - } + status = m.infoMsg() } return tea.NewView(status) } +func (m *statusCmp) infoMsg() string { + t := styles.CurrentTheme() + message := "" + infoType := "" + switch m.info.Type { + case util.InfoTypeError: + infoType = t.S().Base.Background(t.Red).Padding(0, 1).Render("ERROR") + width := m.width - lipgloss.Width(infoType) + message = t.S().Base.Background(t.Error).Foreground(t.White).Padding(0, 1).Width(width).Render(ansi.Truncate(m.info.Msg, width, "…")) + case util.InfoTypeWarn: + infoType = t.S().Base.Foreground(t.BgOverlay).Background(t.Yellow).Padding(0, 1).Render("WARNING") + width := m.width - lipgloss.Width(infoType) + message = t.S().Base.Foreground(t.BgOverlay).Background(t.Warning).Padding(0, 1).Width(width).Render(ansi.Truncate(m.info.Msg, width, "…")) + default: + infoType = t.S().Base.Foreground(t.BgOverlay).Background(t.Green).Padding(0, 1).Render("OKAY!") + width := m.width - lipgloss.Width(infoType) + message = t.S().Base.Background(t.Success).Foreground(t.White).Padding(0, 1).Width(width).Render(ansi.Truncate(m.info.Msg, width, "…")) + } + return strings.Join([]string{infoType, message}, "") +} + func (m *statusCmp) ToggleFullHelp() { m.help.ShowAll = !m.help.ShowAll } diff --git a/internal/tui/keys.go b/internal/tui/keys.go index dda3ad4dba02192626adf74540d2c62aad44a5a1..8af028cd10338eba2108f94156035b8f58f342e2 100644 --- a/internal/tui/keys.go +++ b/internal/tui/keys.go @@ -61,8 +61,8 @@ func (k KeyMap) FullHelp() [][]key.Binding { } } - for i := 0; i < len(cleaned); i += 2 { - end := min(i+2, len(cleaned)) + for i := 0; i < len(cleaned); i += 3 { + end := min(i+3, len(cleaned)) m = append(m, cleaned[i:end]) } return m diff --git a/internal/tui/styles/crush.go b/internal/tui/styles/crush.go index fca7f5d36f090d2f253260116a84dace4a22bb8a..7ee690b99037770bdd2204db7f6270c20d473514 100644 --- a/internal/tui/styles/crush.go +++ b/internal/tui/styles/crush.go @@ -41,6 +41,8 @@ func NewCrushTheme() *Theme { Blue: charmtone.Malibu, + Yellow: charmtone.Mustard, + Green: charmtone.Julep, GreenDark: charmtone.Guac, GreenLight: charmtone.Bok, diff --git a/internal/tui/styles/theme.go b/internal/tui/styles/theme.go index 74df47d8a238f4946f678b5ba1d88ab4f9d89992..4da3bd520f14da5d8e2fbfd561ed31d7a5a56fa2 100644 --- a/internal/tui/styles/theme.go +++ b/internal/tui/styles/theme.go @@ -54,9 +54,13 @@ type Theme struct { // Colors // White White color.Color + // Blues Blue color.Color + // Yellows + Yellow color.Color + // Greens Green color.Color GreenDark color.Color @@ -67,8 +71,6 @@ type Theme struct { RedDark color.Color RedLight color.Color - // TODO: add any others needed - styles *Styles } diff --git a/internal/tui/tui.go b/internal/tui/tui.go index e7f2f99da3e7bbf726ac78d654d6501018ba1351..c6dee6532993becfbda24d115b8e1e5d05e4fd60 100644 --- a/internal/tui/tui.go +++ b/internal/tui/tui.go @@ -94,12 +94,6 @@ func (a *appModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) { switch msg := msg.(type) { case tea.KeyboardEnhancementsMsg: - logging.Info( - "Keyboard enhancements detected", - "Disambiguation", msg.SupportsKeyDisambiguation(), - "ReleaseKeys", msg.SupportsKeyReleases(), - "UniformKeys", msg.SupportsUniformKeyLayout(), - ) return a, nil case tea.WindowSizeMsg: return a, a.handleWindowResize(msg.Width, msg.Height) @@ -260,7 +254,7 @@ func (a *appModel) handleWindowResize(width, height int) tea.Cmd { var cmds []tea.Cmd a.wWidth, a.wHeight = width, height if a.showingFullHelp { - height -= 3 + height -= 4 } else { height -= 2 }