diff --git a/cmd/tools/vrepl.v b/cmd/tools/vrepl.v index 998f14fe6a..41a79ea5c7 100644 --- a/cmd/tools/vrepl.v +++ b/cmd/tools/vrepl.v @@ -422,13 +422,11 @@ fn run_repl(workdir string, vrepl_prefix string) int { } continue } - // Save the source only if the user is printing something, - // but don't add this print call to the `lines` array, - // so that it doesn't get called during the next print. if r.line.starts_with('=') { r.line = 'println(' + r.line[1..] + ')' } if r.line.starts_with('print(') || r.line.starts_with('println(') { + // >>> println('hello') source_code := r.current_source_code(false, false) + '\n${r.line}\n' os.write_file(temp_file, source_code) or { panic(err) } s := repl_run_vfile(temp_file) or { return 1 } @@ -440,6 +438,17 @@ fn run_repl(workdir string, vrepl_prefix string) int { r.lines << r.line } } + } else if r.line.contains('os.input(') { + // >>> s := os.input('name: ') + prompt_str := r.line.all_after('os.input(').all_before(')').trim('\'"') + line_t := r.get_one_line(prompt_str) or { break }.trim_right('\n') + trans_line := r.line.all_before('os.input(') + "'${line_t}'" + source_code := r.current_source_code(false, false) + '\n${trans_line}\n' + os.write_file(temp_file, source_code) or { panic(err) } + s := repl_run_vfile(temp_file) or { return 1 } + if s.exit_code == 0 { + r.lines << trans_line + } } else { mut temp_line := r.line func_call, fntype := r.function_call(r.line) diff --git a/vlib/v/slow_tests/repl/input.repl b/vlib/v/slow_tests/repl/input.repl new file mode 100644 index 0000000000..85cd919d3f --- /dev/null +++ b/vlib/v/slow_tests/repl/input.repl @@ -0,0 +1,9 @@ +mut s := os.input('aaa:') +hello +s +s = os.input('bbb:') +world +s +===output=== +hello +world