diff --git a/codecov.yaml b/codecov.yaml index ec25b4419..f5bc6aa9f 100644 --- a/codecov.yaml +++ b/codecov.yaml @@ -2,5 +2,6 @@ ignore: - "./src/errors.jl" - "./src/_errors.jl" + - "./src/__precompilation.jl" - "./test" - "./scripts" \ No newline at end of file diff --git a/scripts/inspector_gadget.jl b/scripts/inspector_gadget.jl index afd8360cb..29be1875a 100644 --- a/scripts/inspector_gadget.jl +++ b/scripts/inspector_gadget.jl @@ -3,4 +3,4 @@ modules(m::Module) = ccall(:jl_module_usings, Any, (Any,), m) """ Write some function to define all functions and types in a module an submodules. And a "search" function -""" \ No newline at end of file +""" diff --git a/src/Term.jl b/src/Term.jl index 0b21e8842..f60f8efcd 100644 --- a/src/Term.jl +++ b/src/Term.jl @@ -159,7 +159,7 @@ Measures.Measure(segments::AbstractVector) = end # ---------------------------------- others ---------------------------------- # -using .Errors: install_term_stacktrace +using .Errors: install_term_stacktrace, render_backtrace, StacktraceContext using .Logs: install_term_logger, uninstall_term_logger, TermLogger diff --git a/src/__precompilation.jl b/src/__precompilation.jl index dd9a5ffa7..e1857118d 100644 --- a/src/__precompilation.jl +++ b/src/__precompilation.jl @@ -2,9 +2,6 @@ # ---------------------------------------------------------------------------- # # PRECOMPILATION # # ---------------------------------------------------------------------------- # -originalSTDOUT = stdout -(outRead, outWrite) = redirect_stdout() - using SnoopPrecompile SnoopPrecompile.verbose[] = false @@ -13,22 +10,186 @@ SnoopPrecompile.verbose[] = false repeat(["this is a random {red}text{/red} to test {bold}precompilation"], 10), "\n", ) - print(txt) + + mdtext = md""" + # Markdown rendering in Term.jl + ## two + ### three + #### four + ##### five + ###### six + + This is an example of markdown content rendered in Term.jl. + You can use markdown syntax to make words **bold** and *italic* or insert `literals`. + + + You markdown can include in-line latex ``\LaTeX \frac{{1}}{{2}}`` and maths in a new line too: + + ```math + f(a) = \frac{1}{2\pi}\int_{0}^{2\pi} (\alpha+R\cos(\theta))d\theta + ``` + + You can also have links: [Julia](http://www.julialang.org) and + footnotes [^1] for your content [^named]. + + And, of course, you can show some code too: + + ```julia + function say_hi(x) + print("Hellow World") + end + ``` + + --- + + You can use "quotes" to highlight a section: + + > Multi-line quotes can be helpful to make a + > paragram stand out, so that users won't miss it! + > You can use **other inline syntax** in you `quotes` too. + + but if you really need to grab someone's attention, use admonitions: + + !!! note + You can use different levels + + !!! warning + to send different messages + + !!! danger + to your reader + + !!! tip "Wow!" + Turns out that admonitions can be pretty useful! + What will you use them for? + + --- + + Of course you can have classic lists: + * item one + * item two + * And a sublist: + + sub-item one + + sub-item two + + and ordered lists too: + 1. item one + 2. item two + 3. item three + + + !!! note "Tables" + You can use the [Markdown table syntax](https://www.markdownguide.org/extended-syntax/#tables) + to insert tables - Term.jl will convert them to Table object! + + | Term | handles | tables| + |:---------- | ---------- |:------------:| + | Row `1` | Column `2` | | + | *Row* 2 | **Row** 2 | Column ``3`` | + + + ---- + + This is where you print the content of your foot notes: + + [^1]: Numbered footnote text. + + [^note]: + Named footnote text containing several toplevel elements. + """ + + code = """ +function render( +content::Union{Renderable,RenderableText}; +box::Symbol = TERM_THEME[].box, +style::String = TERM_THEME[].line, +title::Union{String,Nothing} = nothing, +title_style::Union{Nothing,String} = nothing, +Δh::Int, +padding::Padding, +background::Union{Nothing,String} = nothing, +kwargs..., +)::Panel +background = get_bg_color(background) +# @info "calling render" content content_measure background + +# create top/bottom rows with titles +box = BOXES[box] # get box object from symbol +top = get_title_row( + :top, + box; + title_style = title_style, + justify = title_justify, +) + +bottom = get_title_row( + :bottom, + box, + subtitle; + width = panel_measure.w, +) + +# get left/right vertical lines +σ(s) = apply_style("\e[0m{" * style * "}" * s * "{/" * style * "}") +left, right = σ(box.mid.left), σ(box.mid.right) + +# get an empty padding line +empty = if isnothing(background) + [Segment(left * " "^(panel_measure.w - 2) * right)] +else + [Segment(left * "{background}" * " "^(panel_measure.w - 2) * "{/background}" * right)] +end +""" + + junkio = IOBuffer() # from https://github.com/timholy/SnoopCompile.jl/issues/308 @precompile_all_calls begin reshape_text(txt, 10) - Panel() |> tprint + print(junkio, Panel()) + tprint(junkio, Panel()) - Panel(txt; fit = false, width = 25) |> tprint - Panel(txt; fit = true) |> tprint + print(junkio, Panel(txt; fit = false, justify = :right, width = 25)) + print( + junkio, + Panel( + txt; + fit = true, + title = "test", + subtitle = "test", + style = "red on_blue", + background = "blue", + ), + ) r = RenderableText(txt; width = 30, style = "red") r2 = RenderableText(txt) p = Panel(txt) r * p r / p + + hLine(10) + hLine(100, "test"; style = "red") + vLine() + + tprintln(junkio, mdtext) + + # repr + termshow(junkio, Panel) + termshow(junkio, print) + termshow(junkio, zeros(100)) + termshow(junkio, zeros(100, 100)) + termshow(junkio, zeros(100, 100, 10)) + + # errors + ctx = StacktraceContext() + bt = backtrace() + + render_backtrace(ctx, bt) + render_backtrace(ctx, bt; hide_frames = false) + + code_h = highlight_syntax(code; style = true) + reshape_code_string(code_h, 30) + + load_code_and_highlight("src/panels.jl", 20) end end - -close(outRead) -redirect_stdout(originalSTDOUT)