tui: improve footer rendering
Made it easier to add segmemts later, better handling of padding
This commit is contained in:
parent
612ea90417
commit
c3a3cb0181
@ -77,7 +77,6 @@ var (
|
|||||||
assistantStyle = lipgloss.NewStyle().Faint(true).Bold(true).Foreground(lipgloss.Color("12"))
|
assistantStyle = lipgloss.NewStyle().Faint(true).Bold(true).Foreground(lipgloss.Color("12"))
|
||||||
messageStyle = lipgloss.NewStyle().PaddingLeft(1)
|
messageStyle = lipgloss.NewStyle().PaddingLeft(1)
|
||||||
headerStyle = lipgloss.NewStyle().
|
headerStyle = lipgloss.NewStyle().
|
||||||
PaddingLeft(1).
|
|
||||||
Background(lipgloss.Color("0"))
|
Background(lipgloss.Color("0"))
|
||||||
contentStyle = lipgloss.NewStyle().
|
contentStyle = lipgloss.NewStyle().
|
||||||
Padding(1)
|
Padding(1)
|
||||||
@ -186,6 +185,12 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (m model) View() string {
|
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
|
||||||
|
return ""
|
||||||
|
}
|
||||||
return lipgloss.JoinVertical(
|
return lipgloss.JoinVertical(
|
||||||
lipgloss.Left,
|
lipgloss.Left,
|
||||||
m.headerView(),
|
m.headerView(),
|
||||||
@ -197,6 +202,8 @@ func (m model) View() string {
|
|||||||
|
|
||||||
func (m *model) headerView() string {
|
func (m *model) headerView() string {
|
||||||
titleStyle := lipgloss.NewStyle().
|
titleStyle := lipgloss.NewStyle().
|
||||||
|
PaddingLeft(1).
|
||||||
|
PaddingRight(1).
|
||||||
Bold(true)
|
Bold(true)
|
||||||
var title string
|
var title string
|
||||||
if m.conversation != nil && m.conversation.Title != "" {
|
if m.conversation != nil && m.conversation.Title != "" {
|
||||||
@ -218,19 +225,33 @@ func (m *model) inputView() string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (m *model) footerView() string {
|
func (m *model) footerView() string {
|
||||||
left := m.status
|
segmentStyle := lipgloss.NewStyle().PaddingLeft(1).PaddingRight(1)
|
||||||
right := fmt.Sprintf("Model: %s", *m.ctx.Config.Defaults.Model)
|
segmentSeparator := "|"
|
||||||
|
|
||||||
totalWidth := lipgloss.Width(left + right)
|
leftSegments := []string{
|
||||||
var padding string
|
segmentStyle.Render(m.status),
|
||||||
if m.content.Width-totalWidth > 0 {
|
}
|
||||||
padding = strings.Repeat(" ", m.content.Width-totalWidth)
|
rightSegments := []string{
|
||||||
} else {
|
segmentStyle.Render(fmt.Sprintf("Model: %s", *m.ctx.Config.Defaults.Model)),
|
||||||
padding = ""
|
|
||||||
}
|
}
|
||||||
|
|
||||||
footer := lipgloss.JoinHorizontal(lipgloss.Center, left, padding, right)
|
left := strings.Join(leftSegments, segmentSeparator)
|
||||||
return footerStyle.Width(m.content.Width).Render(footer)
|
right := strings.Join(rightSegments, segmentSeparator)
|
||||||
|
|
||||||
|
totalWidth := lipgloss.Width(left + right)
|
||||||
|
remaining := m.content.Width - totalWidth
|
||||||
|
|
||||||
|
var padding string
|
||||||
|
if remaining > 0 {
|
||||||
|
padding = strings.Repeat(" ", remaining)
|
||||||
|
}
|
||||||
|
|
||||||
|
footer := left + padding + right
|
||||||
|
if remaining < 0 {
|
||||||
|
ellipses := "... "
|
||||||
|
footer = footer[:m.content.Width-len(ellipses)] + ellipses
|
||||||
|
}
|
||||||
|
return footerStyle.Render(footer)
|
||||||
}
|
}
|
||||||
|
|
||||||
func initialModel(ctx *lmcli.Context, convShortname string) model {
|
func initialModel(ctx *lmcli.Context, convShortname string) model {
|
||||||
|
Loading…
Reference in New Issue
Block a user