repl: implement list and reset commands
parent
6855996cca
commit
a3a19e899d
|
@ -62,6 +62,8 @@ fn repl_help() {
|
||||||
println(util.full_v_version())
|
println(util.full_v_version())
|
||||||
println('
|
println('
|
||||||
help Displays this information.
|
help Displays this information.
|
||||||
|
list Show the program so far.
|
||||||
|
reset Clears the accumulated program, so you can start a fresh.
|
||||||
Ctrl-C, Ctrl-D, exit Exits the REPL.
|
Ctrl-C, Ctrl-D, exit Exits the REPL.
|
||||||
clear Clears the screen.
|
clear Clears the screen.
|
||||||
')
|
')
|
||||||
|
@ -104,10 +106,10 @@ fn run_repl(workdir string, vrepl_prefix string) {
|
||||||
oline := readline.read_line(prompt) or {
|
oline := readline.read_line(prompt) or {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
if oline.trim_space() == '' && oline.ends_with('\n') {
|
line := oline.trim_space()
|
||||||
|
if line == '' && oline.ends_with('\n') {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
line := oline.trim_space()
|
|
||||||
if line.len <= -1 || line == '' || line == 'exit' {
|
if line.len <= -1 || line == '' || line == 'exit' {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
@ -141,6 +143,21 @@ fn run_repl(workdir string, vrepl_prefix string) {
|
||||||
}
|
}
|
||||||
r.line = ''
|
r.line = ''
|
||||||
}
|
}
|
||||||
|
if r.line == 'reset' {
|
||||||
|
r = Repl{}
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if r.line == 'list' {
|
||||||
|
mut all_lines := []string{}
|
||||||
|
all_lines << r.functions
|
||||||
|
all_lines << r.lines
|
||||||
|
all_lines << r.temp_lines
|
||||||
|
source_code := all_lines.join('\n')
|
||||||
|
println('//////////////////////////////////////////////////////////////////////////////////////')
|
||||||
|
println(source_code)
|
||||||
|
println('//////////////////////////////////////////////////////////////////////////////////////')
|
||||||
|
continue
|
||||||
|
}
|
||||||
// Save the source only if the user is printing something,
|
// Save the source only if the user is printing something,
|
||||||
// but don't add this print call to the `lines` array,
|
// but don't add this print call to the `lines` array,
|
||||||
// so that it doesn't get called during the next print.
|
// so that it doesn't get called during the next print.
|
||||||
|
|
Loading…
Reference in New Issue