Basic Wrappers

ShowCases.ShowNothingType
ShowNothing

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.ShowType
Show

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); where x is the object to be wrapped.
ShowCases.PrintType
Print

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); where x is the object to be wrapped.

Examples

julia> Print("spock")
spock

Note the lack of printed " characters.

ShowCases.StyledType
Styled{𝒯}

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 to prinstyled, see also Style.
  • bold: Whether text should be rendered as bold.

List and Element Wrappers

ShowCases.ShowEntryType
ShowEntry

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. with new_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, use Print(", ") 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.ShowKwFunction
ShowKw(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 a Symbol will be printed as in keyword arguments.
  • separator: separator between the name and shown object.
  • kw: Keyword arguments passed to ShowList.
ShowCases.ShowListType
ShowList

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 from brackets. If an argument is given directly, it will be shown as is, i.e. use Print("(") to omit quotes.
  • right_bracket: The right bracket to be shown. By default, this will be computed from brackets. If an argument is given directly, it will be shown as is, i.e. use Print(")") to omit quotes.
  • new_lines::Bool: Whether to print a new line for each entry.
  • indent::AbstractString: Indent to be used
  • delim: Delimiter to use for each entry. This will be printed as is, so for example, use Print(", ") to get commas with spacing.
  • max::Integer: the maximum number of entries to be printed.
  • continuation: object to print when max 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)
ShowCases.ShowTypeType
ShowType

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 from Base 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.ShowTypeOfBaseFunction
ShowTypeOfBase(o; kw...)

Use ShowType on the type of the object o, passing keyword arguments to that constructor. See ShowType.

ShowCases.ShowTypeOfFunction
ShowTypeOf(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. See ShowType for options.
  • kw: All other keyword arguments passed to ShowParams
ShowCases.ShowParamsFunction
ShowParams

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

  • o: the object to be wrapped.
  • show_module::Symbol: whether to show the modules of the type parameters, see ShowType for available options.
  • kw: Any other keyword arguments accepted by ShowList
ShowCases.ShowPropsFunction
ShowProps(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 if new_lines.
  • kw: other keywords passed to ShowList

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.ShowCaseFunction
ShowCase(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, see ShowType.
  • max_params::Integer: maximum number of type parameters to show.
  • show_params::Bool: whether to show params. Note that if max_params=0 and show_params=true, brackets with continuation strings will be shown.
  • kw: other keyword arguments passed to ShowProps.

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.ShowIndentsType
ShowIndents

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.ShowStringType
ShowString

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.ShowLimitType
ShowLimit

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 with limit=3 is equivalent to limit=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.ShowCatFunction
ShowCat(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.StyleType
Style

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 to printstyled. See printstyled documentation for allowed color specifiers (these are either Symbol e.g. :red or integers).
  • bold: A boolean specifying whether the object should be shown with bold text.

Other

ShowCases.AbstractShowType
AbstractShow{𝒯}

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(ζ)).