blob: 8663fd2a3f4c8292282209c2a8a80bd4bf038ffe (
plain) (
blame)
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
100
101
102
103
104
105
106
107
108
109
|
use crate::*;
pub struct InkedFragment {
pub string: String,
pub colour: ColorSpec,
}
impl InkedFragment {
pub fn from(string: impl Into<String>) -> Self {
Self {
string: string.into(),
colour: ColorSpec::new(),
}
}
pub fn to_string(self) -> InkedString {
let mut string = InkedString::new();
string.push(self);
string
}
pub fn print(self) { self.to_string().print(); }
pub fn println(self) { self.to_string().println(); }
pub fn eprint(self) { self.to_string().eprint(); }
pub fn eprintln(self) { self.to_string().eprintln(); }
// ----------------------------------------
pub fn set_colour(mut self, colour: Option<Colour>) -> Self {
match colour {
Some(colour) => self.colour.set_fg(Some(colour.into())),
None => self.colour.set_fg(None),
};
self
}
pub fn set_bold(mut self, bold: bool) -> Self {
self.colour.set_bold(bold);
self
}
pub fn set_dim(mut self, dim: bool) -> Self {
self.colour.set_dimmed(dim);
self
}
// ----------------------------------------
pub fn black(mut self) -> Self {
self.colour.set_fg(Some(Color::Black));
self
}
pub fn red(mut self) -> Self {
self.colour.set_fg(Some(Color::Red));
self
}
pub fn green(mut self) -> Self {
self.colour.set_fg(Some(Color::Green));
self
}
pub fn yellow(mut self) -> Self {
self.colour.set_fg(Some(Color::Yellow));
self
}
pub fn blue(mut self) -> Self {
self.colour.set_fg(Some(Color::Blue));
self
}
pub fn magenta(mut self) -> Self {
self.colour.set_fg(Some(Color::Magenta));
self
}
pub fn cyan(mut self) -> Self {
self.colour.set_fg(Some(Color::Cyan));
self
}
pub fn white(mut self) -> Self {
self.colour.set_fg(Some(Color::White));
self
}
pub fn bold(mut self) -> Self {
self.colour.set_bold(true);
self
}
pub fn dim(mut self) -> Self {
self.colour.set_dimmed(true);
self
}
}
impl From<String> for InkedFragment {
fn from(string: std::string::String) -> Self {
Self {
string,
colour: ColorSpec::new(),
}
}
}
|