From d1f10d2cfca8687c07def44d388fdc86c1111cf0 Mon Sep 17 00:00:00 2001 From: Matt Low Date: Wed, 13 Mar 2024 05:01:36 +0000 Subject: [PATCH] tui: add header with title --- pkg/tui/tui.go | 32 ++++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/pkg/tui/tui.go b/pkg/tui/tui.go index f20c663..29e7074 100644 --- a/pkg/tui/tui.go +++ b/pkg/tui/tui.go @@ -70,11 +70,14 @@ type ( // styles var ( - inputStyle = lipgloss.NewStyle().Foreground(lipgloss.Color("#ff0000")) contentStyle = lipgloss.NewStyle().PaddingLeft(2) userStyle = lipgloss.NewStyle().Bold(true).Foreground(lipgloss.Color("10")) assistantStyle = lipgloss.NewStyle().Bold(true).Foreground(lipgloss.Color("12")) - footerStyle = lipgloss.NewStyle(). + headerStyle = lipgloss.NewStyle(). + PaddingLeft(1). + Background(lipgloss.Color("0")) + footerStyle = lipgloss.NewStyle(). + Faint(true). BorderTop(true). BorderStyle(lipgloss.NormalBorder()) ) @@ -118,7 +121,7 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { } case tea.WindowSizeMsg: m.content.Width = msg.Width - m.content.Height = msg.Height - m.input.Height() - lipgloss.Height(m.footerView()) + m.content.Height = msg.Height - m.input.Height() - lipgloss.Height(m.footerView()) - lipgloss.Height(m.headerView()) m.input.SetWidth(msg.Width - 1) m.updateContent() case msgConversationLoaded: @@ -180,6 +183,7 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { func (m model) View() string { return lipgloss.JoinVertical( lipgloss.Left, + m.headerView(), m.content.View(), m.inputView(), m.footerView(), @@ -349,17 +353,25 @@ func (m *model) updateContent() { } } -func (m model) inputView() string { - var inputView string - if m.waitingForReply { - inputView = inputStyle.Faint(true).Render(m.input.View()) +func (m *model) headerView() string { + titleStyle := lipgloss.NewStyle(). + Bold(true) + var title string + if m.conversation != nil && m.conversation.Title != "" { + title = m.conversation.Title } else { - inputView = inputStyle.Render(m.input.View()) + title = "Untitled" } - return inputView + part := titleStyle.Render(title) + + return headerStyle.Width(m.content.Width).Render(part) } -func (m model) footerView() string { +func (m model) inputView() string { + return m.input.View() +} + +func (m *model) footerView() string { left := m.status right := fmt.Sprintf("Model: %s", *m.ctx.Config.Defaults.Model)