diff options
| author | adamdottv <[email protected]> | 2025-06-12 16:00:20 -0500 |
|---|---|---|
| committer | adamdottv <[email protected]> | 2025-06-12 16:00:26 -0500 |
| commit | 653965ef5908a240f6038609e17bc8fa27640203 (patch) | |
| tree | 439910084fdcea0c45856ad0132f916fd9038a4b /packages/tui/internal/components/chat | |
| parent | ca0ea3f94dc1929071efc93bfcf708c8cf054be8 (diff) | |
| download | opencode-653965ef5908a240f6038609e17bc8fa27640203.tar.gz opencode-653965ef5908a240f6038609e17bc8fa27640203.zip | |
wip: refactoring tui
Diffstat (limited to 'packages/tui/internal/components/chat')
| -rw-r--r-- | packages/tui/internal/components/chat/editor.go | 38 | ||||
| -rw-r--r-- | packages/tui/internal/components/chat/message.go | 4 | ||||
| -rw-r--r-- | packages/tui/internal/components/chat/messages.go | 2 |
3 files changed, 28 insertions, 16 deletions
diff --git a/packages/tui/internal/components/chat/editor.go b/packages/tui/internal/components/chat/editor.go index d1b8bd7fa..ad7d140a6 100644 --- a/packages/tui/internal/components/chat/editor.go +++ b/packages/tui/internal/components/chat/editor.go @@ -119,6 +119,13 @@ func (m *editorComponent) Update(msg tea.Msg) (tea.Model, tea.Cmd) { m.attachments = append(m.attachments, msg.Attachment) case tea.KeyMsg: switch msg.String() { + case "ctrl+c": + if m.textarea.Value() != "" { + m.textarea.Reset() + return m, func() tea.Msg { + return nil + } + } case "shift+enter": value := m.textarea.Value() m.textarea.SetValue(value + "\n") @@ -264,8 +271,12 @@ func (m *editorComponent) View() string { ) textarea = styles.BaseStyle(). Width(m.width). - Border(lipgloss.NormalBorder(), true, true). - BorderForeground(t.Border()). + PaddingTop(1). + PaddingBottom(1). + Background(t.BackgroundElement()). + Border(lipgloss.ThickBorder(), false, true). + BorderForeground(t.BorderActive()). + BorderBackground(t.Background()). Render(textarea) hint := base("enter") + muted(" send ") + base("shift") + muted("+") + base("enter") + muted(" newline") @@ -287,6 +298,7 @@ func (m *editorComponent) View() string { content := lipgloss.JoinVertical( lipgloss.Top, // m.attachmentsContent(), + "", textarea, info, ) @@ -409,21 +421,21 @@ func (m *editorComponent) attachmentsContent() string { func createTextArea(existing *textarea.Model) textarea.Model { t := theme.CurrentTheme() - bgColor := t.Background() + bgColor := t.BackgroundElement() textColor := t.Text() textMutedColor := t.TextMuted() ta := textarea.New() - ta.Placeholder = "It's prompting time..." - - ta.Styles.Blurred.Base = styles.BaseStyle().Background(bgColor).Foreground(textColor) - ta.Styles.Blurred.CursorLine = styles.BaseStyle().Background(bgColor) - ta.Styles.Blurred.Placeholder = styles.BaseStyle().Background(bgColor).Foreground(textMutedColor) - ta.Styles.Blurred.Text = styles.BaseStyle().Background(bgColor).Foreground(textColor) - ta.Styles.Focused.Base = styles.BaseStyle().Background(bgColor).Foreground(textColor) - ta.Styles.Focused.CursorLine = styles.BaseStyle().Background(bgColor) - ta.Styles.Focused.Placeholder = styles.BaseStyle().Background(bgColor).Foreground(textMutedColor) - ta.Styles.Focused.Text = styles.BaseStyle().Background(bgColor).Foreground(textColor) + + ta.Styles.Blurred.Base = lipgloss.NewStyle().Background(bgColor).Foreground(textColor) + ta.Styles.Blurred.CursorLine = lipgloss.NewStyle().Background(bgColor) + ta.Styles.Blurred.Placeholder = lipgloss.NewStyle().Background(bgColor).Foreground(textMutedColor) + ta.Styles.Blurred.Text = lipgloss.NewStyle().Background(bgColor).Foreground(textColor) + ta.Styles.Focused.Base = lipgloss.NewStyle().Background(bgColor).Foreground(textColor) + ta.Styles.Focused.CursorLine = lipgloss.NewStyle().Background(bgColor) + ta.Styles.Focused.Placeholder = lipgloss.NewStyle().Background(bgColor).Foreground(textMutedColor) + ta.Styles.Focused.Text = lipgloss.NewStyle().Background(bgColor).Foreground(textColor) + ta.Styles.Cursor.Color = t.Primary() ta.Prompt = " " ta.ShowLineNumbers = false diff --git a/packages/tui/internal/components/chat/message.go b/packages/tui/internal/components/chat/message.go index f3fbca475..2c2cd03f0 100644 --- a/packages/tui/internal/components/chat/message.go +++ b/packages/tui/internal/components/chat/message.go @@ -292,8 +292,8 @@ func renderToolInvocation( toolArgs = renderArgs(&toolArgsMap, "filePath") title = fmt.Sprintf("Read: %s %s", toolArgs, elapsed) body = "" - filename := toolArgsMap["filePath"].(string) - if metadata["preview"] != nil { + if metadata["preview"] != nil && toolArgsMap["filePath"] != nil { + filename := toolArgsMap["filePath"].(string) body = metadata["preview"].(string) body = renderFile(filename, body, WithTruncate(6)) } diff --git a/packages/tui/internal/components/chat/messages.go b/packages/tui/internal/components/chat/messages.go index 47a9b8362..3985ee0d7 100644 --- a/packages/tui/internal/components/chat/messages.go +++ b/packages/tui/internal/components/chat/messages.go @@ -237,7 +237,7 @@ func (m *messagesComponent) renderView() { } m.viewport.SetHeight(m.height - lipgloss.Height(m.header())) - m.viewport.SetContent(strings.Join(centered, "\n")) + m.viewport.SetContent("\n" + strings.Join(centered, "\n") + "\n") } func (m *messagesComponent) header() string { |
