flagstaff/cli-table3
Every export of flagstaff/cli-table3, with its signature and doc comment: strlen, pad, truncate, wordWrap, hyperlink, mergeOptions and 9 more, plus 3 types.
import Table from 'flagstaff/cli-table3';
import { strlen, pad, truncate, … } from 'flagstaff/cli-table3';Functions
hyperlink
OSC 8 — the terminal hyperlink escape, and not this package's to spell (R12). The
sequence is paratext's link capability rendered against {@link EMITTING }; this function
contributes the argument order and upstream's url || text, and nothing else.
Upstream's hyperlink() is an escape builder, not a policy decision: utils-test.js
grades its exact bytes with no terminal anywhere in the call, and a cell given an href
gets a sequence whatever process.stdout is. So this stays unconditional — the caller
already decided — and the runtime handed to paratext says so out loud. flagstaff/table
is the surface that asks whether the terminal can (rule 6); a façade that started asking
would be reinterpreting its host, and link.test.ts pins these bytes against upstream's.
function hyperlink(url: string, text: string): string;| Parameter | Type |
|---|---|
url | string |
text | string |
Returns string
makeTableLayout
function makeTableLayout(rows: unknown[]): Drawable[][];| Parameter | Type |
|---|---|
rows | unknown[] |
Returns Drawable[][]
mergeOptions
function mergeOptions(options?: TableOptions, defaults?: TableOptions): TableOptions;| Parameter | Type |
|---|---|
options (optional) | TableOptions |
defaults (optional) | TableOptions |
Returns TableOptions
pad
Pad to len columns. right pads on the left, which is upstream's naming, not a typo.
function pad(str: string, len: number, padChar: string, dir?: string): string;| Parameter | Type |
|---|---|
str | string |
len | number |
padChar | string |
dir (optional) | string |
Returns string
strlen
Widest line, measured with SGR removed. Upstream's strlen.
function strlen(str: unknown): number;| Parameter | Type |
|---|---|
str | unknown |
Returns number
truncate
function truncate(str: string, desiredLength: number, truncateChar?: string): string;| Parameter | Type |
|---|---|
str | string |
desiredLength | number |
truncateChar (optional) | string |
Returns string
wordWrap
function wordWrap(maxLength: number, input: string, wrapOnWordBoundary?: boolean): string[];| Parameter | Type |
|---|---|
maxLength | number |
input | string |
wrapOnWordBoundary (optional) | boolean |
Returns string[]
Classes
default
The default export, declared as Table.
A table. Extends Array, because cli-table3 does and its callers push rows onto it.
class Table extends Array<unknown> {
readonly options: ResolvedOptions;
readonly messages?: string[];
constructor(opts?: TableOptions);
/** Clears the module-level message log. The suite calls it after every case. */
static reset(): void;
toString(): string;
get width(): number;
}Cell
class Cell implements Drawable {
x: number;
y: number;
colSpan: number;
rowSpan: number;
content: string;
options: Record<string, unknown>;
chars: TableChars;
truncate: string;
paddingLeft: number;
paddingRight: number;
head?: string[] | undefined;
border?: string[] | undefined;
fixedWidth?: number | null | undefined;
lines: string[];
desiredWidth: number;
desiredHeight: number;
widths: number[];
heights: number[];
width: number;
height: number;
hAlign?: string | undefined;
vAlign?: string | undefined;
drawRight: boolean;
cells?: Drawable[][] | undefined;
href?: string | undefined;
constructor(options?: unknown);
mergeTableOptions(tableOptions: ResolvedOptions, cells: Drawable[][]): void;
computeLines(tableOptions: ResolvedOptions): string[];
/**
* The href is deliberately *not* applied here. `drawLine` truncates the line it is given,
* and a hyperlink wrapped around the content before that point is cut through the middle
* of its own URL — upstream's issue #338, which emits `\x1b]8;;http://e…` and a terminal
* escape that never closes. The link goes on after truncation instead, around whatever
* text actually survived.
*/
wrapLines(computedLines: string[]): string[];
init(tableOptions: ResolvedOptions): void;
draw(lineNum: number | string, spanningCell?: number): string;
drawTop(drawRight: boolean): string;
private topLeftChar;
/** The left edge, which a row-spanning neighbour turns into a `rightMid`. */
private leftEdge;
drawLine(lineNum: number, drawRight: boolean, forceTruncationSymbol: boolean, spanningCell?: number): string;
private stylizeLine;
drawBottom(drawRight: boolean): string;
drawEmpty(drawRight: boolean, spanningCell?: number): string;
}ColSpanCell
A placeholder that draws nothing, holding the place of a column-spanned cell.
class ColSpanCell implements Drawable {
x: number;
y: number;
colSpan: number;
rowSpan: number;
draw(lineNum?: number | string): string;
init(): void;
mergeTableOptions(): void;
}module.exports
A table. Extends Array, because cli-table3 does and its callers push rows onto it.
class Table extends Array<unknown> {
readonly options: ResolvedOptions;
readonly messages?: string[];
constructor(opts?: TableOptions);
/** Clears the module-level message log. The suite calls it after every case. */
static reset(): void;
toString(): string;
get width(): number;
}RowSpanCell
A placeholder that defers to the cell above it, offset by the rows in between.
class RowSpanCell implements Drawable {
readonly originalCell: Cell;
x: number;
y: number;
colSpan: number;
rowSpan: number;
private cellOffset;
private offset;
constructor(originalCell: Cell);
init(tableOptions: ResolvedOptions): void;
draw(lineNum: number | string): string;
mergeTableOptions(): void;
}Table
A table. Extends Array, because cli-table3 does and its callers push rows onto it.
class Table extends Array<unknown> {
readonly options: ResolvedOptions;
readonly messages?: string[];
constructor(opts?: TableOptions);
/** Clears the module-level message log. The suite calls it after every case. */
static reset(): void;
toString(): string;
get width(): number;
}Constants
computeHeights
const computeHeights: (vals: number[], table: Drawable[][]) => void;computeWidths
const computeWidths: (vals: number[], table: Drawable[][]) => void;Interfaces
TableChars
interface TableChars {
[name: string]: string;
}TableOptions
interface TableOptions {
chars?: Partial<TableChars>;
truncate?: string;
colWidths?: (number | null)[];
rowHeights?: (number | null)[];
colAligns?: (string | undefined)[];
rowAligns?: (string | undefined)[];
style?: TableStyle;
head?: unknown[];
wordWrap?: boolean;
/** cli-table3's older name for `wordWrap`, still honoured. */
textWrap?: boolean;
wrapOnWordBoundary?: boolean;
}TableStyle
interface TableStyle {
'padding-left'?: number;
'padding-right'?: number;
head?: string[];
border?: string[];
compact?: boolean;
}