1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
use super::Color;
use EnumBitFlags::EnumBitFlags;
#[EnumBitFlags(bits = 16)]
pub enum CharFlags {
Bold = 0x0001,
Italic = 0x0002,
Underline = 0x0004,
DoubleUnderline = 0x0008,
CurlyUnderline = 0x0010,
DottedUnderline = 0x0020,
StrikeThrough = 0x0040,
}
/// Represents attributes of a character such as foreground color, background color, and flags.
#[derive(Copy, Clone, PartialEq, Debug)]
pub struct CharAttribute {
pub foreground: Color,
pub background: Color,
pub flags: CharFlags,
}
impl CharAttribute {
/// Creates a new `CharAttribute` with the specified foreground [Color], background [Color], and flags.
///
/// # Example
/// ```rust
/// use appcui::prelude::*;
///
/// let attr = CharAttribute::new(Color::Red, Color::Black, CharFlags::Bold);
/// ```
pub fn new(fore: Color, back: Color, flags: CharFlags) -> CharAttribute {
CharAttribute {
foreground: fore,
background: back,
flags,
}
}
/// Creates a new `CharAttribute` with the specified foreground and background colors.
/// The flags are set to `CharFlags::None`.
///
/// # Example
/// ```rust
/// use appcui::prelude::*;
///
/// let attr = CharAttribute::with_color(Color::Red, Color::Black);
/// ```
pub fn with_color(fore: Color, back: Color) -> CharAttribute {
CharAttribute {
foreground: fore,
background: back,
flags: CharFlags::None,
}
}
/// Creates a new `CharAttribute` with the specified foreground color.
/// The background color is set to `Color::Transparent` and the flags are set to `CharFlags::None`.
///
/// # Example
/// ```rust
/// use appcui::prelude::*;
///
/// let attr = CharAttribute::with_fore_color(Color::Red);
/// ```
pub fn with_fore_color(fore: Color) -> CharAttribute {
CharAttribute {
foreground: fore,
background: Color::Transparent,
flags: CharFlags::None,
}
}
/// Creates a new `CharAttribute` with the specified background color.
/// The foreground color is set to `Color::Transparent` and the flags are set to `CharFlags::None`.
///
/// # Example
/// ```rust
/// use appcui::prelude::*;
///
/// let attr = CharAttribute::with_back_color(Color::Black);
/// ```
pub fn with_back_color(back: Color) -> CharAttribute {
CharAttribute {
foreground: Color::Transparent,
background: back,
flags: CharFlags::None,
}
}
}
impl Default for CharAttribute {
fn default() -> Self {
Self {
foreground: Color::White,
background: Color::Black,
flags: CharFlags::None,
}
}
}