module C0::Pretty

Overview

Unicode Control Pictures (U+2400 block) for pretty-printing. Each C0 code at position N maps to U+2400+N.

Defined in:

c0/pretty.cr

Constant Summary

G_DLE = glyph(DLE)
G_EOT = glyph(EOT)
G_FS = glyph(FS)
G_GS = glyph(GS)
G_RS = glyph(RS)
G_SOH = glyph(SOH)
G_US = glyph(US)
PREFIXES = Set {G_FS, G_GS, G_RS, G_SOH, G_US}

Class Method Summary

Class Method Detail

def self.align(pretty : String, mode : FormatMode = FormatMode::Spaced) : String #

Reformat a pretty-form string with column alignment.

Modes:

  • Aligned — column alignment only
  • Spaced — column alignment + space after prefix + space around ␟

[View source]
def self.format(buf : Bytes, indent : String = " ", mode : FormatMode = FormatMode::Compact) : String #

Format a compact C0DATA buffer as a human-readable Unicode string with newlines and indentation.


[View source]
def self.format(buf : Bytes, io : IO, indent : String = " ", mode : FormatMode = FormatMode::Compact) : Nil #

Format to an IO.


[View source]
def self.glyph(byte : UInt8) : Char #

Convert a C0 control byte to its Unicode Control Picture character.


[View source]
def self.parse(str : String) : Bytes #

Parse pretty-form back to compact form.

Rules:

  • Unicode Control Pictures (U+2400-U+241F) → C0 bytes
  • LF/CR are ignored (formatting only)
  • Whitespace (space/tab) adjacent to control codes is trimmed
  • Inside STX/ETX (␂...␃), everything is preserved verbatim (no trimming). This allows STX/ETX to serve as quoting for values with significant whitespace.

[View source]