From b393dcfa3f1a7b84d31c01f271eb69ba678a6c35 Mon Sep 17 00:00:00 2001 From: spiders Date: Wed, 4 May 2022 17:36:31 -0700 Subject: [PATCH] added support for non wrapping mode --- src/bubbles.rs | 18 ++++++++++++++++-- src/main.rs | 4 ++++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/src/bubbles.rs b/src/bubbles.rs index 76145a2..ac16908 100644 --- a/src/bubbles.rs +++ b/src/bubbles.rs @@ -4,6 +4,7 @@ use voca_rs::*; pub struct BubbleConfig { anchor: usize, wrap: usize, + no_wrap: bool, top: String, left: String, @@ -19,7 +20,12 @@ pub struct BubbleConfig { impl BubbleConfig { // assembles a config from critical information, attempting to use sensible defaults where possible - pub fn config_from_string(anchor: usize, wrap: usize, border: Option) -> BubbleConfig { + pub fn config_from_string( + anchor: usize, + wrap: usize, + no_wrap: bool, + border: Option, + ) -> BubbleConfig { if let Some(border) = border { let chars = split::graphemes(&border); let top = if let Some(item) = chars.get(0) { @@ -29,6 +35,7 @@ impl BubbleConfig { return BubbleConfig { anchor, wrap, + no_wrap, top: "_".to_string(), left: "<".to_string(), @@ -91,6 +98,7 @@ impl BubbleConfig { BubbleConfig { anchor, wrap, + no_wrap, top, left, @@ -107,6 +115,7 @@ impl BubbleConfig { BubbleConfig { anchor, wrap, + no_wrap, top: "_".to_string(), left: "<".to_string(), @@ -124,7 +133,11 @@ impl BubbleConfig { // front end to bubble_from_lines which takes normal text. pub fn bubble_from_text(&self, text: &str) -> String { - self.bubble_from_lines(&wrap_block(text, self.wrap)) + if self.no_wrap { + self.bubble_from_lines(&text.lines().map(|s| s.to_string()).collect()) + } else { + self.bubble_from_lines(&wrap_block(text, self.wrap)) + } } // generates a bubble (doesn't end in newline) using a vector of strings as lines. @@ -185,6 +198,7 @@ impl BubbleConfig { } } +// "breaks off" a wrapped line of text and returns it with the rests of the text. fn wrap_once(text: &str, max_length: usize) -> (String, Option) { let whitespace_not_newline = |c: char| c.is_whitespace() && c != '\n'; let mut length: usize = 0; diff --git a/src/main.rs b/src/main.rs index 900a22c..2fa49cf 100644 --- a/src/main.rs +++ b/src/main.rs @@ -54,6 +54,9 @@ struct Args { #[clap(short = 'W', long)] pakala: Option, + #[clap(short = 'n', long)] + pakala_ala: bool, + #[clap(short = 'k', long)] kule: Vec, @@ -189,6 +192,7 @@ impl Args { let bubble_config = BubbleConfig::config_from_string( critter_config.template.anchor, DEFAULT_MAXIMUM_LINE_LENGTH, + self.pakala_ala, None, );