Skip to content

Commit

Permalink
Merge pull request #90 from avencera/dim-unchanged-files-print
Browse files Browse the repository at this point in the history
Dim unchanged files print
  • Loading branch information
praveenperera authored Dec 20, 2023
2 parents c251262 + 928e644 commit a054fd0
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 5 deletions.
11 changes: 11 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ description = "A CLI to sort tailwind CSS classes"
# cli
clap = { version = "4.3", features = ["cargo", "derive", "unstable-styles"] }
indoc = "2.0"
colored = "2.1"

# files
ignore = "0.4"
Expand Down
21 changes: 16 additions & 5 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ use std::sync::atomic::AtomicBool;
use std::sync::atomic::Ordering;

static EXIT_ERROR: Lazy<AtomicBool> = Lazy::new(|| AtomicBool::new(false));
static GRAY: Lazy<colored::CustomColor> = Lazy::new(|| colored::CustomColor::new(120, 120, 120));

#[derive(Parser, Debug)]
#[clap(name = "RustyWind", author, version, about, long_about = None)]
Expand Down Expand Up @@ -158,10 +159,12 @@ fn run_on_file_paths(file_path: &Path, options: &Options) {

match (contents_changed, &options.write_mode) {
(_, WriteMode::ToStdOut) => (),
(_, WriteMode::DryRun) => print_file_name(file_path, options),
(_, WriteMode::DryRun) => print_file_name(file_path, contents_changed, options),

(true, WriteMode::ToFile) => write_to_file(file_path, &sorted_content, options),
(false, WriteMode::ToFile) => print_file_name(file_path, options),
(false, WriteMode::ToFile) => {
print_file_name(file_path, contents_changed, options)
}

// For now print the file contents to the console even if it hasn't changed to
// keep consistent with how rustywind has always worked. But in a later
Expand Down Expand Up @@ -208,7 +211,7 @@ fn should_ignore_current_file(ignored_files: &HashSet<PathBuf>, current_file: &P

fn write_to_file(file_path: &Path, sorted_contents: &str, options: &Options) {
match fs::write(file_path, sorted_contents.as_bytes()) {
Ok(_) => print_file_name(file_path, options),
Ok(_) => print_file_name(file_path, true, options),
Err(err) => {
eprintln!("\nError: {:?}", err);
eprintln!(
Expand All @@ -219,9 +222,17 @@ fn write_to_file(file_path: &Path, sorted_contents: &str, options: &Options) {
}
}

fn print_file_name(file_path: &Path, options: &Options) {
fn print_file_name(file_path: &Path, contents_changed: bool, options: &Options) {
use colored::*;

if !options.quiet {
println!(" * {}", get_file_name(file_path, &options.starting_paths));
let line = format!(" * {}", get_file_name(file_path, &options.starting_paths));

if contents_changed {
println!("{}", line);
} else {
eprintln!("{}", line.custom_color(*GRAY));
}
}
}

Expand Down

0 comments on commit a054fd0

Please sign in to comment.