|
1 |
| -use crate::colors::{ |
2 |
| - PaintType, |
3 |
| - PaletteColor, |
4 |
| - Styles, |
5 |
| - Stylify, |
6 |
| - BLACK, |
7 |
| - BLUE, |
8 |
| - BRIGHT_BLUE, |
9 |
| - BRIGHT_CYAN, |
10 |
| - BRIGHT_GREEN, |
11 |
| - BRIGHT_MAGENTA, |
12 |
| - BRIGHT_RED, |
13 |
| - BRIGHT_WHITE, |
14 |
| - BRIGHT_YELLOW, |
15 |
| - CYAN, |
16 |
| - GRAY, |
17 |
| - GREEN, |
18 |
| - MAGENTA, |
19 |
| - RED, |
20 |
| - Rgb, |
21 |
| - WHITE, |
22 |
| - YELLOW, |
| 1 | +use crate::{ |
| 2 | + ansi_escape_code::ANSIEscapeCode, |
| 3 | + colors::{ |
| 4 | + PaintType, |
| 5 | + PaletteColor, |
| 6 | + Rgb, |
| 7 | + Styles, |
| 8 | + Stylify, |
| 9 | + BLACK, |
| 10 | + BLUE, |
| 11 | + BRIGHT_BLUE, |
| 12 | + BRIGHT_CYAN, |
| 13 | + BRIGHT_GREEN, |
| 14 | + BRIGHT_MAGENTA, |
| 15 | + BRIGHT_RED, |
| 16 | + BRIGHT_WHITE, |
| 17 | + BRIGHT_YELLOW, |
| 18 | + CYAN, |
| 19 | + GRAY, |
| 20 | + GREEN, |
| 21 | + MAGENTA, |
| 22 | + RED, |
| 23 | + WHITE, |
| 24 | + YELLOW, |
| 25 | + }, |
23 | 26 | };
|
24 | 27 |
|
25 | 28 | // =======================================================================
|
@@ -49,36 +52,27 @@ impl StyledText {
|
49 | 52 |
|
50 | 53 | pub fn paint(&mut self) -> String {
|
51 | 54 | println!("{:?}", self.start_styles);
|
52 |
| - let mut default_paint_type = Styles::StylePaintType(PaintType::FG); |
53 |
| - let indexes: Vec<usize> = self.start_styles |
| 55 | + let mut default_paint_type = PaintType::FG; |
| 56 | + |
| 57 | + let start_codes_list: Vec<String> = self.start_styles |
54 | 58 | .iter()
|
55 |
| - .enumerate() |
56 |
| - .filter_map(|(index, style)| { |
57 |
| - match style { |
58 |
| - Styles::StylePaintType(_) => Some(index), |
59 |
| - _ => None, |
| 59 | + .rev() |
| 60 | + .filter_map(|s| { |
| 61 | + if let Styles::StylePaintType(p) = s { |
| 62 | + default_paint_type = p.clone(); |
| 63 | + return None; |
60 | 64 | }
|
| 65 | + let t = s.make_styles(Some(&default_paint_type)); |
| 66 | + Some(ANSIEscapeCode::new(t.as_str()).code()) |
61 | 67 | })
|
| 68 | + .collect::<Vec<_>>() |
| 69 | + .into_iter() |
| 70 | + .rev() |
62 | 71 | .collect();
|
| 72 | + let start_codes = start_codes_list.join(""); |
| 73 | + let end_codes = ANSIEscapeCode::new("0").code(); |
63 | 74 |
|
64 |
| - if indexes.len() == 1 { |
65 |
| - // We sure about 1 element exist on i |
66 |
| - default_paint_type = self.start_styles |
67 |
| - .get(indexes[0]) |
68 |
| - .unwrap_or(&default_paint_type) |
69 |
| - .clone(); |
70 |
| - |
71 |
| - // * call for make style on start_styles |
72 |
| - } |
73 |
| - if indexes.len() > 1 { |
74 |
| - // * each slice get it's own paint type! |
75 |
| - } |
76 |
| - |
77 |
| - println!("{:?}", indexes); |
78 |
| - // Add formatter reset in the end |
79 |
| - // self.end_styles.push(); |
80 |
| - // format!() |
81 |
| - String::new() |
| 75 | + format!("{}{}{}", start_codes, self.text, end_codes) |
82 | 76 | }
|
83 | 77 |
|
84 | 78 | pub fn fg(&mut self) -> &mut Self {
|
|
0 commit comments