-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
style: align console messages outside of tracing
- Loading branch information
Showing
12 changed files
with
134 additions
and
79 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,39 @@ | ||
// (c) 2024 Ross Younger | ||
//! CLI output styling | ||
//! | ||
//! Users of this module probably ought to use anstream's `println!` / `eprintln!` macros, | ||
//! Users of this module probably ought to use anstream's `println!` / `eprintln!` macros. | ||
//! | ||
//! This module provides styles for use with those macros, and also a `RESET` constant to reset | ||
//! styling to the default. | ||
#[allow(clippy::enum_glob_use)] | ||
use anstyle::AnsiColor::*; | ||
use anstyle::Color::Ansi; | ||
use clap::builder::styling::Styles; | ||
|
||
pub(crate) const ERROR: anstyle::Style = anstyle::Style::new().bold().fg_color(Some(Ansi(Red))); | ||
pub(crate) const WARNING: anstyle::Style = | ||
anstyle::Style::new().bold().fg_color(Some(Ansi(Yellow))); | ||
pub(crate) const INFO: anstyle::Style = anstyle::Style::new().fg_color(Some(Ansi(Cyan))); | ||
/// Error message styling. This can be Displayed directly. | ||
pub const ERROR: anstyle::Style = anstyle::Style::new().bold().fg_color(Some(Ansi(Red))); | ||
/// Warning message styling. This can be Displayed directly. | ||
pub const WARNING: anstyle::Style = anstyle::Style::new().bold().fg_color(Some(Ansi(Yellow))); | ||
/// Informational message styling. This can be Displayed directly. | ||
pub const INFO: anstyle::Style = anstyle::Style::new().fg_color(Some(Ansi(Cyan))); | ||
// pub(crate) const DEBUG: anstyle::Style = anstyle::Style::new().fg_color(Some(Ansi(Blue))); | ||
|
||
pub(crate) const CALL_OUT: anstyle::Style = anstyle::Style::new() | ||
pub(crate) const HEADER: anstyle::Style = anstyle::Style::new() | ||
.underline() | ||
.fg_color(Some(Ansi(Yellow))); | ||
|
||
pub(crate) const CLAP_STYLES: Styles = Styles::styled() | ||
.usage(CALL_OUT) | ||
.header(CALL_OUT) | ||
.usage(HEADER) | ||
.header(HEADER) | ||
.literal(anstyle::Style::new().bold()) | ||
.invalid(WARNING) | ||
.error(ERROR) | ||
.valid(INFO.bold().underline()) | ||
.placeholder(INFO); | ||
|
||
/// Resets styling to default. | ||
/// | ||
/// This is purely for convenience; you can also call `ERROR::render_reset()` (etc.) | ||
/// | ||
pub use anstyle::Reset as RESET; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,22 @@ | ||
//! qcp utility - main entrypoint | ||
// (c) 2024 Ross Younger | ||
|
||
use qcp::styles::{ERROR, RESET}; | ||
|
||
#[cfg(all(target_env = "musl", target_pointer_width = "64"))] | ||
#[global_allocator] | ||
static ALLOC: jemallocator::Jemalloc = jemallocator::Jemalloc; | ||
|
||
fn main() -> anyhow::Result<std::process::ExitCode> { | ||
qcp::cli() | ||
fn main() -> std::process::ExitCode { | ||
match qcp::cli() { | ||
Ok(code) => code, | ||
Err(e) => { | ||
if qcp::util::tracing_is_initialised() { | ||
tracing::error!("{e}"); | ||
} else { | ||
eprintln!("{ERROR}Error:{RESET} {e}"); | ||
} | ||
std::process::ExitCode::FAILURE | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.