Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added ability to toggle compact mode on/off with the single letter 'M… #237

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ Misc:
- `C`: toggle compiled mode
- `L`: toggle showing lowered code instead of source code
- `+`/`-`: increase / decrease the number of lines of source code shown
- `M`: toggle compact mode display. Compact mode removes common leading white space

Stepping (basic):
- `n`: step to the next line
Expand Down
1 change: 1 addition & 0 deletions src/commands.jl
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@ function execute_command(state::DebuggerState, ::Union{Val{:help}, Val{:?}}, cmd
- `C`: toggle compiled mode\\
- `L`: toggle showing lowered code instead of source code\\
- `+`/`-`: increase / decrease the number of lines of source code shown\\
- `M`: toggle compact mode display. Compact mode removes common leading white space\\


Stepping (basic):\\
Expand Down
29 changes: 16 additions & 13 deletions src/printing.jl
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ function print_status(io::IO, frame::Frame; force_lowered=false)
end

const NUM_SOURCE_LINES_UP_DOWN = Ref(4)
const COMPACT_MODE = Ref(true)

function print_codeinfo(io::IO, frame::Frame)
src = frame.framecode.src
Expand Down Expand Up @@ -258,20 +259,22 @@ function print_lines(io, code, current_line, breakpoint_lines, startline)
end
stopline = startline + length(code) - 1

# Count indentation level (only count spaces for now)
min_indentation = typemax(Int)
for textline in code
all(isspace, textline) && continue
isempty(textline) && continue
indent_line = 0
for char in textline
char != ' ' && break
indent_line += 1
if COMPACT_MODE[]
# Count indentation level (only count spaces for now)
min_indentation = typemax(Int)
for textline in code
all(isspace, textline) && continue
isempty(textline) && continue
indent_line = 0
for char in textline
char != ' ' && break
indent_line += 1
end
min_indentation = min(min_indentation, indent_line)
end
for i in 1:length(code)
code[i] = code[i][min_indentation+1:end]
end
min_indentation = min(min_indentation, indent_line)
end
for i in 1:length(code)
code[i] = code[i][min_indentation+1:end]
end
lineno = startline
stoplinelength = ndigits(stopline)
Expand Down
11 changes: 11 additions & 0 deletions src/repl.jl
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,18 @@ function RunDebugger(frame, repl = nothing, terminal = nothing; initial_continue
else
LineEdit.edit_insert(s, "-")
end
end,
'M' => function (s, args...)
if isempty(s) || position(LineEdit.buffer(s)) == 0
COMPACT_MODE[] = !COMPACT_MODE[]
println(Base.pipe_writer(terminal))
print_status(Base.pipe_writer(terminal), active_frame(state); force_lowered=state.lowered_status)
LineEdit.write_prompt(state.terminal, panel)
else
LineEdit.edit_insert(s, "-")
end
end

)

state.standard_keymap = Dict{Any,Any}[skeymap, LineEdit.history_keymap, LineEdit.default_keymap, LineEdit.escape_defaults]
Expand Down