From 2ea198d4e147a9def60c2387f1b77c265ae76c7e Mon Sep 17 00:00:00 2001 From: destifo Date: Fri, 2 Feb 2024 23:43:15 +0300 Subject: [PATCH] feat: add patterns highlighting directly --- Cargo.toml | 5 +++-- src/actors/command.rs | 20 +++++--------------- src/actors/custom_highlighter.rs | 28 ++++++++++++++++++++++++++++ src/actors/mod.rs | 1 + 4 files changed, 37 insertions(+), 17 deletions(-) create mode 100644 src/actors/custom_highlighter.rs diff --git a/Cargo.toml b/Cargo.toml index ad734df..dfed978 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -23,7 +23,7 @@ openssl = { version = "0.10.58", features = ["vendored"] } notify = "6.1.1" path-absolutize = "3.1.1" path-clean = "1.0.1" -regex = "1.10.2" +regex = "1.10.3" self_update = { version = "0.39.0", features = [ "archive-tar", "archive-zip", @@ -43,4 +43,5 @@ assert_cmd = "2.0.12" semver = "1.0.20" shlex = "1.2.0" termgraph = "0.4.0" -tailspin = "3.0.0" \ No newline at end of file +tailspin = { git = "https://github.com/destifo/tailspin", branch = "tailspin-lib-crate" } +color-eyre = "0.6.2" diff --git a/src/actors/command.rs b/src/actors/command.rs index fe42c6f..dda13f9 100644 --- a/src/actors/command.rs +++ b/src/actors/command.rs @@ -20,14 +20,15 @@ use std::{ use shlex; -use crate::config::color::ColorOption; use crate::actors::grim_reaper::PermaDeathInvite; +use crate::config::color::ColorOption; use crate::config::{ pipe::{OutputRedirection, Pipe}, Config, Task, }; use super::console::{Output, PanelStatus, RegisterPanel}; +use super::custom_highlighter::CustomHighlighter; use super::watcher::{IgnorePath, WatchGlob}; #[cfg(not(test))] @@ -250,7 +251,6 @@ pub struct CommandActor { watcher: Addr, arbiter: Arbiter, child: Child, - tspin_child: Child, nexts: Vec>, cwd: PathBuf, self_addr: Option>, @@ -288,7 +288,6 @@ impl CommandActor { watcher, arbiter: Arbiter::new(), child: Child::NotStarted, - tspin_child: Child::NotStarted, nexts, cwd, self_addr: None, @@ -412,17 +411,8 @@ impl CommandActor { .unwrap(); let output_file = p.stdout.take().unwrap(); - let mut tspin_p = Exec::cmd("tspin") - .cwd(&self.cwd) - .stdin(output_file) - .stdout(Redirection::Pipe) - .stderr(Redirection::Merge) - .popen() - .unwrap(); - - let tspin_stdout = tspin_p.stdout.take().unwrap(); - let reader = BufReader::new(tspin_stdout); + let reader = BufReader::new(output_file); let console = self.console.clone(); let op_name = self.op_name.clone(); let self_addr = self.self_addr.clone(); @@ -431,10 +421,11 @@ impl CommandActor { let watcher = self.watcher.clone(); let task_pipes = self.pipes.clone(); let task_colors = self.colors.clone(); + let highlighter = CustomHighlighter::build(); let fut = async move { for line in reader.lines() { - let mut line = line.unwrap(); + let mut line = highlighter.apply(vec![line.unwrap()]); let task_pipe = task_pipes.iter().find(|pipe| pipe.regex.is_match(&line)); @@ -498,7 +489,6 @@ impl CommandActor { }; self.child = Child::Process(p); - self.tspin_child = Child::Process(tspin_p); self.started_at = started_at; self.arbiter.spawn(fut); diff --git a/src/actors/custom_highlighter.rs b/src/actors/custom_highlighter.rs new file mode 100644 index 0000000..19c684d --- /dev/null +++ b/src/actors/custom_highlighter.rs @@ -0,0 +1,28 @@ +use tailspin::{ + cli::{self, Cli}, + highlight_processor::HighlightProcessor, + highlighters, + theme::{self, processed::Theme}, + theme_io, +}; + +pub fn build_highlighter(theme: Theme, cli: Cli) -> HighlightProcessor { + let highlighter = highlighters::Highlighters::new(&theme, &cli); + let highlight_processor = HighlightProcessor::new(highlighter); + + highlight_processor +} + +pub struct CustomHighlighter { + // ... +} + +impl CustomHighlighter { + pub fn build() -> HighlightProcessor { + let cli = cli::get_args_or_exit_early(); + let theme = theme_io::load_theme(cli.config_path.clone()); + let processed_theme = theme::mapper::map_or_exit_early(theme); + + build_highlighter(processed_theme, cli) + } +} diff --git a/src/actors/mod.rs b/src/actors/mod.rs index 617c8dd..2d34b8d 100644 --- a/src/actors/mod.rs +++ b/src/actors/mod.rs @@ -2,3 +2,4 @@ pub mod command; pub mod console; pub mod grim_reaper; pub mod watcher; +pub mod custom_highlighter; \ No newline at end of file