Module

poke/pretty

src/poke/pretty.pooka

Print 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.

Pooka
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

src/poke/pretty.pooka:33
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. 0 shows them all.
  • max_depth: show at most this many levels, then .... 0 shows them all.
field

width

src/poke/pretty.pooka:34
width: Int
INFERREDInt
field

indent

src/poke/pretty.pooka:35
indent: Int
INFERREDInt
field

max_items

src/poke/pretty.pooka:36
max_items: Int
INFERREDInt
field

max_depth

src/poke/pretty.pooka:37
max_depth: Int
INFERREDInt
constructor

new

src/poke/pretty.pooka:34
INFERREDfn(Int, Int, Int, Int) -> poke/pretty.Options
method

with_width

src/poke/pretty.pooka:39
with_width(width: Int) -> Options
INFERREDfn(Int) -> poke/pretty.Options
method

with_indent

src/poke/pretty.pooka:43
with_indent(indent: Int) -> Options
INFERREDfn(Int) -> poke/pretty.Options
method

with_max_items

src/poke/pretty.pooka:47
with_max_items(max_items: Int) -> Options
INFERREDfn(Int) -> poke/pretty.Options
method

with_max_depth

src/poke/pretty.pooka:51
with_max_depth(max_depth: Int) -> Options
INFERREDfn(Int) -> poke/pretty.Options
function

defaults

src/poke/pretty.pooka:77
defaults() -> Options
INFERREDfn() -> poke/pretty.Options

Plain text, 80 characters wide, indented by two spaces, nothing left out.

Pooka
import poke/pretty

let narrow = pretty.defaults().with_width(40).with_max_items(10)
function

terminal

src/poke/pretty.pooka:82
terminal() -> Options
INFERREDfn() -> poke/pretty.Options

Fit the terminal width, keeping output plain.

function

format

src/poke/pretty.pooka:93
format(value: a) -> String
INFERREDfn(a) -> String

Lay a value out as plain text.

Pooka
import poke/pretty

assert pretty.format(#(1, "owl", Some(True))) == "#(1, \"owl\", Some(True))"
function

format_with

src/poke/pretty.pooka:105
format_with(value: a, options: Options) -> String
INFERREDfn(a, poke/pretty.Options) -> String

Lay a value out with your own options.

Pooka
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]"
function

print

src/poke/pretty.pooka:126
print(value: a) -> a
INFERREDfn(a) -> a

Print 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.

Pooka
import poke/pretty

main() {
  let total = pretty.print([1, 2, 3])
  pretty.print(total)
}
function

print_with

src/poke/pretty.pooka:132
print_with(value: a, options: Options) -> a
INFERREDfn(a, poke/pretty.Options) -> a

Print a value to standard output with your own options, and hand the same value back.