mirror of
https://github.com/sst/opencode.git
synced 2025-08-10 16:28:06 +00:00
fix: background color rendering issues
This commit is contained in:
parent
7effff56c0
commit
77a6b3bdd6
5 changed files with 38 additions and 50 deletions
|
@ -258,8 +258,8 @@ func (m *editorComponent) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||||
|
|
||||||
func (m *editorComponent) View() string {
|
func (m *editorComponent) View() string {
|
||||||
t := theme.CurrentTheme()
|
t := theme.CurrentTheme()
|
||||||
base := styles.BaseStyle().Render
|
base := styles.BaseStyle().Background(t.Background()).Render
|
||||||
muted := styles.Muted().Render
|
muted := styles.Muted().Background(t.Background()).Render
|
||||||
promptStyle := lipgloss.NewStyle().
|
promptStyle := lipgloss.NewStyle().
|
||||||
Padding(0, 0, 0, 1).
|
Padding(0, 0, 0, 1).
|
||||||
Bold(true).
|
Bold(true).
|
||||||
|
@ -281,7 +281,7 @@ func (m *editorComponent) View() string {
|
||||||
BorderBackground(t.Background()).
|
BorderBackground(t.Background()).
|
||||||
Render(textarea)
|
Render(textarea)
|
||||||
|
|
||||||
hint := base("enter") + muted(" send ") + base("shift") + muted("+") + base("enter") + muted(" newline")
|
hint := base("enter") + muted(" send ")
|
||||||
if m.app.IsBusy() {
|
if m.app.IsBusy() {
|
||||||
hint = muted("working") + m.spinner.View() + muted(" ") + base("esc") + muted(" interrupt")
|
hint = muted("working") + m.spinner.View() + muted(" ") + base("esc") + muted(" interrupt")
|
||||||
}
|
}
|
||||||
|
@ -292,18 +292,12 @@ func (m *editorComponent) View() string {
|
||||||
}
|
}
|
||||||
|
|
||||||
space := m.width - 2 - lipgloss.Width(model) - lipgloss.Width(hint)
|
space := m.width - 2 - lipgloss.Width(model) - lipgloss.Width(hint)
|
||||||
spacer := lipgloss.NewStyle().Width(space).Render("")
|
spacer := lipgloss.NewStyle().Background(t.Background()).Width(space).Render("")
|
||||||
|
|
||||||
info := lipgloss.JoinHorizontal(lipgloss.Left, hint, spacer, model)
|
info := hint + spacer + model
|
||||||
info = styles.Padded().Render(info)
|
info = styles.Padded().Background(t.Background()).Render(info)
|
||||||
|
|
||||||
content := lipgloss.JoinVertical(
|
content := strings.Join([]string{"", textarea, info}, "\n")
|
||||||
lipgloss.Top,
|
|
||||||
// m.attachmentsContent(),
|
|
||||||
"",
|
|
||||||
textarea,
|
|
||||||
info,
|
|
||||||
)
|
|
||||||
|
|
||||||
return content
|
return content
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,6 @@ package chat
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"log/slog"
|
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"slices"
|
"slices"
|
||||||
"strings"
|
"strings"
|
||||||
|
@ -131,8 +130,8 @@ func renderContentBlock(content string, options ...renderingOption) string {
|
||||||
}
|
}
|
||||||
|
|
||||||
style := styles.BaseStyle().
|
style := styles.BaseStyle().
|
||||||
MarginTop(renderer.marginTop).
|
// MarginTop(renderer.marginTop).
|
||||||
MarginBottom(renderer.marginBottom).
|
// MarginBottom(renderer.marginBottom).
|
||||||
PaddingTop(renderer.paddingTop).
|
PaddingTop(renderer.paddingTop).
|
||||||
PaddingBottom(renderer.paddingBottom).
|
PaddingBottom(renderer.paddingBottom).
|
||||||
PaddingLeft(renderer.paddingLeft).
|
PaddingLeft(renderer.paddingLeft).
|
||||||
|
@ -188,6 +187,17 @@ func renderContentBlock(content string, options ...renderingOption) string {
|
||||||
content,
|
content,
|
||||||
lipgloss.WithWhitespaceStyle(lipgloss.NewStyle().Background(t.Background())),
|
lipgloss.WithWhitespaceStyle(lipgloss.NewStyle().Background(t.Background())),
|
||||||
)
|
)
|
||||||
|
if renderer.marginTop > 0 {
|
||||||
|
for range renderer.marginTop {
|
||||||
|
content = "\n" + content
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if renderer.marginBottom > 0 {
|
||||||
|
for range renderer.marginBottom {
|
||||||
|
content = content + "\n"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return content
|
return content
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -210,18 +220,11 @@ func renderText(message client.MessageInfo, text string, author string) string {
|
||||||
}
|
}
|
||||||
info := fmt.Sprintf("%s (%s)", author, timestamp)
|
info := fmt.Sprintf("%s (%s)", author, timestamp)
|
||||||
|
|
||||||
align := lipgloss.Left
|
|
||||||
switch message.Role {
|
|
||||||
case client.User:
|
|
||||||
align = lipgloss.Right
|
|
||||||
case client.Assistant:
|
|
||||||
align = lipgloss.Left
|
|
||||||
}
|
|
||||||
|
|
||||||
textWidth := max(lipgloss.Width(text), lipgloss.Width(info))
|
textWidth := max(lipgloss.Width(text), lipgloss.Width(info))
|
||||||
markdownWidth := min(textWidth, width-padding-4) // -4 for the border and padding
|
markdownWidth := min(textWidth, width-padding-4) // -4 for the border and padding
|
||||||
content := toMarkdown(text, markdownWidth, t.BackgroundSubtle())
|
content := toMarkdown(text, markdownWidth, t.BackgroundSubtle())
|
||||||
content = lipgloss.JoinVertical(align, content, info)
|
content = strings.Join([]string{content, info}, "\n")
|
||||||
|
// content = lipgloss.JoinVertical(align, content, info)
|
||||||
|
|
||||||
switch message.Role {
|
switch message.Role {
|
||||||
case client.User:
|
case client.User:
|
||||||
|
@ -270,6 +273,7 @@ func renderToolInvocation(
|
||||||
PaddingRight(2).
|
PaddingRight(2).
|
||||||
BorderLeft(true).
|
BorderLeft(true).
|
||||||
BorderRight(true).
|
BorderRight(true).
|
||||||
|
BorderBackground(t.Background()).
|
||||||
BorderForeground(t.BackgroundSubtle()).
|
BorderForeground(t.BackgroundSubtle()).
|
||||||
BorderStyle(lipgloss.ThickBorder())
|
BorderStyle(lipgloss.ThickBorder())
|
||||||
|
|
||||||
|
@ -294,10 +298,6 @@ func renderToolInvocation(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(toolArgsMap) == 0 {
|
|
||||||
slog.Debug("no args")
|
|
||||||
}
|
|
||||||
|
|
||||||
body := ""
|
body := ""
|
||||||
error := ""
|
error := ""
|
||||||
finished := result != nil && *result != ""
|
finished := result != nil && *result != ""
|
||||||
|
@ -358,6 +358,7 @@ func renderToolInvocation(
|
||||||
formattedDiff = strings.TrimSpace(formattedDiff)
|
formattedDiff = strings.TrimSpace(formattedDiff)
|
||||||
formattedDiff = lipgloss.NewStyle().
|
formattedDiff = lipgloss.NewStyle().
|
||||||
BorderStyle(lipgloss.ThickBorder()).
|
BorderStyle(lipgloss.ThickBorder()).
|
||||||
|
BorderBackground(t.Background()).
|
||||||
BorderForeground(t.BackgroundSubtle()).
|
BorderForeground(t.BackgroundSubtle()).
|
||||||
BorderLeft(true).
|
BorderLeft(true).
|
||||||
BorderRight(true).
|
BorderRight(true).
|
||||||
|
|
|
@ -242,8 +242,8 @@ func (m *messagesComponent) header() string {
|
||||||
|
|
||||||
t := theme.CurrentTheme()
|
t := theme.CurrentTheme()
|
||||||
width := layout.Current.Container.Width
|
width := layout.Current.Container.Width
|
||||||
base := styles.BaseStyle().Render
|
base := styles.BaseStyle().Background(t.Background()).Render
|
||||||
muted := styles.Muted().Render
|
muted := styles.Muted().Background(t.Background()).Render
|
||||||
headerLines := []string{}
|
headerLines := []string{}
|
||||||
headerLines = append(headerLines, toMarkdown("# "+m.app.Session.Title, width-6, t.Background()))
|
headerLines = append(headerLines, toMarkdown("# "+m.app.Session.Title, width-6, t.Background()))
|
||||||
if m.app.Session.Share != nil && m.app.Session.Share.Url != "" {
|
if m.app.Session.Share != nil && m.app.Session.Share.Url != "" {
|
||||||
|
@ -257,7 +257,7 @@ func (m *messagesComponent) header() string {
|
||||||
Width(width).
|
Width(width).
|
||||||
PaddingLeft(2).
|
PaddingLeft(2).
|
||||||
PaddingRight(2).
|
PaddingRight(2).
|
||||||
// Background(t.BackgroundElement()).
|
Background(t.Background()).
|
||||||
BorderLeft(true).
|
BorderLeft(true).
|
||||||
BorderRight(true).
|
BorderRight(true).
|
||||||
BorderBackground(t.Background()).
|
BorderBackground(t.Background()).
|
||||||
|
@ -289,15 +289,11 @@ func (m *messagesComponent) View() string {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *messagesComponent) home() string {
|
func (m *messagesComponent) home() string {
|
||||||
// t := theme.CurrentTheme()
|
t := theme.CurrentTheme()
|
||||||
baseStyle := styles.BaseStyle()
|
baseStyle := styles.BaseStyle().Background(t.Background())
|
||||||
base := baseStyle.Render
|
base := baseStyle.Render
|
||||||
muted := styles.Muted().Render
|
muted := styles.Muted().Background(t.Background()).Render
|
||||||
|
|
||||||
// mark := `
|
|
||||||
// ███▀▀█
|
|
||||||
// ███ █
|
|
||||||
// ▀▀▀▀▀▀ `
|
|
||||||
open := `
|
open := `
|
||||||
█▀▀█ █▀▀█ █▀▀ █▀▀▄
|
█▀▀█ █▀▀█ █▀▀ █▀▀▄
|
||||||
█░░█ █░░█ █▀▀ █░░█
|
█░░█ █░░█ █▀▀ █░░█
|
||||||
|
@ -309,9 +305,8 @@ func (m *messagesComponent) home() string {
|
||||||
|
|
||||||
logo := lipgloss.JoinHorizontal(
|
logo := lipgloss.JoinHorizontal(
|
||||||
lipgloss.Top,
|
lipgloss.Top,
|
||||||
// styles.BaseStyle().Foreground(t.Primary()).Render(mark),
|
muted(open),
|
||||||
styles.Muted().Render(open),
|
base(code),
|
||||||
styles.BaseStyle().Render(code),
|
|
||||||
)
|
)
|
||||||
// cwd := app.Info.Path.Cwd
|
// cwd := app.Info.Path.Cwd
|
||||||
// config := app.Info.Path.Config
|
// config := app.Info.Path.Config
|
||||||
|
@ -327,7 +322,7 @@ func (m *messagesComponent) home() string {
|
||||||
|
|
||||||
commandLines := []string{}
|
commandLines := []string{}
|
||||||
for _, command := range commands {
|
for _, command := range commands {
|
||||||
commandLines = append(commandLines, (base(command[0]) + " " + muted(command[1])))
|
commandLines = append(commandLines, (base(command[0]+" ") + muted(command[1])))
|
||||||
}
|
}
|
||||||
|
|
||||||
logoAndVersion := lipgloss.JoinVertical(
|
logoAndVersion := lipgloss.JoinVertical(
|
||||||
|
@ -347,22 +342,18 @@ func (m *messagesComponent) home() string {
|
||||||
lines = append(lines, commandLines...)
|
lines = append(lines, commandLines...)
|
||||||
lines = append(lines, "")
|
lines = append(lines, "")
|
||||||
if m.rendering {
|
if m.rendering {
|
||||||
lines = append(lines, styles.Muted().Render("Loading session..."))
|
lines = append(lines, base("Loading session..."))
|
||||||
} else {
|
} else {
|
||||||
lines = append(lines, "")
|
lines = append(lines, "")
|
||||||
}
|
}
|
||||||
|
|
||||||
t := theme.CurrentTheme()
|
|
||||||
return lipgloss.Place(
|
return lipgloss.Place(
|
||||||
m.width,
|
m.width,
|
||||||
m.height,
|
m.height,
|
||||||
lipgloss.Center,
|
lipgloss.Center,
|
||||||
lipgloss.Center,
|
lipgloss.Center,
|
||||||
baseStyle.Width(lipgloss.Width(logoAndVersion)).Render(
|
baseStyle.Width(lipgloss.Width(logoAndVersion)).Render(
|
||||||
lipgloss.JoinVertical(
|
strings.Join(lines, "\n"),
|
||||||
lipgloss.Top,
|
|
||||||
lines...,
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
lipgloss.WithWhitespaceStyle(lipgloss.NewStyle().Background(t.Background())),
|
lipgloss.WithWhitespaceStyle(lipgloss.NewStyle().Background(t.Background())),
|
||||||
)
|
)
|
||||||
|
|
|
@ -140,14 +140,15 @@ func formatTokensAndCost(tokens float32, contextWindow float32, cost float32) st
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m statusComponent) View() string {
|
func (m statusComponent) View() string {
|
||||||
|
t := theme.CurrentTheme()
|
||||||
if m.app.Session.Id == "" {
|
if m.app.Session.Id == "" {
|
||||||
return styles.BaseStyle().
|
return styles.BaseStyle().
|
||||||
|
Background(t.Background()).
|
||||||
Width(m.width).
|
Width(m.width).
|
||||||
Height(2).
|
Height(2).
|
||||||
Render("")
|
Render("")
|
||||||
}
|
}
|
||||||
|
|
||||||
t := theme.CurrentTheme()
|
|
||||||
logo := logo()
|
logo := logo()
|
||||||
|
|
||||||
cwd := styles.Padded().
|
cwd := styles.Padded().
|
||||||
|
|
|
@ -227,6 +227,7 @@ func (c *completionDialogComponent) View() string {
|
||||||
BorderBottom(false).
|
BorderBottom(false).
|
||||||
BorderRight(true).
|
BorderRight(true).
|
||||||
BorderLeft(true).
|
BorderLeft(true).
|
||||||
|
BorderBackground(t.Background()).
|
||||||
BorderForeground(t.BackgroundSubtle()).
|
BorderForeground(t.BackgroundSubtle()).
|
||||||
Width(c.width).
|
Width(c.width).
|
||||||
Render(c.list.View())
|
Render(c.list.View())
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue