spruce/output
Pipeable output accumulation.
An Output threads a Spruce context and a buffer of rendered blocks
through a pipeline, so several renderers compose with |> and emit
together. It stays pure: nothing is printed until print, and the context
is threaded for you so each renderer sees the right color level and indent
depth.
import spruce
import spruce/message
import spruce/output
pub fn main() {
let sp = spruce.detect()
output.new(sp)
|> output.append(message.start(_, "compiling"))
|> output.group("Tests", fn(o) {
o |> output.append(message.info(_, "running"))
})
|> output.print
}
append accepts any Spruce -> String renderer via a _ capture, so it
works with every spruce module without per-type variants. For eager,
streaming grouping that prints as work happens and can return a value, use
spruce/group.group instead.
Types
Values
pub fn append(
output: Output,
render: fn(spruce.Spruce) -> String,
) -> Output
Append a rendered block produced by render, which receives the output’s
context. Works with any Spruce -> String renderer via a _ capture, e.g.
output.append(message.success(_, "done")).
pub fn context(output: Output) -> spruce.Spruce
The context the output renders with. Reflects the current group depth inside
a group body.
pub fn group(
output: Output,
title: String,
body: fn(Output) -> Output,
) -> Output
Append a styled group title, then run body with the output’s context
indented one level deeper. Blocks appended inside body nest under the
title. Unlike spruce/group.group, this buffers output rather than printing.