Map ctrl+c to abort the current line

This commit is contained in:
Kovid Goyal
2022-11-05 12:32:02 +05:30
parent 67b12159f4
commit 13a266aa42
3 changed files with 11 additions and 2 deletions

View File

@@ -584,12 +584,12 @@ func (self *Readline) perform_action(ac Action, repeat_count uint) error {
return nil
}
case ActionHistoryPreviousOrCursorUp:
if self.perform_action(ActionCursorUp, repeat_count) != nil {
if self.perform_action(ActionCursorUp, repeat_count) == ErrCouldNotPerformAction {
return self.perform_action(ActionHistoryPrevious, repeat_count)
}
return nil
case ActionHistoryNextOrCursorDown:
if self.perform_action(ActionCursorDown, repeat_count) != nil {
if self.perform_action(ActionCursorDown, repeat_count) == ErrCouldNotPerformAction {
return self.perform_action(ActionHistoryNext, repeat_count)
}
return nil
@@ -643,6 +643,10 @@ func (self *Readline) perform_action(ac Action, repeat_count uint) error {
if self.yank(repeat_count, true) {
return nil
}
case ActionAbortCurrentLine:
self.loop.QueueWriteString("\r\n")
self.ResetText()
return nil
}
return ErrCouldNotPerformAction
}

View File

@@ -60,6 +60,7 @@ const (
ActionHistoryLast
ActionClearScreen
ActionAddText
ActionAbortCurrentLine
ActionStartKillActions
ActionKillToEndOfLine

View File

@@ -49,10 +49,14 @@ var default_shortcuts = map[string]Action{
"ctrl+y": ActionYank,
"alt+y": ActionPopYank,
"up": ActionHistoryPreviousOrCursorUp,
"down": ActionHistoryNextOrCursorDown,
"ctrl+p": ActionHistoryPrevious,
"ctrl+n": ActionHistoryNext,
"alt+<": ActionHistoryFirst,
"alt+>": ActionHistoryLast,
"ctrl+c": ActionAbortCurrentLine,
}
func action_for_key_event(event *loop.KeyEvent, shortcuts map[string]Action) Action {