tui: minor fixed and cleanup

This commit is contained in:
Matt Low 2024-03-14 06:39:25 +00:00
parent 29d8138dc0
commit f49b772960
1 changed files with 13 additions and 9 deletions

View File

@ -225,7 +225,6 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
m.err = error(msg)
}
var cmd tea.Cmd
m.spinner, cmd = m.spinner.Update(msg)
if cmd != nil {
@ -253,7 +252,7 @@ func (m model) View() string {
if m.content.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 below view functions may do weird things
// without this, the m.*View() functions may crash
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 {
h := 0
h += m.input.Height()
@ -349,21 +350,23 @@ func (m *model) footerView() string {
segmentStyle := lipgloss.NewStyle().PaddingLeft(1).PaddingRight(1).Faint(true)
segmentSeparator := "|"
savingStyle := segmentStyle.Copy().Bold(true)
saving := ""
if m.persistence {
saving = segmentStyle.Copy().Bold(true).Foreground(lipgloss.Color("2")).Render("✅💾")
saving = savingStyle.Foreground(lipgloss.Color("2")).Render("✅💾")
} else {
saving = segmentStyle.Copy().Bold(true).Foreground(lipgloss.Color("1")).Render("❌💾")
saving = savingStyle.Foreground(lipgloss.Color("1")).Render("❌💾")
}
status := m.status
if m.waitingForReply {
status += m.spinner.View()
status = segmentStyle.Render(status)
}
leftSegments := []string{
saving,
segmentStyle.Render(status),
status,
}
rightSegments := []string{
segmentStyle.Render(fmt.Sprintf("Model: %s", *m.ctx.Config.Defaults.Model)),
@ -383,9 +386,11 @@ func (m *model) footerView() string {
footer := left + padding + right
if remaining < 0 {
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 {
@ -632,8 +637,7 @@ func (m *model) updateContent() {
case models.MessageRoleAssistant:
icon = ""
style = assistantStyle
case models.MessageRoleToolCall:
case models.MessageRoleToolResult:
case models.MessageRoleToolCall, models.MessageRoleToolResult:
icon = "🔧"
}