CLI-Table-Swift

CI codecov GitHub Release Platform Compatibility GitHub License

使用 Swift 编写的 macOS 命令行工具表格构建库

┌─────────┬─────┬────────────────┐
│ Name    │ Age │ City           │
├─────────┼─────┼────────────────┤
│ Matheus │ 23  │ São Paulo      │
├─────────┼─────┼────────────────┤
│ Alice   │ 30  │ Rio de Janeiro │
└─────────┴─────┴────────────────┘

用法

默认使用终端颜色

import CLITable

let headers = ["Name", "Age", "City"]
        
var table = CLITable(headers: headers)

let rows = [
    ["Matheus", "23", "São Paulo"],
    ["Alice", "30", "Rio de Janeiro"]
]
        
table.addRows(rows)
table.showTable()

如果你喜欢,你可以这样添加行

let headers = ["Name", "Age", "City"]
        
var table = CLITable(headers: headers)
        
table.addRow(["Matheus", "23", "São Paulo"])
table.addRow(["Matheus", "23", "São Paulo"])
        
table.showTable()

要自定义表格,你可以为行和文本添加颜色,或者只为其中一些添加颜色

var table = CLITable(headers: headers, tableColor: .blue, textColor: .green)
var table = CLITable(headers: headers, tableColor: .hex("#FF5733"), textColor: .hex("#2ECC71"))

or

var table = CLITable(headers: headers, tableColor: .blue)
var table = CLITable(headers: headers, tableColor: .hex("#FF5733"))

or

var table = CLITable(headers: headers, textColor: .green)
var table = CLITable(headers: headers, textColor: .hex("#2ECC71"))

安装

dependencies: [
  .package(
    url: "https://github.com/heroesofcode/CLI-Table-Swift",
    from: "1.1.0"
  ),
]
targets: [
  .target(name: "MyApp"),
  .testTarget(
    name: "MyAppTests",
    dependencies: [
      "MyApp",
      .product(name: "CLITable", package: "CLI-Table-Swift"),
    ]
  )
]

贡献

要贡献,只需 Fork 这个项目,然后打开一个 Pull Request。欢迎贡献,提出想法,并在 Issue 标签页中提出任何问题。

许可

CLITable 使用 MIT 许可证发布。有关详细信息,请参见 LICENSE