Private
Public Access
1
0

TUI view management and input handling cleanup

This commit is contained in:
2024-09-16 15:40:04 +00:00
parent 24b5cdbbf6
commit 463ca9ef40
7 changed files with 169 additions and 154 deletions

View File

@@ -4,13 +4,31 @@ import (
tea "github.com/charmbracelet/bubbletea"
)
type Shared struct {
// An analogue to tea.Model with support for checking if the model has been
// initialized before
type ViewModel interface {
Init() tea.Cmd
Update(tea.Msg) (ViewModel, tea.Cmd)
View() string
Initialized() bool // Return whether this view is initialized
}
type ViewState struct {
Initialized bool
Width int
Height int
Err error
}
type View int
const (
ViewChat View = iota
ViewConversations
//StateSettings
//StateHelp
)
// a convenience struct for holding rendered content for indiviudal UI
// elements
type Sections struct {
@@ -28,6 +46,8 @@ type (
MsgViewEnter struct{}
// sent when an error occurs
MsgError error
// sent when the view has handled a key input
MsgKeyHandled tea.KeyMsg
)
func ViewEnter() tea.Cmd {
@@ -36,17 +56,14 @@ func ViewEnter() tea.Cmd {
}
}
func KeyHandled(key tea.KeyMsg) tea.Cmd {
return func() tea.Msg {
return MsgKeyHandled(key)
}
}
func WrapError(err error) tea.Cmd {
return func() tea.Msg {
return MsgError(err)
}
}
type View int
const (
StateChat View = iota
StateConversations
//StateSettings
//StateHelp
)