Term
Term.Term
Term.CodeTheme
Term.Measures.Measure
Term.Measures.Measure
Term.Theme
Highlights.Format.render
Term.calc_nrows_ncols
Term.chars
Term.cleantext
Term.do_by_line
Term.escape_brackets
Term.excise_link_display_text
Term.expr2string
Term.fillin
Term.fix_ansi_across_lines
Term.fix_markup_across_lines
Term.get_bg_color
Term.get_closing_ansi_tag
Term.get_file_format
Term.get_lr_widths
Term.has_ansi
Term.has_markup
Term.highlight
Term.highlight
Term.highlight_syntax
Term.is_closing_ansi_tag
Term.join_lines
Term.justify
Term.load_code_and_highlight
Term.load_code_and_highlight
Term.loop_last
Term.ltrim_str
Term.read_file_lines
Term.remove_ansi
Term.remove_markup
Term.replace_multi
Term.replace_text
Term.replace_text
Term.reshape_code_string
Term.reshape_text
Term.rtrim_str
Term.split_lines
Term.str_trunc
Term.string_type
Term.text_to_width
Term.textlen
Term.tview
Term.unescape_brackets
Term.unspace_commas
Term.@make_color_macro
Term.@make_mode_macro
Term.@style
Term.Term
— ModuleTerm.jl
Welcome to Term.jl! Term.jl is a Julia library for producing styled, beautiful terminal output.
Documentation
See https://fedeclaudi.github.io/Term.jl for documentation.
Demonstration
using Term
const term_demo = joinpath(dirname(pathof(Term)), "..", "README.jl")
include(term_demo) # view demo
less(term_demo) # see demo code
Example
julia begin println(@green "this is green") println(@blue "and this is blue") println() println(@bold "this is bold") println(@underline "and this is underlined") end ```
Term.CodeTheme
— TypeCustom hilighting theme for Highlighters.jl https://juliadocs.github.io/Highlights.jl/stable/man/theme/
Term.Measures.Measure
— MethodMeasure(segments::AbstractVector)
gives the measure of a vector of segments
Term.Measures.Measure
— MethodMeasure(seg::Segment)
gives the measure of a segment
Term.Theme
— TypeTheme
Stores colors for different semantically relevant items, used to style outputs to terminal.
Highlights.Format.render
— MethodFormat.render(io::IO, ::MIME"text/ansi", tokens::Format.TokenIterator)
custom ANSI lexer for Highlighters.jl
Term.calc_nrows_ncols
— Functioncalc_nrows_ncols(n, aspect::Union{Nothing,Number,NTuple} = nothing)
Computes the number of rows and columns to fit a given number n
of subplots in a figure with aspect aspect
. If aspect
is nothing
, chooses the best fir between a default and a unit aspect ratios.
Adapted from: stackoverflow.com/a/43366784
Term.chars
— MethodSplit a string into a vector of Chars.
Term.cleantext
— Methodcleantext(str::AbstractString)
Remove all style information from a string.
Term.do_by_line
— Methoddo_by_line(fn::Function, text::String)
Apply fn
to each line in the text
.
The function fn
should accept a single ::String
argument.
Term.escape_brackets
— Methodescape_brackets(text)::Stringremove_ansi(str)::String
Replace each curly bracket with a double copy of itself
Term.excise_link_display_text
— Methodexcise_link_display_text(link::String)
Given a link string of the form: "]8;;LINKDESTINATION\LINKDISPLAYTEXT]8;;\" this function returns "LINKDISPLAY_TEXT" alone.
Term.expr2string
— MethodGet a clean string representation of an expression
Term.fillin
— Methodfillin(text::String)::String
Ensure that each line in a multi-line text has the same width.
Term.fix_ansi_across_lines
— MethodSame as fix_markup_across_lines
but for ANSI style tags.
Term.fix_markup_across_lines
— Methodfix_markup_across_lines(lines::Vector{AbstractString})::Vector{AbstractString}
When splitting text with markup tags across multiple lines, tags can get separated across lines. This is a problem when the text gets printed side by side with other text with style information. This fixes that by copying/closing markup tags across lines as requested. Essentially, if a tag is opened but not closed in a line, close it at the end of the line and add the same open tag at the start of the next, taking care of doing things in the correct order when multiple tags are in the same line.
Term.get_bg_color
— Methodget_bg_color(style::String)
Add "on_" to background style info.
Term.get_closing_ansi_tag
— MethodGiven an ANSI tag, get the correct closer tag
Term.get_file_format
— Methodgetfileformat(nbytes; suffix="B")
Return a string with formatted file size.
Term.get_lr_widths
— Methodgetlrwidths(width::Int)
To split something with width
in 2, get the lengths of the left/right widths.
When width is even that's easy, when it's odd we need to be careful.
Term.has_ansi
— Methodhas_ansi(text::String)
Returns true
if text
includes a MarkupTag
Term.has_markup
— Methodhas_markup(text::String)
Returns true
if text
includes a MarkupTag
Term.highlight
— Methodhighlight(text::AbstractString, theme::Theme, like::Symbol)
Hilights an entire text as if it was a type of semantically relevant text of type :like.
Term.highlight
— Methodhighlight(text::AbstractString, theme::Theme)
Highlighs a text introducing markup to style semantically relevant segments, colors specified by a theme object.
Term.highlight_syntax
— Methodhighlight_syntax(code::AbstractString; style::Bool=true)
Highlight Julia code syntax in a string.
Term.is_closing_ansi_tag
— MethodCheck if an ANSI tag is a closer
Term.join_lines
— Methodjoin_lines(lines)
Merge a vector of strings in a single string.
Term.justify
— Methodjustify(text::AbstractString, width::Int)::String
Justify a piece of text spreading out text to fill in a given width.
Term.load_code_and_highlight
— Methodload_code_and_highlight(path::AbstractString, lineno::Int; δ::Int=3, width::INt=120)
Load a file, get the code and format it. Return styled text
Term.load_code_and_highlight
— Methodload_code_and_highlight(path::AbstractString)::String
Load and highlight the syntax of an entire file
Term.loop_last
— Methodloop_last(v)
Returns an iterable yielding tuples (is_last, value).
Term.ltrim_str
— Methodltrim_str(str, width)
Cut a chunk of width width
form the left of a string
Term.read_file_lines
— Methodread_file_lines(path::String, start::Int, stop::Int)
Read a file and select only lines in range start
-> stop
.
Returns a vector of tuples with the line number and line content.
Term.remove_ansi
— Methodremove_ansi(input_text::AbstractString)::AbstractString
Remove all ANSI tags from a string of text
Term.remove_markup
— Methodremove_markup(input_text::AbstractString)::AbstractString
Remove all markup tags from a string of text.
Term.replace_multi
— Methodmultiple strings replacement.
Term.replace_text
— Functionreplace_text(text::AbstractString, start::Int, stop::Int, char::Char='_')
Replace a section of a text
between start
and stop
with another string composed of repeats of a given character char
.
Term.replace_text
— Methodreplace_text(text::AbstractString, start::Int, stop::Int, replace::AbstractString)
Replace a section of a text
between start
and stop
with replace
.
Term.reshape_code_string
— MethodReshaping strings with Julia code requires particular care
Term.reshape_text
— Methodreshape_text(text::AbstractString, width::Int)
Reshape a text to have a given width.
Insert newline characters in a string so that each line is within the given width.
Term.rtrim_str
— Methodrtrim_str(str, width)
Cut a chunk of width width
form the right of a string
Term.split_lines
— Methodsplit_lines(text::AbstractString)
Split a string into its composing lines.
Term.str_trunc
— Methodstr_trunc(text::AbstractString, width::Int)
Shorten a string of text to a target width
Term.string_type
— Methodstring_type(x)
Return the type of x
if it's an AbstractString, else String
Term.text_to_width
— Methodtext_to_width(text::AbstractString, width::Int)::String
Cast a text to have a given width by reshaping, it and padding. It includes an option to justify the text (:left, :right, :center, :justify).
Term.textlen
— Methodtextlen(x::AbstractString)
Get length of text after all style information is removed.
Term.tview
— Methodtview(text, start::Int, stop::Int)
Get a view object with appropriate indices
Term.unescape_brackets
— Methodunescape_brackets(text)::String
Replece every double squared parenthesis with a single copy of itself
Term.unspace_commas
— Methodunspace_commas(text::AbstractString)
Remove spaces after commas.
Term.@make_color_macro
— MacroMacro to create macros such as @green
which colors text accordingly
Term.@make_mode_macro
— MacroMacro to create macros such as @underline
which styles text accordingly.
Term.@style
— Macro@style "text" style1 style2...
Applies a sequence of styles to a piece of text, such that
println(@style "my text" bold green underline)
will print my text
as bold, green and underlined