mirror of
https://github.com/vlang/v.git
synced 2025-09-16 10:57:25 -04:00
vrepl: fix os.input() (#21811)
This commit is contained in:
parent
4475759c35
commit
1571645b00
@ -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)
|
||||
|
9
vlib/v/slow_tests/repl/input.repl
Normal file
9
vlib/v/slow_tests/repl/input.repl
Normal file
@ -0,0 +1,9 @@
|
||||
mut s := os.input('aaa:')
|
||||
hello
|
||||
s
|
||||
s = os.input('bbb:')
|
||||
world
|
||||
s
|
||||
===output===
|
||||
hello
|
||||
world
|
Loading…
x
Reference in New Issue
Block a user