Private
Public Access
1
0

Clean up tui View handling

This commit is contained in:
2024-05-30 07:04:55 +00:00
parent c1792f27ff
commit ed784bb1cf
4 changed files with 78 additions and 57 deletions

View File

@@ -29,6 +29,7 @@ type (
type Model struct {
shared.State
shared.Sections
conversations []loadedConversation
cursor int // index of the currently selected conversation
@@ -129,12 +130,12 @@ func (m Model) Update(msg tea.Msg) (Model, tea.Cmd) {
}
if m.Width > 0 {
m.Views.Header = m.headerView()
m.Views.Footer = "" // TODO: show /something/
m.Views.Error = tuiutil.ErrorBanner(m.Err, m.Width)
fixedHeight := tuiutil.Height(m.Views.Header) + tuiutil.Height(m.Views.Error) + tuiutil.Height(m.Views.Footer)
m.Header = m.headerView()
m.Footer = "" // TODO: show /something/
m.Error = tuiutil.ErrorBanner(m.Err, m.Width)
fixedHeight := tuiutil.Height(m.Header) + tuiutil.Height(m.Error) + tuiutil.Height(m.Footer)
m.content.Height = m.Height - fixedHeight
m.Views.Content = m.content.View()
m.Content = m.content.View()
}
return m, tea.Batch(cmds...)
}
@@ -156,6 +157,28 @@ func (m *Model) loadConversations() tea.Cmd {
}
}
func (m Model) View() string {
if m.Width == 0 {
return ""
}
sections := make([]string, 0, 6)
if m.Header != "" {
sections = append(sections, m.Header)
}
sections = append(sections, m.Content)
if m.Error != "" {
sections = append(sections, m.Error)
}
if m.Footer != "" {
sections = append(sections, m.Footer)
}
return lipgloss.JoinVertical(lipgloss.Left, sections...)
}
func (m *Model) headerView() string {
titleStyle := lipgloss.NewStyle().Bold(true)
header := titleStyle.Render("Conversations")