tui: add header with title

This commit is contained in:
Matt Low 2024-03-13 05:01:36 +00:00
parent 1bd6baa837
commit d1f10d2cfc

View File

@ -70,11 +70,14 @@ type (
// styles // styles
var ( var (
inputStyle = lipgloss.NewStyle().Foreground(lipgloss.Color("#ff0000"))
contentStyle = lipgloss.NewStyle().PaddingLeft(2) contentStyle = lipgloss.NewStyle().PaddingLeft(2)
userStyle = lipgloss.NewStyle().Bold(true).Foreground(lipgloss.Color("10")) userStyle = lipgloss.NewStyle().Bold(true).Foreground(lipgloss.Color("10"))
assistantStyle = lipgloss.NewStyle().Bold(true).Foreground(lipgloss.Color("12")) assistantStyle = lipgloss.NewStyle().Bold(true).Foreground(lipgloss.Color("12"))
headerStyle = lipgloss.NewStyle().
PaddingLeft(1).
Background(lipgloss.Color("0"))
footerStyle = lipgloss.NewStyle(). footerStyle = lipgloss.NewStyle().
Faint(true).
BorderTop(true). BorderTop(true).
BorderStyle(lipgloss.NormalBorder()) BorderStyle(lipgloss.NormalBorder())
) )
@ -118,7 +121,7 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
} }
case tea.WindowSizeMsg: case tea.WindowSizeMsg:
m.content.Width = msg.Width 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.input.SetWidth(msg.Width - 1)
m.updateContent() m.updateContent()
case msgConversationLoaded: case msgConversationLoaded:
@ -180,6 +183,7 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
func (m model) View() string { func (m model) View() string {
return lipgloss.JoinVertical( return lipgloss.JoinVertical(
lipgloss.Left, lipgloss.Left,
m.headerView(),
m.content.View(), m.content.View(),
m.inputView(), m.inputView(),
m.footerView(), m.footerView(),
@ -349,17 +353,25 @@ func (m *model) updateContent() {
} }
} }
func (m model) inputView() string { func (m *model) headerView() string {
var inputView string titleStyle := lipgloss.NewStyle().
if m.waitingForReply { Bold(true)
inputView = inputStyle.Faint(true).Render(m.input.View()) var title string
if m.conversation != nil && m.conversation.Title != "" {
title = m.conversation.Title
} else { } 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 left := m.status
right := fmt.Sprintf("Model: %s", *m.ctx.Config.Defaults.Model) right := fmt.Sprintf("Model: %s", *m.ctx.Config.Defaults.Model)