Private
Public Access
1
0

More monior TUI refactor/cleanup

`tui/tui.go` is no longer responsible for passing window resize updates
to all views, instead we request a new window size message to be sent at
the same time we enter the view, allowing the view to catch and handle
it.

Add `Initialized` to `tui/shared/View` model, now we only call
`Init` on a view before entering it for the first time, rather than
calling `Init` on all views when the application starts.

Renames file, small cleanups
This commit is contained in:
2024-09-16 14:04:08 +00:00
parent 7c0bfefc65
commit 24b5cdbbf6
6 changed files with 68 additions and 66 deletions

View File

@@ -24,12 +24,12 @@ type LaunchOptions struct {
}
type Model struct {
App *model.AppModel
view shared.View
App *model.AppModel
view shared.View
// views
chat chat.Model
conversations conversations.Model
Width int
Height int
}
func initialModel(ctx *lmcli.Context, opts LaunchOptions) Model {
@@ -50,8 +50,6 @@ func initialModel(ctx *lmcli.Context, opts LaunchOptions) Model {
func (m Model) Init() tea.Cmd {
return tea.Batch(
m.conversations.Init(),
m.chat.Init(),
func() tea.Msg {
return shared.MsgViewChange(m.view)
},
@@ -96,15 +94,23 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
}
case shared.MsgViewChange:
m.view = shared.View(msg)
var cmds []tea.Cmd
switch m.view {
case shared.StateChat:
m.chat.HandleResize(m.Width, m.Height)
case shared.StateConversations:
m.conversations.HandleResize(m.Width, m.Height)
if !m.conversations.Initialized {
cmds = append(cmds, m.conversations.Init())
m.conversations.Initialized = true
}
case shared.StateChat:
if !m.chat.Initialized {
cmds = append(cmds, m.chat.Init())
m.chat.Initialized = true
}
}
return m, func() tea.Msg { return shared.MsgViewEnter(struct{}{}) }
case tea.WindowSizeMsg:
m.Width, m.Height = msg.Width, msg.Height
cmds = append(cmds, tea.WindowSize(), shared.ViewEnter())
return m, tea.Batch(cmds...)
}
var cmd tea.Cmd