Skip to content

Commit e302d48

Browse files
authored
show breakpoints in source code, also remove some bold (#94)
1 parent c8771c0 commit e302d48

File tree

3 files changed

+819
-804
lines changed

3 files changed

+819
-804
lines changed

src/printing.jl

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,21 @@ function print_next_expr(io::IO, frame::Frame)
7373
println(io)
7474
end
7575

76+
function breakpoint_linenumbers(frame::Frame)
77+
framecode = frame.framecode
78+
breakpoint_lines = Int[]
79+
for stmtidx in 1:length(framecode.breakpoints)
80+
isassigned(framecode.breakpoints, stmtidx) || continue
81+
bp = framecode.breakpoints[stmtidx]
82+
push!(breakpoint_lines, JuliaInterpreter.linenumber(frame, stmtidx))
83+
end
84+
return breakpoint_lines
85+
end
86+
7687
function print_status(io::IO, frame::Frame)
7788
# Buffer to avoid flickering
7889
outbuf = IOContext(IOBuffer(), io)
79-
printstyled(outbuf, "In ", locdesc(frame), "\n"; color=:bold)
90+
printstyled(outbuf, "In ", locdesc(frame), "\n")
8091
loc = locinfo(frame)
8192

8293
if loc !== nothing
@@ -85,7 +96,8 @@ function print_status(io::IO, frame::Frame)
8596
else
8697
read(loc.filepath, String)
8798
end
88-
print_sourcecode(outbuf, data, loc.line, loc.defline)
99+
breakpoint_lines = breakpoint_linenumbers(frame)
100+
print_sourcecode(outbuf, data, loc.line, loc.defline, breakpoint_lines)
89101
else
90102
print_codeinfo(outbuf, frame)
91103
end
@@ -110,9 +122,9 @@ function print_codeinfo(io::IO, frame::Frame)
110122

111123
color = (lineno < active_line) ? :white : :normal
112124
if lineno == active_line
113-
printstyled(io, rpad(lineno, 4), bold = true, color = :yellow)
125+
printstyled(io, rpad(lineno, 4), color = :yellow)
114126
else
115-
printstyled(io, rpad(lineno, 4), bold = true, color = color)
127+
printstyled(io, rpad(lineno, 4), color = color)
116128
end
117129
printstyled(io, line, color = color)
118130
println(io)
@@ -188,13 +200,13 @@ end
188200

189201
const RESET = Crayon(reset = true)
190202

191-
function print_sourcecode(io::IO, code::String, line::Integer, defline::Integer)
203+
function print_sourcecode(io::IO, code::String, line::Integer, defline::Integer, breakpoint_lines::Vector{Int} = [])
192204
code = highlight_code(code; context=io)
193205
file = SourceFile(code)
194206
startoffset, stopoffset = compute_source_offsets(code, file.offsets[line], defline, line+NUM_SOURCE_LINES_UP_DOWN[]; file=file)
195207

196208
if startoffset == -1
197-
printstyled(io, "Line out of file range (bad debug info?)", color=:bold)
209+
printstyled(io, "Line out of file range (bad debug info?)")
198210
return
199211
end
200212

@@ -214,6 +226,7 @@ function print_sourcecode(io::IO, code::String, line::Integer, defline::Integer)
214226
# Count indentation level (only count spaces for now)
215227
min_indentation = typemax(Int)
216228
for textline in code
229+
isempty(textline) && continue
217230
indent_line = 0
218231
for char in textline
219232
char != ' ' && break
@@ -225,15 +238,17 @@ function print_sourcecode(io::IO, code::String, line::Integer, defline::Integer)
225238
code[i] = code[i][min_indentation+1:end]
226239
end
227240

228-
stoplinelength += stoplinelength == ndigits(current_line)
241+
filter!(x -> x in(startline:stopline), breakpoint_lines)
242+
229243
for textline in code
230-
prefix = lineno == current_line ? ">" :
231-
ndigits(lineno) > ndigits(current_line) ?
232-
"" :
233-
" "
244+
break_on_line = lineno in breakpoint_lines
245+
prefix = (" ", :normal)
246+
break_on_line && (prefix = ("", :light_red))
247+
lineno == current_line && (prefix = (">", :yellow))
234248
printstyled(io,
235-
string(lpad(string(prefix, lineno), stoplinelength , " "), " "),
236-
color = lineno == current_line ? :yellow : :bold)
249+
string(prefix[1], lpad(lineno, stoplinelength), " "),
250+
color = prefix[2])
251+
237252
println(io, textline)
238253
lineno += 1
239254
end

0 commit comments

Comments
 (0)