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