Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat--pattern-highlighting #1

Merged
merged 1 commit into from
Feb 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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"
tailspin = { git = "https://github.com/destifo/tailspin", branch = "tailspin-lib-crate" }
color-eyre = "0.6.2"
20 changes: 5 additions & 15 deletions src/actors/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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))]
Expand Down Expand Up @@ -250,7 +251,6 @@ pub struct CommandActor {
watcher: Addr<WatcherAct>,
arbiter: Arbiter,
child: Child,
tspin_child: Child,
nexts: Vec<Addr<CommandActor>>,
cwd: PathBuf,
self_addr: Option<Addr<CommandActor>>,
Expand Down Expand Up @@ -288,7 +288,6 @@ impl CommandActor {
watcher,
arbiter: Arbiter::new(),
child: Child::NotStarted,
tspin_child: Child::NotStarted,
nexts,
cwd,
self_addr: None,
Expand Down Expand Up @@ -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();
Expand All @@ -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));

Expand Down Expand Up @@ -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);

Expand Down
28 changes: 28 additions & 0 deletions src/actors/custom_highlighter.rs
Original file line number Diff line number Diff line change
@@ -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)
}
}
1 change: 1 addition & 0 deletions src/actors/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ pub mod command;
pub mod console;
pub mod grim_reaper;
pub mod watcher;
pub mod custom_highlighter;