Skip to content

Commit

Permalink
Make ConsoleText ExpressibleByStringInterpolation (#131)
Browse files Browse the repository at this point in the history
* conform ConsoleText to ExpressibleByStringInterpolation

* Fixed 'swift build' calls in GH Workflow

* fix swift build test

Co-authored-by: Caleb Kleveter <caleb.kleveter@gmail.com>
  • Loading branch information
tanner0101 and calebkleveter committed Jan 23, 2020
1 parent c525884 commit 5458574
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 8 deletions.
8 changes: 2 additions & 6 deletions .github/workflows/test.yml
Expand Up @@ -8,15 +8,11 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- run: |
swift build
swift test --enable-test-discovery --sanitize=thread
- run: swift test --enable-test-discovery --sanitize=thread
bionic:
container:
image: swift:5.1-bionic
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- run: |
swift build
swift test --enable-test-discovery --sanitize=thread
- run: swift test --enable-test-discovery --sanitize=thread
4 changes: 2 additions & 2 deletions Sources/ConsoleKit/Command/CommandGroup.swift
Expand Up @@ -51,8 +51,8 @@ extension CommandGroup {
}

private func outputGroupHelp(using context: inout CommandContext) {
context.console.output("Usage: ".consoleText(.info) + context.input.executable.consoleText() + " ", newLine: false)
context.console.output("<command> ".consoleText(.warning), newLine: false)
context.console.output("\("Usage: ", style: .info) \(context.input.executable)", newLine: false)
context.console.output("\("<command>", style: .warning) ", newLine: false)
context.console.print()

if !self.help.isEmpty {
Expand Down
26 changes: 26 additions & 0 deletions Sources/ConsoleKit/Output/ConsoleText.swift
Expand Up @@ -96,3 +96,29 @@ public func +(lhs: ConsoleText, rhs: ConsoleText) -> ConsoleText {
public func +=(lhs: inout ConsoleText, rhs: ConsoleText) {
lhs = lhs + rhs
}

extension ConsoleText: ExpressibleByStringInterpolation {
public init(stringInterpolation: StringInterpolation) {
self.fragments = stringInterpolation.fragments
}

public struct StringInterpolation: StringInterpolationProtocol {
public var fragments: [ConsoleTextFragment]

public init(literalCapacity: Int, interpolationCount: Int) {
self.fragments = []
self.fragments.reserveCapacity(literalCapacity)
}

public mutating func appendLiteral(_ literal: String) {
self.fragments.append(.init(string: literal))
}

public mutating func appendInterpolation(
_ value: String,
style: ConsoleStyle = .plain
) {
self.fragments.append(.init(string: value, style: style))
}
}
}

0 comments on commit 5458574

Please sign in to comment.