Skip to content

Commit 3a41ba1

Browse files
committed
refactor: refactor Ctrl+C handler into bye function
- Add a new `bye` function to handle Ctrl+C exit with "Bye!" message - Replace inline Ctrl+C handler with the new `bye` function Signed-off-by: wecoding <wecoding@yeah.net>
1 parent 19a584b commit 3a41ba1

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

internal/ui/console/key_bindings.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@ var deleteWholeLine = func(p *prompt.Prompt) bool {
1313
return true
1414
}
1515

16+
var bye = func(p *prompt.Prompt) bool {
17+
fmt.Println("Bye!")
18+
os.Exit(0)
19+
return true
20+
}
21+
1622
func makeNecessaryKeyBindings() []prompt.KeyBind {
1723
keyBinds := []prompt.KeyBind{
1824
{
@@ -25,11 +31,7 @@ func makeNecessaryKeyBindings() []prompt.KeyBind {
2531
},
2632
{
2733
Key: prompt.ControlC,
28-
Fn: func(b *prompt.Prompt) bool {
29-
fmt.Println("Bye!")
30-
os.Exit(0)
31-
return true
32-
},
34+
Fn: bye,
3335
},
3436
}
3537

0 commit comments

Comments
 (0)