aboutsummaryrefslogtreecommitdiff
path: root/screens/screens.go
diff options
context:
space:
mode:
authorBobby <[email protected]>2024-09-08 02:32:17 -0400
committerBobby <[email protected]>2024-09-08 02:32:17 -0400
commit61bc5b38044bc52442415f83390ba72ed3b27491 (patch)
tree73b727180897573d6a13c0a84ac4e1bb617f33ed /screens/screens.go
downloadyato-61bc5b38044bc52442415f83390ba72ed3b27491.tar.xz
yato-61bc5b38044bc52442415f83390ba72ed3b27491.zip
Initial Commit with MAL Auth
Diffstat (limited to 'screens/screens.go')
-rw-r--r--screens/screens.go69
1 files changed, 69 insertions, 0 deletions
diff --git a/screens/screens.go b/screens/screens.go
new file mode 100644
index 0000000..1675ec7
--- /dev/null
+++ b/screens/screens.go
@@ -0,0 +1,69 @@
+package screens
+
+import (
+ "os"
+
+ tea "github.com/charmbracelet/bubbletea"
+ "golang.org/x/term"
+)
+
+type ScreenSwitcher struct {
+ currentScreen tea.Model
+}
+
+type Globals struct {
+ width int
+ height int
+}
+
+var globals Globals
+
+func (s ScreenSwitcher) Init() tea.Cmd {
+ return s.currentScreen.Init()
+}
+
+func (s ScreenSwitcher) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
+ var cmd tea.Cmd
+ var model tea.Model
+
+ switch m := msg.(type) {
+ case tea.WindowSizeMsg:
+ globals.width, globals.height = m.Width, m.Height
+ }
+
+ model, cmd = s.currentScreen.Update(msg)
+
+ return ScreenSwitcher{currentScreen: model}, cmd
+}
+
+func (s ScreenSwitcher) View() string {
+ return s.currentScreen.View()
+}
+
+func (s ScreenSwitcher) Switch(screen tea.Model) (tea.Model, tea.Cmd) {
+ s.currentScreen = screen
+ return s.currentScreen, s.currentScreen.Init()
+}
+
+func screen() ScreenSwitcher {
+ screen := homeScreen()
+
+ return ScreenSwitcher{
+ currentScreen: screen,
+ }
+}
+
+func Initialize() tea.Model {
+
+ width, height, err := term.GetSize(int(os.Stdout.Fd()))
+
+ if err != nil {
+ width = 80
+ height = 30
+ }
+
+ globals.width = width
+ globals.height = height
+
+ return screen()
+}