diff --git a/src/actors/console.rs b/src/actors/console.rs index c320252..49a6aaa 100644 --- a/src/actors/console.rs +++ b/src/actors/console.rs @@ -174,12 +174,14 @@ impl ConsoleActor { } pub fn next(&mut self) { - self.index.clone_from(&self.order[(self.idx() + 1) % self.order.len()]); + self.index + .clone_from(&self.order[(self.idx() + 1) % self.order.len()]); self.list_state.select(Some(self.idx())) } pub fn previous(&mut self) { - self.index.clone_from(&self.order[(self.idx() + self.order.len() - 1) % self.order.len()]); + self.index + .clone_from(&self.order[(self.idx() + self.order.len() - 1) % self.order.len()]); self.list_state.select(Some(self.idx())) } diff --git a/src/config/color.rs b/src/config/color.rs index aeb8dee..2861787 100644 --- a/src/config/color.rs +++ b/src/config/color.rs @@ -15,7 +15,7 @@ impl ColorOption { Self { regex, color } } - pub fn from(color_config: (&String, &String)) -> anyhow::Result { + pub fn from(color_config: (&str, &str)) -> anyhow::Result { let (regex, color_str) = color_config; let regex = Regex::new(regex)?; let color = ColorOption::parse_color(color_str)?; @@ -78,19 +78,44 @@ impl<'b> Colorizer<'b> { pub fn patch_text<'a>(&self, str: &'a str) -> Vec> { let text = str.into_text().unwrap().patch_style(self.base_style); - if self.colors.is_empty() { - // We don't have color options. - // Just return base-styled lines. - return text.lines; - } + let mut color_options = vec![ + ColorOption::from(("GET", "green")).unwrap(), + ColorOption::from(("POST", "#FFA500")).unwrap(), + ColorOption::from(("PUT", "#800080")).unwrap(), + ColorOption::from(("PATCH", "#800080")).unwrap(), + ColorOption::from(("DELETE", "red")).unwrap(), + ColorOption::from(("ERROR", "red")).unwrap(), + ColorOption::from(("RELOAD", "#800080")).unwrap(), + ColorOption::from(( + r"(?x) + \b + \d+ + (\. + \d+ + )? + \b", + "cyan", + )) + .unwrap(), + ColorOption::from(( + r"(?x) + (?P + [~/.][\w./-]* + /[\w.-]* + )", + "green", + )) + .unwrap(), + ColorOption::from((r"https?://[^\s]+", "blue")).unwrap(), // https + ]; + color_options.extend(self.colors.clone()); - // Iterate over lines and patch them one-by-one text.lines .iter() .map(|line| { let mut styled_line = line.clone(); let pure_str = Colorizer::line_as_string(line); - for opt in self.colors { + for opt in color_options.iter() { styled_line = self.merge_lines(&styled_line, &self.apply_color_option(&pure_str, opt)); } diff --git a/src/config/mod.rs b/src/config/mod.rs index 3504033..703c597 100644 --- a/src/config/mod.rs +++ b/src/config/mod.rs @@ -178,7 +178,7 @@ impl RawConfig { let task_color_options: Vec = task .color .iter() - .filter_map(|color_config| ColorOption::from(color_config).ok()) + .filter_map(|(r, c)| ColorOption::from((&r, &c)).ok()) .collect(); colors.insert(task_name.to_owned(), task_color_options);