Skip to content

Commit 4e6f629

Browse files
committed
Refactor; upgrade deps; popping the top of the
stack quits
1 parent 23b71be commit 4e6f629

File tree

3 files changed

+50
-30
lines changed

3 files changed

+50
-30
lines changed

go.mod

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,19 @@ go 1.19
55
require github.com/charmbracelet/bubbletea v0.23.2
66

77
require (
8-
github.com/aymanbagabas/go-osc52 v1.2.1 // indirect
8+
github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect
99
github.com/containerd/console v1.0.3 // indirect
1010
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
1111
github.com/mattn/go-isatty v0.0.17 // indirect
1212
github.com/mattn/go-localereader v0.0.1 // indirect
1313
github.com/mattn/go-runewidth v0.0.14 // indirect
14-
github.com/muesli/ansi v0.0.0-20211018074035-2e021307bc4b // indirect
14+
github.com/muesli/ansi v0.0.0-20230316100256-276c6243b2f6 // indirect
1515
github.com/muesli/cancelreader v0.2.2 // indirect
1616
github.com/muesli/reflow v0.3.0 // indirect
17-
github.com/muesli/termenv v0.14.0 // indirect
18-
github.com/rivo/uniseg v0.2.0 // indirect
17+
github.com/muesli/termenv v0.15.1 // indirect
18+
github.com/rivo/uniseg v0.4.4 // indirect
1919
golang.org/x/sync v0.1.0 // indirect
20-
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab // indirect
21-
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211 // indirect
22-
golang.org/x/text v0.3.7 // indirect
20+
golang.org/x/sys v0.6.0 // indirect
21+
golang.org/x/term v0.6.0 // indirect
22+
golang.org/x/text v0.8.0 // indirect
2323
)

go.sum

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
github.com/aymanbagabas/go-osc52 v1.2.1 h1:q2sWUyDcozPLcLabEMd+a+7Ea2DitxZVN9hTxab9L4E=
22
github.com/aymanbagabas/go-osc52 v1.2.1/go.mod h1:zT8H+Rk4VSabYN90pWyugflM3ZhpTZNC7cASDfUCdT4=
3+
github.com/aymanbagabas/go-osc52 v1.2.2 h1:NT7wkhEhPTcKnBCdPi9djmyy9L3JOL4+3SsfJyqptCo=
4+
github.com/aymanbagabas/go-osc52 v1.2.2/go.mod h1:zT8H+Rk4VSabYN90pWyugflM3ZhpTZNC7cASDfUCdT4=
5+
github.com/aymanbagabas/go-osc52/v2 v2.0.1 h1:HwpRHbFMcZLEVr42D4p7XBqjyuxQH5SMiErDT4WkJ2k=
6+
github.com/aymanbagabas/go-osc52/v2 v2.0.1/go.mod h1:uYgXzlJ7ZpABp8OJ+exZzJJhRNQ2ASbcXHWsFqH8hp8=
37
github.com/charmbracelet/bubbletea v0.23.2 h1:vuUJ9HJ7b/COy4I30e8xDVQ+VRDUEFykIjryPfgsdps=
48
github.com/charmbracelet/bubbletea v0.23.2/go.mod h1:FaP3WUivcTM0xOKNmhciz60M6I+weYLF76mr1JyI7sM=
59
github.com/containerd/console v1.0.3 h1:lIr7SlA5PxZyMV30bDW0MGbiOPXwc63yRuCP0ARubLw=
@@ -16,24 +20,36 @@ github.com/mattn/go-runewidth v0.0.14 h1:+xnbZSEeDbOIg5/mE6JF0w6n9duR1l3/WmbinWV
1620
github.com/mattn/go-runewidth v0.0.14/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
1721
github.com/muesli/ansi v0.0.0-20211018074035-2e021307bc4b h1:1XF24mVaiu7u+CFywTdcDo2ie1pzzhwjt6RHqzpMU34=
1822
github.com/muesli/ansi v0.0.0-20211018074035-2e021307bc4b/go.mod h1:fQuZ0gauxyBcmsdE3ZT4NasjaRdxmbCS0jRHsrWu3Ho=
23+
github.com/muesli/ansi v0.0.0-20230316100256-276c6243b2f6 h1:ZK8zHtRHOkbHy6Mmr5D264iyp3TiX5OmNcI5cIARiQI=
24+
github.com/muesli/ansi v0.0.0-20230316100256-276c6243b2f6/go.mod h1:CJlz5H+gyd6CUWT45Oy4q24RdLyn7Md9Vj2/ldJBSIo=
1925
github.com/muesli/cancelreader v0.2.2 h1:3I4Kt4BQjOR54NavqnDogx/MIoWBFa0StPA8ELUXHmA=
2026
github.com/muesli/cancelreader v0.2.2/go.mod h1:3XuTXfFS2VjM+HTLZY9Ak0l6eUKfijIfMUZ4EgX0QYo=
2127
github.com/muesli/reflow v0.3.0 h1:IFsN6K9NfGtjeggFP+68I4chLZV2yIKsXJFNZ+eWh6s=
2228
github.com/muesli/reflow v0.3.0/go.mod h1:pbwTDkVPibjO2kyvBQRBxTWEEGDGq0FlB1BIKtnHY/8=
2329
github.com/muesli/termenv v0.14.0 h1:8x9NFfOe8lmIWK4pgy3IfVEy47f+ppe3tUqdPZG2Uy0=
2430
github.com/muesli/termenv v0.14.0/go.mod h1:kG/pF1E7fh949Xhe156crRUrHNyK221IuGO7Ez60Uc8=
31+
github.com/muesli/termenv v0.15.1 h1:UzuTb/+hhlBugQz28rpzey4ZuKcZ03MeKsoG7IJZIxs=
32+
github.com/muesli/termenv v0.15.1/go.mod h1:HeAQPTzpfs016yGtA4g00CsdYnVLJvxsS4ANqrZs2sQ=
2533
github.com/rivo/uniseg v0.1.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
2634
github.com/rivo/uniseg v0.2.0 h1:S1pD9weZBuJdFmowNwbpi7BJ8TNftyUImj/0WQi72jY=
2735
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
36+
github.com/rivo/uniseg v0.4.4 h1:8TfxU8dW6PdqD27gjM8MVNuicgxIjxpm4K7x4jp8sis=
37+
github.com/rivo/uniseg v0.4.4/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88=
2838
golang.org/x/sync v0.1.0 h1:wsuoTGHzEhffawBOhz5CYhcrV4IdKZbEyZjBMuTp12o=
2939
golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
3040
golang.org/x/sys v0.0.0-20210124154548-22da62e12c0c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
3141
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
3242
golang.org/x/sys v0.0.0-20220204135822-1c1b9b1eba6a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
3343
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab h1:2QkjZIsXupsJbJIdSjjUOgWK3aEtzyuh2mPt3l/CkeU=
3444
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
45+
golang.org/x/sys v0.6.0 h1:MVltZSvRTcU2ljQOhs94SXPftV6DCNnZViHeQps87pQ=
46+
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
3547
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211 h1:JGgROgKl9N8DuW20oFS5gxc+lE67/N3FcwmBPMe7ArY=
3648
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
49+
golang.org/x/term v0.6.0 h1:clScbb1cHjoCkyRbWwBEUZ5H/tIFu5TAXIqaZD0Gcjw=
50+
golang.org/x/term v0.6.0/go.mod h1:m6U89DPEgQRMq3DNkDClhWw02AUbt2daBVO4cn4Hv9U=
3751
golang.org/x/text v0.3.7 h1:olpwvP2KacW1ZWvsR7uQhoyTYvKAupfQrRGBFM352Gk=
3852
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
53+
golang.org/x/text v0.8.0 h1:57P1ETyNKtuIjB4SRd15iJxuhj8Gc416Y78H3qgMh68=
54+
golang.org/x/text v0.8.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8=
3955
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=

