All Projects → JanGorman → Table

JanGorman / Table

Licence: MIT license
CLI tables in Swift

Programming Languages

swift
15916 projects

Projects that are alternatives of or similar to Table

Hippolyte
HTTP Stubbing in Swift
Stars: ✭ 109 (+105.66%)
Mutual labels:  swift-package-manager, spm, swift5, swift-5
Match3Kit
Library for simple Match3 games.
Stars: ✭ 38 (-28.3%)
Mutual labels:  swift-package-manager, spm, swift5
MMActionSheet
An actionSheet view implement with pure swift
Stars: ✭ 25 (-52.83%)
Mutual labels:  swift-package-manager, spm, swift5
SwiftGradients
Useful extensions for UIViews and CALayer classes to add beautiful color gradients.
Stars: ✭ 15 (-71.7%)
Mutual labels:  swift-package-manager, spm, swift5
PagedLists
Paginated UITableView and UICollectionViews for iOS.
Stars: ✭ 69 (+30.19%)
Mutual labels:  swift-package-manager, spm, swift5
TVToday
iOS TV Shows app with TMDb Api. RxSwift, MVVM, Clean Architecture. Tuist + Swift Package Manager
Stars: ✭ 27 (-49.06%)
Mutual labels:  swift-package-manager, spm, swift5
EKAstrologyCalc
Astrology Calculator calculates moon's rise/set times, moon Age, moon phases and Zodiac Sign for location and time
Stars: ✭ 31 (-41.51%)
Mutual labels:  swift-package-manager, swift5
Sketchkit
A lightweight auto-layout DSL library for iOS & tvOS.
Stars: ✭ 40 (-24.53%)
Mutual labels:  swift-package-manager, spm
Expandable Collection View Kit
🗂 Expandable, hierarchical, flexible, declarative UICollectionView with diffable data sources & SwiftUI-like tree items builder [Swift 5.1, iOS & iPadOS 13].
Stars: ✭ 69 (+30.19%)
Mutual labels:  swift-package-manager, spm
Carekit
CareKit is an open source software framework for creating apps that help people better understand and manage their health.
Stars: ✭ 2,142 (+3941.51%)
Mutual labels:  swift-package-manager, swift5
BetterMappable
Better Mappable through Property Wrappers using ObjectMapper
Stars: ✭ 26 (-50.94%)
Mutual labels:  swift-package-manager, swift5
Bettersegmentedcontrol
An easy to use, customizable replacement for UISegmentedControl & UISwitch.
Stars: ✭ 1,782 (+3262.26%)
Mutual labels:  swift-package-manager, swift5
CSV
A simple CSV file parser and serializer
Stars: ✭ 31 (-41.51%)
Mutual labels:  swift-package-manager, spm
Keepwords
📱🔐 Need an iOS password managing app with no pods? We got you covered!
Stars: ✭ 17 (-67.92%)
Mutual labels:  swift5, swift-5
xcframework-maker
macOS utility for converting fat-frameworks to SPM-compatible XCFramework with arm64-simulator support
Stars: ✭ 239 (+350.94%)
Mutual labels:  swift-package-manager, spm
concurrency-kit
🚄 Concurrency abstractions framework for Apple Platforms [Task, Atomic, Lock, Operation, etc.].
Stars: ✭ 17 (-67.92%)
Mutual labels:  swift-package-manager, spm
Flexcolorpicker
Modern color picker library written in Swift 5 that can be easily extended and customized. It aims to provide great UX and performance with stable, quality code.
Stars: ✭ 164 (+209.43%)
Mutual labels:  swift-package-manager, spm
Swift-FFDB
a Object/Relational Mapping (ORM) support to iOS and MacOS .Since SwiftFFDB is build on top of FMDB.
Stars: ✭ 22 (-58.49%)
Mutual labels:  swift-package-manager, swift5
SupportEmail
Pre-populates emails with support information in iOS/iPadOS apps
Stars: ✭ 20 (-62.26%)
Mutual labels:  swift-package-manager, spm
swift-watch
Watches over your Swift project's source
Stars: ✭ 43 (-18.87%)
Mutual labels:  swift-package-manager, spm

Swift Tables

CI SPM codecov

Working on CLI tools in Swift? Need to display tables? Continue reading.

Add the dependency to your Package.swift file:

import PackageDescription

let package = Package(
    name: "My awesome CLI tool"
    dependencies: [
        .package(
            url: "https://github.com/JanGorman/Table",
            from: "1.0.0"
        )
    ]
)

Basic Usage

import Table

func doSomething() throws {
    let data = [
      ["0A", "0B", "0C"],
      ["1A", "1B", "1C"],
      ["2A", "2B", "2C"],
    ]

    let table = try Table(data: data).table()

    print(table)
}

Results in a pretty table:

╔════╤════╤════╗
║ 0A │ 0B │ 0C ║
╟────┼────┼────╢
║ 1A │ 1B │ 1C ║
╟────┼────┼────╢
║ 2A │ 2B │ 2C ║
╚════╧════╧════╝

Alignment

You can align your table rows by passing in a Configuration:

import Table

func doSomething() throws {
    let data = [
      ["0A", "0B", "0C"],
    ]
    // Give alignment and a minimum width
    let columns = [
      Column(alignment: .left, width: 10),
      Column(alignment: .center, width: 10),
      Column(alignment: .right, width: 10)
    ]
    let configuration = Configuration(columns: columns)
    let table = try Table(data: data).table()

    print(table)
}

Results in:

╔══════════╤══════════╤══════════╗
║0A        │    0B    │        0C║
╚══════════╧══════════╧══════════╝

Padding

The Configuration also allows for padding:

import Table

func doSomething() throws {
    let data = [
      ["0A", "0B", "0C"],
    ]
    let columns = [
      Column(paddingLeft: 3, paddingRight: 4),
      Column(paddingLeft: 8, paddingRight: 8),
      Column(paddingLeft: 3, paddingRight: 4)
    ]
    let configuration = Configuration(columns: columns)
    let table = try Table(data: data).table()

    print(table)
}

Would give you:

╔═════════╤══════════════════╤═════════╗
║   0A    │        0B        │   0C    ║
╚═════════╧══════════════════╧═════════╝

Custom Border Style

To use a custom border for your tables simply create a struct conforming to the Border protocol and pass it as part of a custom Configuration. For example:

import Table

struct CustomBorder: Border {
  public let topBody = ""
  public let topJoin = ""
  public let topLeft = ""
  public let topRight = ""

  public let bottomBody = ""
  public let bottomJoin = ""
  public let bottomLeft = ""
  public let bottomRight = ""

  public let bodyLeft = ""
  public let bodyRight = ""
  public let bodyJoin = ""

  public let joinBody = ""
  public let joinLeft = ""
  public let joinRight = ""
  public let joinJoin = ""
}

func doSomething() throws -> String {
  
  let configuration = Configuration(border: CustomBorder(), columns: columns)
  return try Table(data: data).table()
}

Licence

Table is released under the MIT license. See LICENSE for details.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].