Skip to content

Commit

Permalink
Honor the --raw flag for new stdout messages
Browse files Browse the repository at this point in the history
  • Loading branch information
x3ro committed Oct 23, 2024
1 parent 6da363e commit b77d08c
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ pub struct Args {
#[clap(long, default_value = ",")]
pub name_separator: char,

// Output only raw output of processes, disables
// prettifying and concurrently coloring.
/// Output only raw output of processes, disables
/// prettifying and coloring.
#[clap(short, long)]
pub raw: bool,

Expand Down
4 changes: 4 additions & 0 deletions src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,10 @@ impl Command {

format!("{}{}{}", left, ELLIPSIS, right)
}

pub fn disable_output(&self) -> bool {
self.raw || self.hide
}
}

/// Helper to generate a list of [`Command`]s from a [`crate::Config`]
Expand Down
6 changes: 6 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ pub struct Config {
pub kill_others_on_fail: bool,
}

impl Config {
pub fn disable_output(&self) -> bool {
self.raw
}
}

fn maybe_repeat(input: &str, separator: char, count: usize) -> Vec<String> {
let mut result: Vec<_> = input.split(separator).map(|s| s.to_string()).collect();

Expand Down
8 changes: 4 additions & 4 deletions src/event_loop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use crate::{Command, Config};

macro_rules! rly_println {
($cmd:expr, $($arg:tt)*) => {{
if !$cmd.raw && !$cmd.hide {
if !$cmd.disable_output() {
println!($($arg)*);
}
}};
Expand Down Expand Up @@ -141,7 +141,7 @@ async fn handle_next_event(
});

Ok(true)
} else if should_kill_others(&state, &status) {
} else if should_kill_others(state, &status) {
rly_println!(cmd, "--> Sending SIGTERM to other processes..");
for mut opt in state.kill_channels.drain(..) {
if let Some(tx) = opt.take() {
Expand Down Expand Up @@ -193,11 +193,11 @@ pub async fn event_loop(config: &'static Config) -> Result<()> {
loop {
tokio::select! {
_ = handle_ctrlc() => {
println!("Ctrl-C issued");
rly_println!(config, "Ctrl-C issued");
if state.kill_channels.is_empty() {
break;
} else {
println!("Terminating all processes..");
rly_println!(config, "Terminating all processes..");
for mut opt in state.kill_channels.drain(..) {
if let Some(tx) = opt.take() {
tx.send(()).unwrap_or(());
Expand Down

0 comments on commit b77d08c

Please sign in to comment.