Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/heroesofcode/cli-table-swift

Build Table for command line tools for macOS written in Swift
https://github.com/heroesofcode/cli-table-swift

Last synced: 1 day ago
JSON representation

Build Table for command line tools for macOS written in Swift

Awesome Lists containing this project

README

        

## CLI-Table-Swift

[![CI](https://github.com/heroesofcode/CLI-Table-Swift/actions/workflows/CI.yml/badge.svg)](https://github.com/heroesofcode/CLI-Table-Swift/actions/workflows/CI.yml)
[![codecov](https://codecov.io/gh/heroesofcode/CLI-Table-Swift/graph/badge.svg?token=DRwwBttVQh)](https://codecov.io/gh/heroesofcode/CLI-Table-Swift)
![GitHub Release](https://img.shields.io/github/v/release/heroesofcode/CLI-Table-Swift)
[![Platform Compatibility](https://img.shields.io/badge/Platforms-%20macOS%20-orange)]()
[![GitHub License](https://img.shields.io/github/license/heroesofcode/CLI-Table-Swift)](https://github.com/heroesofcode/CLI-Table-Swift/blob/main/LICENSE)

Build Table for command line tools for macOS written in Swift

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

## Usage

Default with terminal color
```swift
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()
```
If you prefer, you can add the row like this
```swift
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()
```

To customize the table you can add color to the line and text or just some of them
```swift
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"))
```

## Installing

```swift
dependencies: [
.package(
url: "https://github.com/heroesofcode/CLI-Table-Swift",
from: "1.1.0"
),
]
```

```swift
targets: [
.target(name: "MyApp"),
.testTarget(
name: "MyAppTests",
dependencies: [
"MyApp",
.product(name: "CLITable", package: "CLI-Table-Swift"),
]
)
]
```

## Contributing

To contribute, just fork this project and then open a pull request, feel free to contribute, bring ideas and raise any problem in the issue tab.

## License

CLITable is released under the MIT license. See [LICENSE](https://github.com/heroesofcode/CLI-Table-Swift/blob/main/LICENSE) for details.