stacker.go

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ package stacker
33
import tea "github.com/charmbracelet/bubbletea"
44

55
func NewStacker(m tea.Model) tea.Model {
6+
if m == nil {
7+
return nil
8+
}
69
return &Stacker{
710
stack: []tea.Model{m}}
811
}
@@ -11,10 +14,28 @@ type pushSceneMsg struct {
1114
model tea.Model
1215
}
1316

17+
func AddScene(m tea.Model) tea.Cmd {
18+
return func() tea.Msg {
19+
return pushSceneMsg{m}
20+
}
21+
}
22+
1423
type popSceneMsg struct {
1524
silent bool
1625
}
1726

27+
func PopScene() tea.Cmd {
28+
return func() tea.Msg {
29+
return popSceneMsg{}
30+
}
31+
}
32+
33+
func PopSceneSilent() tea.Cmd {
34+
return func() tea.Msg {
35+
return popSceneMsg{silent: true}
36+
}
37+
}
38+
1839
type Stacker struct {
1940
stack []tea.Model
2041
}
@@ -25,15 +46,16 @@ func (m *Stacker) Init() tea.Cmd {
2546

2647
func (m *Stacker) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
2748
switch msg := msg.(type) {
28-
case tea.KeyMsg:
29-
switch msg.String() {
30-
case "ctrl+c":
31-
return m, tea.Quit
32-
}
3349
case pushSceneMsg:
3450
m.stack = append(m.stack, msg.model)
3551
return m, msg.model.Init()
3652
case popSceneMsg:
53+
// TODO:
54+
// If this stack is on a stack, it should somehow only pop itself...
55+
// I don't think it's possible with the current API/structs/etc.
56+
if len(m.stack) == 1 {
57+
return m, tea.Quit
58+
}
3759
curScene := m.stack[len(m.stack)-1]
3860
m.stack = m.stack[:len(m.stack)-1]
3961
if msg.silent {
@@ -49,21 +71,3 @@ func (m *Stacker) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
4971
func (m *Stacker) View() string {
5072
return m.stack[len(m.stack)-1].View()
5173
}
52-
53-
func AddScene(m tea.Model) tea.Cmd {
54-
return func() tea.Msg {
55-
return pushSceneMsg{m}
56-
}
57-
}
58-
59-
func PopScene() tea.Cmd {
60-
return func() tea.Msg {
61-
return popSceneMsg{}
62-
}
63-
}
64-
65-
func PopSceneSilent() tea.Cmd {
66-
return func() tea.Msg {
67-
return popSceneMsg{silent: true}
68-
}
69-
}

0 commit comments

Comments
 (0)