hwylterm/tables

Search:
Group by:
Source   Edit  

Types

ColumnAlign = enum
  Left, Center, Right
Source   Edit  
HwylTable = object
  rows*: seq[seq[BbString]]
Source   Edit  
HwylTableError = object of CatchableError
Source   Edit  
HwylTableSeps = object
Source   Edit  
HwylTableSepType = enum
  None, Ascii, Box, BoxRounded
Source   Edit  
HwylTableStyle = object
  headerStyle* = "bold"
  rowStyles*: seq[string] = []
  headerAlign*: seq[ColumnAlign] = []
  colAlign*: seq[ColumnAlign] = []
  header* = true
  border* = true
  headerSep* = true
  rowSep* = false
  colSep* = true
  sepStyle* = ""
  seps* = (topLeft: "╭", topRight: "╮", topMiddle: "┬", bottomLeft: "╰",
           bottomRight: "╯", bottomMiddle: "┴", centerLeft: "├",
           centerRight: "┤", centerMiddle: "┼", vertical: "│",
           horizontal: "─")
Source   Edit  

Consts

HwylTableSepsByType = [(topLeft: " ", topRight: " ", topMiddle: " ",
                        bottomLeft: " ", bottomRight: " ", bottomMiddle: " ",
                        centerLeft: " ", centerRight: " ", centerMiddle: " ",
                        vertical: " ", horizontal: " "), (topLeft: "+",
    topRight: "+", topMiddle: "+", bottomLeft: "+", bottomRight: "+",
    bottomMiddle: "+", centerLeft: "+", centerRight: "+", centerMiddle: "+",
    vertical: "|", horizontal: "-"), (topLeft: "┌", topRight: "┐",
                                      topMiddle: "┬", bottomLeft: "└",
                                      bottomRight: "┘", bottomMiddle: "┴",
                                      centerLeft: "├", centerRight: "┤",
                                      centerMiddle: "┼", vertical: "│",
                                      horizontal: "─"), (topLeft: "╭",
    topRight: "╮", topMiddle: "┬", bottomLeft: "╰", bottomRight: "╯",
    bottomMiddle: "┴", centerLeft: "├", centerRight: "┤",
    centerMiddle: "┼", vertical: "│", horizontal: "─")]
Source   Edit  

Procs

func addCol(t: var HwylTable; col: varargs[BbString]) {.
    ...raises: [HwylTableError], tags: [], forbids: [].}
Source   Edit  
func addCol(t: var HwylTable; col: varargs[string]) {....raises: [HwylTableError],
    tags: [], forbids: [].}
Source   Edit  
func addRow(t: var HwylTable; cols: varargs[BbString]) {....raises: [], tags: [],
    forbids: [].}
Source   Edit  
func addRow(t: var HwylTable; cols: varargs[string]) {....raises: [], tags: [],
    forbids: [].}
Source   Edit  
func borderMiddle(colWidths: seq[int]; style: HwylTableStyle; top = false): string {.
    ...raises: [], tags: [], forbids: [].}
Source   Edit  
func borderMiddleSep(style: HwylTableStyle; top = false): string {....raises: [],
    tags: [], forbids: [].}
Source   Edit  
func bottomBorder(colWidths: seq[int]; style: HwylTableStyle): BbString {.
    ...raises: [], tags: [], forbids: [].}
Source   Edit  
func getColWidths(t: HwylTable): seq[int] {....raises: [], tags: [], forbids: [].}
Source   Edit  
func getRowLengths(t: HwylTable): seq[seq[int]] {....raises: [], tags: [],
    forbids: [].}
Source   Edit  
func newHwylTableStyle(sepType: HwylTableSepType): HwylTableStyle {....raises: [],
    tags: [], forbids: [].}
Source   Edit  
proc render(t: HwylTable; style = HwylTableStyle()): BbString {.
    ...raises: [HwylTableError], tags: [], forbids: [].}
Source   Edit  
func renderDiv(t: HwylTable; style: HwylTableStyle; colWidths: seq[int]): BbString {.
    ...raises: [], tags: [], forbids: [].}
Source   Edit  
func renderHeader(t: HwylTable; style: HwylTableStyle; colWidths: seq[int]): BbString {.
    ...raises: [], tags: [], forbids: [].}
Source   Edit  
func renderRow(row: seq[BbString]; style: HwylTableStyle; colWidths: seq[int]): BbString {.
    ...raises: [], tags: [], forbids: [].}
Source   Edit  
func renderRows(t: HwylTable; style: HwylTableStyle; colWidths: seq[int]): BbString {.
    ...raises: [], tags: [], forbids: [].}
Source   Edit  
proc toHwylTable[A, B](pairs: openArray[(A, B)]): HwylTable
Source   Edit  
proc toHwylTable[A, B](t: OrderedTable[A, B]): HwylTable
Source   Edit  
proc toHwylTable[A, B](t: Table[A, B]): HwylTable
Source   Edit  
proc topBorder(colWidths: seq[int]; style: HwylTableStyle): BbString {.
    ...raises: [], tags: [], forbids: [].}
Source   Edit  
proc transform(t: HwylTable; s: HwylTableStyle; widths: seq[int]): HwylTable {.
    ...raises: [], tags: [], forbids: [].}
apply cell level styling and alignment Source   Edit  
proc validate(t: HwylTable) {....raises: [HwylTableError], tags: [], forbids: [].}
Source   Edit  

Macros

macro hwylTableBlock(body: untyped): untyped

create a table from a list of tuples

let blockTable = hwylTableBlock:
  ["ID",  "Name"               ,  "Department"        ]
  ("1" ,bb"[bold]Alice Johnson",  "Engineering"       )
  ("2" ,  "Bob Smith"          ,bb"[blue]Marketing"   )
  ("3" ,bb"[bold]Carol White"  ,  "Sales"             )
  ("4" ,  "David Brown"        ,bb"[green]Engineering")

Source   Edit  
macro toBbSeq(items: varargs[untyped]): untyped

convience macro to generate a seq[Bbstring] essentially wraps all arguments in bb(bbEscape(item)) for a regular BbString these are both noops

 toBbSeq(bb"[red] a bb string", "a non bb string"))

Source   Edit  
macro toCol(items: varargs[untyped]): untyped

convience macro to generate a seq[Bbstring] essentially wraps all arguments in bb(bbEscape(item)) for a regular BbString these are both noops

 toCol(bb"[red] a bb string", "a non bb string"))

Source   Edit  
macro toRow(items: varargs[untyped]): untyped

convience macro to generate a seq[Bbstring] essentially wraps all arguments in bb(bbEscape(item)) for a regular BbString these are both noops

 toRow(bb"[red] a bb string", "a non bb string"))

Source   Edit