From 823c93bbf0a620878c2e8ab7ed9e8889fdaa00ca Mon Sep 17 00:00:00 2001 From: Don MacMillen Date: Wed, 11 Dec 2019 13:02:04 -0800 Subject: [PATCH] Added ability to toggle compact mode on/off with the single letter 'M' debugger command. Compact mode removes common leading white space from the line listing --- README.md | 1 + src/commands.jl | 1 + src/printing.jl | 29 ++++++++++++++++------------- src/repl.jl | 11 +++++++++++ 4 files changed, 29 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index e3c5493..52869a9 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/src/commands.jl b/src/commands.jl index 4c64b81..cd9f3e6 100644 --- a/src/commands.jl +++ b/src/commands.jl @@ -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):\\ diff --git a/src/printing.jl b/src/printing.jl index 5dade8f..2d8691c 100644 --- a/src/printing.jl +++ b/src/printing.jl @@ -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 @@ -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) diff --git a/src/repl.jl b/src/repl.jl index 77cb74f..2218b61 100644 --- a/src/repl.jl +++ b/src/repl.jl @@ -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]