From 1f9e195fa6bbe6ba23fa1c7d38dc212453284697 Mon Sep 17 00:00:00 2001 From: adamdottv <2363879+adamdottv@users.noreply.github.com> Date: Thu, 3 Jul 2025 06:49:37 -0500 Subject: [PATCH] fix(tui): better highlight visuals --- .../tui/internal/components/chat/message.go | 44 +++++++++++++------ packages/tui/internal/tui/tui.go | 11 ++--- 2 files changed, 36 insertions(+), 19 deletions(-) diff --git a/packages/tui/internal/components/chat/message.go b/packages/tui/internal/components/chat/message.go index 4ef73856..4dde09ea 100644 --- a/packages/tui/internal/components/chat/message.go +++ b/packages/tui/internal/components/chat/message.go @@ -162,18 +162,16 @@ func renderContentBlock( if highlight { style = style. - BorderLeftBackground(t.Primary()). - BorderLeftForeground(t.Primary()). - BorderRightForeground(t.Primary()). - BorderRightBackground(t.Primary()) + BorderLeftForeground(borderColor). + BorderRightForeground(borderColor) } } if highlight { style = style. Foreground(t.Text()). - Bold(true). - Background(t.BackgroundElement()) + Background(t.BackgroundElement()). + Bold(true) } content = style.Render(content) @@ -211,7 +209,7 @@ func renderContentBlock( ) header = styles.NewStyle().Background(t.Background()).Padding(0, 1).Render(header) - content = "\n\n\n" + header + "\n\n" + content + "\n\n" + content = "\n\n\n" + header + "\n\n" + content + "\n\n\n" } return content @@ -229,7 +227,9 @@ func renderText( ) string { t := theme.CurrentTheme() - timestamp := time.UnixMilli(int64(message.Metadata.Time.Created)).Local().Format("02 Jan 2006 03:04 PM") + timestamp := time.UnixMilli(int64(message.Metadata.Time.Created)). + Local(). + Format("02 Jan 2006 03:04 PM") if time.Now().Format("02 Jan 2006") == timestamp[:11] { // don't show the date if it's today timestamp = timestamp[12:] @@ -338,8 +338,10 @@ func renderToolDetails( finished := result != nil && *result != "" t := theme.CurrentTheme() backgroundColor := t.BackgroundPanel() + borderColor := t.BackgroundPanel() if highlight { backgroundColor = t.BackgroundElement() + borderColor = t.BorderActive() } switch toolCall.ToolInvocation.ToolName { @@ -362,7 +364,11 @@ func renderToolDetails( diff.WithWidth(width-2), ) body = strings.TrimSpace(formattedDiff) - style := styles.NewStyle().Background(backgroundColor).Foreground(t.TextMuted()).Padding(1, 2).Width(width - 4) + style := styles.NewStyle(). + Background(backgroundColor). + Foreground(t.TextMuted()). + Padding(1, 2). + Width(width - 4) if highlight { style = style.Foreground(t.Text()).Bold(true) } @@ -375,7 +381,14 @@ func renderToolDetails( title := renderToolTitle(toolCall, messageMetadata, width) title = style.Render(title) content := title + "\n" + body - content = renderContentBlock(app, content, highlight, width, WithPadding(0)) + content = renderContentBlock( + app, + content, + highlight, + width, + WithPadding(0), + WithBorderColor(borderColor), + ) return content } } @@ -478,7 +491,7 @@ func renderToolDetails( title := renderToolTitle(toolCall, messageMetadata, width) content := title + "\n\n" + body - return renderContentBlock(app, content, highlight, width) + return renderContentBlock(app, content, highlight, width, WithBorderColor(borderColor)) } func renderToolName(name string) string { @@ -489,8 +502,8 @@ func renderToolName(name string) string { return "Plan" default: normalizedName := name - if strings.HasPrefix(name, "opencode_") { - normalizedName = strings.TrimPrefix(name, "opencode_") + if after, ok := strings.CutPrefix(name, "opencode_"); ok { + normalizedName = after } return cases.Title(language.Und).String(normalizedName) } @@ -651,7 +664,10 @@ func renderDiagnostics(metadata opencode.MessageMetadataTool, filePath string) s } line := diag.Range.Start.Line + 1 // 1-based column := diag.Range.Start.Character + 1 // 1-based - errorDiagnostics = append(errorDiagnostics, fmt.Sprintf("Error [%d:%d] %s", line, column, diag.Message)) + errorDiagnostics = append( + errorDiagnostics, + fmt.Sprintf("Error [%d:%d] %s", line, column, diag.Message), + ) } if len(errorDiagnostics) == 0 { return "" diff --git a/packages/tui/internal/tui/tui.go b/packages/tui/internal/tui/tui.go index 53178294..1c326678 100644 --- a/packages/tui/internal/tui/tui.go +++ b/packages/tui/internal/tui/tui.go @@ -41,7 +41,7 @@ const ( ) const interruptDebounceTimeout = 1 * time.Second -const fileViewerFullWidthCutoff = 200 +const fileViewerFullWidthCutoff = 160 type appModel struct { width, height int @@ -111,18 +111,19 @@ func isScrollRelatedInput(keyString string) bool { if len(keyString) == 0 { return false } - + for _, char := range keyString { charStr := string(char) if !BUGGED_SCROLL_KEYS[charStr] { return false } } - - if len(keyString) > 3 && (keyString[len(keyString)-1] == 'M' || keyString[len(keyString)-1] == 'm') { + + if len(keyString) > 3 && + (keyString[len(keyString)-1] == 'M' || keyString[len(keyString)-1] == 'm') { return true } - + return len(keyString) > 1 }