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: patterns highlighting #117

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
499 changes: 417 additions & 82 deletions Cargo.lock

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion 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,3 +43,5 @@ assert_cmd = "2.0.12"
semver = "1.0.20"
shlex = "1.2.0"
termgraph = "0.4.0"
tailspin = { git = "https://github.com/destifo/tailspin", branch = "tailspin-lib-crate" }
color-eyre = "0.6.2"
14 changes: 8 additions & 6 deletions src/actors/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,13 @@ 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 crate::utils::custom_highlighter::CustomHighlighter;

use super::console::{Output, PanelStatus, RegisterPanel};
use super::watcher::{IgnorePath, WatchGlob};
Expand Down Expand Up @@ -409,9 +410,9 @@ impl CommandActor {
.popen()
.unwrap();

let stdout = p.stdout.take().unwrap();
let reader = BufReader::new(stdout);
let output_file = p.stdout.take().unwrap();

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 @@ -420,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 All @@ -440,7 +442,7 @@ impl CommandActor {
console.do_send(RegisterPanel {
name: tab_name.to_owned(),
addr: addr.clone(),
colors: task_colors.clone()
colors: task_colors.clone(),
});
}
console.do_send(Output::now(tab_name.to_owned(), line.clone(), false));
Expand Down Expand Up @@ -515,7 +517,7 @@ impl Actor for CommandActor {
self.console.do_send(RegisterPanel {
name: self.op_name.clone(),
addr,
colors: self.colors.clone()
colors: self.colors.clone(),
});

let watches = self.operator.watch.resolve();
Expand Down
2 changes: 1 addition & 1 deletion src/actors/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pub mod command;
pub mod console;
pub mod grim_reaper;
pub mod watcher;
pub mod watcher;
2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use whiz::{
args::Command,
config::Config,
global_config::GlobalConfig,
utils::recurse_config_file,
utils::util_functions::recurse_config_file,
};
mod graph;

Expand Down
2 changes: 1 addition & 1 deletion src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use crate::{
watcher::WatcherActor,
},
config::Config,
utils::recurse_config_file,
utils::util_functions::recurse_config_file,
};
use actix::{actors::mocker::Mocker, prelude::*};
use assert_cmd::Command;
Expand Down
29 changes: 29 additions & 0 deletions src/utils/custom_highlighter.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
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)
}
}
2 changes: 2 additions & 0 deletions src/utils/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
pub mod custom_highlighter;
pub mod util_functions;
2 changes: 2 additions & 0 deletions src/utils.rs → src/utils/util_functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ use std::{
path::{Path, PathBuf},
};



pub fn find_config_path(location: &Path, config_name: &str) -> Result<PathBuf, std::io::Error> {
let config_name_as_path = Path::new(config_name);
let mut config_path = location.to_path_buf();
Expand Down
Loading