Implement clear screen c-l binding

This commit is contained in:
Kovid Goyal 2022-10-25 09:40:12 +05:30
parent 19bf07abd9
commit b7816d26be
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
4 changed files with 13 additions and 1 deletions

View File

@ -252,6 +252,10 @@ func (self *Loop) AllowLineWrapping(allow bool) {
} }
} }
func (self *Loop) ClearScreen() {
self.QueueWriteString("\x1b[H\x1b[2J")
}
func (self *Loop) Quit(exit_code int) { func (self *Loop) Quit(exit_code int) {
self.exit_code = exit_code self.exit_code = exit_code
self.keep_going = false self.keep_going = false

View File

@ -429,7 +429,12 @@ func (self *Readline) perform_action(ac Action, repeat_count uint) error {
} }
} }
return self.perform_action(ActionCursorDown, repeat_count) return self.perform_action(ActionCursorDown, repeat_count)
case ActionClearScreen:
self.loop.StartAtomicUpdate()
self.loop.ClearScreen()
self.RedrawNonAtomic()
self.loop.EndAtomicUpdate()
return nil
} }
return ErrCouldNotPerformAction return ErrCouldNotPerformAction
} }

View File

@ -55,6 +55,7 @@ const (
ActionHistoryNextOrCursorDown ActionHistoryNextOrCursorDown
ActionHistoryNext ActionHistoryNext
ActionHistoryPrevious ActionHistoryPrevious
ActionClearScreen
) )
type Readline struct { type Readline struct {

View File

@ -35,6 +35,8 @@ var default_shortcuts = map[string]Action{
"right": ActionCursorRight, "right": ActionCursorRight,
"ctrl+f": ActionCursorRight, "ctrl+f": ActionCursorRight,
"ctrl+l": ActionClearScreen,
"ctrl+d": ActionEndInput, "ctrl+d": ActionEndInput,
"enter": ActionAcceptInput, "enter": ActionAcceptInput,
} }