-
Notifications
You must be signed in to change notification settings - Fork 116
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into readable-symbol-link-disambiguation
# Conflicts: # Sources/SwiftDocC/Infrastructure/Link Resolution/PathHierarchy+DisambiguatedPaths.swift # Sources/SwiftDocC/Infrastructure/Link Resolution/PathHierarchy+Dump.swift # Sources/SwiftDocC/Infrastructure/Link Resolution/PathHierarchy+Error.swift # Sources/SwiftDocC/Infrastructure/Link Resolution/PathHierarchy+Find.swift # Sources/SwiftDocC/Infrastructure/Link Resolution/PathHierarchy+PathComponent.swift # Sources/SwiftDocC/Infrastructure/Link Resolution/PathHierarchy.swift
- Loading branch information
Showing
56 changed files
with
1,176 additions
and
222 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
Sources/SwiftDocC/Infrastructure/Diagnostics/ANSIAnnotation.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/* | ||
This source file is part of the Swift.org open source project | ||
Copyright (c) 2023 Apple Inc. and the Swift project authors | ||
Licensed under Apache License v2.0 with Runtime Library Exception | ||
See https://swift.org/LICENSE.txt for license information | ||
See https://swift.org/CONTRIBUTORS.txt for Swift project authors | ||
*/ | ||
|
||
import Foundation | ||
|
||
struct ANSIAnnotation { | ||
enum Color: UInt8 { | ||
case normal = 0 | ||
case red = 31 | ||
case green = 32 | ||
case yellow = 33 | ||
case `default` = 39 | ||
} | ||
|
||
enum Trait: UInt8 { | ||
case normal = 0 | ||
case bold = 1 | ||
case italic = 3 | ||
} | ||
|
||
private var color: Color | ||
private var trait: Trait | ||
|
||
/// The textual representation of the annotation. | ||
private var code: String { | ||
"\u{001B}[\(trait.rawValue);\(color.rawValue)m" | ||
} | ||
|
||
init(color: Color, trait: Trait = .normal) { | ||
self.color = color | ||
self.trait = trait | ||
} | ||
|
||
func applied(to message: String) -> String { | ||
"\(code)\(message)\(ANSIAnnotation.normal.code)" | ||
} | ||
|
||
static var normal: ANSIAnnotation { | ||
self.init(color: .normal, trait: .normal) | ||
} | ||
|
||
/// Annotation used for highlighting source text. | ||
static var sourceHighlight: ANSIAnnotation { | ||
ANSIAnnotation(color: .green, trait: .bold) | ||
} | ||
/// Annotation used for highlighting source suggestion. | ||
static var sourceSuggestionHighlight: ANSIAnnotation { | ||
ANSIAnnotation(color: .default, trait: .bold) | ||
} | ||
} |
Oops, something went wrong.