terminal_table/selectors

Composable selectors for addressing table cells independently of rendering.

Types

CellAddress = object
  section*: TableSection
  rowIndex*: int
  columnIndex*: int
Stable model address returned by matchingCells.
CellContext = object
  section*: TableSection
  rowIndex*: int
  columnIndex*: int
  cell*: Cell
Read-only information supplied to predicate selectors.
CellModifier = proc (cell: var Cell) {.closure.}
CellPredicate = proc (context: CellContext): bool {.closure.}
Selector = object
A reusable predicate over header, body, and footer cells.
TableSection = enum
  sectionHeader, sectionBody, sectionFooter
A selectable fixed-grid section.

Procs

proc allCellsSelector(): Selector {....raises: [ValueError], tags: [], forbids: [].}
Selects header, body, and footer cells.
proc apply(table: var Table; selector: Selector; modifier: CellModifier) {.
    ...raises: [ValueError, Exception], tags: [RootEffect], forbids: [].}
Applies modifier once to every selected cell.
proc cellSelector(rowIndex, columnIndex: Natural): Selector {.
    ...raises: [ValueError], tags: [], forbids: [].}
Selects one body cell.
proc columnSelector(columnIndex: Natural): Selector {....raises: [ValueError],
    tags: [], forbids: [].}
Selects one column in the header, body, and footer.
proc footerSelector(): Selector {....raises: [ValueError], tags: [], forbids: [].}
Selects every footer cell.
proc headerSelector(): Selector {....raises: [ValueError], tags: [], forbids: [].}
Selects every header cell.
proc matchingCells(table: Table; selector: Selector): seq[CellAddress] {.
    ...raises: [ValueError, Exception], tags: [RootEffect], forbids: [].}
Returns matching model addresses in header/body/footer order.
proc `or`(left, right: Selector): Selector {....raises: [ValueError], tags: [],
    forbids: [].}
Combines selectors as a set union.
proc predicateSelector(predicate: CellPredicate): Selector {.
    ...raises: [ValueError], tags: [], forbids: [].}
Selects every cell for which predicate returns true.
proc rowSelector(rowIndex: Natural): Selector {....raises: [ValueError], tags: [],
    forbids: [].}
Selects one zero-based body row.
proc segmentSelector(firstRow, firstColumn, lastRow, lastColumn: Natural): Selector {.
    ...raises: [ValueError], tags: [], forbids: [].}
Selects an inclusive rectangular body segment.