-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
72 lines (59 loc) · 1.46 KB
/
main.go
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package main
import (
tea "github.com/charmbracelet/bubbletea"
"github.com/charmbracelet/lipgloss"
bl "github.com/winder/bubblelayout"
)
type layoutModel struct {
layout bl.BubbleLayout
leftID bl.ID
rightID bl.ID
leftSize bl.Size
rightSize bl.Size
}
func New() tea.Model {
layoutModel := layoutModel{layout: bl.New()}
layoutModel.leftID = layoutModel.layout.Add("width 10")
layoutModel.rightID = layoutModel.layout.Add("grow")
return layoutModel
}
func (m layoutModel) Init() tea.Cmd {
return func() tea.Msg {
return m.layout.Resize(80, 40)
}
}
func (m layoutModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
switch msg := msg.(type) {
case tea.KeyMsg:
switch msg.String() {
case "q", "esc", "ctrl+c":
return m, tea.Quit
}
case tea.WindowSizeMsg:
// Convert WindowSizeMsg to BubbleLayoutMsg.
return m, func() tea.Msg {
return m.layout.Resize(msg.Width, msg.Height)
}
case bl.BubbleLayoutMsg:
m.leftSize, _ = msg.Size(m.leftID)
m.rightSize, _ = msg.Size(m.rightID)
}
return m, nil
}
func boxStyle(size bl.Size, bg lipgloss.Color) lipgloss.Style {
return lipgloss.NewStyle().
Background(bg).
Foreground(lipgloss.Color("0")).
Width(size.Width).
Height(size.Height).
Align(lipgloss.Center, lipgloss.Center)
}
func (m layoutModel) View() string {
return lipgloss.JoinHorizontal(0,
boxStyle(m.leftSize, "9").Render("left"),
boxStyle(m.rightSize, "13").Render("right"))
}
func main() {
p := tea.NewProgram(New())
p.Run()
}