CommandLineToolkit

Форк
0
/
ConsoleStyle.swift 
96 строк · 2.5 Кб
1
enum ConsoleAttribute: Int, Equatable {
2
    case normal         = 0
3
    case bold           = 1
4
    case dim            = 2
5
    case italic         = 3
6
    case underline      = 4
7
    case blink          = 5
8
    case overline       = 6
9
    case inverse        = 7
10
    case hidden         = 8
11
    case strike         = 9
12
    case noBold         = 21
13
    case noDim          = 22
14
    case noItalic       = 23
15
    case noUnderline    = 24
16
    case noBlink        = 25
17
    case noOverline     = 26
18
    case noInverse      = 27
19
    case noHidden       = 28
20
    case noStrike       = 29
21
}
22

23
/// Representation of a style for outputting to a Console in different colors with differing attributes.
24
/// A few suggested default styles are provided.
25
struct ConsoleStyle: Equatable {
26
    /// Optional text color. If `nil`, text is plain.
27
    let color: ConsoleColor?
28

29
    /// Optional background color. If `nil` background is plain.
30
    let background: ConsoleColor?
31

32
    /// If `true`, text is bold.
33
    let attributes: [ConsoleAttribute]
34

35
    /// Creates a new `ConsoleStyle`.
36
    init(
37
        color: ConsoleColor? = nil,
38
        background: ConsoleColor? = nil,
39
        attributes: [ConsoleAttribute] = []
40
    ) {
41
        self.color = color
42
        self.background = background
43
        self.attributes = attributes
44
    }
45
}
46

47
extension ConsoleStyle {
48
    /// Plain text with no color or background.
49
    static let plain: ConsoleStyle = .init()
50
    
51
    static let progressBarProgress: ConsoleStyle = .init(
52
        color: .palette(28)
53
    )
54
    
55
    static let progressBarUnfinished: ConsoleStyle = .init(
56
        color: .palette(8)
57
    )
58
    
59
    /// Green text with no background.
60
    static let success: ConsoleStyle = .init(
61
        color: .palette(28),
62
        attributes: [.bold]
63
    )
64

65
    /// Light blue text with no background.
66
    static var info: ConsoleStyle = .init(
67
        color: .palette(36)
68
    )
69

70
    /// Light blue text with no background.
71
    static var notice: ConsoleStyle = .init(
72
        color: .palette(36),
73
        attributes: [.bold]
74
    )
75

76
    /// Yellow text with no background.
77
    static var warning: ConsoleStyle = .init(
78
        color: .palette(214),
79
        attributes: [.bold]
80
    )
81

82
    /// Red text with no background.
83
    static var error: ConsoleStyle = .init(
84
        color: .palette(9/*196*/),
85
        attributes: [.bold]
86
    )
87

88
    static let headerTitle: ConsoleStyle = .init(
89
        attributes: [.bold]
90
    )
91

92
    static var help: ConsoleStyle = .init(
93
        color: .palette(180),
94
        attributes: [.italic]
95
    )
96
}
97

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.