Basic Wrappers
ShowCases.ShowNothing
— TypeShowNothing
A type which shows nothing. Neither show(io, ShowNothing())
and print(io, ShowNothing())
will insert anything into the stream. This can be useful as a placeholder in some other functions in the ShowCases
module.
ShowCases.Show
— TypeShow
An AbstractShow
wrapper of another object. This is useful for methods which require AbstractShow
objects, for example the multi-argument Base.show
method.
Constructors
Show(x)
; wherex
is the object to be wrapped.
ShowCases.Print
— TypePrint
An AbstractShow
wrapper that forces the underlying object to be shown using the print
method. That is, calling show(io, Print(x))
is equivalent to print(io, x)
. This is particularly useful for passing arbitrary strings to functions in the ShowCases
module.
Constructors
Print(x)
; wherex
is the object to be wrapped.
Examples
julia> Print("spock")
spock
Note the lack of printed "
characters.
ShowCases.Styled
— TypeStyled{𝒯}
An AbstractShow
wrapper which when shown will be shown as the wrapped object but with Style
such as color or text boldness.
Constructors
Styled(o, color, bold=false)
Styled(o; color=:normal, bold=false)
Arguments
o
: The object to be wrapped.color
: A color specifier as it would be passed toprinstyled
, see alsoStyle
.bold
: Whether text should be rendered as bold.
List and Element Wrappers
ShowCases.ShowEntry
— TypeShowEntry
An AbstractShow
wrapper type for showing entries in a list. Allows for specification of list-context options.
Constructors
ShowEntry(o; new_line=false, indent=" ", delim=Print(", "))
Arguments
o
: the object to be wrapped.new_line::Bool
: whether to show (or print) the entry on a new line.indent::AbstractString
: If a new line is created (i.e. withnew_line=true
), the created line will start with this indent.delim
: An object that will be shown at the end of an entry, typically a comma. The object passed will be shown as is, so for example a", "
will print quotes, usePrint(", ")
to omit quotes.
Examples
julia> ShowEntry(1) # by default we just get commas
1,
julia> ShowEntry("a", new_line=true, indent="__", delim=Print(": "))
__"a":
ShowCases.ShowKw
— FunctionShowKw(o, name, separator=Print("="); kw...)
ShowKw(o, name::Symbol, separator=Print("="); kw...)
Show an object as if it were a keyword argument with name name
. For example ShowKw(x, :x)
shows x=x
.
Constructors
o
: the object to be wrapped.name
: The name of the object, if aSymbol
will be printed as in keyword arguments.separator
: separator between the name and shown object.kw
: Keyword arguments passed toShowList
.
ShowCases.ShowList
— TypeShowList
An AbstractShow
wrapper type for showing iterables. Note that, since the ShowCases
module is intended primarily for creating show
methods with output resembling Julia syntax, all iterables are shown as if they are of rank 1. Higher rank arrays should be shown with built-in methods or tools specifically intended for handling them.
Note that ShowList
will show any element which is a ShowEntry
object as is. Therefore, one can pass it ShowEntry
objects to override defaults only for specific entries.
Constructors
ShowList(o; brackets="()", left_bracket=Print("("), right_bracket=Print(")"), new_lines=false, indent=" ", delim=Print(", "), max=8, continuation=Print("…"), entry_style=nothing)
ShowList(o...; kw...)
(same keyword arguments as above)
Arguments
o
: Object or objects to be wrapped. If only one is passed, it must be an iterable.brackets
: A string containing the brackets to be used (e.g."()", "[]", "{}", "''"
)left_bracket
: The left bracket to be shown. By default, this will be computed frombrackets
. If an argument is given directly, it will be shown as is, i.e. usePrint("(")
to omit quotes.right_bracket
: The right bracket to be shown. By default, this will be computed frombrackets
. If an argument is given directly, it will be shown as is, i.e. usePrint(")")
to omit quotes.new_lines::Bool
: Whether to print a new line for each entry.indent::AbstractString
: Indent to be useddelim
: Delimiter to use for each entry. This will be printed as is, so for example, usePrint(", ")
to get commas with spacing.max::Integer
: the maximum number of entries to be printed.continuation
: object to print whenmax
is hit. Will be shown as is.
Exmaples
julia> ShowList(1, 2)
(1, 2)
julia> ShowList(1, 2, new_lines=true)
(
1,
2
)
julia> ShowList(1, 2, max=1)
(1, …)
# pass ShowEntry objects to override defaults set by `ShowList`
julia> ShowList(ShowEntry("a", delim=Print(": "), new_line=true), 1, 2)
(
"a": 1, 2)
Type Related Wrappers
ShowCases.ShowType
— TypeShowType
An AbstractShow
wrapper for showing a type with some relevant options, such as whether the module should be shown.
Note that it is expected that ShowType
is only used to show Type
objects, though for generality it does not forbid the printing of other objects.
See ShowTypeOf
for showing the type of the wrapped object.
Constructors
ShowType(o; show_module=:context)
Arguments
o
: the object to be wrapped.show_module::Symbol
: (valid options::always
,:never
,:context
) specifies whether the module name should be shown. If:context
, the default behavior fromBase
will be used in which the printing of the module is contextual. If:never
, the module will never be shown. If:always
, it will always be shown.
ShowCases.ShowTypeOfBase
— FunctionShowTypeOfBase(o; kw...)
Use ShowType
on the type of the object o
, passing keyword arguments to that constructor. See ShowType
.
ShowCases.ShowTypeOf
— FunctionShowTypeOf(o, type_style=Style(), show_module=:context, show_params=true, kw...)
Show the type of object o
.
Arguments
type_style::Style
: Style to use for the type.show_module::Symbol
: whether to show modules for the type and its parameters. SeeShowType
for options.kw
: All other keyword arguments passed toShowParams
ShowCases.ShowParams
— FunctionShowParams
An AbstractShow
wrapper for showing the type parameters of the type of the wrapped object.
The underlying type is determined recursively, so if an AbstractShow
object is wrapped, the type of the (deepest) wrapped object will be shown.
Constructors
ShowParams(o; show_module=:context, kw...)
Arguments
ShowCases.ShowProps
— FunctionShowProps(o, props=propertynames(o);
show_keywords=true, new_lines=false, keyword_style=Style(), entry_style=Style()
separator=(new_lines ? Print(" = ") : Print("=")),
kw...)
Show the properties of an object o
via ShowList
with entries using ShowKw
.
Arguments
props
: Symbols with names of properties to show.show_keywords
: whether or not to show the property names.keyword_style::Style
: a style to apply to the keywords.entry_style::Style
: style to apply to entries.separator
: Separator to use between keyword and property. By default, spacing will be added ifnew_lines
.kw
: other keywords passed toShowList
Examples
julia> propertynames(1.0 + im)
(:re, :im)
julia> ShowProps(1.0 + im)
(re=1.0, im=1.0)
julia> ShowProps(1.0 + im, [:re])
(re=1.0)
julia> ShowProps(1.0 + im, [:re], keyword_style=Style(:red), new_lines=true)
(
re = 1.0
)
julia> ShowProps(1.0 + im, show_keywords=false)
(1.0, 1.0)
ShowCases.ShowCase
— FunctionShowCase(o, props=propertynames(o);
type_style=Style(), show_module=:context,
max_params=3, show_params=true, kw...)
Creates and AbstractShow
object which combines all elements used in default show
methods. This concatenates ShowTypeOf
and ShowProps
.
Arguments
o
: object to be wrapped.props
: properties of the object to be shown.type_style
: Style to be used for the type.show_module::Symbol
: whether to show the module of type and type parameters, seeShowType
.max_params::Integer
: maximum number of type parameters to show.show_params::Bool
: whether to show params. Note that ifmax_params=0
andshow_params=true
, brackets with continuation strings will be shown.kw
: other keyword arguments passed toShowProps
.
Examples
julia> ShowCase(1.0 + im)
ComplexF64{Float64}(re=1.0, im=1.0)
julia> ShowCase(1.0 + im, new_lines=true)
ComplexF64{Float64}(
re = 1.0,
im = 1.0
)
julia> ShowCase(1.0 + im, type_style=Style(:cyan, true), max_params=0)
ComplexF64{…}(re=1.0, im=1.0)
julia> ShowCase(1.0 + im, [:im], keyword_style=Style(:magenta))
ComplexF64{Float64}(im=1.0)
Misc Wrappers
ShowCases.ShowIndents
— TypeShowIndents
An AbstractShow
wrapper which inserts indents into each line in the shown output of the object it wraps.
Constructors
ShowIndents(o, indent=" ")
Arguments
o
: the object to be wrapped.indent::AbstractString
: the indent to insert.
ShowCases.ShowString
— TypeShowString
An AbstractShow
wrapper for showing strings. This implements some behaviors which are particularly useful for strings, in particular, if the string contains multiple lines, block quotes ("""
) will be used and indents will be inserted.
Constructors
ShowString(o; block::Symbol=:context, indent="")
Arguments
o
: the object to be wrapped. Typically, but not necessarily a string.block::Symbol
: (options::context
,:always
,:never
) whether to print the string as a block. If:context
, this will be done iff the string contains multiple lines.indent::AbstractString
: indent to use on new lines.
ShowCases.ShowLimit
— TypeShowLimit
An AbstractShow
wrapper for showing an object with the shown string limited to a fixed number of characters.
Constructors
ShowLimit(o; limit=typemax(Int), n=0, continuation_string="…", check_brackets=true)
Arguments
o
: the object to be wrapped.limit
: the maximum number of characters, excluding starting delimiters and the continuation string, which can be shown.n::Integer
: the position of the start of the shown string. This is useful if showing multiple outputs with a fixed limit. For example,n=1
withlimit=3
is equivalent tolimit=2
.continuation_string::AbstractString
: string to be printed if the limit is reached. Not counted toward the limit.check_brackets
: whether to check for the existence of opening brackets at the beginning of the shown string. This is useful for showing closing brackets regardless of whether the limit is reached.
Examples
julia> ShowLimit(123, limit=2)
12…
julia> ShowLimit("abc", limit=2)
"a…"
julia> ShowLimit("abc", limit=2, check_brackets=false)
"a…
julia> ShowLimit(123, limit=2, n=1)
1…
ShowCases.ShowCat
— FunctionShowCat(o...; kw...)
🐈 Show objects in series with no separation. kw
are passed to ShowList
.
For example, ShowCat("a", 1, 2)
will show "a"12
.
Style
ShowCases.Style
— TypeStyle
A struct containing metadata for specifying the "style" (i.e. color and other attributes used when printing to some displays) of an object to be shown.
Styles can be used in show
or print
with show(io, 𝔰, x)
or print(io, 𝔰, x)
where 𝔰
is a Style
and x
is any other object.
Constructors
Style(color, bold)
Style(;color=:normal, bold=false)
Arguments
color
: The color to print or show with as it would be provided toprintstyled
. Seeprintstyled
documentation for allowed color specifiers (these are eitherSymbol
e.g.:red
or integers).bold
: A boolean specifying whether the object should be shown with bold text.
Other
ShowCases.AbstractShow
— TypeAbstractShow{𝒯}
The abstract type of objects to be shown in the ShowCases
module. All such objects wrap a single object of type 𝒯
accessible via the object
field name.
Objects of the AbstractShow
type can be provided to the multi-argument show
method, e.g. show(io, Show(ξ), Print(" + "), Show(ζ))
.