From afd9ad0560d76c2a6d161dad52553b10ff428905 Mon Sep 17 00:00:00 2001 From: Kujtim Hoxha Date: Thu, 27 Mar 2025 22:35:48 +0100 Subject: rework llm --- internal/tui/components/core/dialog.go | 41 ++++++++++++++++++++++++++++++---- internal/tui/components/core/status.go | 11 +++++++-- 2 files changed, 46 insertions(+), 6 deletions(-) (limited to 'internal/tui/components/core') diff --git a/internal/tui/components/core/dialog.go b/internal/tui/components/core/dialog.go index 954e26e87..a8fef2e86 100644 --- a/internal/tui/components/core/dialog.go +++ b/internal/tui/components/core/dialog.go @@ -14,7 +14,12 @@ type SizeableModel interface { } type DialogMsg struct { - Content SizeableModel + Content SizeableModel + WidthRatio float64 + HeightRatio float64 + + MinWidth int + MinHeight int } type DialogCloseMsg struct{} @@ -36,7 +41,18 @@ type DialogCmp interface { } type dialogCmp struct { - content SizeableModel + content SizeableModel + screenWidth int + screenHeight int + + widthRatio float64 + heightRatio float64 + + minWidth int + minHeight int + + width int + height int } func (d *dialogCmp) Init() tea.Cmd { @@ -45,8 +61,26 @@ func (d *dialogCmp) Init() tea.Cmd { func (d *dialogCmp) Update(msg tea.Msg) (tea.Model, tea.Cmd) { switch msg := msg.(type) { + case tea.WindowSizeMsg: + d.screenWidth = msg.Width + d.screenHeight = msg.Height + d.width = max(int(float64(d.screenWidth)*d.widthRatio), d.minWidth) + d.height = max(int(float64(d.screenHeight)*d.heightRatio), d.minHeight) + if d.content != nil { + d.content.SetSize(d.width, d.height) + } + return d, nil case DialogMsg: d.content = msg.Content + d.widthRatio = msg.WidthRatio + d.heightRatio = msg.HeightRatio + d.minWidth = msg.MinWidth + d.minHeight = msg.MinHeight + d.width = max(int(float64(d.screenWidth)*d.widthRatio), d.minWidth) + d.height = max(int(float64(d.screenHeight)*d.heightRatio), d.minHeight) + if d.content != nil { + d.content.SetSize(d.width, d.height) + } case DialogCloseMsg: d.content = nil return d, nil @@ -75,8 +109,7 @@ func (d *dialogCmp) BindingKeys() []key.Binding { } func (d *dialogCmp) View() string { - w, h := d.content.GetSize() - return lipgloss.NewStyle().Width(w).Height(h).Render(d.content.View()) + return lipgloss.NewStyle().Width(d.width).Height(d.height).Render(d.content.View()) } func NewDialogCmp() DialogCmp { diff --git a/internal/tui/components/core/status.go b/internal/tui/components/core/status.go index 8c9b3f60b..cd9dc55a0 100644 --- a/internal/tui/components/core/status.go +++ b/internal/tui/components/core/status.go @@ -3,6 +3,8 @@ package core import ( tea "github.com/charmbracelet/bubbletea" "github.com/charmbracelet/lipgloss" + "github.com/kujtimiihoxha/termai/internal/config" + "github.com/kujtimiihoxha/termai/internal/llm/models" "github.com/kujtimiihoxha/termai/internal/tui/styles" "github.com/kujtimiihoxha/termai/internal/tui/util" "github.com/kujtimiihoxha/termai/internal/version" @@ -57,14 +59,19 @@ func (m statusCmp) View() string { Width(m.availableFooterMsgWidth()). Render(m.info) } - + status += m.model() status += versionWidget return status } func (m statusCmp) availableFooterMsgWidth() int { // -2 to accommodate padding - return max(0, m.width-lipgloss.Width(helpWidget)-lipgloss.Width(versionWidget)) + return max(0, m.width-lipgloss.Width(helpWidget)-lipgloss.Width(versionWidget)-lipgloss.Width(m.model())) +} + +func (m statusCmp) model() string { + model := models.SupportedModels[config.Get().Model.Coder] + return styles.Padded.Background(styles.Grey).Foreground(styles.Text).Render(model.Name) } func NewStatusCmp() tea.Model { -- cgit v1.2.3