From 9d5898946f47f57dd05e7c81a736ab533a41b4e5 Mon Sep 17 00:00:00 2001 From: Arne Beer Date: Sat, 11 Jul 2020 18:25:04 +0200 Subject: [PATCH] Run cargo fmt and remove unnecessary is_tty() call --- client/output.rs | 33 ++++++++++++++++++++++++++------- client/output_helper.rs | 10 +++++++--- 2 files changed, 33 insertions(+), 10 deletions(-) diff --git a/client/output.rs b/client/output.rs index 36b4a11d..9631303d 100644 --- a/client/output.rs +++ b/client/output.rs @@ -237,10 +237,17 @@ pub fn print_log(task_log: &mut TaskLogMessage, settings: &Settings) { let is_tty = io::stdout().is_tty(); // Print task id and exit code. - let task_text = style_text(format!("Task {}", task.id), is_tty, None, Some(Attribute::Bold)); + let task_text = style_text( + format!("Task {}", task.id), + is_tty, + None, + Some(Attribute::Bold), + ); let (exit_status, color) = match &task.result { Some(TaskResult::Success) => ("completed successfully".into(), Color::Green), - Some(TaskResult::Failed(exit_code)) => (format!("failed with exit code {}", exit_code), Color::Red), + Some(TaskResult::Failed(exit_code)) => { + (format!("failed with exit code {}", exit_code), Color::Red) + } Some(TaskResult::FailedToSpawn(err)) => (format!("failed to spawn: {}", err), Color::Red), Some(TaskResult::Killed) => ("killed by system or user".into(), Color::Red), Some(TaskResult::DependencyFailed) => ("dependency failed".into(), Color::Red), @@ -283,11 +290,13 @@ pub fn print_local_log_output(task_id: usize, settings: &Settings, is_tty: bool) // Stdout handler to directly write log file output to io::stdout // without having to load anything into memory. let mut stdout = io::stdout(); - let is_tty = stdout.is_tty(); if let Ok(metadata) = stdout_log.metadata() { if metadata.len() != 0 { - println!("\n{}", style_text("stdout:", is_tty, Some(Color::Green), Some(Attribute::Bold))); + println!( + "\n{}", + style_text("stdout:", is_tty, Some(Color::Green), Some(Attribute::Bold)) + ); if let Err(err) = io::copy(&mut stdout_log, &mut stdout) { println!("Failed reading local stdout log file: {}", err); @@ -298,7 +307,10 @@ pub fn print_local_log_output(task_id: usize, settings: &Settings, is_tty: bool) if let Ok(metadata) = stderr_log.metadata() { if metadata.len() != 0 { // Add a spacer line between stdout and stderr - println!("\n{}", style_text("stderr:", is_tty, Some(Color::Red), Some(Attribute::Bold))); + println!( + "\n{}", + style_text("stderr:", is_tty, Some(Color::Red), Some(Attribute::Bold)) + ); if let Err(err) = io::copy(&mut stderr_log, &mut stdout) { println!("Failed reading local stderr log file: {}", err); @@ -326,14 +338,21 @@ pub fn print_task_output_from_daemon(task_log: &TaskLogMessage, is_tty: bool) { } /// Print log output of a finished process. -pub fn print_remote_task_output(task_log: &TaskLogMessage, is_tty: bool, stdout: bool) -> Result<()> { +pub fn print_remote_task_output( + task_log: &TaskLogMessage, + is_tty: bool, + stdout: bool, +) -> Result<()> { let (pre_text, color, bytes) = if stdout { ("stdout: ", Color::Green, task_log.stdout.as_ref().unwrap()) } else { ("stderr: ", Color::Red, task_log.stderr.as_ref().unwrap()) }; - println!("\n{}", style_text(pre_text, is_tty, Some(color), Some(Attribute::Bold))); + println!( + "\n{}", + style_text(pre_text, is_tty, Some(color), Some(Attribute::Bold)) + ); let mut decompressor = FrameDecoder::new(bytes.as_slice()); diff --git a/client/output_helper.rs b/client/output_helper.rs index 93eaeffa..4a1ff161 100644 --- a/client/output_helper.rs +++ b/client/output_helper.rs @@ -1,14 +1,18 @@ -use ::crossterm::style::{Color, Attribute, style}; +use ::crossterm::style::{style, Attribute, Color}; use ::std::collections::BTreeMap; use ::pueue::state::State; use ::pueue::task::Task; - /// This is a simple small helper function with the purpose of easily styling text, /// while also prevent styling if we're printing to a non-tty output. /// If there's any kind of styling in the code, it should be done with the help of this function. -pub fn style_text(text: T, is_tty: bool, color: Option, attribute: Option) -> String { +pub fn style_text( + text: T, + is_tty: bool, + color: Option, + attribute: Option, +) -> String { if is_tty { let mut styled = style(text.to_string()); if let Some(color) = color {