Table widget
This module provides table widgets for displaying structured data in rows and columns, with support for headers, selection, scrolling, and styling.
Types
BorderStyle = enum NoBorder, SimpleBorder, RoundedBorder, DoubleBorder
- Table border drawing style
Column = object title*: string width*: Option[int] alignment*: ColumnAlignment style*: Option[Style]
- Table column definition
ColumnAlignment = enum AlignLeft, AlignCenter, AlignRight
- Column text alignment options
SelectionMode = enum None, Single, Multiple
- Table selection behavior
Table = ref object of Widget columns*: seq[Column] rows*: seq[TableRow] selectionMode*: SelectionMode selectedIndices*: seq[int] highlightedIndex*: int scrollOffset*: int visibleRowCount*: int showHeader*: bool borderStyle*: BorderStyle columnSpacing*: int showScrollbar*: bool headerStyle*: Style normalRowStyle*: Style selectedRowStyle*: Style highlightedRowStyle*: Style borderStyleOptions*: Style onSelect*: proc (index: int) onMultiSelect*: proc (indices: seq[int]) onHighlight*: proc (index: int)
- Table widget for structured data
Procs
proc calculateColumnWidths(widget: Table; availableWidth: int): seq[int] {. ...raises: [], tags: [], forbids: [].}
- Calculate actual column widths based on content and constraints
proc calculateTotalLineWidth(columnWidths: seq[int]; columnSpacing: int; hasBorders: bool): int {....raises: [], tags: [], forbids: [].}
- Calculate the total width needed for a table line including borders and spacing
proc clearSelection(widget: Table) {....raises: [Exception], tags: [RootEffect], forbids: [].}
- Clear all selections
proc column(title: string): Column {....raises: [], tags: [], forbids: [].}
- Convenience constructor for simple column
proc column(title: string; alignment: ColumnAlignment): Column {....raises: [], tags: [], forbids: [].}
- Create column with specific alignment
proc deselectRow(widget: Table; index: int) {....raises: [Exception], tags: [RootEffect], forbids: [].}
- Deselect a row (for multiple selection mode)
proc formatCell(content: string; width: int; alignment: ColumnAlignment): string {. ...raises: [], tags: [], forbids: [].}
- Format a cell's content within the given width
proc fullPageDown(widget: Table) {....raises: [Exception], tags: [RootEffect], forbids: [].}
- Scroll down by full page (vim: Ctrl-F)
proc fullPageUp(widget: Table) {....raises: [Exception], tags: [RootEffect], forbids: [].}
- Scroll up by full page (vim: Ctrl-B)
proc getBorderChars(style: BorderStyle): tuple[horizontal: string, vertical: string, topLeft: string, topRight: string, bottomLeft: string, bottomRight: string, cross: string, topT: string, bottomT: string, leftT: string, rightT: string] {....raises: [], tags: [], forbids: [].}
- Get border characters for the specified border style
proc handleKeyEvent(widget: Table; event: KeyEvent): bool {....raises: [Exception], tags: [RootEffect], forbids: [].}
- Handle keyboard input for the table with vim-like navigation Returns true if the event was handled
proc highlightFirst(widget: Table) {....raises: [Exception], tags: [RootEffect], forbids: [].}
- Move highlight to first selectable row (vim: gg)
proc highlightLast(widget: Table) {....raises: [Exception], tags: [RootEffect], forbids: [].}
- Move highlight to last selectable row (vim: G)
proc highlightNext(widget: Table) {....raises: [Exception], tags: [RootEffect], forbids: [].}
- Move highlight to next selectable row
proc highlightPrevious(widget: Table) {....raises: [Exception], tags: [RootEffect], forbids: [].}
- Move highlight to previous selectable row
proc isSelected(widget: Table; index: int): bool {....raises: [], tags: [], forbids: [].}
- Check if a row is selected
proc newColumn(title: string; width: Option[int] = none(int); alignment: ColumnAlignment = AlignLeft; style: Option[Style] = none(Style)): Column {....raises: [], tags: [], forbids: [].}
- Create a new table column
proc newTable(columns: seq[Column] = @[]; rows: seq[TableRow] = @[]; selectionMode: SelectionMode = Single; showHeader: bool = true; borderStyle: BorderStyle = SimpleBorder; columnSpacing: int = 1; showScrollbar: bool = true; headerStyle: Style = style(White, BrightBlack); normalRowStyle: Style = defaultStyle(); selectedRowStyle: Style = style(Black, White); highlightedRowStyle: Style = style(White, BrightBlack); borderStyleOptions: Style = style(BrightBlack); onSelect: proc (index: int) = nil; onMultiSelect: proc (indices: seq[int]) = nil; onHighlight: proc (index: int) = nil): Table {....raises: [], tags: [], forbids: [].}
- Create a new Table widget
proc newTableRow(cells: seq[string]; style: Option[Style] = none(Style); selectable: bool = true): TableRow {....raises: [], tags: [], forbids: [].}
- Create a new table row
proc removeColumn(widget: Table; index: int) {....raises: [], tags: [], forbids: [].}
- Remove a column from the table
proc scrollDown(widget: Table; lines: int = 1) {....raises: [], tags: [], forbids: [].}
- Scroll the table down
proc toggleSelection(widget: Table; index: int) {....raises: [Exception], tags: [RootEffect], forbids: [].}
- Toggle selection of a row
Methods
method getMinSize(widget: Table): Size {....raises: [], tags: [], forbids: [].}
- Get minimum size for table widget
method getPreferredSize(widget: Table; available: Size): Size {....raises: [], tags: [], forbids: [].}
- Get preferred size for table widget