term_ctrl/
codes.rs

1// Copyright 2017 Lyndon Brown
2//
3// Licensed under the MIT license or the Apache license (version 2.0), at your option. You may not
4// copy, modify, or distribute this file except in compliance with said license. You can find copies
5// of these licenses either in the LICENSE-MIT and LICENSE-APACHE files, or alternatively at
6// <http://opensource.org/licenses/MIT> and <http://www.apache.org/licenses/LICENSE-2.0>
7// respectively.
8
9//! Code constants
10//!
11//! In string form.
12//!
13//! If you want whole predefined sequences, see the `predefined` mod. This mode offers simply the
14//! numeric codes (as strings), should that be useful to anyone. Note that you cannot give these to
15//! the `seq` macro; you will just get an error unfortunately - a limitation of the macro system.
16
17use crate::codes;
18
19// Alias for the non-British-English speakers
20pub use self::colours as colors;
21
22/// The start of a control sequence
23pub const SEQ_PREFIX: &str = "\u{1B}[";
24/// The end of a control sequence
25pub const SEQ_POSTFIX: &str = "m";
26
27/// Resets everything to defaults (removes all effects and colours specified)
28pub const RESET: &str = codes!(0);
29
30/// Effects
31pub mod effects {
32    use super::codes;
33
34    /// Alias for reset-all
35    pub const NORMAL:      &str = super::RESET;
36    /// Bold (increase intensity)
37    pub const BOLD:        &str = codes!(1);
38    /// Dim (aka faint; decrease intensity)
39    pub const DIM:         &str = codes!(2);
40    /// Italic
41    pub const ITALIC:      &str = codes!(3);
42    /// Underline
43    pub const UNDERLINE:   &str = codes!(4);
44    /// Blink
45    pub const BLINK:       &str = codes!(5);
46    /// Rapid-blink
47    pub const RAPID_BLINK: &str = codes!(6);
48    /// Inverse (swap foreground/background colours)
49    pub const INVERSE:     &str = codes!(7);
50    /// Invisible (hidden)
51    pub const INVISIBLE:   &str = codes!(8);
52    /// Strike-through
53    pub const STRIKE:      &str = codes!(9);
54
55    /* `10`-`19` are used for font selection, covered by the font mod */
56
57    /// Fraktur
58    pub const FRAKTUR:       &str = codes!(20);
59    /// Double-underline
60    pub const DBL_UNDERLINE: &str = codes!(21);
61
62    /// Alias for removing blink
63    pub const STEADY:    &str = remove::BLINK;
64    /// Alias for removing inverse
65    pub const POSITIVE:  &str = remove::INVISIBLE;
66    /// Alias for v invisible
67    pub const VISIBLE:   &str = remove::INVISIBLE;
68
69    /// Sequences that remove specific effects
70    pub mod remove {
71        use super::codes;
72
73        /// Removes bold and/or dim
74        pub const BOLD_DIM:  &str = codes!(22);
75        /// Removes italic
76        pub const ITALIC:    &str = codes!(23);
77        /// Removes underline
78        pub const UNDERLINE: &str = codes!(24);
79        /// Removes blink
80        pub const BLINK:     &str = codes!(25);
81        /* `26` is unused? */
82        /// Removes inverse
83        pub const INVERSE:   &str = codes!(27);
84        /// Removes invisible
85        pub const INVISIBLE: &str = codes!(28);
86        /// Removes strike-through
87        pub const STRIKE:    &str = codes!(29);
88
89        /// Alias for `BOLD_DIM` (reset intensity)
90        pub const INTENSITY:  &str = BOLD_DIM;
91    }
92}
93
94/// Font selection
95pub mod fonts {
96    use super::codes;
97
98    /// Select the primary (default) font
99    pub const DEFAULT: &str = codes!(10);
100    /// Select alternate font #1
101    pub const ALT1: &str = codes!(11);
102    /// Select alternate font #2
103    pub const ALT2: &str = codes!(12);
104    /// Select alternate font #3
105    pub const ALT3: &str = codes!(13);
106    /// Select alternate font #4
107    pub const ALT4: &str = codes!(14);
108    /// Select alternate font #5
109    pub const ALT5: &str = codes!(15);
110    /// Select alternate font #6
111    pub const ALT6: &str = codes!(16);
112    /// Select alternate font #7
113    pub const ALT7: &str = codes!(17);
114    /// Select alternate font #8
115    pub const ALT8: &str = codes!(18);
116    /// Select alternate font #9
117    pub const ALT9: &str = codes!(19);
118}
119
120/// Text foreground and background colours
121pub mod colours {
122    use super::codes;
123
124    /// Reset both foreground and background colours
125    pub const RESET:    &str = codes!(39, 49);
126    /// Alias for resetting foreground colour
127    pub const RESET_FG: &str = fg::RESET;
128    /// Alias for resetting background colour
129    pub const RESET_BG: &str = bg::RESET;
130
131    /// Text (foreground) colour
132    pub mod fg {
133        use super::codes;
134
135        pub const BLACK:   &str = codes!(30);
136        pub const RED:     &str = codes!(31);
137        pub const GREEN:   &str = codes!(32);
138        pub const YELLOW:  &str = codes!(33);
139        pub const BLUE:    &str = codes!(34);
140        pub const MAGENTA: &str = codes!(35);
141        pub const CYAN:    &str = codes!(36);
142        pub const WHITE:   &str = codes!(37);
143
144        /// Resets foreground colour to default
145        pub const RESET:   &str = codes!(39);
146
147        /// Bright variants
148        pub mod bright {
149            use super::codes;
150
151            pub const BLACK:   &str = codes!(90);
152            pub const RED:     &str = codes!(91);
153            pub const GREEN:   &str = codes!(92);
154            pub const YELLOW:  &str = codes!(93);
155            pub const BLUE:    &str = codes!(94);
156            pub const MAGENTA: &str = codes!(95);
157            pub const CYAN:    &str = codes!(96);
158            pub const WHITE:   &str = codes!(97);
159        }
160    }
161
162    /// Text (background) highlighting colour
163    pub mod bg {
164        use super::codes;
165
166        pub const BLACK:   &str = codes!(40);
167        pub const RED:     &str = codes!(41);
168        pub const GREEN:   &str = codes!(42);
169        pub const YELLOW:  &str = codes!(43);
170        pub const BLUE:    &str = codes!(44);
171        pub const MAGENTA: &str = codes!(45);
172        pub const CYAN:    &str = codes!(46);
173        pub const WHITE:   &str = codes!(47);
174
175        /// Resets background-highlight colour to default
176        pub const RESET:   &str = codes!(49);
177
178        /// Bright variants
179        pub mod bright {
180            use super::codes;
181
182            pub const BLACK:   &str = codes!(100);
183            pub const RED:     &str = codes!(101);
184            pub const GREEN:   &str = codes!(102);
185            pub const YELLOW:  &str = codes!(103);
186            pub const BLUE:    &str = codes!(104);
187            pub const MAGENTA: &str = codes!(105);
188            pub const CYAN:    &str = codes!(106);
189            pub const WHITE:   &str = codes!(107);
190        }
191    }
192}
193
194/// Miscellaneous
195pub mod misc {
196    use super::codes;
197
198    /// Framed
199    pub const FRAMED:    &str = codes!(51);
200    /// Encircled
201    pub const ENCIRCLED: &str = codes!(52);
202    /// Overlined
203    pub const OVERLINED: &str = codes!(53);
204
205    /// Remove misc effects
206    pub mod remove {
207        use super::codes;
208
209        /// Remove framed and encircled effects
210        pub const FRAMED_ENCIRCLED: &str = codes!(54);
211        /// Remove overlined effects
212        pub const OVERLINED:        &str = codes!(55);
213    }
214
215    /// Ideogram stuff
216    pub mod ideogram {
217        use super::codes;
218
219        /// Ideogram underline or right side line
220        pub const UNDERLINE:      &str = codes!(60);
221        /// Ideogram double underline or double line on the right side
222        pub const DBL_UNDERLINE:  &str = codes!(61);
223        /// Ideogram overline or left side line
224        pub const OVERLINE:       &str = codes!(62);
225        /// Ideogram double overline or double line on the left side
226        pub const DBL_OVERLINE:   &str = codes!(63);
227        /// Ideogram stress marking
228        pub const STRESS_MARKING: &str = codes!(64);
229        /// Ideogram attributes off
230        pub const RESET:          &str = codes!(65);
231    }
232}
233
234/// Combinations
235pub mod combinations {
236    use super::codes;
237
238    /// Combined bold + text (foreground) colour
239    pub mod fg_bold {
240        use super::*;
241
242        pub const BLACK:   &str = codes!(30,1);
243        pub const RED:     &str = codes!(31,1);
244        pub const GREEN:   &str = codes!(32,1);
245        pub const YELLOW:  &str = codes!(33,1);
246        pub const BLUE:    &str = codes!(34,1);
247        pub const MAGENTA: &str = codes!(35,1);
248        pub const CYAN:    &str = codes!(36,1);
249        pub const WHITE:   &str = codes!(37,1);
250    }
251}