nim-terminaltables

terminal tables for nim
授权协议 BSD-3-Clause License
开发语言 C/C++
所属分类 应用工具、 终端/远程登录
软件类型 开源软件
地区 不详
投 递 者 孔硕
操作系统 跨平台
开源组织
适用人群 未知
 软件概览

nim-terminaltables

terminal tables for nim

API

API docs available hereterminaltables has a very small API

  • newUnicodeTable uses unicodeStyle
  • newAsciiTable uses asciiStyle

Table style is configurable using Style object. Here's an example of how asciiStyle and unicodeStyle are defined

let asciiStyle =   Style(rowSeparator:"-", colSeparator:"|", cellEdgeLeft:"+", cellEdgeRight:"+", topLeft:"+", topRight:"+", bottomLeft:"-", bottomRight:"-", topRowSeparator:"-", bottomRowSeparator:"-", dashLineLeft:"+", dashLineRight:"+", dashLineColSeparatorLastRow:"+", dashLineColSeparatorTopRow:"+", dashLineColSeparator:"+")
let unicodeStyle = Style(rowSeparator:"─", colSeparator:"│", cellEdgeLeft:"├", cellEdgeRight:"┤", topLeft:"┌", topRight:"┐", bottomLeft:"└", bottomRight:"┘", topRowSeparator:"┬", bottomRowSeparator:"┴", dashLineLeft:"├", dashLineRight:"┤", dashLineColSeparatorLastRow:"┴", dashLineColSeparatorTopRow:"┬", dashLineColSeparator:"┼")
  • newUnicodeTable to create Table with unicode table style
  • newAsciiTable to create Table with ascii table style
  • separateRows controls if you want to add dashline between rows.
  • addRow used to add a row to the table
  • setHeaders used to set headers of the table and it accepts strings or cell objects with padding information.
  • a
let t2 = newUnicodeTable()
  t2.separateRows = false
  t2.setHeaders(@["ID", "Name", "Fav animal", "Date"])
  # t2.setHeaders(@[newCell("ID", pad=5), newCell("Name", rightpad=10), newCell("Fav animal", pad=2), newCell("Date", 5)])
  t2.addRow(@["1", "xmonader", "Cat, Dog", "2018-10-22"])
  t2.addRow(@["2", "ahmed", "Shark", "2015-12-6"])
  t2.addRow(@["3", "dr who", "Humans", "1018-5-2"])
  printTable(t2)

Examples

var t = newTerminalTable()
  var width = 150
  when not defined(js):
    width = termColumns()
    echo "termColumns: " & $termColumns()

  # width of the table is the terminal COLUMNS - the amount of separators (columns + 1)  multiplied by length of the separator
  t.tableWidth = width - (t.columnsCount() * len($t.style.colSeparator)) - 10
  t.setHeaders(@["ID", "Name", "Fav animal", "Date", "OK"])
  t.addRow(@["1", "xmonader", "Cat, Dog", "2018-10-2", "yes"])
  t.addRow(@["2", "ahmed", "Shark", "2018-10-2", "yes"])
  t.addRow(@["3", "dr who", "Humans", "1018-5-2", "no"])
  printTable(t)
  
  t.tableWidth = 0
  printTable(t)

  t.tableWidth = 0
  t.separateRows = false
  printTable(t)
  
  t.reset()

  let t2 = newUnicodeTable()
  t2.separateRows = false
  t2.setHeaders(@[newCell("ID", pad=5), newCell("Name", rightpad=10), newCell("Fav animal", pad=2), newCell("Date", 5)])
  t2.addRow(@["1", "xmonader", "Cat, Dog", "2018-10-22"])
  t2.addRow(@["2", "ahmed", "Shark", "2015-12-6"])
  t2.addRow(@["3", "dr who", "Humans", "1018-5-2"])
  printTable(t2)
+------------------------+------------------------+------------------------+------------------------+------------------------+
| ID                     | Name                   | Fav animal             | Date                   | OK                     |
+------------------------+------------------------+------------------------+------------------------+------------------------+
| 1                      | xmonader               | Cat, Dog               | 2018-10-2              | yes                    |
+------------------------+------------------------+------------------------+------------------------+------------------------+
| 2                      | ahmed                  | Shark                  | 2018-10-2              | yes                    |
+------------------------+------------------------+------------------------+------------------------+------------------------+
| 3                      | dr who                 | Humans                 | 1018-5-2               | no                     |
-------------------------+------------------------+------------------------+------------------------+-------------------------

+----+----------+------------+-----------+-----+
| ID | Name     | Fav animal | Date      | OK  |
+----+----------+------------+-----------+-----+
| 1  | xmonader | Cat, Dog   | 2018-10-2 | yes |
+----+----------+------------+-----------+-----+
| 2  | ahmed    | Shark      | 2018-10-2 | yes |
+----+----------+------------+-----------+-----+
| 3  | dr who   | Humans     | 1018-5-2  | no  |
-----+----------+------------+-----------+------

