Skip to content

Commit

Permalink
fix(qf): improve logger to take less space on the screen
Browse files Browse the repository at this point in the history
  • Loading branch information
Ph0enixKM committed Jul 29, 2024
1 parent ec45821 commit 0dc2b09
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 18 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "heraclitus-compiler"
version = "1.7.2"
version = "1.7.3"
edition = "2021"
description = "Compiler frontend for developing great programming languages"
license = "MIT"
Expand Down
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ let tokens = cc.tokenize()?;

# Change log 🚀

## Version 1.7.3
### Fix:
- `Logger::text` now doesn't end with a new line
### Feature:
- Added `Logger::line` method that adds a new line in the end (works just like old `Logger::text`)

## Version 1.7.2
### Fix:
- `PositionInfo::from_between_tokens` shows the range even if the end token is None
Expand Down
22 changes: 15 additions & 7 deletions src/compiling/failing/logger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,20 +43,28 @@ impl Logger {
.black()
.bold()
.on_color(self.kind_to_color());
eprintln!("{formatted}");
eprint!("{formatted} ");
self
}

/// Render text with supplied coloring
pub fn text(self, text: Option<String>) -> Self {
if let Some(text) = text {
eprint!("{}", text.color(self.kind_to_color()));
}
self
}

/// Render text with supplied coloring and end it with a newline
pub fn line(self, text: Option<String>) -> Self {
if let Some(text) = text {
eprintln!("{}", text.color(self.kind_to_color()));
}
self
}

/// Render padded text with supplied coloring
pub fn padded_text(self, text: Option<String>) -> Self {
/// Render padded text with a newline, applying the supplied coloring, and end it with another newline
pub fn padded_line(self, text: Option<String>) -> Self {
if let Some(text) = text {
eprintln!("\n{}", text.color(self.kind_to_color()));
}
Expand All @@ -83,7 +91,7 @@ impl Logger {
None => {
"at [unknown]:0:0".to_string()
}
};
}.trim_end().to_string();
eprintln!("{}", path.color(self.kind_to_color()).dimmed());
self
}
Expand Down Expand Up @@ -233,7 +241,7 @@ mod test {
];
super::Logger::new(MessageType::Error, &trace)
.header(MessageType::Error)
.text(Some(format!("Cannot call function \"foobar\" on a number")))
.line(Some(format!("Cannot call function \"foobar\" on a number")))
.path()
.snippet(Some(code));
}
Expand All @@ -250,7 +258,7 @@ mod test {
];
super::Logger::new(MessageType::Error, &trace)
.header(MessageType::Error)
.text(Some(format!("Cannot call function \"foobar\" on a number")))
.line(Some(format!("Cannot call function \"foobar\" on a number")))
.path()
.snippet(Some(code));
}
Expand All @@ -270,7 +278,7 @@ mod test {
];
super::Logger::new(MessageType::Error, &trace)
.header(MessageType::Error)
.text(Some(format!("Cannot call function \"foobar\" on a number")))
.line(Some(format!("Cannot call function \"foobar\" on a number")))
.path()
.snippet(Some(code));
}
Expand Down
15 changes: 6 additions & 9 deletions src/compiling/failing/message.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//! Display your errors
//!
//!
//! Logger makes it easy for you to display errors. This sub-module is pretty powerful
//! to be used extensively instead of building own implementation of such mechanism.
//! However, if you need more specific functionality - it is encouraged to create your
Expand All @@ -22,7 +22,7 @@ pub enum MessageType {
}

/// Logger itself
///
///
/// Log the message you want to show to the user
/// # Example
/// ```should_panic
Expand Down Expand Up @@ -144,7 +144,7 @@ impl Message {
self
}

/// Shows (renders) the message while giving
/// Shows (renders) the message while giving
/// the ownership to this object away
pub fn show(&self) {
// If this error is based in code
Expand All @@ -153,15 +153,15 @@ impl Message {
.header(self.kind.clone())
.text(self.message.clone())
.path()
.padded_text(self.comment.clone())
.padded_line(self.comment.clone())
.snippet(self.code.clone());
}
// If this error is a message error
else {
Logger::new(self.kind.clone(), &self.trace)
.header(self.kind.clone())
.text(self.message.clone())
.padded_text(self.comment.clone());
.padded_line(self.comment.clone());
}
}

Expand All @@ -174,7 +174,7 @@ impl Message {

#[cfg(test)]
mod test {

#[test]
fn test_logger() {
// use super::Logger;
Expand All @@ -184,6 +184,3 @@ mod test {
// .exit();
}
}



0 comments on commit 0dc2b09

Please sign in to comment.