Skip to content

Commit

Permalink
Improve the formatting of the completion error message
Browse files Browse the repository at this point in the history
  • Loading branch information
pepicrft committed Apr 17, 2024
1 parent 04824e6 commit 2fe93a0
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 30 deletions.
6 changes: 3 additions & 3 deletions Sources/SwiftTerminal/Components/CompletionMessage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,22 @@ public enum CompletionMessage {
case let .error(errorMessage, context, nextSteps):
var content = """
\("✘ An error ocurred".hexColorIfEnabled(theme.danger, environment: environment).bold)
\(errorMessage.split(separator: "\n").map { " \($0)" }.joined(separator: "\n"))
\(errorMessage.split(separator: "\n").map { " \($0)".dimIfColorEnabled(environment: environment) }.joined(separator: "\n"))
"""
if let context {
content = """
\(content)
\(" \("Context".underline)".hexColorIfEnabled(theme.danger, environment: environment))
\(context.split(separator: "\n").map { " \($0)" }.joined(separator: "\n"))
\(context.split(separator: "\n").map { " \($0)".dimIfColorEnabled(environment: environment) }.joined(separator: "\n"))
"""
}
if !nextSteps.isEmpty {
content = """
\(content)
\(" \("Next steps".underline)".hexColorIfEnabled(theme.danger, environment: environment))
\(nextSteps.map { " ▪︎ \($0)" }.joined(separator: "\n"))
\(nextSteps.map { " ▪︎ \($0)".dimIfColorEnabled(environment: environment) }.joined(separator: "\n"))
"""
}
await standardPipelines.error.write(content: "\(content)\n")
Expand Down
8 changes: 8 additions & 0 deletions Sources/SwiftTerminal/Utilities/Rainbow+Extras.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,14 @@ extension String {
return self
}
}

func dimIfColorEnabled(environment: Environment = .default) -> String {
if environment.shouldColor {
return dim
} else {
return self
}
}

func hexColorIfEnabled(_ hex: String, environment: Environment = .default) -> String {
if environment.shouldColor {
Expand Down
2 changes: 1 addition & 1 deletion Sources/SwiftTerminal/Utilities/Renderer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ public actor Renderer {

private func eraseLines(_ lines: Int, standardPipeline: StandardPipelining) async {
if lines == 0 { return }
for index in 0 ... lines {
for index in 0...lines {
await eraseLine(standardPipeline: standardPipeline)
if index < lastRenderedContent.count {
await moveCursorUp(standardPipeline: standardPipeline)
Expand Down
11 changes: 1 addition & 10 deletions Sources/SwiftTerminal/Utilities/StandardPipelines.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,7 @@ public actor StandardOutputPipeline: StandardPipelining {
public init() {}

public func write(content: String) {
#if os(Linux)
print(content)
#endif

#if os(macOS)
if let data = content.data(using: .utf8) {
// swiftlint:disable:next force_try
try! FileHandle.standardOutput.write(contentsOf: data)
}
#endif
print(content, terminator: "")
}
}

Expand Down
32 changes: 16 additions & 16 deletions Sources/swift-terminal/swift-terminal.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,35 +35,35 @@ enum CLI {
// await CompletionMessage.render(message: .warnings(["Your hosted version of Tuist Cloud is outdated", "We detected
// invalid binaries in the cache"]), theme: tuistTheme, standardPipelines: standardPipelines)
//
await standardPipelines.output.write(content: "\n\n----- CollapsibleStream -----\n".bold)
try await CollapsibleStream.render(
title: "xcodebuild -scheme 1 -workspace Tuist.xcworkspace",
stream: makeStream(),
theme: tuistTheme
)
// await standardPipelines.output.write(content: "\n\n----- CollapsibleStream -----\n".bold)
// try await CollapsibleStream.render(
// title: "xcodebuild -scheme 1 -workspace Tuist.xcworkspace",
// stream: makeStream(),
// theme: tuistTheme
// )
// try await CollapsibleStream.render(title: "xcodebuild -scheme 2 -workspace Tuist.xcworkspace", stream: makeStream(),
// theme: tuistTheme)
// try await CollapsibleStream.render(title: "xcodebuild -scheme 3 -workspace Tuist.xcworkspace", stream: makeStream(),
// theme: tuistTheme)
// try await CollapsibleStream.render(title: "xcodebuild -scheme 4 -workspace Tuist.xcworkspace", stream: makeStream(),
// theme: tuistTheme)
// try await TerminalConcurrentAsyncStreams.render(title: "Uploading frameworks to Tuist Cloud", completionMessage:
// "Completed uploading", theme: tuistTheme, asyncStreams: [
// "FrameworkA": makeProgressStream(),
// "FrameworkB": makeProgressStream(),
// "FrameworkC": makeProgressStream(),
// "FrameworkD": makeProgressStream(),
// "FrameworkE": makeProgressStream(),
// "FrameworkF": makeProgressStream()
// ])
try await TerminalConcurrentAsyncStreams.render(title: "Uploading frameworks to Tuist Cloud", completionMessage:
"Completed uploading", theme: tuistTheme, asyncStreams: [
"FrameworkA": makeProgressStream(),
"FrameworkB": makeProgressStream(),
"FrameworkC": makeProgressStream(),
"FrameworkD": makeProgressStream(),
"FrameworkE": makeProgressStream(),
"FrameworkF": makeProgressStream()
])
//
// print("\n\n")
//

//
// print("\n\n")

//

// try await TerminalCollapsibleTitledStream.renderSectioned(section: "Building XCFrameworks", renderables: [
// (title: "xcodebuild -scheme 1 -workspace Tuist.xcworkspace", stream: makeStream()),
// (title: "xcodebuild -scheme 2 -workspace Tuist.xcworkspace", stream: makeStream()),
Expand Down

0 comments on commit 2fe93a0

Please sign in to comment.