Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 21 additions & 8 deletions src/commands.jl
Original file line number Diff line number Diff line change
Expand Up @@ -76,23 +76,36 @@ end

function stacklength(frame)
s = 0
JuliaInterpreter.traverse(fr -> (s += 1; JuliaInterpreter.caller(fr)), JuliaInterpreter.leaf(frame))
while frame !== nothing
s += 1
frame = caller(frame)
end
return s
end

execute_command(state::DebuggerState, ::Val{:st}, cmd) = true

function execute_command(state::DebuggerState, ::Union{Val{:f}, Val{:fr}}, cmd)
subcmds = split(cmd,' ')[2:end]
if isempty(subcmds) || subcmds[1] == "v"
print_frame(Base.pipe_writer(state.terminal), state.level, active_frame(state))
return false
subcmds = split(cmd, ' ')
if length(subcmds) == 1
new_level = 1
else
new_level = parse(Int, subcmds[1])
if new_level > stacklength(state.frame) || new_level < 1
printstyled(stderr, "Not a valid frame index\n"; color=:red)
new_level = tryparse(Int, subcmds[2])
if new_level == nothing
printstyled(stderr, "Failed to parse $(subcmds[2]) as an integer\n"; color=:red)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
printstyled(stderr, "Failed to parse $(subcmds[2]) as an integer\n"; color=:red)
printstyled(stderr, "Failed to parse $(repr(subcmds[2])) as an integer\n"; color=:red)

return false
end
end

if new_level > stacklength(state.frame) || new_level < 1
printstyled(stderr, "Not a valid frame index\n"; color=:red)
return false
end

if subcmds[1] == "f"
print_frame(Base.pipe_writer(state.terminal), new_level, state.frame)
return false
else
state.level = new_level
return true
end
Expand Down
1 change: 1 addition & 0 deletions test/ui.jl
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ end
run_terminal_test(@make_frame(my_gcd(10, 20)),
["n\n","`", "my_gc\t\n", "a\n", UP_ARROW, UP_ARROW, UP_ARROW, CTRL_C,
"w add a\n", "w add sin(a)\n", "w add b\n", "w\n", "w rm 1\n", "w\n",
"s\n", "f 1\n", "f 2\n", "fr 2\n", "fr 1\n",
"bt\n", "st\n", "c\n", "c\n"],
"ui/history_gcd.multiout")

Expand Down
Loading