fix(tui): better highlight visuals

This commit is contained in:
adamdottv 2025-07-03 06:49:37 -05:00
parent 73c012c76c
commit 1f9e195fa6
No known key found for this signature in database
GPG key ID: 9CB48779AF150E75
2 changed files with 36 additions and 19 deletions

View file

@ -162,18 +162,16 @@ func renderContentBlock(
if highlight { if highlight {
style = style. style = style.
BorderLeftBackground(t.Primary()). BorderLeftForeground(borderColor).
BorderLeftForeground(t.Primary()). BorderRightForeground(borderColor)
BorderRightForeground(t.Primary()).
BorderRightBackground(t.Primary())
} }
} }
if highlight { if highlight {
style = style. style = style.
Foreground(t.Text()). Foreground(t.Text()).
Bold(true). Background(t.BackgroundElement()).
Background(t.BackgroundElement()) Bold(true)
} }
content = style.Render(content) content = style.Render(content)
@ -211,7 +209,7 @@ func renderContentBlock(
) )
header = styles.NewStyle().Background(t.Background()).Padding(0, 1).Render(header) 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 return content
@ -229,7 +227,9 @@ func renderText(
) string { ) string {
t := theme.CurrentTheme() 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] { if time.Now().Format("02 Jan 2006") == timestamp[:11] {
// don't show the date if it's today // don't show the date if it's today
timestamp = timestamp[12:] timestamp = timestamp[12:]
@ -338,8 +338,10 @@ func renderToolDetails(
finished := result != nil && *result != "" finished := result != nil && *result != ""
t := theme.CurrentTheme() t := theme.CurrentTheme()
backgroundColor := t.BackgroundPanel() backgroundColor := t.BackgroundPanel()
borderColor := t.BackgroundPanel()
if highlight { if highlight {
backgroundColor = t.BackgroundElement() backgroundColor = t.BackgroundElement()
borderColor = t.BorderActive()
} }
switch toolCall.ToolInvocation.ToolName { switch toolCall.ToolInvocation.ToolName {
@ -362,7 +364,11 @@ func renderToolDetails(
diff.WithWidth(width-2), diff.WithWidth(width-2),
) )
body = strings.TrimSpace(formattedDiff) 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 { if highlight {
style = style.Foreground(t.Text()).Bold(true) style = style.Foreground(t.Text()).Bold(true)
} }
@ -375,7 +381,14 @@ func renderToolDetails(
title := renderToolTitle(toolCall, messageMetadata, width) title := renderToolTitle(toolCall, messageMetadata, width)
title = style.Render(title) title = style.Render(title)
content := title + "\n" + body content := title + "\n" + body
content = renderContentBlock(app, content, highlight, width, WithPadding(0)) content = renderContentBlock(
app,
content,
highlight,
width,
WithPadding(0),
WithBorderColor(borderColor),
)
return content return content
} }
} }
@ -478,7 +491,7 @@ func renderToolDetails(
title := renderToolTitle(toolCall, messageMetadata, width) title := renderToolTitle(toolCall, messageMetadata, width)
content := title + "\n\n" + body content := title + "\n\n" + body
return renderContentBlock(app, content, highlight, width) return renderContentBlock(app, content, highlight, width, WithBorderColor(borderColor))
} }
func renderToolName(name string) string { func renderToolName(name string) string {
@ -489,8 +502,8 @@ func renderToolName(name string) string {
return "Plan" return "Plan"
default: default:
normalizedName := name normalizedName := name
if strings.HasPrefix(name, "opencode_") { if after, ok := strings.CutPrefix(name, "opencode_"); ok {
normalizedName = strings.TrimPrefix(name, "opencode_") normalizedName = after
} }
return cases.Title(language.Und).String(normalizedName) 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 line := diag.Range.Start.Line + 1 // 1-based
column := diag.Range.Start.Character + 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 { if len(errorDiagnostics) == 0 {
return "" return ""

View file

@ -41,7 +41,7 @@ const (
) )
const interruptDebounceTimeout = 1 * time.Second const interruptDebounceTimeout = 1 * time.Second
const fileViewerFullWidthCutoff = 200 const fileViewerFullWidthCutoff = 160
type appModel struct { type appModel struct {
width, height int width, height int
@ -111,18 +111,19 @@ func isScrollRelatedInput(keyString string) bool {
if len(keyString) == 0 { if len(keyString) == 0 {
return false return false
} }
for _, char := range keyString { for _, char := range keyString {
charStr := string(char) charStr := string(char)
if !BUGGED_SCROLL_KEYS[charStr] { if !BUGGED_SCROLL_KEYS[charStr] {
return false 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 true
} }
return len(keyString) > 1 return len(keyString) > 1
} }