repos / pico

pico services mono repo
git clone https://github.com/picosh/pico.git

commit
5800855
parent
81b7404
author
Antonio Mika
date
2025-04-02 21:32:12 -0400 EDT
Don't require focus for adding
2 files changed,  +55, -34
M pkg/tui/pubkeys.go
+25, -12
 1@@ -188,6 +188,31 @@ func NewAddPubkeyPage(shrd *SharedModel) *AddKeyPage {
 2 	}
 3 }
 4 
 5+func (m *AddKeyPage) Footer() []Shortcut {
 6+	return []Shortcut{
 7+		{Shortcut: "tab", Text: "focus"},
 8+		{Shortcut: "shift+click", Text: "select text"},
 9+		{Shortcut: "enter", Text: "add public key"},
10+	}
11+}
12+
13+func (m *AddKeyPage) CaptureEvent(ev vaxis.Event) (vxfw.Command, error) {
14+	switch msg := ev.(type) {
15+	case vaxis.Key:
16+		if msg.Matches(vaxis.KeyEnter) {
17+			err := m.addPubkey(m.input.GetValue())
18+			m.err = err
19+			if err == nil {
20+				m.input.Reset()
21+				m.shared.App.PostEvent(Navigate{To: "pubkeys"})
22+				return nil, nil
23+			}
24+			return vxfw.RedrawCmd{}, nil
25+		}
26+	}
27+	return nil, nil
28+}
29+
30 func (m *AddKeyPage) HandleEvent(ev vaxis.Event, phase vxfw.EventPhase) (vxfw.Command, error) {
31 	switch msg := ev.(type) {
32 	case PageIn:
33@@ -207,18 +232,6 @@ func (m *AddKeyPage) HandleEvent(ev vaxis.Event, phase vxfw.EventPhase) (vxfw.Co
34 			m.focus = "input"
35 			return m.input.FocusIn()
36 		}
37-		if msg.Matches(vaxis.KeyEnter) {
38-			if m.focus == "button" {
39-				err := m.addPubkey(m.input.GetValue())
40-				m.err = err
41-				if err == nil {
42-					m.input.Reset()
43-					m.shared.App.PostEvent(Navigate{To: "pubkeys"})
44-					return nil, nil
45-				}
46-				return vxfw.RedrawCmd{}, nil
47-			}
48-		}
49 	}
50 
51 	return nil, nil
M pkg/tui/tokens.go
+30, -22
 1@@ -178,9 +178,39 @@ func (m *AddTokenPage) Footer() []Shortcut {
 2 	return []Shortcut{
 3 		{Shortcut: "tab", Text: "focus"},
 4 		{Shortcut: "shift+click", Text: "select text"},
 5+		{Shortcut: "enter", Text: "add token"},
 6 	}
 7 }
 8 
 9+func (m *AddTokenPage) CaptureEvent(ev vaxis.Event) (vxfw.Command, error) {
10+	switch msg := ev.(type) {
11+	case vaxis.Key:
12+		if msg.Matches(vaxis.KeyEnter) {
13+			if m.token != "" {
14+				copyToken := m.token
15+				m.token = ""
16+				m.err = nil
17+				m.input.Reset()
18+				m.shared.App.PostEvent(Navigate{To: "tokens"})
19+				return vxfw.BatchCmd([]vxfw.Command{
20+					vxfw.CopyToClipboardCmd(copyToken),
21+					vxfw.RedrawCmd{},
22+				}), nil
23+			}
24+			token, err := m.addToken(m.input.GetValue())
25+			m.token = token
26+			m.focus = "button"
27+			m.err = err
28+
29+			return vxfw.BatchCmd([]vxfw.Command{
30+				vxfw.FocusWidgetCmd(m.btn),
31+				vxfw.RedrawCmd{},
32+			}), err
33+		}
34+	}
35+	return nil, nil
36+}
37+
38 func (m *AddTokenPage) HandleEvent(ev vaxis.Event, phase vxfw.EventPhase) (vxfw.Command, error) {
39 	switch msg := ev.(type) {
40 	case PageIn:
41@@ -189,9 +219,6 @@ func (m *AddTokenPage) HandleEvent(ev vaxis.Event, phase vxfw.EventPhase) (vxfw.
42 		return m.input.FocusIn()
43 	case vaxis.Key:
44 		if msg.Matches(vaxis.KeyTab) {
45-			if m.token != "" {
46-				return nil, nil
47-			}
48 			if m.focus == "input" {
49 				m.focus = "button"
50 				cmd, _ := m.input.FocusOut()
51@@ -203,25 +230,6 @@ func (m *AddTokenPage) HandleEvent(ev vaxis.Event, phase vxfw.EventPhase) (vxfw.
52 			m.focus = "input"
53 			return m.input.FocusIn()
54 		}
55-		if msg.Matches(vaxis.KeyEnter) {
56-			if m.focus == "button" {
57-				if m.token != "" {
58-					copyToken := m.token
59-					m.token = ""
60-					m.err = nil
61-					m.input.Reset()
62-					m.shared.App.PostEvent(Navigate{To: "tokens"})
63-					return vxfw.BatchCmd([]vxfw.Command{
64-						vxfw.CopyToClipboardCmd(copyToken),
65-						vxfw.RedrawCmd{},
66-					}), nil
67-				}
68-				token, err := m.addToken(m.input.GetValue())
69-				m.token = token
70-				m.err = err
71-				return vxfw.RedrawCmd{}, nil
72-			}
73-		}
74 	}
75 
76 	return nil, nil