From 333ea6ec4b2abfc2c1a9c3f6b0918ca5d296347f Mon Sep 17 00:00:00 2001 From: Kujtim Hoxha Date: Fri, 18 Apr 2025 20:17:38 +0200 Subject: implement patch, update ui, improve rendering --- internal/tui/page/chat.go | 31 ++++++++++++++----------------- internal/tui/page/logs.go | 13 +++++++------ 2 files changed, 21 insertions(+), 23 deletions(-) (limited to 'internal/tui/page') diff --git a/internal/tui/page/chat.go b/internal/tui/page/chat.go index 632e10764..b99dc3dfe 100644 --- a/internal/tui/page/chat.go +++ b/internal/tui/page/chat.go @@ -54,9 +54,11 @@ func (p *chatPage) Init() tea.Cmd { } func (p *chatPage) Update(msg tea.Msg) (tea.Model, tea.Cmd) { + var cmds []tea.Cmd switch msg := msg.(type) { case tea.WindowSizeMsg: - p.layout.SetSize(msg.Width, msg.Height) + cmd := p.layout.SetSize(msg.Width, msg.Height) + cmds = append(cmds, cmd) case chat.SendMsg: cmd := p.sendMessage(msg.Text) if cmd != nil { @@ -68,8 +70,10 @@ func (p *chatPage) Update(msg tea.Msg) (tea.Model, tea.Cmd) { switch { case key.Matches(msg, keyMap.NewSession): p.session = session.Session{} - p.clearSidebar() - return p, util.CmdHandler(chat.SessionClearedMsg{}) + return p, tea.Batch( + p.clearSidebar(), + util.CmdHandler(chat.SessionClearedMsg{}), + ) case key.Matches(msg, keyMap.Cancel): if p.session.ID != "" { // Cancel the current session's generation process @@ -80,11 +84,9 @@ func (p *chatPage) Update(msg tea.Msg) (tea.Model, tea.Cmd) { } } u, cmd := p.layout.Update(msg) + cmds = append(cmds, cmd) p.layout = u.(layout.SplitPaneLayout) - if cmd != nil { - return p, cmd - } - return p, nil + return p, tea.Batch(cmds...) } func (p *chatPage) setSidebar() tea.Cmd { @@ -92,16 +94,11 @@ func (p *chatPage) setSidebar() tea.Cmd { chat.NewSidebarCmp(p.session, p.app.History), layout.WithPadding(1, 1, 1, 1), ) - p.layout.SetRightPanel(sidebarContainer) - width, height := p.layout.GetSize() - p.layout.SetSize(width, height) - return sidebarContainer.Init() + return tea.Batch(p.layout.SetRightPanel(sidebarContainer), sidebarContainer.Init()) } -func (p *chatPage) clearSidebar() { - p.layout.SetRightPanel(nil) - width, height := p.layout.GetSize() - p.layout.SetSize(width, height) +func (p *chatPage) clearSidebar() tea.Cmd { + return p.layout.SetRightPanel(nil) } func (p *chatPage) sendMessage(text string) tea.Cmd { @@ -124,8 +121,8 @@ func (p *chatPage) sendMessage(text string) tea.Cmd { return tea.Batch(cmds...) } -func (p *chatPage) SetSize(width, height int) { - p.layout.SetSize(width, height) +func (p *chatPage) SetSize(width, height int) tea.Cmd { + return p.layout.SetSize(width, height) } func (p *chatPage) GetSize() (int, int) { diff --git a/internal/tui/page/logs.go b/internal/tui/page/logs.go index 0efc69e6e..f0d35fb7b 100644 --- a/internal/tui/page/logs.go +++ b/internal/tui/page/logs.go @@ -23,15 +23,14 @@ type logsPage struct { } func (p *logsPage) Update(msg tea.Msg) (tea.Model, tea.Cmd) { + var cmds []tea.Cmd switch msg := msg.(type) { case tea.WindowSizeMsg: p.width = msg.Width p.height = msg.Height - p.table.SetSize(msg.Width, msg.Height/2) - p.details.SetSize(msg.Width, msg.Height/2) + return p, p.SetSize(msg.Width, msg.Height) } - var cmds []tea.Cmd table, cmd := p.table.Update(msg) cmds = append(cmds, cmd) p.table = table.(layout.Container) @@ -60,11 +59,13 @@ func (p *logsPage) GetSize() (int, int) { } // SetSize implements LogPage. -func (p *logsPage) SetSize(width int, height int) { +func (p *logsPage) SetSize(width int, height int) tea.Cmd { p.width = width p.height = height - p.table.SetSize(width, height/2) - p.details.SetSize(width, height/2) + return tea.Batch( + p.table.SetSize(width, height/2), + p.details.SetSize(width, height/2), + ) } func (p *logsPage) Init() tea.Cmd { -- cgit v1.2.3