readline: give the possibility to ignore the empty line in the history (#13452)
parent
57e850e932
commit
bf11df40e2
|
@ -42,7 +42,9 @@ enum FnType {
|
||||||
|
|
||||||
fn new_repl() Repl {
|
fn new_repl() Repl {
|
||||||
return Repl{
|
return Repl{
|
||||||
readline: readline.Readline{}
|
readline: readline.Readline{
|
||||||
|
skip_empty: true
|
||||||
|
}
|
||||||
modules: ['os', 'time', 'math']
|
modules: ['os', 'time', 'math']
|
||||||
vstartup_lines: os.read_file(vstartup) or { '' }.trim_right('\n\r').split_into_lines()
|
vstartup_lines: os.read_file(vstartup) or { '' }.trim_right('\n\r').split_into_lines()
|
||||||
// Test file used to check if a function as a void return or a
|
// Test file used to check if a function as a void return or a
|
||||||
|
|
|
@ -28,6 +28,7 @@ mut:
|
||||||
prompt string
|
prompt string
|
||||||
prompt_offset int
|
prompt_offset int
|
||||||
previous_lines [][]rune
|
previous_lines [][]rune
|
||||||
|
skip_empty bool // skip the empty lines when calling .history_previous()
|
||||||
search_index int
|
search_index int
|
||||||
is_tty bool
|
is_tty bool
|
||||||
}
|
}
|
||||||
|
|
|
@ -551,9 +551,14 @@ fn (mut r Readline) history_previous() {
|
||||||
r.previous_lines[0] = r.current
|
r.previous_lines[0] = r.current
|
||||||
}
|
}
|
||||||
r.search_index++
|
r.search_index++
|
||||||
r.current = r.previous_lines[r.search_index]
|
prev_line := r.previous_lines[r.search_index]
|
||||||
r.cursor = r.current.len
|
if r.skip_empty && prev_line == [] {
|
||||||
r.refresh_line()
|
r.history_previous()
|
||||||
|
} else {
|
||||||
|
r.current = prev_line
|
||||||
|
r.cursor = r.current.len
|
||||||
|
r.refresh_line()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// history_next sets current line to the content of the next line in the history buffer.
|
// history_next sets current line to the content of the next line in the history buffer.
|
||||||
|
|
Loading…
Reference in New Issue