readline: clear the screen on ctrl+l

pull/1822/head
Henrixounez 2019-09-02 13:14:40 +02:00 committed by Alexander Medvednikov
parent 892c948a44
commit 9b8de9b59c
1 changed files with 9 additions and 0 deletions

View File

@ -59,6 +59,7 @@ enum Action {
history_previous
history_next
overwrite
clear_screen
}
// Toggle raw mode of the terminal by changing its attributes
@ -128,6 +129,7 @@ fn (r Readline) analyse(c byte) Action {
case 255 : return Action.eof
case `\n`: return Action.commit_line
case `\r`: return Action.commit_line
case `\f`: return Action.clear_screen // CTRL + L
case `\b`: return Action.delete_left // Backspace
case 127 : return Action.delete_left // DEL
case 27 : return r.analyse_control() // ESC
@ -189,6 +191,7 @@ fn (r mut Readline) execute(a Action, c byte) bool {
case Action.move_cursor_end: r.move_cursor_end()
case Action.move_cursor_word_left: r.move_cursor_word_left()
case Action.move_cursor_word_right: r.move_cursor_word_right()
case Action.clear_screen: r.clear_screen()
}
return false
}
@ -340,3 +343,9 @@ fn (r mut Readline) move_cursor_word_right() {
r.refresh_line()
}
}
fn (r mut Readline) clear_screen() {
term.set_cursor_position(1, 1)
term.erase_clear()
r.refresh_line()
}