diff --git a/Project.toml b/Project.toml index 395b789..6eeff64 100644 --- a/Project.toml +++ b/Project.toml @@ -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" [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" diff --git a/README.md b/README.md index 813d3ea..bf79893 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/src/Debugger.jl b/src/Debugger.jl index b9b59bc..5756a8d 100644 --- a/src/Debugger.jl +++ b/src/Debugger.jl @@ -1,7 +1,6 @@ module Debugger using Highlights -using Crayons import InteractiveUtils using Markdown diff --git a/src/printing.jl b/src/printing.jl index 17365d7..5d8201a 100644 --- a/src/printing.jl +++ b/src/printing.jl @@ -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 @@ -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 ? '●' : '◐' @@ -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 diff --git a/test/misc.jl b/test/misc.jl index db879c8..762f276 100644 --- a/test/misc.jl +++ b/test/misc.jl @@ -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()