Skip to content

Commit 77a6b3b

Browse files
committed
fix: background color rendering issues
1 parent 7effff5 commit 77a6b3b

File tree

5 files changed

+38
-50
lines changed

5 files changed

+38
-50
lines changed

packages/tui/internal/components/chat/editor.go

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -258,8 +258,8 @@ func (m *editorComponent) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
258258

259259
func (m *editorComponent) View() string {
260260
t := theme.CurrentTheme()
261-
base := styles.BaseStyle().Render
262-
muted := styles.Muted().Render
261+
base := styles.BaseStyle().Background(t.Background()).Render
262+
muted := styles.Muted().Background(t.Background()).Render
263263
promptStyle := lipgloss.NewStyle().
264264
Padding(0, 0, 0, 1).
265265
Bold(true).
@@ -281,7 +281,7 @@ func (m *editorComponent) View() string {
281281
BorderBackground(t.Background()).
282282
Render(textarea)
283283

284-
hint := base("enter") + muted(" send ") + base("shift") + muted("+") + base("enter") + muted(" newline")
284+
hint := base("enter") + muted(" send ")
285285
if m.app.IsBusy() {
286286
hint = muted("working") + m.spinner.View() + muted(" ") + base("esc") + muted(" interrupt")
287287
}
@@ -292,18 +292,12 @@ func (m *editorComponent) View() string {
292292
}
293293

294294
space := m.width - 2 - lipgloss.Width(model) - lipgloss.Width(hint)
295-
spacer := lipgloss.NewStyle().Width(space).Render("")
295+
spacer := lipgloss.NewStyle().Background(t.Background()).Width(space).Render("")
296296

297-
info := lipgloss.JoinHorizontal(lipgloss.Left, hint, spacer, model)
298-
info = styles.Padded().Render(info)
297+
info := hint + spacer + model
298+
info = styles.Padded().Background(t.Background()).Render(info)
299299

300-
content := lipgloss.JoinVertical(
301-
lipgloss.Top,
302-
// m.attachmentsContent(),
303-
"",
304-
textarea,
305-
info,
306-
)
300+
content := strings.Join([]string{"", textarea, info}, "\n")
307301

308302
return content
309303
}

packages/tui/internal/components/chat/message.go

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package chat
22

33
import (
44
"fmt"
5-
"log/slog"
65
"path/filepath"
76
"slices"
87
"strings"
@@ -131,8 +130,8 @@ func renderContentBlock(content string, options ...renderingOption) string {
131130
}
132131

133132
style := styles.BaseStyle().
134-
MarginTop(renderer.marginTop).
135-
MarginBottom(renderer.marginBottom).
133+
// MarginTop(renderer.marginTop).
134+
// MarginBottom(renderer.marginBottom).
136135
PaddingTop(renderer.paddingTop).
137136
PaddingBottom(renderer.paddingBottom).
138137
PaddingLeft(renderer.paddingLeft).
@@ -188,6 +187,17 @@ func renderContentBlock(content string, options ...renderingOption) string {
188187
content,
189188
lipgloss.WithWhitespaceStyle(lipgloss.NewStyle().Background(t.Background())),
190189
)
190+
if renderer.marginTop > 0 {
191+
for range renderer.marginTop {
192+
content = "\n" + content
193+
}
194+
}
195+
if renderer.marginBottom > 0 {
196+
for range renderer.marginBottom {
197+
content = content + "\n"
198+
}
199+
}
200+
191201
return content
192202
}
193203

@@ -210,18 +220,11 @@ func renderText(message client.MessageInfo, text string, author string) string {
210220
}
211221
info := fmt.Sprintf("%s (%s)", author, timestamp)
212222

213-
align := lipgloss.Left
214-
switch message.Role {
215-
case client.User:
216-
align = lipgloss.Right
217-
case client.Assistant:
218-
align = lipgloss.Left
219-
}
220-
221223
textWidth := max(lipgloss.Width(text), lipgloss.Width(info))
222224
markdownWidth := min(textWidth, width-padding-4) // -4 for the border and padding
223225
content := toMarkdown(text, markdownWidth, t.BackgroundSubtle())
224-
content = lipgloss.JoinVertical(align, content, info)
226+
content = strings.Join([]string{content, info}, "\n")
227+
// content = lipgloss.JoinVertical(align, content, info)
225228

226229
switch message.Role {
227230
case client.User:
@@ -270,6 +273,7 @@ func renderToolInvocation(
270273
PaddingRight(2).
271274
BorderLeft(true).
272275
BorderRight(true).
276+
BorderBackground(t.Background()).
273277
BorderForeground(t.BackgroundSubtle()).
274278
BorderStyle(lipgloss.ThickBorder())
275279

@@ -294,10 +298,6 @@ func renderToolInvocation(
294298
}
295299
}
296300

297-
if len(toolArgsMap) == 0 {
298-
slog.Debug("no args")
299-
}
300-
301301
body := ""
302302
error := ""
303303
finished := result != nil && *result != ""
@@ -358,6 +358,7 @@ func renderToolInvocation(
358358
formattedDiff = strings.TrimSpace(formattedDiff)
359359
formattedDiff = lipgloss.NewStyle().
360360
BorderStyle(lipgloss.ThickBorder()).
361+
BorderBackground(t.Background()).
361362
BorderForeground(t.BackgroundSubtle()).
362363
BorderLeft(true).
363364
BorderRight(true).

packages/tui/internal/components/chat/messages.go

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -242,8 +242,8 @@ func (m *messagesComponent) header() string {
242242

243243
t := theme.CurrentTheme()
244244
width := layout.Current.Container.Width
245-
base := styles.BaseStyle().Render
246-
muted := styles.Muted().Render
245+
base := styles.BaseStyle().Background(t.Background()).Render
246+
muted := styles.Muted().Background(t.Background()).Render
247247
headerLines := []string{}
248248
headerLines = append(headerLines, toMarkdown("# "+m.app.Session.Title, width-6, t.Background()))
249249
if m.app.Session.Share != nil && m.app.Session.Share.Url != "" {
@@ -257,7 +257,7 @@ func (m *messagesComponent) header() string {
257257
Width(width).
258258
PaddingLeft(2).
259259
PaddingRight(2).
260-
// Background(t.BackgroundElement()).
260+
Background(t.Background()).
261261
BorderLeft(true).
262262
BorderRight(true).
263263
BorderBackground(t.Background()).
@@ -289,15 +289,11 @@ func (m *messagesComponent) View() string {
289289
}
290290

291291
func (m *messagesComponent) home() string {
292-
// t := theme.CurrentTheme()
293-
baseStyle := styles.BaseStyle()
292+
t := theme.CurrentTheme()
293+
baseStyle := styles.BaseStyle().Background(t.Background())
294294
base := baseStyle.Render
295-
muted := styles.Muted().Render
295+
muted := styles.Muted().Background(t.Background()).Render
296296

297-
// mark := `
298-
// ███▀▀█
299-
// ███ █
300-
// ▀▀▀▀▀▀ `
301297
open := `
302298
█▀▀█ █▀▀█ █▀▀ █▀▀▄
303299
█░░█ █░░█ █▀▀ █░░█
@@ -309,9 +305,8 @@ func (m *messagesComponent) home() string {
309305

310306
logo := lipgloss.JoinHorizontal(
311307
lipgloss.Top,
312-
// styles.BaseStyle().Foreground(t.Primary()).Render(mark),
313-
styles.Muted().Render(open),
314-
styles.BaseStyle().Render(code),
308+
muted(open),
309+
base(code),
315310
)
316311
// cwd := app.Info.Path.Cwd
317312
// config := app.Info.Path.Config
@@ -327,7 +322,7 @@ func (m *messagesComponent) home() string {
327322

328323
commandLines := []string{}
329324
for _, command := range commands {
330-
commandLines = append(commandLines, (base(command[0]) + " " + muted(command[1])))
325+
commandLines = append(commandLines, (base(command[0]+" ") + muted(command[1])))
331326
}
332327

333328
logoAndVersion := lipgloss.JoinVertical(
@@ -347,22 +342,18 @@ func (m *messagesComponent) home() string {
347342
lines = append(lines, commandLines...)
348343
lines = append(lines, "")
349344
if m.rendering {
350-
lines = append(lines, styles.Muted().Render("Loading session..."))
345+
lines = append(lines, base("Loading session..."))
351346
} else {
352347
lines = append(lines, "")
353348
}
354349

355-
t := theme.CurrentTheme()
356350
return lipgloss.Place(
357351
m.width,
358352
m.height,
359353
lipgloss.Center,
360354
lipgloss.Center,
361355
baseStyle.Width(lipgloss.Width(logoAndVersion)).Render(
362-
lipgloss.JoinVertical(
363-
lipgloss.Top,
364-
lines...,
365-
),
356+
strings.Join(lines, "\n"),
366357
),
367358
lipgloss.WithWhitespaceStyle(lipgloss.NewStyle().Background(t.Background())),
368359
)

packages/tui/internal/components/core/status.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,14 +140,15 @@ func formatTokensAndCost(tokens float32, contextWindow float32, cost float32) st
140140
}
141141

142142
func (m statusComponent) View() string {
143+
t := theme.CurrentTheme()
143144
if m.app.Session.Id == "" {
144145
return styles.BaseStyle().
146+
Background(t.Background()).
145147
Width(m.width).
146148
Height(2).
147149
Render("")
148150
}
149151

150-
t := theme.CurrentTheme()
151152
logo := logo()
152153

153154
cwd := styles.Padded().

packages/tui/internal/components/dialog/complete.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,7 @@ func (c *completionDialogComponent) View() string {
227227
BorderBottom(false).
228228
BorderRight(true).
229229
BorderLeft(true).
230+
BorderBackground(t.Background()).
230231
BorderForeground(t.BackgroundSubtle()).
231232
Width(c.width).
232233
Render(c.list.View())

0 commit comments

Comments
 (0)