- commit
- 81b7404
- parent
- 378cfe0
- author
- Eric Bower
- date
- 2025-03-31 15:00:08 -0400 EDT
fix(tui.tokens): add explainer text about how to copy tokens
1 files changed,
+33,
-14
+33,
-14
1@@ -161,7 +161,7 @@ type AddTokenPage struct {
2 }
3
4 func NewAddTokenPage(shrd *SharedModel) *AddTokenPage {
5- btn := button.New("ADD", func() (vxfw.Command, error) { return nil, nil })
6+ btn := button.New("OK", func() (vxfw.Command, error) { return nil, nil })
7 btn.Style = button.StyleSet{
8 Default: vaxis.Style{Background: grey},
9 Focus: vaxis.Style{Background: oj, Foreground: black},
10@@ -174,6 +174,13 @@ func NewAddTokenPage(shrd *SharedModel) *AddTokenPage {
11 }
12 }
13
14+func (m *AddTokenPage) Footer() []Shortcut {
15+ return []Shortcut{
16+ {Shortcut: "tab", Text: "focus"},
17+ {Shortcut: "shift+click", Text: "select text"},
18+ }
19+}
20+
21 func (m *AddTokenPage) HandleEvent(ev vaxis.Event, phase vxfw.EventPhase) (vxfw.Command, error) {
22 switch msg := ev.(type) {
23 case PageIn:
24@@ -199,11 +206,15 @@ func (m *AddTokenPage) HandleEvent(ev vaxis.Event, phase vxfw.EventPhase) (vxfw.
25 if msg.Matches(vaxis.KeyEnter) {
26 if m.focus == "button" {
27 if m.token != "" {
28+ copyToken := m.token
29 m.token = ""
30 m.err = nil
31 m.input.Reset()
32 m.shared.App.PostEvent(Navigate{To: "tokens"})
33- return vxfw.RedrawCmd{}, nil
34+ return vxfw.BatchCmd([]vxfw.Command{
35+ vxfw.CopyToClipboardCmd(copyToken),
36+ vxfw.RedrawCmd{},
37+ }), nil
38 }
39 token, err := m.addToken(m.input.GetValue())
40 m.token = token
41@@ -224,42 +235,50 @@ func (m *AddTokenPage) Draw(ctx vxfw.DrawContext) (vxfw.Surface, error) {
42 w := ctx.Max.Width
43 h := ctx.Max.Height
44 root := vxfw.NewSurface(w, h, m)
45+ ah := 0
46
47 if m.token == "" {
48 header := text.New("Enter a name for the token")
49 headerSurf, _ := header.Draw(ctx)
50- root.AddChild(0, 0, headerSurf)
51+ root.AddChild(0, ah, headerSurf)
52+ ah += int(headerSurf.Size.Height)
53
54 inputSurf, _ := m.input.Draw(createDrawCtx(ctx, 4))
55- root.AddChild(0, 3, inputSurf)
56+ root.AddChild(0, ah, inputSurf)
57+ ah += int(inputSurf.Size.Height)
58
59 btnSurf, _ := m.btn.Draw(vxfw.DrawContext{
60 Characters: ctx.Characters,
61- Max: vxfw.Size{Width: 5, Height: 1},
62+ Max: vxfw.Size{Width: 4, Height: 1},
63 })
64- root.AddChild(0, 6, btnSurf)
65+ root.AddChild(0, ah, btnSurf)
66+ ah += int(btnSurf.Size.Height)
67 } else {
68 header := text.New(
69- fmt.Sprintf(
70- "Save this token: %s\n\nAfter you exit this screen you will *not* be able to see it again.",
71- m.token,
72- ),
73+ "After you exit this screen you will *not* be able to see it again. Use shift+click to select and copy text. If your terminal supports OSC52 then we will copy to your host clipboard upon exit of this screen.\n\n",
74 )
75 headerSurf, _ := header.Draw(ctx)
76- root.AddChild(0, 0, headerSurf)
77+ root.AddChild(0, ah, headerSurf)
78+ ah += int(headerSurf.Size.Height)
79+
80+ token := text.New(m.token + "\n")
81+ tokenSurf, _ := token.Draw(ctx)
82+ root.AddChild(0, ah, tokenSurf)
83+ ah += int(tokenSurf.Size.Height)
84
85 btnSurf, _ := m.btn.Draw(vxfw.DrawContext{
86 Characters: ctx.Characters,
87- Max: vxfw.Size{Width: 5, Height: 1},
88+ Max: vxfw.Size{Width: 4, Height: 1},
89 })
90- root.AddChild(0, 7, btnSurf)
91+ root.AddChild(0, ah, btnSurf)
92+ ah += int(btnSurf.Size.Height)
93 }
94
95 if m.err != nil {
96 e := text.New(m.err.Error())
97 e.Style = vaxis.Style{Foreground: red}
98 errSurf, _ := e.Draw(ctx)
99- root.AddChild(0, 9, errSurf)
100+ root.AddChild(0, ah, errSurf)
101 }
102
103 return root, nil