+----+----------+------------+-----------+-----+
| ID | Name     | Fav animal | Date      | OK  |
+----+----------+------------+-----------+-----+
| 1  | xmonader | Cat, Dog   | 2018-10-2 | yes |
| 2  | ahmed    | Shark      | 2018-10-2 | yes |
| 3  | dr who   | Humans     | 1018-5-2  | no  |
-----+----------+------------+-----------+------

┌────────────┬───────────────────┬──────────────┬────────────────┐
│     ID     │ Name              │  Fav animal  │     Date       │
├────────────┼───────────────────┼──────────────┼────────────────┤
│     1      │ xmonader          │  Cat, Dog    │     2018-10-22 │
│     2      │ ahmed             │  Shark       │     2015-12-6  │
│     3      │ dr who            │  Humans      │     1018-5-2   │
└────────────┴───────────────────┴──────────────┴────────────────┘

using custom styles

Using custom styles is pretty easy

var t2 = newUnicodeTable()
  t2.separateRows = false
  t2.setHeaders(@[newCell("ID", pad=5), newCell("Name", rightpad=10), newCell("Fav animal", pad=2), newCell("Date", 5)])
  t2.addRow(@["1", "xmonader", "Cat, Dog", "2018-10-22"])
  t2.addRow(@["2", "ahmed", "Shark", "2015-12-6"])
  t2.addRow(@["3", "dr who", "Humans", "1018-5-2"])
  t2.separateRows = true
  let testStyle =  Style(rowSeparator:"┈", colSeparator:"┇", cellEdgeLeft:"├", cellEdgeRight:"┤", topLeft:"┏", topRight:"┓", bottomLeft:"└", bottomRight:"┘", topRowSeparator:"┬", bottomRowSeparator:"┴", dashLineLeft:"├", dashLineRight:"┤", dashLineColSeparatorLastRow:"┴", dashLineColSeparatorTopRow:"┬", dashLineColSeparator:"┼")

  t2.style = testStyle
  printTable(t2)
┏┈┈┈┈┈┈┈┈┈┈┈┈┬┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┬┈┈┈┈┈┈┈┈┈┈┈┈┈┈┬┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┓
┇     ID     ┇ Name              ┇  Fav animal  ┇     Date       ┇
├┈┈┈┈┈┈┈┈┈┈┈┈┼┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┼┈┈┈┈┈┈┈┈┈┈┈┈┈┈┼┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┤
┇     1      ┇ xmonader          ┇  Cat, Dog    ┇     2018-10-22 ┇
├┈┈┈┈┈┈┈┈┈┈┈┈┼┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┼┈┈┈┈┈┈┈┈┈┈┈┈┈┈┼┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┤
┇     2      ┇ ahmed             ┇  Shark       ┇     2015-12-6  ┇
├┈┈┈┈┈┈┈┈┈┈┈┈┼┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┼┈┈┈┈┈┈┈┈┈┈┈┈┈┈┼┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┤
┇     3      ┇ dr who            ┇  Humans      ┇     1018-5-2   ┇
└┈┈┈┈┈┈┈┈┈┈┈┈┴┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┴┈┈┈┈┈┈┈┈┈┈┈┈┈┈┴┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┘


 相关资料
  • Nim

    Nimrod(已改名为 Nim)是一种静态类型的编译系统编程语言。它结合了 Python、Ada和Modula等成熟语言的成功理念。 高效的 Nim生成不依赖于虚拟机的本机无依赖可执行文件,这些可执行文件很小并且允许重新分配。 Nim编译器和生成的可执行文件支持所有主要平台,例如Windows,Linux,BSD和macOS。 在C ++和Rust的启发下,Nim的内存管理是确定性的,并且可以使用

  • nim-asciitables simple terminal ascii tables for nim DEPRECATION project is deprecated in favor for nim-terminaltables How to use asciitables has a very simple api setHeaders to set column names addRo

  • Dashing is a library to quickly create terminal-based dashboards in Nim. Dashing provides high-level components: vertical and horizontal charts, gauges, log panes, text windows and screen splitting. I

  • Gatabase Works with ARC, ORC, --panics:on, --experimental:strictFuncs. Use Gatabase is designed as 1 simplified Strong Static Typed Connection-Pooling Compile-Time SQL DSL Sugar. Nim mimics SQL. ~1000

  • allographer An asynchronous query builder library inspired by Laravel/PHP and Orator/Python for Nim Easy to access Rdb Query Builder import asyncdispatchimport allographer/connectionimport allographer

  • libssh2.nim Nim wrapper for libssh2 For document please refer to libssh2 website Requirements In order to use this wrapper, libssh2 must installed on your system: Mac OSX:$ port install libssh2 Ubuntu

相关阅读

相关文章

相关问答

相关文档