Module
poke/pretty
src/poke/pretty.pookaPrint values so that people can read them.
echo puts a value on one line, however long. Poke’s formatter lays it out: a value
that fits the width stays on one line, and one that does not is broken
over several, indented, one item per line. Output stays plain in terminals and snapshot files.
import poke/pretty
class Owl(name: String, age: Int, friends: List(String))
main() {
pretty.print(Owl("Ada", 3, ["Bramble", "Fig", "Thistle"]))
}
Poke’s formatter shows values the way they are written in Pooka: Some(1),
#(1, "a"), Owl("Ada", 3, []). Field names are not kept when a program
runs, so fields appear in the order they were declared.
API reference
class Options(
width: Int,
indent: Int,
max_items: Int,
max_depth: Int,
)
How to lay a value out.
width: the longest line allowed, in characters.indent: how many spaces each level moves to the right.max_items: show at most this many items of a list, dict or set, then say how many were left out.0shows them all.max_depth: show at most this many levels, then....0shows them all.
width: Int
Intindent: Int
Intmax_items: Int
Intmax_depth: Int
Int
fn(Int, Int, Int, Int) -> poke/pretty.Optionswith_width(width: Int) -> Options
fn(Int) -> poke/pretty.Optionswith_indent(indent: Int) -> Options
fn(Int) -> poke/pretty.Optionswith_max_items(max_items: Int) -> Options
fn(Int) -> poke/pretty.Optionswith_max_depth(max_depth: Int) -> Options
fn(Int) -> poke/pretty.Optionsdefaults() -> Options
fn() -> poke/pretty.OptionsPlain text, 80 characters wide, indented by two spaces, nothing left out.
import poke/pretty
let narrow = pretty.defaults().with_width(40).with_max_items(10)
terminal() -> Options
fn() -> poke/pretty.OptionsFit the terminal width, keeping output plain.
format(value: a) -> String
fn(a) -> StringLay a value out as plain text.
import poke/pretty
assert pretty.format(#(1, "owl", Some(True))) == "#(1, \"owl\", Some(True))"
format_with(value: a, options: Options) -> String
fn(a, poke/pretty.Options) -> StringLay a value out with your own options.
import poke/pretty
let options = pretty.defaults().with_width(8)
assert pretty.format_with([100, 200, 300], options) == "[\n 100,\n 200,\n 300\n]"
print(value: a) -> a
fn(a) -> aPrint a value to standard output, fitted to the terminal, and hand the same value back, so it can sit in the middle of a pipeline.
import poke/pretty
main() {
let total = pretty.print([1, 2, 3])
pretty.print(total)
}
print_with(value: a, options: Options) -> a
fn(a, poke/pretty.Options) -> aPrint a value to standard output with your own options, and hand the same value back.