repl: fix readline history (#7596)

pull/7606/head
zakuro 2020-12-27 19:41:48 +09:00 committed by GitHub
parent 79117f5581
commit 9d71a54a61
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 5 additions and 10 deletions

View File

@ -11,6 +11,7 @@ import v.util
struct Repl {
mut:
readline readline.Readline
indent int // indentation level
in_func bool // are we inside a new custom user function
line string // the current line entered by the user
@ -29,6 +30,7 @@ const (
fn new_repl() &Repl {
return &Repl{
readline: readline.Readline{}
modules: ['os', 'time', 'math']
}
}
@ -131,9 +133,7 @@ fn run_repl(workdir string, vrepl_prefix string) {
} else {
prompt = '... '
}
oline := r.get_one_line(prompt) or {
break
}
oline := r.get_one_line(prompt) or { break }
line := oline.trim_space()
if line == '' && oline.ends_with('\n') {
continue
@ -314,9 +314,7 @@ fn print_output(s os.Result) {
} else if line.contains('.vrepl.v:') {
// Ensure that .vrepl.v: is at the start, ignore the path
// This is needed to have stable .repl tests.
idx := line.index('.vrepl.v:') or {
return
}
idx := line.index('.vrepl.v:') or { return }
println(line[idx..])
} else {
println(line)
@ -347,7 +345,6 @@ fn rerror(s string) {
}
fn (mut r Repl) get_one_line(prompt string) ?string {
mut readline := readline.Readline{}
if is_stdin_a_pipe {
iline := os.get_raw_line()
if iline.len == 0 {
@ -355,8 +352,6 @@ fn (mut r Repl) get_one_line(prompt string) ?string {
}
return iline
}
rline := readline.read_line(prompt) or {
return none
}
rline := r.readline.read_line(prompt) or { return none }
return rline
}