cligen/textUt

Search:
Group by:

Types

NoCSI_OSC = object
Call-to-call state used by the noCSI_OSC iterator
TextTab = seq[seq[string]]

Lets

ttyWidth = terminalWidth()

Procs

proc addPrefix(prefix: string; multiline = ""): string {....raises: [], tags: [],
    forbids: [].}
proc alignTable(tab: TextTab; prefixLen = 0; colGap = 2; minLast = 16;
                rowSep = ""; cols = @[0, 1]; attrOn = @["", ""];
                attrOff = @["", ""]; aligns = ""; width = ttyWidth;
                measure = printedLen): string {....raises: [], tags: [],
    forbids: [].}
proc distDamerau[T](a, b: openArray[T]; maxDist = mxC; idC = C(1); subC = C(1);
                    xpoC = C(1); dI: var seq[C]): C
True Damerau(1964) distance with unrestricted transpositions.
proc getAll[T](cb: CritBitTree[T]; key: string): seq[tuple[key: string, val: T]]
A query function sometimes helpful in making CritBitTree[T] code more like Table[string,T] code. result.len > 1 only on ambiguous matches.
proc initCritBitTree[T](): CritBitTree[T]
A constructor sometimes helpful when replacing Table[string,T] with CritBitTree[T].
proc keys[T](cb: CritBitTree[T]): seq[string]
proc keys[T](x: seq[tuple[key: string, val: T]]): seq[string]
An extractor of just the key part of a seq[(key,val)].
proc match[T](cb: CritBitTree[T]; key, tag: string; err = stderr): tuple[
    key: string, val: T]
Wrapper around above match that on failure writes user-friendly messages to err (nil suppresses this) and raises KeyError with a message that starts with "Ambiguous" or "Unknown".
proc match[T](cb: CritBitTree[T]; key, tag: string; msg: var string;
              suppress = false): tuple[key: string, val: T]
One stop lookup of a key in cb giving either the (key, value) matched or an ambiguous|unknown error message with possible suggestions if non-empty, unless suppress is true in which case msg is simply non-empty. tag is a category for the message, like 'color' or such.
proc printedLen(a: openArray[char]): int {....raises: [], tags: [], forbids: [].}
Rendered width in terminal cells, accounting for ANSI SGR colors &| utf8. This counts invalid start-bytes as 1 cell.
proc stripEsc(a: openArray[char]): string {....raises: [], tags: [], forbids: [].}
Use noCSI_OSC to give a without non-rendering terminal escape seqs.
proc stripSGR(a: openArray[char]): string {....raises: [], tags: [], forbids: [].}
Alias for stripEsc.
proc suggestions[T](wrong: string; match, right: openArray[T];
                    enoughResults = 3; unrelatedDistance = C(4)): seq[string]
Return entries from right if the parallel entry in match is "close" to wrong in order of (in Damerau distance units). Considering further distances is halted once result has enoughResults (but all suggestions for a given distance are included). Matches >= unrelatedDistance are not considered.
proc termAlign(s: string; count: Natural; padding = ' '): string {....raises: [],
    tags: [], forbids: [].}
Just like strutils.align but assess width via printedLen.
proc termAlignLeft(s: string; count: Natural; padding = ' '): string {.
    ...raises: [], tags: [], forbids: [].}
Just like strutils.alignLeft but assess width via printedLen.
proc toSetChar(s: string; unescape = false): set[char] {....raises: [ValueError],
    tags: [], forbids: [].}
Make & return character set built from a string, maybe un-escaping.
proc wrap(s: string; maxWidth = ttyWidth; power = 3; prefixLen = 0): string {.
    ...raises: [], tags: [], forbids: [].}
Multi-paragraph with indent==>pre-formatted optimal line wrapping using the badness metric sum excessSpace^power.
proc wrapWidth(envVar: string; defaultWidth = ttyWidth): int {.
    ...raises: [ValueError], tags: [ReadEnvEffect], forbids: [].}

Iterators

iterator noCSI_OSC(a: openArray[char]; nc: var NoCSI_OSC = nc0): char {.
    ...raises: [], tags: [], forbids: [].}
Iterate over chars in a skipping CSI/OSC term escape seqs ("\e[..m", "\e]..\e\\"). See en.wikipedia.org/wiki/ANSI_escape_code "Fe Escape". To aid buffered use, if provided, nc can propagate parser state.
iterator paragraphs(s: string; indent = {' ', '\t'}): tuple[pre: bool,
    para: string] {....raises: [], tags: [], forbids: [].}
This iterator frames paragraphs in s delimited either by double-newline or by changes in indent status. Any indented line is considered a whole, pre-formatted paragraph. This indent rule allows easy author control over what text is eligible for word-wrapping.
iterator unescaped(s: string): char {....raises: [ValueError], tags: [],
                                      forbids: [].}
Handles 1-byte octal, [abtnvfre], and xDD hex escapes