Split up tui code into packages (views/*, shared, util)
This commit is contained in:
55
pkg/tui/shared/shared.go
Normal file
55
pkg/tui/shared/shared.go
Normal file
@@ -0,0 +1,55 @@
|
||||
package shared
|
||||
|
||||
import (
|
||||
"git.mlow.ca/mlow/lmcli/pkg/lmcli"
|
||||
tea "github.com/charmbracelet/bubbletea"
|
||||
)
|
||||
|
||||
type Values struct {
|
||||
ConvShortname string
|
||||
}
|
||||
|
||||
type State struct {
|
||||
Ctx *lmcli.Context
|
||||
Values *Values
|
||||
Views *Views
|
||||
Width int
|
||||
Height int
|
||||
Err error
|
||||
}
|
||||
|
||||
// this struct holds the final rendered content of various UI components, and
|
||||
// gets populated in the application's Update() method. View() simply composes
|
||||
// these elements into the final output
|
||||
// TODO: consider removing this, let each view be responsible
|
||||
type Views struct {
|
||||
Header string
|
||||
Content string
|
||||
Error string
|
||||
Input string
|
||||
Footer string
|
||||
}
|
||||
|
||||
type (
|
||||
// send to change the current state
|
||||
MsgViewChange View
|
||||
// sent to a state when it is entered
|
||||
MsgViewEnter struct{}
|
||||
// sent when an error occurs
|
||||
MsgError error
|
||||
)
|
||||
|
||||
func WrapError(err error) tea.Cmd {
|
||||
return func() tea.Msg {
|
||||
return MsgError(err)
|
||||
}
|
||||
}
|
||||
|
||||
type View int
|
||||
|
||||
const (
|
||||
StateChat View = iota
|
||||
StateConversations
|
||||
//StateSettings
|
||||
//StateHelp
|
||||
)
|
||||
Reference in New Issue
Block a user