@@ -36,6 +36,10 @@ type Connections struct {
3636 renaming bool
3737 renameInput string
3838
39+ // manual pair-by-ID state
40+ pairing bool
41+ pairInput string
42+
3943 err error
4044 notice string
4145}
@@ -90,6 +94,38 @@ func (c Connections) Update(msg tea.Msg) (Screen, tea.Cmd) {
9094}
9195
9296func (c Connections ) handleKey (msg tea.KeyPressMsg ) (Screen , tea.Cmd ) {
97+ // pair mode — capture device ID input
98+ if c .pairing {
99+ switch msg .String () {
100+ case "enter" :
101+ if c .pairInput != "" {
102+ client , id := c .client , c .pairInput
103+ c .pairing = false
104+ c .pairInput = ""
105+ return c , func () tea.Msg {
106+ return ConnectionActionMsg {Err : client .AcceptDevice (id , "" )}
107+ }
108+ }
109+ c .pairing = false
110+ c .pairInput = ""
111+ case "esc" :
112+ c .pairing = false
113+ c .pairInput = ""
114+ case "backspace" , "ctrl+h" :
115+ if len (c .pairInput ) > 0 {
116+ runes := []rune (c .pairInput )
117+ c .pairInput = string (runes [:len (runes )- 1 ])
118+ }
119+ default :
120+ for _ , r := range msg .String () {
121+ if unicode .IsPrint (r ) {
122+ c .pairInput += string (r )
123+ }
124+ }
125+ }
126+ return c , nil
127+ }
128+
93129 // rename mode — capture input
94130 if c .renaming {
95131 switch msg .String () {
@@ -153,6 +189,10 @@ func (c Connections) handleKey(msg tea.KeyPressMsg) (Screen, tea.Cmd) {
153189 return ConnectionActionMsg {Err : client .DismissDevice (id )}
154190 }
155191 }
192+ case "p" :
193+ c .pairing = true
194+ c .pairInput = ""
195+ c .notice = ""
156196 }
157197 return c , nil
158198}
@@ -163,9 +203,9 @@ func (c Connections) View(width, height int) string {
163203 Render (fmt .Sprintf ("error: %v" , c .err ))
164204 }
165205
166- // reserve 2 rows at the bottom for the rename bar when active
206+ // reserve 2 rows at the bottom for the rename/pair bar when active
167207 contentH := height
168- if c .renaming {
208+ if c .renaming || c . pairing {
169209 contentH -= 2
170210 }
171211
@@ -206,11 +246,14 @@ func (c Connections) View(width, height int) string {
206246
207247 content := strings .Join (rows [:min (len (rows ), contentH )], "\n " )
208248
249+ divider := c .theme .Border .Render (strings .Repeat ("─" , width ))
250+ cur := c .theme .Accent .Render ("█" )
251+ prefix := c .theme .Accent .Render ("> " )
209252 if c .renaming {
210- divider := c . theme . Border . Render ( strings . Repeat ( "─" , width ))
211- prefix := c . theme . Accent . Render ( "> " )
212- cursor := c . theme . Accent . Render ( "█" )
213- bar := prefix + c .renameInput + cursor
253+ bar := prefix + c . renameInput + cur
254+ content = content + " \n " + divider + " \n " + bar
255+ } else if c . pairing {
256+ bar := prefix + c .pairInput + cur
214257 content = content + "\n " + divider + "\n " + bar
215258 }
216259
@@ -293,13 +336,14 @@ func (c Connections) Title() string {
293336}
294337
295338func (c Connections ) CapturesKey (msg tea.KeyPressMsg ) bool {
296- return c .renaming
339+ return c .renaming || c . pairing
297340}
298341
299342func (c Connections ) KeyBindings () []key.Binding {
300343 return []key.Binding {
301344 key .NewBinding (key .WithKeys ("j" , "k" ), key .WithHelp ("j/k" , "navigate" )),
302345 key .NewBinding (key .WithKeys ("r" ), key .WithHelp ("r" , "rename device" )),
346+ key .NewBinding (key .WithKeys ("p" ), key .WithHelp ("p" , "pair by device ID" )),
303347 key .NewBinding (key .WithKeys ("a" ), key .WithHelp ("a" , "accept pending" )),
304348 key .NewBinding (key .WithKeys ("d" ), key .WithHelp ("d" , "dismiss pending" )),
305349 }
0 commit comments