Skip to content

Commit 13066a1

Browse files
Ctrl C behaviour mimics bash (#192)
1 parent d378d6a commit 13066a1

1 file changed

Lines changed: 6 additions & 8 deletions

File tree

internal/terminal/terminal.go

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ import (
2323
)
2424

2525
var (
26-
ErrCtrlC = errors.New("ctrl + C")
2726
ErrCtrlD = errors.New("ctrl + D")
2827
)
2928

@@ -497,9 +496,6 @@ func (t *Terminal) Run() error {
497496
//This will break if the user does CTRL+D apparently we need to reset the whole terminal if a user does this.... so just exit instead
498497
line, err := t.ReadLine()
499498
if err != nil {
500-
if err == ErrCtrlC {
501-
continue
502-
}
503499
return err
504500
}
505501

@@ -926,6 +922,12 @@ func (t *Terminal) handleKey(key rune) (line string, ok bool) {
926922
t.cursorX, t.cursorY = 0, 0
927923
t.advanceCursor(visualLength(t.prompt))
928924
t.setLine(t.line, t.pos)
925+
case keyCtrlC:
926+
t.queue([]rune("^C\r\n"))
927+
t.queue(t.prompt)
928+
t.cursorX = 0
929+
t.advanceCursor(visualLength(t.prompt))
930+
t.setLine([]rune{}, 0)
929931
default:
930932
if t.AutoCompleteCallback != nil {
931933
prefix := string(t.line[:t.pos])
@@ -1125,10 +1127,6 @@ func (t *Terminal) readLine() (line string, err error) {
11251127
return "", ErrCtrlD
11261128
}
11271129
}
1128-
if key == keyCtrlC {
1129-
t.remainder = nil
1130-
return "", ErrCtrlC
1131-
}
11321130
if key == keyPasteStart {
11331131
t.pasteActive = true
11341132
if len(t.line) == 0 {

0 commit comments

Comments
 (0)