Clean up tui View handling
This commit is contained in:
@@ -14,7 +14,6 @@ import (
|
||||
"git.mlow.ca/mlow/lmcli/pkg/tui/views/chat"
|
||||
"git.mlow.ca/mlow/lmcli/pkg/tui/views/conversations"
|
||||
tea "github.com/charmbracelet/bubbletea"
|
||||
"github.com/charmbracelet/lipgloss"
|
||||
)
|
||||
|
||||
// Application model
|
||||
@@ -31,7 +30,6 @@ func initialModel(ctx *lmcli.Context, values shared.Values) Model {
|
||||
State: shared.State{
|
||||
Ctx: ctx,
|
||||
Values: &values,
|
||||
Views: &shared.Views{},
|
||||
},
|
||||
}
|
||||
|
||||
@@ -126,36 +124,17 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||
|
||||
func (m Model) View() string {
|
||||
if m.State.Width == 0 {
|
||||
// this is the case upon initial startup, but it's also a safe bet that
|
||||
// we can just skip rendering if the terminal is really 0 width...
|
||||
// without this, the m.*View() functions may crash
|
||||
return ""
|
||||
}
|
||||
sections := make([]string, 0, 6)
|
||||
|
||||
if m.State.Views.Header != "" {
|
||||
sections = append(sections, m.State.Views.Header)
|
||||
}
|
||||
|
||||
switch m.state {
|
||||
case shared.StateConversations:
|
||||
sections = append(sections, m.State.Views.Content)
|
||||
if m.State.Views.Error != "" {
|
||||
sections = append(sections, m.State.Views.Error)
|
||||
}
|
||||
return m.conversations.View()
|
||||
case shared.StateChat:
|
||||
sections = append(sections, m.State.Views.Content)
|
||||
if m.State.Views.Error != "" {
|
||||
sections = append(sections, m.State.Views.Error)
|
||||
}
|
||||
sections = append(sections, m.State.Views.Input)
|
||||
return m.chat.View()
|
||||
default:
|
||||
return ""
|
||||
}
|
||||
|
||||
if m.State.Views.Footer != "" {
|
||||
sections = append(sections, m.State.Views.Footer)
|
||||
}
|
||||
|
||||
return lipgloss.JoinVertical(lipgloss.Left, sections...)
|
||||
}
|
||||
|
||||
func Launch(ctx *lmcli.Context, convShortname string) error {
|
||||
|
||||
Reference in New Issue
Block a user