class

PrettyPrint

Inherits Reference / Object

This class implements a pretty printing algorithm. It finds line breaks and nice indentations for grouped structure.

References

Constructors

new(output : IO, maxwidth : Int32 = 79, newline : String = "\n", indent : Int32 = 0)

Creates a new pretty printer that will write to the given output and be capped at maxwidth.

Source

Class methods

format(obj, io : IO, width : Int32, newline = "\n", indent = 0)

Pretty prints obj into io with the given width as a limit and starting with the given indentation.

Source
format(io : IO, width : Int32, newline = "\n", indent = 0, &)

Creates a pretty printer and yields it to the block, appending any output to the given io.

Source

Instance methods

breakable(sep = " ") : Nil

Appends an element that can turn into a newline if necessary.

Source
comma

Same as:

text ","
breakable
Source
fill_breakable(sep = " ") : Nil

Similar to #breakable except the decision to break or not is determined individually.

Source
flush

Outputs any buffered data.

Source
group(indent = 0, open_obj = "", close_obj = "", &)

Creates a group of objects. Inside a group all breakable objects are either turned into newlines or are output as is, depending on the available width.

Source
list(left, elements, right, &) : Nil

Appends a list of elements surrounded by left and right and separated by commas, yielding each element to the given block.

Source
list(left, elements, right) : Nil

Appends a list of elements surrounded by left and right and separated by commas.

Source
nest(indent = 1, &)

Increases the indentation for breakables inside the current group.

Source
surround(left, right, left_break = "", right_break = "", &) : Nil

Appends a group that is surrounded by the given left and right objects, and optionally is surrounded by the given breakable objects.

Source
text(obj) : Nil

Appends a text element.

Source