From bbb7aaccc430980cda952a5a7198e4766535d4ae Mon Sep 17 00:00:00 2001 From: ozwaldorf Date: Thu, 19 Jan 2023 00:08:09 -0500 Subject: [PATCH 1/6] fix: parse multi-byte unicode chars correctly --- .gitignore | 1 + ascii/src/lib.rs | 5 +++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index de30f33ad..2cdbd84c9 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,4 @@ .DS_Store result **/generated-* +**/.idea diff --git a/ascii/src/lib.rs b/ascii/src/lib.rs index a247329ae..b242513cb 100644 --- a/ascii/src/lib.rs +++ b/ascii/src/lib.rs @@ -211,9 +211,10 @@ fn add_styled_segment(base: &mut String, segment: &str, color: DynColors, bold: type ParseResult<'a, R> = Option<(&'a str, R)>; fn token(s: &str, predicate: impl FnOnce(char) -> Option) -> ParseResult { - let token = s.chars().next()?; + let mut chars = s.chars(); + let token = chars.next()?; let result = predicate(token)?; - Some((s.get(1..).unwrap(), result)) + Some((chars.as_str(), result)) } // Parsers From 93ffe462f565abb5e40adeb6c8efc0d743c49d29 Mon Sep 17 00:00:00 2001 From: ozwaldorf Date: Thu, 19 Jan 2023 10:15:10 -0500 Subject: [PATCH 2/6] tests(ascii): add unicode block assertation to render --- ascii/src/lib.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/ascii/src/lib.rs b/ascii/src/lib.rs index b242513cb..d9e699c1e 100644 --- a/ascii/src/lib.rs +++ b/ascii/src/lib.rs @@ -314,6 +314,12 @@ mod test { "\u{1b}[39;1m \u{1b}[0m" ); + // https://github.com/o2sh/onefetch/issues/935 + assert_eq!( + Tokens("███").render(Vec::new().as_slice(), 0, 3, true), + "\u{1b}[39;1m███\u{1b}[0m" + ); + assert_eq!( Tokens(" {1} {5} {9} a").render(&colors_shim, 4, 10, true), "\u{1b}[39;1m\u{1b}[0m\u{1b}[39;1m\u{1b}[0m\u{1b}[39;1m \u{1b}[0m\u{1b}[39;1m a\u{1b}[0m " From db1916cfae40e7e638d6059791177cec7d9f6ee0 Mon Sep 17 00:00:00 2001 From: ozwaldorf Date: Thu, 19 Jan 2023 10:15:38 -0500 Subject: [PATCH 3/6] docs(ascii): add AsciiArt usage example --- ascii/src/lib.rs | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/ascii/src/lib.rs b/ascii/src/lib.rs index d9e699c1e..5dae0f303 100644 --- a/ascii/src/lib.rs +++ b/ascii/src/lib.rs @@ -1,6 +1,52 @@ +//! # onefetch-ascii +//! +//! Provides the ascii template interface for [onefetch](https://github.com/ +//! +//! ```rust +//! use onefetch_ascii::AsciiArt; +//! use owo_colors::{DynColors, AnsiColors}; +//! +//! const ASCII: &str = r#" +//! {2} .:--::////::--.` +//! {1} `/yNMMNho{2}////////////:. +//! {1} `+NMMMMMMMMmy{2}/////////////:` +//! {0} `-:::{1}ohNMMMMMMMNy{2}/////////////:` +//! {0} .::::::::{1}odMMMMMMMNy{2}/////////////- +//! {0} -:::::::::::{1}/hMMMMMMMmo{2}////////////- +//! {0} .::::::::::::::{1}oMMMMMMMMh{2}////////////- +//! {0}`:::::::::::::{1}/dMMMMMMMMMMNo{2}///////////` +//! {0}-::::::::::::{1}sMMMMMMmMMMMMMMy{2}//////////- +//! {0}-::::::::::{1}/dMMMMMMs{0}:{1}+NMMMMMMd{2}/////////: +//! {0}-:::::::::{1}+NMMMMMm/{0}:::{1}/dMMMMMMm+{2}///////: +//! {0}-::::::::{1}sMMMMMMh{0}:::::::{1}dMMMMMMm+{2}//////- +//! {0}`:::::::{1}sMMMMMMy{0}:::::::::{1}dMMMMMMm+{2}/////` +//! {0} .:::::{1}sMMMMMMs{0}:::::::::::{1}mMMMMMMd{2}////- +//! {0} -:::{1}sMMMMMMy{0}::::::::::::{1}/NMMMMMMh{2}//- +//! {0} .:{1}+MMMMMMd{0}::::::::::::::{1}oMMMMMMMo{2}- +//! {1} `yMMMMMN/{0}:::::::::::::::{1}hMMMMMh. +//! {1} -yMMMo{0}::::::::::::::::{1}/MMMy- +//! {1} `/s{0}::::::::::::::::::{1}o/` +//! {0} ``.---::::---..` +//! "#; +//! +//! let colors = vec![ +//! DynColors::Ansi(AnsiColors::Blue), +//! DynColors::Ansi(AnsiColors::Default), +//! DynColors::Ansi(AnsiColors::BrightBlue) +//! ]; +//! +//! let art = AsciiArt::new(ASCII, colors.as_slice(), true); +//! +//! for line in art { +//! println!("{line}") +//! } +//! ``` +//! + use owo_colors::{AnsiColors, DynColors, OwoColorize, Style}; use std::fmt::Write; +/// Renders an ascii template with the given colors truncated to the correct width. pub struct AsciiArt<'a> { content: Box>, colors: &'a [DynColors], From ce9e36fa19723bb5d2284b98d7a2e61247664b47 Mon Sep 17 00:00:00 2001 From: ozwaldorf Date: Thu, 19 Jan 2023 10:23:50 -0500 Subject: [PATCH 4/6] docs(ascii): fix ascii doc onefetch link --- ascii/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ascii/src/lib.rs b/ascii/src/lib.rs index 5dae0f303..0725613ba 100644 --- a/ascii/src/lib.rs +++ b/ascii/src/lib.rs @@ -1,6 +1,6 @@ //! # onefetch-ascii //! -//! Provides the ascii template interface for [onefetch](https://github.com/ +//! Provides the ascii template interface for [onefetch](https://github.com/o2sh/onefetch). //! //! ```rust //! use onefetch_ascii::AsciiArt; From 300c689513645196d229fa1e5ed3abff7b11c0a1 Mon Sep 17 00:00:00 2001 From: ozwaldorf Date: Thu, 19 Jan 2023 10:24:13 -0500 Subject: [PATCH 5/6] docs(ascii): add badges to readme --- ascii/README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/ascii/README.md b/ascii/README.md index 896fe9d9c..6ffec13b9 100644 --- a/ascii/README.md +++ b/ascii/README.md @@ -1,5 +1,8 @@ # ascii +[![crates.io](https://img.shields.io/crates/v/onefetch-ascii)](https://crates.io/crates/onefetch-ascii) +[![docs.rs](https://img.shields.io/docsrs/onefetch-ascii)](https://docs.rs/onefetch-ascii) + Provides the primary interface to display ascii art to the terminal. More info [here](https://github.com/o2sh/onefetch/wiki/ascii-art). From 00beed312def603eb99b6ba28d76459e60e1a53e Mon Sep 17 00:00:00 2001 From: ozwaldorf Date: Thu, 19 Jan 2023 10:25:20 -0500 Subject: [PATCH 6/6] docs(ascii): add no_run to example --- ascii/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ascii/src/lib.rs b/ascii/src/lib.rs index 0725613ba..0e8802774 100644 --- a/ascii/src/lib.rs +++ b/ascii/src/lib.rs @@ -2,7 +2,7 @@ //! //! Provides the ascii template interface for [onefetch](https://github.com/o2sh/onefetch). //! -//! ```rust +//! ```rust,no_run //! use onefetch_ascii::AsciiArt; //! use owo_colors::{DynColors, AnsiColors}; //!