From 9d71a54a615224ad0c7dd3ee7aaa834eea0f03bb Mon Sep 17 00:00:00 2001 From: zakuro Date: Sun, 27 Dec 2020 19:41:48 +0900 Subject: [PATCH] repl: fix readline history (#7596) --- cmd/tools/vrepl.v | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/cmd/tools/vrepl.v b/cmd/tools/vrepl.v index 84a90f351b..ad029498f8 100644 --- a/cmd/tools/vrepl.v +++ b/cmd/tools/vrepl.v @@ -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 }