feat: wip tui updates
This commit is contained in:
parent
5d7e9d79c4
commit
dde2d98a84
5 changed files with 158 additions and 24 deletions
30
tui/app.go
30
tui/app.go
|
|
@ -1,6 +1,7 @@
|
|||
package tui
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
tea "github.com/charmbracelet/bubbletea"
|
||||
|
|
@ -11,13 +12,19 @@ type (
|
|||
Size Size
|
||||
Header HeaderModel
|
||||
Screen tea.Model
|
||||
Screens []tea.Model
|
||||
}
|
||||
)
|
||||
|
||||
func NewApp() AppModel {
|
||||
screens := []tea.Model{
|
||||
NewHomeScreen(),
|
||||
NewNotificationScreen(),
|
||||
}
|
||||
return AppModel{
|
||||
Header: NewHeader(),
|
||||
Screen: NewHomeScreen(),
|
||||
Screen: screens[0],
|
||||
Screens: screens,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -30,7 +37,11 @@ func (m AppModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
|||
|
||||
switch msg := msg.(type) {
|
||||
case tea.WindowSizeMsg:
|
||||
m.Size = NewSizeFromWindow(msg)
|
||||
m.SetSize(msg.Width, msg.Height)
|
||||
case SwitchHomeScreenMsg:
|
||||
m.Screen = m.Screens[0]
|
||||
case SwitchNotificationScreenMsg:
|
||||
m.Screen = m.Screens[1]
|
||||
}
|
||||
|
||||
m.Header, headerCmd = m.Header.Update(msg)
|
||||
|
|
@ -39,8 +50,23 @@ func (m AppModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
|||
return m, tea.Batch(cmd, headerCmd, screenCmd)
|
||||
}
|
||||
|
||||
func (m *AppModel) SetSize(width, height int) {
|
||||
m.Size = NewSize(width, height)
|
||||
m.Header.SetWidth(width)
|
||||
screenHeight := height - m.Header.Size.Height
|
||||
switch screen := m.Screen.(type) {
|
||||
case Sized:
|
||||
m.Screen = screen.SetSize(width, screenHeight)
|
||||
case SizedWidth:
|
||||
m.Screen = screen.SetWidth(width)
|
||||
case SizedHeight:
|
||||
m.Screen = screen.SetHeight(screenHeight)
|
||||
}
|
||||
}
|
||||
|
||||
func (m AppModel) View() string {
|
||||
return strings.Join([]string{
|
||||
fmt.Sprintf("%d x %d", m.Size.Width, m.Size.Height),
|
||||
m.Header.View(),
|
||||
m.Screen.View(),
|
||||
}, "\n")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue