diff --git a/Cargo.lock b/Cargo.lock index 46d38c0..c4f9b9b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -372,12 +372,6 @@ dependencies = [ name = "helptext" version = "0.1.1" -[[package]] -name = "hermit-abi" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fbf6a919d6cf397374f7dfeeea91d974c7c0a7221d0d0f4f20d859d329e53fcc" - [[package]] name = "home" version = "0.5.9" @@ -403,17 +397,6 @@ dependencies = [ "winapi-util", ] -[[package]] -name = "is-terminal" -version = "0.4.13" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "261f68e344040fbd0edea105bef17c66edf46f984ddb1115b775ce31be948f4b" -dependencies = [ - "hermit-abi", - "libc", - "windows-sys 0.52.0", -] - [[package]] name = "is_ci" version = "1.2.0" @@ -516,7 +499,7 @@ checksum = "317f146e2eb7021892722af37cf1b971f0a70c8406f487e24952667616192c64" dependencies = [ "cfg-if", "owo-colors", - "supports-color 3.0.2", + "supports-color", "supports-hyperlinks", "supports-unicode", "terminal_size", @@ -694,9 +677,10 @@ dependencies = [ "pcre2", "pomsky", "predicates 2.1.5", + "regex", "serde", "serde_json", - "supports-color 2.1.0", + "supports-color", ] [[package]] @@ -906,16 +890,6 @@ version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" -[[package]] -name = "supports-color" -version = "2.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d6398cde53adc3c4557306a96ce67b302968513830a77a95b2b17305d9719a89" -dependencies = [ - "is-terminal", - "is_ci", -] - [[package]] name = "supports-color" version = "3.0.2" diff --git a/helptext/src/color.rs b/helptext/src/color.rs deleted file mode 100644 index be3438e..0000000 --- a/helptext/src/color.rs +++ /dev/null @@ -1,69 +0,0 @@ -/// All supported colors in the formatting machinery -#[non_exhaustive] -#[derive(Debug, Clone, Copy, PartialEq, Eq)] -pub enum Color { - /// Cyan text; alias: c - Cyan, - /// Green text; alias: g - Green, - /// Magenta text; alias: m - Magenta, - /// Red text; alias: r - Red, - /// Yellow text; alias: y - Yellow, - /// Cyan bold text; alias: C - CyanBold, - /// Green bold text; alias: G - GreenBold, - /// Magenta bold text; alias: M - MagentaBold, - /// Red bold text; alias: R - RedBold, - /// Yellow bold text; alias: Y - YellowBold, -} - -#[allow(non_upper_case_globals)] -impl Color { - pub const c: Color = Color::Cyan; - pub const g: Color = Color::Green; - pub const m: Color = Color::Magenta; - pub const r: Color = Color::Red; - pub const y: Color = Color::Yellow; - - pub const C: Color = Color::CyanBold; - pub const G: Color = Color::GreenBold; - pub const M: Color = Color::MagentaBold; - pub const R: Color = Color::RedBold; - pub const Y: Color = Color::YellowBold; - - pub(crate) const ANSI_RESET: &'static str = "\x1b[0m"; - pub(crate) const ANSI_C: &'static str = "\x1b[36m"; - pub(crate) const ANSI_G: &'static str = "\x1b[32m"; - pub(crate) const ANSI_M: &'static str = "\x1b[35m"; - pub(crate) const ANSI_R: &'static str = "\x1b[31m"; - pub(crate) const ANSI_Y: &'static str = "\x1b[33m"; - pub(crate) const ANSI_CB: &'static str = "\x1b[36;1m"; - pub(crate) const ANSI_GB: &'static str = "\x1b[32;1m"; - pub(crate) const ANSI_MB: &'static str = "\x1b[35;1m"; - pub(crate) const ANSI_RB: &'static str = "\x1b[31;1m"; - pub(crate) const ANSI_YB: &'static str = "\x1b[33;1m"; -} - -impl Color { - pub fn ansi_code(self) -> &'static str { - match self { - Color::Cyan => Self::ANSI_C, - Color::Green => Self::ANSI_G, - Color::Magenta => Self::ANSI_M, - Color::Red => Self::ANSI_R, - Color::Yellow => Self::ANSI_Y, - Color::CyanBold => Self::ANSI_CB, - Color::GreenBold => Self::ANSI_GB, - Color::MagentaBold => Self::ANSI_MB, - Color::RedBold => Self::ANSI_RB, - Color::YellowBold => Self::ANSI_YB, - } - } -} diff --git a/helptext/src/help.rs b/helptext/src/help.rs index 6ba166f..69aebfc 100644 --- a/helptext/src/help.rs +++ b/helptext/src/help.rs @@ -1,6 +1,6 @@ use std::io::{self, Write}; -use crate::Color; +use crate::Style; /// A structured help message. /// @@ -9,9 +9,9 @@ use crate::Color; pub struct Help<'a>(pub &'a [HelpSection<'a>]); impl Help<'_> { - pub fn write(&self, buf: &mut impl Write, long: bool, colored: bool) -> io::Result<()> { + pub fn write(&self, buf: &mut impl Write, long: bool, styled: bool) -> io::Result<()> { for section in self.0 { - section.write(buf, long, colored, 0, false)?; + section.write(buf, long, styled, 0, false)?; } Ok(()) } @@ -35,19 +35,19 @@ impl HelpSection<'_> { &self, buf: &mut impl Write, long: bool, - colored: bool, + styled: bool, indent: usize, same_line: bool, ) -> io::Result { match *self { HelpSection::Short(section) => { if !long { - return section.write(buf, long, colored, indent, same_line); + return section.write(buf, long, styled, indent, same_line); } } HelpSection::Long(section) => { if long { - return section.write(buf, long, colored, indent, same_line); + return section.write(buf, long, styled, indent, same_line); } } HelpSection::Text(segments) => { @@ -57,7 +57,7 @@ impl HelpSection<'_> { )?; } for segment in segments { - segment.write(&mut *buf, colored, indent)?; + segment.write(&mut *buf, styled, indent)?; } buf.write_all(b"\n")?; return Ok(true); @@ -67,10 +67,10 @@ impl HelpSection<'_> { &b"\n "[..indent + 1], )?; - if colored { - buf.write_all(Color::ANSI_Y.as_bytes())?; + if styled { + buf.write_all(Style::ANSI_UB.as_bytes())?; buf.write_all(name.as_bytes())?; - buf.write_all(Color::ANSI_RESET.as_bytes())?; + buf.write_all(Style::ANSI_RESET.as_bytes())?; } else { buf.write_all(name.as_bytes())?; } @@ -84,7 +84,7 @@ impl HelpSection<'_> { &b" "[..new_indent], )?; } - line_written |= section.write(buf, long, colored, new_indent, false)?; + line_written |= section.write(buf, long, styled, new_indent, false)?; } return Ok(line_written); } @@ -114,10 +114,10 @@ impl HelpSection<'_> { &b" "[..indent], )?; - if colored { - buf.write_all(Color::ANSI_G.as_bytes())?; + if styled { + buf.write_all(Style::ANSI_G.as_bytes())?; buf.write_all(key.as_bytes())?; - buf.write_all(Color::ANSI_RESET.as_bytes())?; + buf.write_all(Style::ANSI_RESET.as_bytes())?; } else { buf.write_all(key.as_bytes())?; } @@ -136,7 +136,7 @@ impl HelpSection<'_> { line_written |= section.write( buf, long, - colored, + styled, new_indent, is_small && !line_written, )?; @@ -162,7 +162,7 @@ pub enum TableMode { #[derive(Debug, Clone)] pub struct Segment<'a> { - pub style: Option, + pub style: Option