Skip to content
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
6 changes: 3 additions & 3 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,19 @@ version = "0.7.16"

[deps]
CodeTracking = "da1fd8a2-8d9e-5ec2-8556-3022fb5608a2"
Crayons = "a8cc5b0e-0ffa-5ad4-8c14-923d3ee1735f"
Highlights = "eafb193a-b7ab-5a9e-9068-77385905fa72"
InteractiveUtils = "b77e0a4c-d291-57a0-90e8-8db25a27a240"
JuliaInterpreter = "aa1ae85d-cabe-5617-a682-6adf51b2e16a"
Markdown = "d6f4376e-aef5-505a-96c1-9c027394607a"
REPL = "3fa0cd96-eef1-5676-8a61-b3b8758bbffb"
tree_sitter_julia_jll = "52be201e-a5e9-5cfe-8bf2-2dc4b062171c"
Copy link
Member

Choose a reason for hiding this comment

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

What is this for?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

the new highlighter version requires users depend on treesitter jlls for the languages that they highlight

Copy link
Member

Choose a reason for hiding this comment

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

Maybe we can load the package and use the

using tree_sitter_julia_jll
highlight(code, tree_sitter_julia_jll, "Dracula")

format? It just feels strange to depend on a package and then not load it..

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm fine with that. I agree that it's a little weird to depend but not load.


[compat]
CodeTracking = "2, 3"
Crayons = "4.1"
Highlights = "0.4.3, 0.5"
Highlights = "0.6"
JuliaInterpreter = "0.10"
julia = "1.6"
tree_sitter_julia_jll = "0.25.0"

[extras]
TerminalRegressionTests = "98bfdc55-cc95-5876-a49a-74609291cbe0"
Expand Down
7 changes: 2 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -238,11 +238,8 @@ union!(JuliaInterpreter.compiled_modules, SomePackage)
### Syntax highlighting

The source code preview is syntax highlighted and this highlighting has some options.
The theme can be set by calling `Debugger.set_theme(theme)` where `theme` is a [Highlights.jl theme](https://juliadocs.github.io/Highlights.jl/stable/demo/themes/).
It can be completely turned off or alternatively, different quality settings for the colors might be chosen by calling `Debugger.set_highlight(opt)` where `opt` is a `Debugger.HighlightOption` enum.
The choices are `HIGHLIGHT_OFF` `HIGHLIGHT_SYSTEM_COLORS`, `HIGHLIGHT_256_COLORS`, `HIGHLIGHT_24_BIT`. System colors works in pretty much all terminals, 256 in most terminals (with the exception of Windows)
and 24 bit in some terminals.

The theme can be set by calling `Debugger.set_theme(theme)` where `theme` is a [Highlights.jl theme](https://highlights.juliadocs.org/dev/themes/).
It can be completely turned off by calling `Debugger.set_highlight(false)`

[travis-img]: https://travis-ci.org/JuliaDebug/Debugger.jl.svg?branch=master
[travis-url]: https://travis-ci.org/JuliaDebug/Debugger.jl
Expand Down
1 change: 0 additions & 1 deletion src/Debugger.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
module Debugger

using Highlights
using Crayons
import InteractiveUtils

using Markdown
Expand Down
47 changes: 11 additions & 36 deletions src/printing.jl
Original file line number Diff line number Diff line change
Expand Up @@ -202,43 +202,21 @@ function compute_source_offsets(code::AbstractString, current_offsetline::Intege
startoffset, stopoffset
end

@enum HighlightOption begin
HIGHLIGHT_OFF
HIGHLIGHT_SYSTEM_COLORS
HIGHLIGHT_256_COLORS
HIGHLIGHT_24_BIT
end

const _syntax_highlighting = Ref(Sys.iswindows() ? HIGHLIGHT_SYSTEM_COLORS : HIGHLIGHT_256_COLORS)
const _current_theme = Ref{Type{<:Highlights.AbstractTheme}}(Highlights.Themes.MonokaiMiniTheme)
# TODO: Remove on next breaking change. These exist for back compat
const HIGHLIGHT_OFF = false
const HIGHLIGHT_SYSTEM_COLORS = true
const HIGHLIGHT_256_COLORS = true
const HIGHLIGHT_24_BIT = true

set_theme(theme::Type{<:Highlights.AbstractTheme}) = _current_theme[] = theme
set_highlight(opt::HighlightOption) = _syntax_highlighting[] = opt

function Format.render(io::IO, ::MIME"text/ansi-debugger", tokens::Format.TokenIterator)
for (str, id, style) in tokens
fg = style.fg.active ? map(Int, (style.fg.r, style.fg.g, style.fg.b)) : nothing
bg = style.bg.active ? map(Int, (style.bg.r, style.bg.g, style.bg.b)) : nothing
crayon = Crayon(
foreground = fg,
background = bg,
bold = style.bold ? true : nothing,
italics = style.italic ? true : nothing,
underline = style.underline ? true : nothing,
)
if _syntax_highlighting[] == HIGHLIGHT_256_COLORS
crayon = Crayons.to_256_colors(crayon)
elseif _syntax_highlighting[] == HIGHLIGHT_SYSTEM_COLORS
crayon = Crayons.to_system_colors(crayon)
end
print(io, crayon, str, inv(crayon))
end
end
const _syntax_highlighting = Ref(true)
const _current_theme = Ref("Monokai Dark")
set_theme(theme::String) = _current_theme[] = theme
set_highlight(opt::Bool) = _syntax_highlighting[] = opt

function highlight_code(code; context=nothing)
if _syntax_highlighting[] != HIGHLIGHT_OFF
if _syntax_highlighting[]
try
sprint(highlight, MIME("text/ansi-debugger"), code, Lexers.JuliaLexer, _current_theme[]; context=context)
sprint(highlight, MIME("text/ansi"), code, :julia, _current_theme[]; context=context)
catch e
printstyled(stderr, "failed to highlight code, $e\n"; color=Base.warn_color())
return code
Expand All @@ -248,8 +226,6 @@ function highlight_code(code; context=nothing)
end
end


const RESET = Crayon(reset = true)
function breakpoint_char(bp::BreakpointState)
if bp.isactive
return bp.condition === JuliaInterpreter.truecondition ? '●' : '◐'
Expand Down Expand Up @@ -314,6 +290,5 @@ function print_lines(io, code, current_line, breakpoint_lines, startline)
println(io, textline)
lineno += 1
end
_syntax_highlighting[] == HIGHLIGHT_OFF || print(io, RESET)
println(io)
end
4 changes: 2 additions & 2 deletions test/misc.jl
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,10 @@ defline, deffile, current_line, body = Debugger.locinfo(state.frame)
f_unicode() = √

try
Debugger.set_highlight(Debugger.HIGHLIGHT_SYSTEM_COLORS)
Debugger.set_highlight(true)
frame = Debugger.@make_frame f()
st = chomp(sprint(Debugger.print_status, frame; context = :color => true))
x_1_plus_1_colored = "x \e[91m=\e[39m 1 \e[91m+\e[39m"
x_1_plus_1_colored = "x\e[0m \e[38;2;249;248;245m=\e[0m \e[38;2;244;191;117m1\e[0m \e[38;2;249;248;245m+\e[0m \e[38;2;244;191;117m"
@test occursin(x_1_plus_1_colored, st)

frame = Debugger.@make_frame f_unicode()
Expand Down
Loading