tui: minor fixed and cleanup

This commit is contained in:
Matt Low 2024-03-14 06:39:25 +00:00
parent cf46088762
commit fdf8033aff

View File

@ -225,7 +225,6 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
m.err = error(msg) m.err = error(msg)
} }
var cmd tea.Cmd var cmd tea.Cmd
m.spinner, cmd = m.spinner.Update(msg) m.spinner, cmd = m.spinner.Update(msg)
if cmd != nil { if cmd != nil {
@ -253,7 +252,7 @@ func (m model) View() string {
if m.content.Width == 0 { if m.content.Width == 0 {
// this is the case upon initial startup, but it's also a safe bet that // 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... // we can just skip rendering if the terminal is really 0 width...
// without this, the below view functions may do weird things // without this, the m.*View() functions may crash
return "" return ""
} }
@ -279,6 +278,8 @@ func (m model) View() string {
) )
} }
// returns the total height of "fixed" components, which are those which don't
// change height dependent on window size.
func (m *model) getFixedComponentHeight() int { func (m *model) getFixedComponentHeight() int {
h := 0 h := 0
h += m.input.Height() h += m.input.Height()
@ -349,21 +350,23 @@ func (m *model) footerView() string {
segmentStyle := lipgloss.NewStyle().PaddingLeft(1).PaddingRight(1).Faint(true) segmentStyle := lipgloss.NewStyle().PaddingLeft(1).PaddingRight(1).Faint(true)
segmentSeparator := "|" segmentSeparator := "|"
savingStyle := segmentStyle.Copy().Bold(true)
saving := "" saving := ""
if m.persistence { if m.persistence {
saving = segmentStyle.Copy().Bold(true).Foreground(lipgloss.Color("2")).Render("✅💾") saving = savingStyle.Foreground(lipgloss.Color("2")).Render("✅💾")
} else { } else {
saving = segmentStyle.Copy().Bold(true).Foreground(lipgloss.Color("1")).Render("❌💾") saving = savingStyle.Foreground(lipgloss.Color("1")).Render("❌💾")
} }
status := m.status status := m.status
if m.waitingForReply { if m.waitingForReply {
status += m.spinner.View() status += m.spinner.View()
status = segmentStyle.Render(status)
} }
leftSegments := []string{ leftSegments := []string{
saving, saving,
segmentStyle.Render(status), status,
} }
rightSegments := []string{ rightSegments := []string{
segmentStyle.Render(fmt.Sprintf("Model: %s", *m.ctx.Config.Defaults.Model)), segmentStyle.Render(fmt.Sprintf("Model: %s", *m.ctx.Config.Defaults.Model)),
@ -383,9 +386,11 @@ func (m *model) footerView() string {
footer := left + padding + right footer := left + padding + right
if remaining < 0 { if remaining < 0 {
ellipses := "... " ellipses := "... "
footer = footer[:m.width-len(ellipses)] + ellipses // this doesn't work very well, due to trying to trim a string with
// ansii chars already in it
footer = footer[:(len(footer)+remaining)-len(ellipses)-3] + ellipses
} }
return footerStyle.Render(footer) return footerStyle.Width(m.width).Render(footer)
} }
func initialModel(ctx *lmcli.Context, convShortname string) model { func initialModel(ctx *lmcli.Context, convShortname string) model {
@ -632,8 +637,7 @@ func (m *model) updateContent() {
case models.MessageRoleAssistant: case models.MessageRoleAssistant:
icon = "" icon = ""
style = assistantStyle style = assistantStyle
case models.MessageRoleToolCall: case models.MessageRoleToolCall, models.MessageRoleToolResult:
case models.MessageRoleToolResult:
icon = "🔧" icon = "🔧"
} }