feat: wip tui application
This commit is contained in:
parent
a161b86c9a
commit
5d7e9d79c4
7 changed files with 286 additions and 0 deletions
47
tui/app.go
Normal file
47
tui/app.go
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
package tui
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
tea "github.com/charmbracelet/bubbletea"
|
||||
)
|
||||
|
||||
type (
|
||||
AppModel struct{
|
||||
Size Size
|
||||
Header HeaderModel
|
||||
Screen tea.Model
|
||||
}
|
||||
)
|
||||
|
||||
func NewApp() AppModel {
|
||||
return AppModel{
|
||||
Header: NewHeader(),
|
||||
Screen: NewHomeScreen(),
|
||||
}
|
||||
}
|
||||
|
||||
func (m AppModel) Init() tea.Cmd {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m AppModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||
var cmd, headerCmd, screenCmd tea.Cmd
|
||||
|
||||
switch msg := msg.(type) {
|
||||
case tea.WindowSizeMsg:
|
||||
m.Size = NewSizeFromWindow(msg)
|
||||
}
|
||||
|
||||
m.Header, headerCmd = m.Header.Update(msg)
|
||||
m.Screen, screenCmd = m.Screen.Update(msg)
|
||||
|
||||
return m, tea.Batch(cmd, headerCmd, screenCmd)
|
||||
}
|
||||
|
||||
func (m AppModel) View() string {
|
||||
return strings.Join([]string{
|
||||
m.Header.View(),
|
||||
m.Screen.View(),
|
||||
}, "\n")
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue