Skip to content

Commit

Permalink
disable coloring if terminal does not support it
Browse files Browse the repository at this point in the history
  • Loading branch information
msmoiz committed Aug 14, 2020
1 parent 93608d3 commit 8457aca
Show file tree
Hide file tree
Showing 4 changed files with 114 additions and 3 deletions.
107 changes: 107 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ regex = "*"
rust-ini = "0.15"
serde = {version = "*", features = ["derive"]}
serde_json = "*"
colored = "2"
colored = "2"
term = "*"
6 changes: 4 additions & 2 deletions src/printer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@ use std::io::{stdout, Write};
pub struct Print;

impl Print {

/// Toggles coloring based on environment.
/// For instance, colors do not work for `cmd`on Windows.
pub fn check_support_for_colors() {

let term = term::stdout().unwrap();
if !term.supports_color() {
colored::control::set_override(false);
}
}

/// Print a header. Includes a preliminary newline.
Expand Down
1 change: 1 addition & 0 deletions src/renamer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ impl Renamer {

/// Start the renaming process.
pub fn start(&mut self) -> Result<(), Box<dyn Error>> {
Print::check_support_for_colors();
Print::header("Welcome to Renom");
Print::header("Project Details");
Print::basic("Tell us a little about your project.");
Expand Down

0 comments on commit 8457aca

Please sign in to comment.