Reference
GarishPrint.ColorPreference
— TypeColorPreference
The color preference type.
GarishPrint.ColorPreference
— MethodColorPreference(;kw...)
See pprint
for available keyword configurations.
GarishPrint.GarishIO
— TypeGarishIO{IO_t <: IO} <: IO
GarishIO
contains the pretty printing preference and states.
Members
bland_io::IO_t
: the original io.indent::Int
: indentation size.compact::Bool
: whether the printing should be compact.width::Int
: the terminal width.show_indent
: print the indentation hint or not.color
: color preference, eitherColorPreference
ornothing
for no color.state
: the state of the printer, seePrintState
.
GarishPrint.GarishIO
— MethodGarishIO(io::IO, garish_io::GarishIO; kw...)
Create a new similar GarishIO
with new bland IO object io
based on an existing garish io preference. The preference can be overloaded by kw
. See pprint
for the available keyword arguments.
GarishPrint.GarishIO
— MethodGarishIO(io::IO; kw...)
See pprint
for available keywords.
GarishPrint.PrintType
— Type@enum PrintType
PrintType
to tell lower level printing some useful context. Currently only supports Unknown
and StructField
.
GarishPrint.default_colors_256
— Methoddefault_colors_256()
The default color 256 theme.
GarishPrint.default_colors_ansi
— Methoddefault_colors_ansi()
The default ANSI color theme.
GarishPrint.pprint
— Methodpprint(io::IO, mime::MIME, x; kw...)
Pretty print an object x with given MIME
type.
currently only supports MIME"text/plain"
, the implementation of MIME"text/html"
is coming soon. Please also feel free to file an issue if you have a desired format wants to support.
GarishPrint.pprint
— Methodpprint([io::IO=stdout, ]xs...; kw...)
Pretty print given objects xs
to io
, default io is stdout
.
Keyword Arguments
indent::Int
: indent size, default is2
.compact::Bool
: whether print withint one line, default isget(io, :compact, false)
.width::Int
: the width hint of printed string, note this is not stricted obeyed,
default is displaysize(io)[2].
show_indent::Bool
: whether print indentation hint, default istrue
.color::Bool
: whether print with color, default istrue
.
Color Preference
color preference is available as keyword arguments to override the default color scheme. These arguments may take any of the values :normal
, :default
, :bold
, :black
, :blink
, :blue
, :cyan
, :green
, :hidden
, :light_black
, :light_blue
, :light_cyan
, :light_green
, :light_magenta
, :light_red
, :light_yellow
, :magenta
, :nothing
, :red
, :reverse
, :underline
, :white
, or :yellow
or an integer between 0 and 255 inclusive. Note that not all terminals support 256 colors.
The default color scheme can be checked via GarishPrint.default_colors_256()
for 256 color, and GarishPrint.default_colors_ansi()
for ANSI color. The 256 color will be used when the terminal is detected to support 256 color.
fieldname
: field name of a struct.type
: the color of a type.operator
: the color of an operator, e.g+
,=>
.literal
: the color of literals.constant
: the color of constants, e.gπ
.number
: the color of numbers, e.g1.2
,1
.string
: the color of string.comment
: comments, e.g# some comments
undef
: the const binding toUndefInitializer
linenumber
: line numbers.
Notes
The color print and compact print can also be turned on/off by setting IOContext
, e.g IOContext(io, :color=>false)
will print without color, and IOContext(io, :compact=>true)
will print within one line. This is also what the standard Julia IO
objects follows in printing by default.
GarishPrint.pprint_list_like
— Functionpprint_list_like(io::GarishIO, list, opn='[', cls=']'; compact::Bool=io.compact)
Print a list-like object list
. A list-like object should support the iterable interface such as Base.iterate
and Base.length
. This is modified based on base/arrayshow.jl:show_vector
.
Arguments
io::GarishIO
: theGarishIO
object one wants to print to.list
: the list-like object.opn
: the openning marker, default is[
.cls
: the closing marker, default is]
.
Keyword Arguments
compact::Bool
: print the list within one line or not.
GarishPrint.pprint_struct
— Methodpprint_struct(io::GarishIO, ::MIME, x)
Print x
as a struct type.
GarishPrint.print_indent
— Methodprint_indent(io::GarishIO)
Print an indentation. This should be only used under MIME"text/plain"
or equivalent.
GarishPrint.print_operator
— Methodprint_operator(io::GarishIO, op)
Print an operator, such as =
, +
, =>
etc. This should be only used under MIME"text/plain"
or equivalent.
GarishPrint.print_token
— Methodprint_token(f, io::GarishIO, type::Symbol, xs...)
Print xs
to a GarishIO
as given token type using f(io, xs...)
GarishPrint.print_token
— Methodprint_token(io::GarishIO, type::Symbol, xs...)
Print xs
to a GarishIO
as given token type. The token type should match the field name of ColorPreference
.
GarishPrint.supports_color256
— Methodsupports_color256()
Check if the terminal supports color 256.
GarishPrint.tty_has_color
— Methodtty_has_color()
Check if TTY supports color. This is mainly for lower Julia version like 1.0.
GarishPrint.within_nextlevel
— Methodwithin_nextlevel(f, io::GarishIO)
Run f()
within the next level of indentation where f
is a function that print into io
.