Skip to content

Commit be7592d

Browse files
authored
Merge pull request #77 from shadr/fix-logging
Print logs to the stderr instead of stdout
2 parents aebb219 + 3e1c2e5 commit be7592d

1 file changed

Lines changed: 8 additions & 5 deletions

File tree

src/main.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
112112
eprintln!("The input passed via stdin is not formatted");
113113
std::process::exit(1);
114114
} else {
115-
println!("The input passed via stdin is already formatted");
115+
eprintln!("The input passed via stdin is already formatted");
116116
}
117117
} else {
118118
print!("{}", formatted_content);
@@ -136,7 +136,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
136136

137137
let total_files = input_gdscript_files.len();
138138

139-
print!(
139+
eprint!(
140140
"Formatting {} file{}...",
141141
total_files,
142142
if total_files == 1 { "" } else { "s" }
@@ -192,6 +192,9 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
192192
} else if args.stdout {
193193
// Clear the progress message before printing formatted files to stdout
194194
terminal_clear_line();
195+
// A little bit hacky, but because terminals by default output both stdout and stderr
196+
// we need to return carriage to the start to print formatted output from the start of the line
197+
eprint!("\r");
195198
// If there are multiple input files we still allow stdout but we print a separator
196199
if total_files > 1 {
197200
println!("#--file:{}", output.file_path.display());
@@ -216,15 +219,15 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
216219
if args.check {
217220
if all_formatted {
218221
terminal_clear_line();
219-
println!("\rAll {} file(s) are formatted", total_files);
222+
eprintln!("\rAll {} file(s) are formatted", total_files);
220223
} else {
221224
terminal_clear_line();
222225
eprintln!("\rSome files are not formatted");
223226
std::process::exit(1);
224227
}
225228
} else if !args.stdout {
226229
terminal_clear_line();
227-
println!(
230+
eprintln!(
228231
"\rFormatted {} file{}",
229232
total_files,
230233
if total_files == 1 { "" } else { "s" }
@@ -235,5 +238,5 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
235238
}
236239

237240
fn terminal_clear_line() {
238-
print!("\r{}", " ".repeat(80));
241+
eprint!("\r{}", " ".repeat(80));
239242
}

0 commit comments

Comments
 (0)