Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix loading timestamp #56

Merged
merged 4 commits into from
Mar 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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