Skip to content

Commit 48f42d3

Browse files
committed
feat(tui): use terminal width for UI
1 parent 0ccfe23 commit 48f42d3

2 files changed

Lines changed: 9 additions & 12 deletions

File tree

internal/tui/model.go

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ type model struct {
3838
// State
3939
isWorking bool
4040
cancel context.CancelFunc
41+
width int
4142

4243
// Views
4344
spinner spinner.Model
@@ -64,8 +65,6 @@ func initialModel(agent *agent.Agent) model {
6465
styles := t.Styles()
6566
styles.Focused.CursorLine = styles.Focused.CursorLine.UnsetBackground()
6667

67-
t.MaxWidth = maxWidth - len(t.Prompt) - 2*textareaPadding
68-
6968
t.Focus()
7069
t.SetHeight(1)
7170
t.SetStyles(styles)
@@ -94,7 +93,8 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
9493

9594
switch msg := msg.(type) {
9695
case tea.WindowSizeMsg:
97-
m.textarea.SetWidth(msg.Width)
96+
m.width = msg.Width
97+
m.textarea.SetWidth(msg.Width - textareaStyle.GetHorizontalFrameSize())
9898
m.help.SetWidth(msg.Width)
9999
case tea.KeyPressMsg:
100100
switch {
@@ -299,10 +299,12 @@ func (m *model) mustRenderToolCallMarkdown(s string) string {
299299
// mustRenderMarkdownWithStyle renders a string as markdown with the given style. It
300300
// panics if there is a render error.
301301
func (m *model) mustRenderMarkdownWithStyle(s string, style ansi.StyleConfig) string {
302-
t, err := glamour.NewTermRenderer(
303-
glamour.WithStyles(style),
304-
glamour.WithWordWrap(maxWidth),
305-
)
302+
options := []glamour.TermRendererOption{glamour.WithStyles(style)}
303+
if m.width > 0 {
304+
options = append(options, glamour.WithWordWrap(m.width))
305+
}
306+
307+
t, err := glamour.NewTermRenderer(options...)
306308
if err != nil {
307309
panic(err)
308310
}

internal/tui/style.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,6 @@ package tui
44

55
import "charm.land/lipgloss/v2"
66

7-
// maxWidth is the maximum width of the UI. It was taken from Python black's default
8-
// line length. I usually use wide monitors and prose becomes too long too read with no
9-
// wrapping.
10-
const maxWidth = 88
11-
127
// textareaPadding is the horizontal padding around the text area.
138
const textareaPadding = 1
149

0 commit comments

Comments
 (0)