Skip to content

Commit

Permalink
chore: remove colors & ANSI characters.
Browse files Browse the repository at this point in the history
  owo-colors has proven to be quite a pain to work with inside Aiken. So at this point, I am not sure we want to commit yet to using it. So I've simplified the panic hook to be less fancy looking, but still provide the valuable information. We can re-assess later whether and how we can to make it prettier.
  • Loading branch information
KtorZ committed Dec 29, 2024
1 parent 97baa42 commit 5fb28df
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 91 deletions.
77 changes: 0 additions & 77 deletions Cargo.lock

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

2 changes: 0 additions & 2 deletions crates/amaru/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ gasket = { version = "0.8.0", features = ["derive"] }
hex = "0.4.3"
miette = "7.2.0"
indoc = "2.0"
strip-ansi-escapes = "0.1.1"
owo-colors = { version = "3.5.0", features = ["supports-colors"] }
ouroboros = { git = "https://github.com/pragma-org/ouroboros", rev = "ca1d447a6c106e421e6c2b1c7d9d59abf5ca9589" }
ouroboros-praos = { git = "https://github.com/pragma-org/ouroboros", rev = "ca1d447a6c106e421e6c2b1c7d9d59abf5ca9589" }
pallas-addresses = "0.31.0"
Expand Down
17 changes: 5 additions & 12 deletions crates/amaru/src/bin/amaru/panic.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use owo_colors::OwoColorize;

/// Installs a panic handler that prints some useful diagnostics and
/// asks the user to report the issue.
pub fn panic_handler() {
Expand Down Expand Up @@ -47,8 +45,8 @@ pub fn panic_handler() {
{location}{message}"#,
info = node_info(),
fatal = "amaru::fatal::error".red().bold(),
location = location.purple(),
fatal = "amaru::fatal::error",
location = location,
};

println!("\n{}", indent(&error_message, 3));
Expand All @@ -67,7 +65,7 @@ pub fn indent(lines: &str, n: usize) -> String {
}

pub fn pad_left(mut text: String, n: usize, delimiter: &str) -> String {
let diff = n as i32 - ansi_len(&text) as i32;
let diff = n as i32 - text.len() as i32;
if diff.is_positive() {
for _ in 0..diff {
text.insert_str(0, delimiter);
Expand All @@ -76,18 +74,12 @@ pub fn pad_left(mut text: String, n: usize, delimiter: &str) -> String {
text
}

pub fn ansi_len(s: &str) -> usize {
String::from_utf8(strip_ansi_escapes::strip(s).unwrap())
.unwrap()
.chars()
.count()
}

// TODO: pulled from aiken; should we have our own config utility crate?
// https://github.com/aiken-lang/aiken/blob/main/crates/aiken-project/src/config.rs#L382C1-L393C2
mod built_info {
include!(concat!(env!("OUT_DIR"), "/built.rs"));
}

pub fn node_info() -> String {
format!(
r#"
Expand All @@ -99,6 +91,7 @@ Version: {}"#,
node_version(true),
)
}

pub fn node_version(include_commit_hash: bool) -> String {
let version = built_info::PKG_VERSION;
let suffix = if include_commit_hash {
Expand Down

0 comments on commit 5fb28df

Please sign in to comment.