aboutsummaryrefslogtreecommitdiff
path: root/screens/root.go
blob: 590c4db530b7f825c06b0511de68425a087313f4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package screens

import (
	"nectar/components/root"

	tea "github.com/charmbracelet/bubbletea"
	"github.com/charmbracelet/lipgloss"
)

type rootScreen struct {
	mainArea root.MainAreaModel
}

func _root() tea.Model {
	return &rootScreen{
		mainArea: root.NewMainArea(),
	}
}

func (r *rootScreen) Init() tea.Cmd {
	return r.mainArea.Init()
}

func (r *rootScreen) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
	switch msg := msg.(type) {
	case tea.WindowSizeMsg:
		globals.Width, globals.Height = msg.Width, msg.Height
	case tea.KeyMsg:
		switch msg.String() {
		case "ctrl+c", "q":
			return r, tea.Quit
		}
	}

	var cmd tea.Cmd
	r.mainArea, cmd = r.mainArea.Update(msg)
	return r, cmd
}

func (r *rootScreen) View() string {
	return lipgloss.JoinVertical(
		lipgloss.Top,
		lipgloss.JoinHorizontal(
			lipgloss.Left,
			root.Sidebar(&globals),
			root.MainArea(&globals, r.mainArea),
		),
		root.StatusBar(&globals),
	)
}