Closed tecosaur closed 1 year ago
Very cool!
It can't go in this package, though, because this needs to stay extremely lightweight. It's the foundation for JuliaInterpreter, which is then a foundation for both the debuggers and for Revise. But an add-on package would make sense, or perhaps contributing that under a @require
to OhMyREPL?
Closing this simply because of the need to keep this package very lightweight, otherwise it's quite cool.
With weak deps I feel better about turning this into a PR based on weakdeps. Let's see if I can get around to that 🙂
Update: now that JuliaSyntaxHighlighting is about to be part of 1.11 (and I plan on making a compat release to General), it seems like the obvious lightweight way to do this.
As a weakdep, it will automatically be loaded in the REPL in 1.11+ (REPL > Markdown > JuliaSyntaxHighlighting
), which makes this seem like a very obvious/simple approach to take.
Hey, this seemed nifty so I made a variant macro
@code_src
that prints a syntax-highlighted@code_string
using OhMyREPL. I have no idea if optional dependencies are easy, or if this of interest, but just in case here's what I have:""" macro code_src(expr...) codestr = InteractiveUtils.gen_call_with_extracted_types_and_kwargs(CodeTracking, :code_string, expr) quote tokens = collect(Tokenize.tokenize($codestr)) crayons = Vector{Crayon}(undef, length(tokens)) fill!(crayons, Crayon()) OhMyREPL.Passes.SyntaxHighlighter.SYNTAX_HIGHLIGHTER_SETTINGS(crayons, tokens, 0) print(stdout, " ") OhMyREPL.untokenize_with_ANSI(crayons, tokens, 2) end end