Skip to content

Commit

Permalink
Merge pull request #56 from 0x20F/fix-loading-timestamp
Browse files Browse the repository at this point in the history
Fix loading timestamp
  • Loading branch information
0x20F authored Mar 30, 2023
2 parents c3f0c77 + 04f1852 commit c56e404
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 31 deletions.
22 changes: 0 additions & 22 deletions .github/workflows/rust_test.yml

This file was deleted.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "paris"
version = "1.5.14"
version = "1.5.15"
authors = ["Poly <[email protected]>"]
edition = "2018"

Expand Down
28 changes: 24 additions & 4 deletions src/logger/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,8 +198,8 @@ impl<'a> Logger<'a> {
i = 0;
}

let message = format!("\r<cyan>{}</> {}", frames[i], &message);
output::stdout(colorize_string(message), "");
let message = format!("<cyan>{}</> {}", frames[i], &message);
output::stdout(colorize_string(message), "", true);
io::stdout().flush().unwrap();

thread::sleep(Duration::from_millis(100));
Expand Down Expand Up @@ -278,7 +278,11 @@ impl<'a> Logger<'a> {
self.done();
let message = message.to_string();

output::stdout(self.formatter.colorize(&message), &self.get_line_ending());
output::stdout(
self.formatter.colorize(&message),
&self.get_line_ending(),
false,
);
self
}

Expand All @@ -290,7 +294,11 @@ impl<'a> Logger<'a> {
self.done();
let message = message.to_string();

output::stderr(self.formatter.colorize(&message), &self.get_line_ending());
output::stderr(
self.formatter.colorize(&message),
&self.get_line_ending(),
false,
);
self
}

Expand Down Expand Up @@ -345,6 +353,18 @@ mod tests {
logger.success("Loading done!");
}

#[cfg(feature = "timestamps")]
#[test]
fn loading_with_timestamps() {
let mut logger = Logger::new();
logger.loading("Loading in the middle of a test is not good!");
thread::sleep(Duration::from_secs(4));
logger.loading("Still loading...");
thread::sleep(Duration::from_secs(4));

logger.success("Loading done!");
}

#[test]
fn same() {
let mut logger = Logger::new();
Expand Down
20 changes: 16 additions & 4 deletions src/output/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,23 +24,35 @@ fn current_time() -> String {

/// Writes to stdout without replacing keys
#[cfg(not(feature = "no_logger"))]
pub fn stdout<T>(message: T, line_ending: &str)
pub fn stdout<T>(message: T, line_ending: &str, with_carriage: bool)
where
T: Display,
{
let mut carriage = "";

if with_carriage {
carriage = "\r";
}

let timestamp = current_time();
let message = format!("{}{}{}", timestamp, message, line_ending);
let message = format!("{}{}{}{}", carriage, timestamp, message, line_ending);
print!("{}", message);
}

/// Writes to stderr without replacing keys
#[cfg(not(feature = "no_logger"))]
pub fn stderr<T>(message: T, line_ending: &str)
pub fn stderr<T>(message: T, line_ending: &str, with_carriage: bool)
where
T: Display,
{
let mut carriage = "";

if with_carriage {
carriage = "\r";
}

let timestamp = current_time();
let message = format!("{}{}{}", timestamp, message, line_ending);
let message = format!("{}{}{}{}", carriage, timestamp, message, line_ending);
eprint!("{}", message);
}

Expand Down

0 comments on commit c56e404

Please sign in to comment.