### Install Term.jl Package Source: https://github.com/fedeclaudi/term.jl/blob/master/README.md This snippet shows how to install the Term.jl package using Julia's built-in package manager. It guides the user to enter the package interface and then add the Term package. ```Julia julia> ] # enters the pkg interface pkg> add Term ``` -------------------------------- ### Install Global REPL Representation Source: https://github.com/fedeclaudi/term.jl/blob/master/docs/src/adv/repr.md Shows how to install a global terminal representation handler using `install_term_repr()` from Term.jl. Once installed, any object displayed in the REPL will automatically use `termshow` for its representation. A warning is included against using this in production code intended for others. ```Julia install_term_repr() Panel ``` -------------------------------- ### Define and Print Function in Julia Source: https://github.com/fedeclaudi/term.jl/blob/master/test/txtfiles/markdown_3.txt This Julia code defines a simple function `say_hi` that prints 'Hello World' to the console. It's a basic example of function definition and output in Julia, often used for introductory demonstrations. ```Julia function say_hi(x) print("Hello World") end ``` -------------------------------- ### Install Term.jl in Julia REPL Source: https://github.com/fedeclaudi/term.jl/blob/master/dev/index.html This shows the process of installing the Term.jl package directly within the Julia REPL. It involves entering the package interface by typing ']' and then using the 'add Term' command. ```Julia julia> ] # enters the pkg interface pkg> add Term ``` -------------------------------- ### Term.jl: Basic ProgressJob Example Source: https://github.com/fedeclaudi/term.jl/blob/master/docs/src/adv/progressbars.md Demonstrates the basic usage of `ProgressBar` and `addjob!` to display a progress bar with a spinner column. It shows how to add a job with a description and update its progress within a `with` context. ```Julia pbar = ProgressBar(; columns=:spinner) job = addjob!(pbar; description="how long is this") with(pbar) do for i in 1:10 update!(job) sleep(0.001) end end ``` -------------------------------- ### Displaying Julia Dictionaries Source: https://github.com/fedeclaudi/term.jl/blob/master/test/txtfiles/termshow_2.txt Demonstrates how to display a Julia dictionary with a key-value pair in the REPL. The example shows a dictionary with a String key and a String value. ```Julia Dict(:z => "a") ``` -------------------------------- ### Use AsciiTree Guides for Tree Rendering Source: https://github.com/fedeclaudi/term.jl/blob/master/docs/src/ren/tree.md Demonstrates how to change the style of the tree's connecting lines (guides) to the 'asciitree' format. Other predefined styles are also available, and custom styles can be created using AbstractTree.TreeCharSet. ```Julia print( Tree(data, guides=:asciitree ) ) ``` -------------------------------- ### Term.jl Table Display Source: https://github.com/fedeclaudi/term.jl/blob/master/test/txtfiles/markdown_3.txt Demonstrates how Term.jl displays tables. It shows a table with rows and columns, highlighting its ability to render structured data. ```Julia ╭───────────┬──────────────┬────────────╮ \n │ Term │ handles │ tables │ \n ├───────────┼──────────────┼────────────┤ \n │ Row `1` │ Column `2` │ │ \n ├───────────┼──────────────┼────────────┤ \n │ Row 2 │ Row 2 │ Column 3 │ \n ╰───────────┴──────────────┴────────────╯ ``` -------------------------------- ### Install Term.jl Stacktrace Handling Source: https://github.com/fedeclaudi/term.jl/blob/master/dev/adv/errors_tracebacks/index.html This snippet demonstrates how to install Term.jl's custom stack trace functionality. It involves importing a specific function and calling it to enable the stylized error output. Note the warning about potential issues in production environments. ```Julia import Term: install_term_stacktrace install_term_stacktrace() # entering the danger zone 1 + "this wont work" ``` -------------------------------- ### Term.jl Logo Example Source: https://github.com/fedeclaudi/term.jl/blob/master/dev/index.html Demonstrates how to import the Term.jl library and print its generated logo to the terminal. This showcases the package's ability to create visually appealing terminal output. ```Julia import Term print(Term.make_logo()) ``` -------------------------------- ### Term.jl Footnote Handling Source: https://github.com/fedeclaudi/term.jl/blob/master/test/txtfiles/markdown_3.txt Shows how Term.jl handles footnotes, including both numbered and named footnotes with potentially complex content. ```Julia [1]: Numbered footnote text. \n\n[note]: Named footnote text containing several toplevel \nelements. ``` -------------------------------- ### Example on_layout_change for TextWidget Source: https://github.com/fedeclaudi/term.jl/blob/master/docs/src/live/widgets.md A simple implementation of `on_layout_change` for a `TextWidget` that updates its internal measure. ```julia on_layout_change(t::TextWidget, m::Measure) = t.internals.measure = m ``` -------------------------------- ### Basic Logging with TermLogger in Julia Source: https://github.com/fedeclaudi/term.jl/blob/master/dev/adv/logging/index.html Demonstrates the enhanced output of standard Julia logging macros when TermLogger is installed. It shows how messages, arguments, and evaluated expressions are displayed with additional context and styling. ```Julia import Term: install_term_logger install_term_logger() @info "My log message" 1+1 n="a string!" :x ``` -------------------------------- ### Term.jl Install Term Logger Function Source: https://github.com/fedeclaudi/term.jl/blob/master/dev/api/api_logging/index.html Provides the `install_term_logger` function to set `TermLogger` as the global logging system in Term.jl. It allows customization of the logging theme by accepting an optional `Theme` object. ```Julia install_term_logger(theme::Theme=theme) # Install `TermLogger` as the global logging system. # `theme::Theme` can be passed to specify the theme to use for styling objects. ``` -------------------------------- ### Create Highly Customized Table Source: https://github.com/fedeclaudi/term.jl/blob/master/docs/src/ren/table.md Presents a comprehensive example of table customization, including header/footer styles and justification, column styles and justification, box style, and overall table styling. ```julia data = Dict( :Parameter => [:α, :β, :γ], :Value => [1, 2, 3], ) Table(data; header_style="bold white on_black", header_justify=[:right, :left], columns_style=["bold white", "dim"], columns_justify=[:right, :left], footer=["", "{bold red}3{/bold red} params"], footer_justify=[:right, :left], box=:SIMPLE, style="#9bb3e0" ) ``` -------------------------------- ### Julia Tree Structure Example Source: https://github.com/fedeclaudi/term.jl/blob/master/test/txtfiles/tree_2_3_2.txt This snippet demonstrates the tree structure of the term.jl project, showing nested directories and their corresponding dictionary values. It highlights the organization and data representation within the project. ```Julia tree_2_3_2 +-- nested2 => Dict("n1" => "a", "n2" => 2) | +-- n1 => a | `-- n2 => 2 `-- nested => Dict("n1" => 1, "n2" => 2) +-- n1 => 1 `-- n2 => 2 ``` -------------------------------- ### Display Annotated Information in Terminal Source: https://github.com/fedeclaudi/term.jl/blob/master/test/txtfiles/annotations_2.txt This snippet demonstrates how to use annotations to display information in the terminal. It utilizes ANSI escape codes for coloring and formatting to create a structured and readable output, highlighting key messages. ```Julia println("This is an example of an annotation to display nicely some info") println("\u1b[2m\u1b[38;2;144;202;249m───┬\u1b[2m\u1b[38;2;144;202;249m\u1b[2m\u1b[38;2;144;202;249m───\u1b[22m\u1b[39m\u1b[22m\u1b[39m\u1b[0m\u1b[22m\u1b[39m \u1b[2m\u1b[34m─────┬\u1b[2m\u1b[34m\u1b[2m\u1b[34m────\u1b[22m\u1b[39m\u1b[22m\u1b[39m\u1b[2m\u1b[34m\u1b[0m\u1b[22m\u1b[39m \u1b[2m\u1b[3m\u1b[32m────┬\u1b[2m\u1b[3m\u1b[32m\u1b[2m\u1b[3m\u1b[32m────\u1b[22m\u1b[23m\u1b[39m\u1b[22m\u1b[23m\u1b[39m\u1b[2m\u1b[3m\u1b[32m\u1b[0m\u1b[22m\u1b[23m\u1b[39m \u1b[2m\u1b[38;2;144;202;249m│\u1b[22m\u1b[39m \u1b[2m\u1b[34m│\u1b[22m\u1b[39m \u1b[2m\u1b[3m\u1b[32m│\u1b[22m\u1b[23m\u1b[39m \u1b[2m\u1b[38;2;144;202;249m│\u1b[22m\u1b[39m \u1b[0m\u1b[2m\u1b[38;2;144;202;249m╭───────────────────────────────────────────╮\u1b[22m\u1b[39m\u1b[0m \u1b[2m\u1b[38;2;144;202;249m╰─\u1b[22m\u1b[39m\u1b[2m\u1b[38;2;144;202;249m│\u1b[22m\u1b[39m \u1b[38;2;144;202;249mvery simple but important, pay attenti \u1b[39m \u1b[2m\u1b[38;2;144;202;249m│\u1b[22m\u1b[39m \u1b[2m\u1b[38;2;144;202;249m│\u1b[22m\u1b[39m \u1b[38;2;144;202;249m on! \u1b[39m \u1b[2m\u1b[38;2;144;202;249m│\u1b[22m\u1b[39m \u1b[0m\u1b[2m\u1b[38;2;144;202;249m╰───────────────────────────────────────────╯\u1b[22m\u1b[39m\u1b[0m \u1b[2m\u1b[34m│\u1b[22m\u1b[39m \u1b[2m\u1b[3m\u1b[32m│\u1b[22m\u1b[23m\u1b[39m \u1b[2m\u1b[34m│\u1b[22m\u1b[39m \u1b[0m\u1b[2m\u1b[34m╭────────────╮\u1b[22m\u1b[39m\u1b[0m \u1b[2m\u1b[3m\u1b[32m│\u1b[22m\u1b[23m\u1b[39m \u1b[2m\u1b[34m╰─\u1b[22m\u1b[39m\u1b[2m\u1b[34m│\u1b[22m\u1b[39m \u1b[34mis it \u1b[39m \u1b[2m\u1b[34m│\u1b[22m\u1b[39m \u1b[2m\u1b[3m\u1b[32m│\u1b[22m\u1b[23m\u1b[39m \u1b[2m\u1b[34m│\u1b[22m\u1b[39m \u1b[34mhelpful? \u1b[39m \u1b[2m\u1b[34m│\u1b[22m\u1b[39m \u1b[2m\u1b[3m\u1b[32m│\u1b[22m\u1b[23m\u1b[39m \u1b[0m\u1b[2m\u1b[34m╰────────────╯\u1b[22m\u1b[39m\u1b[0m \u1b[2m\u1b[3m\u1b[32m│\u1b[22m\u1b[23m\u1b[39m \u1b[2m\u1b[3m\u1b[32m│\u1b[22m\u1b[23m\u1b[39m \u1b[2m\u1b[3m\u1b[32m│\u1b[22m\u1b[23m\u1b[39m \u1b[0m\u1b[2m\u1b[3m\u1b[32m╭─────╮\u1b[22m\u1b[23m\u1b[39m\u1b[0m \u1b[2m\u1b[3m\u1b[32m╰─\u1b[22m\u1b[23m\u1b[39m\u1b[2m\u1b[3m\u1b[32m│\u1b[22m\u1b[23m\u1b[39m \u1b[3m\u1b[32mh\u1b[23m\u1b[39m \u1b[2m\u1b[3m\u1b[32m│\u1b[22m\u1b[23m\u1b[39m \u1b[2m\u1b[3m\u1b[32m│\u1b[22m\u1b[23m\u1b[39m \u1b[3m\u1b[32mo\u1b[23m\u1b[39m \u1b[2m\u1b[3m\u1b[32m│\u1b[22m\u1b[23m\u1b[39m \u1b[2m\u1b[3m\u1b[32m│\u1b[22m\u1b[23m\u1b[39m \u1b[3m\u1b[32mp\u1b[23m\u1b[39m \u1b[2m\u1b[3m\u1b[32m│\u1b[22m\u1b[23m\u1b[39m \u1b[2m\u1b[3m\u1b[32m│\u1b[22m\u1b[23m\u1b[39m \u1b[3m\u1b[32me\u1b[23m\u1b[39m \u1b[2m\u1b[3m\u1b[32m│\u1b[22m\u1b[23m\u1b[39m \u1b[2m\u1b[3m\u1b[32m│\u1b[22m\u1b[23m\u1b[39m \u1b[3m\u1b[32mf\u1b[23m\u1b[39m \u1b[2m\u1b[3m\u1b[32m│\u1b[22m\u1b[23m\u1b[39m \u1b[2m\u1b[3m\u1b[32m│\u1b[22m\u1b[23m\u1b[39m \u1b[3m\u1b[32mu\u1b[23m\u1b[39m \u1b[2m\u1b[3m\u1b[32m│\u1b[22m\u1b[23m\u1b[39m \u1b[2m\u1b[3m\u1b[32m│\u1b[22m\u1b[23m\u1b[39m \u1b[3m\u1b[32ml\u1b[23m\u1b[39m \u1b[2m\u1b[3m\u1b[32m│\u1b[22m\u1b[23m\u1b[39m \u1b[2m\u1b[3m\u1b[32m│\u1b[22m\u1b[23m\u1b[39m \u1b[3m\u1b[32ml\u1b[23m\u1b[39m \u1b[2m\u1b[3m\u1b[32m│\u1b[22m\u1b[23m\u1b[39m \u1b[2m\u1b[3m\u1b[32m│\u1b[22m\u1b[23m\u1b[39m \u1b[3m\u1b[32my\u1b[23m\u1b[39m \u1b[2m\u1b[3m\u1b[32m│\u1b[22m\u1b[23m\u1b[39m \u1b[2m\u1b[3m\u1b[32m│\u1b[22m\u1b[23m\u1b[39m \u1b[3m\u1b[32m\u1b[23m\u1b[39m \u1b[2m\u1b[3m\u1b[32m│\u1b[22m\u1b[23m\u1b[39m \u1b[2m\u1b[3m\u1b[32m│\u1b[22m\u1b[23m\u1b[39m \u1b[3m\u1b[32mu\u1b[23m\u1b[39m \u1b[2m\u1b[3m\u1b[32m│\u1b[22m\u1b[23m\u1b[39m \u1b[2m\u1b[3m\u1b[32m│\u1b[22m\u1b[23m\u1b[39m \u1b[3m\u1b[32ms\u1b[23m\u1b[39m \u1b[2m\u1b[3m\u1b[32m│\u1b[22m\u1b[23m\u1b[39m \u1b[2m\u1b[3m\u1b[32m│\u1b[22m\u1b[23m\u1b[39m \u1b[3m\u1b[32me\u1b[23m\u1b[39m \u1b[2m\u1b[3m\u1b[32m│\u1b[22m\u1b[23m\u1b[39m \u1b[2m\u1b[3m\u1b[32m│\u1b[22m\u1b[23m\u1b[39m \u1b[3m\u1b[32mf\u1b[23m\u1b[39m \u1b[2m\u1b[3m\u1b[32m│\u1b[22m\u1b[23m\u1b[39m \u1b[2m\u1b[3m\u1b[32m│\u1b[22m\u1b[23m\u1b[39m \u1b[3m\u1b[32mu\u1b[23m\u1b[39m \u1b[2m\u1b[3m\u1b[32m│\u1b[22m\u1b[23m\u1b[39m \u1b[2m\u1b[3m\u1b[32m│\u1b[22m\u1b[23m\u1b[39m \u1b[3m\u1b[32ml\u1b[23m\u1b[39m \u1b[2m\u1b[3m\u1b[32m│\u1b[22m\u1b[23m\u1b[39m \u1b[0m\u1b[2m\u1b[3m\u1b[32m╰─────╯\u1b[22m\u1b[23m\u1b[39m\u1b[0m\u1b[0m") ``` -------------------------------- ### Create TextBox with Title and Subtitle Source: https://github.com/fedeclaudi/term.jl/blob/master/dev/basics/renderables/index.html Shows how to create a TextBox with a repeating string content, a title, and a subtitle. This example demonstrates the basic usage of TextBox for rendering text with associated metadata and styling. ```Julia import Term: TextBox print( TextBox( ","^100 * "\n", title="title!", subtitle="sub title!", width=30, title_style="bold red", subtitle_style="dim", title_justify=:center, ) ) ``` -------------------------------- ### Padding with hstack and vstack in Term.jl Source: https://github.com/fedeclaudi/term.jl/blob/master/docs/src/layout/stacking.md Demonstrates how to add padding (spacing) between renderables when using `hstack` and `vstack` in Term.jl. It shows examples of applying horizontal and vertical padding to arrange elements with spacing. ```Julia import Term.Layout: vstack, hstack # hide import Term: Panel # hide p1 = Panel(height=4, width=8) # hide hstack(p1, p1, p1, p1; pad=8) ``` ```Julia import Term.Layout: vstack, hstack # hide import Term: Panel # hide p1 = Panel(height=4, width=8) # hide vstack(p1, p1, p1, p1; pad=1) ``` -------------------------------- ### Integrate ProgressLogging with Term.jl Logger Source: https://github.com/fedeclaudi/term.jl/blob/master/docs/src/adv/progressbars.md Shows how to use Term.jl's logger with the `ProgressLogging` package. By installing the Term logger, `@progress` macros from `ProgressLogging` will render using Term's styling. ```Julia using ProgressLogging import Term: install_term_logger install_term_logger() @progress "outer...." for i in 1:3 sleep(0.01) end ``` -------------------------------- ### Install Term.jl using Pkg Source: https://github.com/fedeclaudi/term.jl/blob/master/docs/src/index.md This snippet shows how to add the Term.jl package to your Julia project using the Pkg manager. It can be executed either within a Julia script or directly in the Julia REPL. ```Julia using Pkg Pkg.add("Term") ``` ```Shell julia> ] # enters the pkg interface pkg> add Term ``` -------------------------------- ### Using hstack and vstack for Multiple Renderables Source: https://github.com/fedeclaudi/term.jl/blob/master/docs/src/layout/stacking.md Shows how to use the `hstack` and `vstack` functions in Term.jl for stacking multiple renderables, which is often more readable than using the '*' and '/' operators repeatedly. Demonstrates basic usage. ```Julia import Term.Layout: vstack, hstack # hide import Term: Panel # hide p1 = Panel(height=4, width=8) # hide p1 * p1 * p1 * p1 ``` -------------------------------- ### Get RGB Color Value in Julia Source: https://github.com/fedeclaudi/term.jl/blob/master/test/txtfiles/code_highlight_6_4_3_trunc.txt This example illustrates how to retrieve the RGB color representation from a hex color string in Julia, with an option to specify if it's for a background. This function is essential for color conversions and manipulations. ```Julia @test get_color(hex; bg = true) isa RGBColor ``` -------------------------------- ### Create and Display a Simple Text App in Julia Source: https://github.com/fedeclaudi/term.jl/blob/master/docs/src/live/app_intro.md This snippet demonstrates how to create a basic Term.jl application displaying a single TextWidget. It initializes an App with the widget and shows how to preview the app's appearance using the `frame` function. Requires Term 2.0. ```Julia using Term using Term.LiveWidgets app = App( TextWidget(""" The starting point of any good \"live\" or interactive terminal display is an `App`. The `App` takes care of generating and updating the visuals as well as taking in user input making use of it (e.g. to update the display accordingly). An app has some content. This content is in the form of `AbstractWidget` elements. These widgets are single content elements that serve a specific function, for example displaying some text or acting as buttons etc. More on widgets later. In addition to knowing **what** is in an app, we also need to specify **how** it should look like. Specifically, how should the different widgets be layed out. So in addition to creating widgets, you will need to specify a layout for your app. There's a lot more to apps, but for now we can start with some simple examples """) ); frame(app) ``` -------------------------------- ### Display Additional Variables in Term.jl ProgressBar Source: https://github.com/fedeclaudi/term.jl/blob/master/docs/src/adv/progressbars.md Illustrates how to display extra information below the progress bar using a `Dict{String, <:Any}`. The example shows updating variables like iteration time and start time within the progress loop. ```Julia using Term.Progress, Dates a = 10 iteration_time = NaN extra_info = Dict("Speed" => "$iteration_time s/it", "Start time" => now(), "a" => a) pbar = ProgressBar(; extra_info) job = addjob!(pbar; N = 5) start!(pbar) for i in 1:5 iteration_time = @elapsed begin println("Epoch $i") pbar.extra_info["a"] = 10 - i pbar.extra_info["Speed"] = "$iteration_time s/it" update!(job) render(pbar) sleep(1) end end stop!(pbar) ``` -------------------------------- ### Create Basic Table with Matrix Data Source: https://github.com/fedeclaudi/term.jl/blob/master/docs/src/ren/table.md Demonstrates how to create a basic table using a matrix of data with the `Term.Tables` interface. This is the fundamental way to initialize a table. ```julia using Term.Tables t = 1:3 data = hcat(t, rand(Int8, length(t))) Table(data) ``` -------------------------------- ### Julia: Progress Bar with Multiple Jobs and `with` Source: https://github.com/fedeclaudi/term.jl/blob/master/docs/src/adv/progressbars.md Illustrates how to use Term.jl's `with` function to manage progress bars, ensuring they are started and stopped correctly even if errors occur. This example shows handling multiple jobs simultaneously and printing text without disrupting the progress bar. ```Julia pbar = ProgressBar() job1 = addjob!(pbar; N=5) job2 = addjob!(pbar; N=10) with(pbar) do for i in 1:10 update!(job1) update!(job2) i % 3 == 0 && println("text appears here!") sleep(0.001) end end ``` -------------------------------- ### Create Simple Layout with Grid Source: https://github.com/fedeclaudi/term.jl/blob/master/docs/src/layout/compositor.md Demonstrates creating a simple layout using `grid` with multiple panels of the same size. ```Julia using Term: Panel using Term.Layout import Term.Grid: grid plarge = Panel(height=10, width=60) psmall = Panel(height=10, width=20) panels = repeat([psmall], 3) plarge / grid(panels, layout=(1, 3)) ``` -------------------------------- ### Create Compositor with Basic Layout Expression Source: https://github.com/fedeclaudi/term.jl/blob/master/docs/src/layout/compositor.md Demonstrates creating a `Compositor` instance with a simple layout expression defining two placeholders. ```Julia layout = :(A(5, 45) * B(5, 45)) Compositor(layout) ``` -------------------------------- ### Install TermLogger in Julia Source: https://github.com/fedeclaudi/term.jl/blob/master/dev/adv/logging/index.html Installs Term.jl's custom logger globally to enhance terminal output for logging messages. This is a prerequisite for using the styled logging features. ```Julia import Term: install_term_logger install_term_logger() ``` -------------------------------- ### Install Term.jl in Julia Script Source: https://github.com/fedeclaudi/term.jl/blob/master/dev/index.html This code snippet demonstrates how to add the Term.jl package to your Julia project using a script. It utilizes the Pkg.add() function to manage package installations. ```Julia using Pkg Pkg.add("Term") ``` -------------------------------- ### Create and Print Dendogram Source: https://github.com/fedeclaudi/term.jl/blob/master/docs/src/ren/dendogram.md Demonstrates how to create a basic Dendogram with a title and leaves, and then print it to the console. This is the fundamental way to initialize and display a dendogram. ```Julia import Term.Dendograms: Dendogram dendo = Dendogram("trunk", "the", "tree", "has", "leaves") print(dendo) ``` -------------------------------- ### Install Term Logger in Julia Source: https://github.com/fedeclaudi/term.jl/blob/master/docs/src/adv/logging.md Installs the TermLogger as the global logger to handle all error messages, enabling enhanced logging features and styling provided by the Term.jl library. ```Julia import Term: install_term_logger install_term_logger() ``` -------------------------------- ### Create a Basic Grid Layout Source: https://github.com/fedeclaudi/term.jl/blob/master/docs/src/layout/grid.md Demonstrates the basic usage of the `grid` function to arrange a list of renderables into a default grid layout. Requires importing `Panel` and `grid` from the Term library. ```Julia import Term: Panel import Term.Grid: grid panels = repeat([Panel(height=6, width=12)], 8) grid(panels) ``` -------------------------------- ### Create and Ask a Basic Prompt in Julia Source: https://github.com/fedeclaudi/term.jl/blob/master/docs/src/basics/prompt.md Demonstrates how to create a simple Prompt object in Term.jl and use the `ask` function to display the prompt and capture user input. The `ask` function returns the user's answer. ```julia using Term.Prompts prompt = Prompt("Simple, right?"); prompt |> ask ``` -------------------------------- ### Create a Styled Panel with Title and Subtitle Source: https://github.com/fedeclaudi/term.jl/blob/master/docs/src/ren/panel.md Demonstrates creating a `Panel` with styled content, a title, and a subtitle. It showcases options for title and subtitle styling, justification, width, and overall panel style. ```julia import Term: Panel print( Panel( "{red}awesome{/red}", title="Term's", title_style="bold green", style="gold1 bold", subtitle="Panels", subtitle_style="bold blue", subtitle_justify=:right, width=18, justify=:center ) ) ``` -------------------------------- ### Julia: Get Color from Hex Source: https://github.com/fedeclaudi/term.jl/blob/master/test/txtfiles/code_highlight_5_2_1.txt This snippet demonstrates how to use the `get_color` function in Julia to retrieve color information. It takes a hexadecimal color string and an optional boolean `bg` parameter to specify if the background color should be considered. The function returns an `RGBColor` object. ```Julia get_color(hex; bg = true) RGBColor ``` -------------------------------- ### Styling Prompts in Term.jl Source: https://github.com/fedeclaudi/term.jl/blob/master/docs/src/basics/prompt.md Shows how to apply styles to prompt elements, such as text color and option colors, either through the `Theme` or directly during prompt creation. ```julia Prompt("Do you like this color?", "red") |> println DefaultPrompt(["yes", "no"], 1, "Confirm?", "green", "blue", "red") |> println ``` -------------------------------- ### Install Term Stacktrace Source: https://github.com/fedeclaudi/term.jl/blob/master/docs/src/adv/errors_tracebacks.md Installs Term's custom stack trace handler for Julia. This function replaces the default error reporting mechanism with Term's enhanced, stylized output. It's recommended to use this function to improve the readability and debugging experience of error messages. ```Julia import Term: install_term_stacktrace install_term_stacktrace() # entering the danger zone function test() sum([]) end test() ``` -------------------------------- ### Displaying Expressions with Term.jl in Julia Source: https://github.com/fedeclaudi/term.jl/blob/master/test/txtfiles/termshow_8.txt This snippet shows how to use the Term.jl package to display a Julia expression. It highlights the package's ability to render structured data, including mathematical operators and type annotations, with rich formatting for terminal output. The example involves an expression representing 'x / y + sqrt(9)'. ```Julia using Term # Example expression expr = :(\frac{x}{y} + \sqrt{9}) # Display the expression using Term.jl println(expr) ``` -------------------------------- ### Horizontal and Vertical Stacking with Panel Source: https://github.com/fedeclaudi/term.jl/blob/master/dev/basics/content_layout/index.html Demonstrates stacking Panel objects horizontally using '*' and vertically using '/'. This showcases the basic layout composition in Term.jl. ```Julia println( Panel("horizontally") * Panel("stacked") ) println("&\n") println( Panel("vertically") / Panel("stacked") ) ``` -------------------------------- ### Horizontal and Vertical Stacking in Term.jl Source: https://github.com/fedeclaudi/term.jl/blob/master/docs/src/layout/stacking.md Demonstrates basic horizontal stacking using '*' and vertical stacking using '/' with Term.jl Panels. It shows how these operators arrange renderables side-by-side or one above the other. ```Julia import Term: Panel # hide println( Panel("horizontally"; fit=true) * Panel("stacked"; fit=true) ) println("&\n") println( Panel("vertically"; fit=true) / Panel("stacked"; fit=true) ) ``` -------------------------------- ### Basic Text Styling with Term.jl Source: https://github.com/fedeclaudi/term.jl/blob/master/docs/src/basics/renderables.md Demonstrates how to apply basic styling, such as color and bold text, to strings using the Term.jl library's `tprint` function. This is a foundational step for creating visually appealing terminal output. ```Julia using Term tprint("{green}...have seen how to add some {gold3 bold underline}style{/gold3 bold underline} to our text") ``` -------------------------------- ### Julia: Basic Progress Bar Usage Source: https://github.com/fedeclaudi/term.jl/blob/master/docs/src/adv/progressbars.md Demonstrates the fundamental steps to create and manage a progress bar in Term.jl. This includes initializing a ProgressBar, adding a job, starting the bar, updating job progress, rendering the bar, and stopping it. ```Julia using Term.Progress pbar = ProgressBar() job = addjob!(pbar; N=5) start!(pbar) for i in 1:5 update!(job) sleep(0.01) render(pbar) end stop!(pbar) ``` -------------------------------- ### Get Console Height in Term.jl Source: https://github.com/fedeclaudi/term.jl/blob/master/dev/api/api_console/index.html Retrieves the current height of the console using the `console_height` function. This is useful for layout and rendering calculations. ```Julia Term.console.console_height() ``` -------------------------------- ### Inspect Method Calls with @showme Source: https://github.com/fedeclaudi/term.jl/blob/master/docs/src/adv/repr.md Demonstrates the `@showme` macro from Term.jl, which leverages `CodeTracking` to display the source code of the specific method being called for a given function and arguments. It also shows how to display all available methods for a function. ```Julia import Term.Repr: @showme @showme tprint(stdout, "this is TERM") # which method is being called? ``` ```Julia @showme tprint("this is also TERM") # different method ``` ```Julia @showme tprint("still TERM") show_all_methods=true ``` -------------------------------- ### Display Julia Code Snippets Source: https://github.com/fedeclaudi/term.jl/blob/master/docs/src/basics/markdown.md Shows how to display a Julia function definition within the Markdown rendering using `tprint`. The function itself is a simple example. ```Julia tprint("\n"this function is a bit pointless"\nfunction my_useless_fn(x) println(\"I don't do much!\") return x end\n\n") ``` -------------------------------- ### Replace Text Section with String - Term.jl Source: https://github.com/fedeclaudi/term.jl/blob/master/dev/api/api_term/index.html This overload of `replace_text` replaces a specified section of a string (between `start` and `stop` indices) with a custom replacement string. ```Julia function replace_text(text::AbstractString, start::Int, stop::Int, replace::AbstractString) # Implementation to replace text section with a string end ``` -------------------------------- ### Create App with Multiple Text Widgets Source: https://github.com/fedeclaudi/term.jl/blob/master/docs/src/live/app_intro.md Demonstrates creating a Term.jl app with two text widgets arranged in a layout. The widgets are configured as panels, and the app is displayed using the `frame` function. This example highlights how Term.jl manages widget activation and visual feedback. ```Julia layout = :(a(25, .5) * b(25, .5)) widgets = Dict( :a => TextWidget("To create an app with multiple widgets, you'll need the layout info as shown above and a `Dict` with the widgets you want your app to display. The keys in the `Dict` need to match the layout elements names. For example, to create an app showing two pieces of text. "; as_panel=true), :b => TextWidget(" The starting point of any good \"live\" or interactive terminal display is an `App`. The `App` takes care of generating and updating the visuals as well as taking in user input making use of it (e.g. to update the display accordingly). An app has some content. This content is in the form of `AbstractWidget` elements. These widgets are single content elements that serve a specific function, for example displaying some text or acting as buttons etc. More on widgets later. In addition to knowing **what** is in an app, we also need to specify **how** it should look like. Specifically, how should the different widgets be layed out. So in addition to creating widgets, you will need to specify a layout for your app. There's a lot more to apps, but for now we can start with some simple examples "; as_panel=true) ) App(layout; widgets=widgets) |> frame ``` -------------------------------- ### Displaying Julia Vectors Source: https://github.com/fedeclaudi/term.jl/blob/master/test/txtfiles/termshow_2.txt Illustrates the display of a Julia vector containing integers in the REPL. The example shows a vector with elements 1, 2, and 3. ```Julia [1, 2, 3] ``` -------------------------------- ### Create Panel with Content Source: https://github.com/fedeclaudi/term.jl/blob/master/test/txtfiles/annotations_1.txt Demonstrates the basic usage of the Panel struct constructor in Term.jl. The 'content' argument defines what is displayed within the panel. ```Julia Panel(content) ``` -------------------------------- ### Term.jl Color API - Get Color (get_color) Source: https://github.com/fedeclaudi/term.jl/blob/master/dev/api/api_color/index.html A function to extract a color type from a string that contains color information. It can optionally specify if the color is for the background. ```Julia get_color(string::AbstractString; bg=false)::AbstractColor Extract a color type from a string with color information. ``` -------------------------------- ### Panel Sizing and Fitting Behavior Source: https://github.com/fedeclaudi/term.jl/blob/master/docs/src/ren/panel.md Explains and demonstrates the `width` and `height` parameters for `Panel`, as well as the `fit` option. It shows how `fit=true` (default) makes the panel adapt to content, while `fit=false` or explicit dimensions can lead to truncation or reshaping. ```julia print(Panel("."^10)) print(Panel("."^30)) print(Panel("."^60)) ``` ```julia Panel("."^10; height=5, width=20) ``` ```julia Panel("."^10; fit=false) ``` ```julia p1 = Panel("."^10; height=5, width=60) print(Panel(p1; height=2, width=30)) # fit=true -> expand out panel, width/height ignored print(Panel(p1; height=10, width=30, fit=false)) # fit=false -> truncate the content print(Panel("very long text"^20; height=10, width=30, fit=false)) # text is reshaped to fit the panel ```