5.61. kink/io/OUTPUT_PRINTER

Provides a printer implementation wrapping output.

5.61.1. OUTPUT_PRINTER.new(Output Charset Newline ...[$config={}])

`new` makes a val which supports both `printer` and `output` types, which encodes str using `Charset`, and writes bin to `Output`.

Config method:

• C.flush_on_print

If C.flush_on_print is called, the buffer of `Output` is flushed every time after `print` or `print_line` is called.

Preconditions

• `Output` must be an output

• `Charset` must be a charset

• `Newline` must be a str

Example

:BIN_OUTPUT.require_from('kink/io/')
:OUTPUT_PRINTER.require_from('kink/io/')
:CHARSET.require_from('kink/charset/')

:Out <- BIN_OUTPUT.new
:P <- OUTPUT_PRINTER.new(Out CHARSET.utf8 "\r\n"){(:W)
  W.flush_on_print
}
P.print_line('foo')
stdout.print_line(Out.bin.repr) # => (bin 0x66 0x6f 0x6f 0x0d 0x0a)