added support for non wrapping mode
This commit is contained in:
parent
905ea38557
commit
b393dcfa3f
|
@ -4,6 +4,7 @@ use voca_rs::*;
|
||||||
pub struct BubbleConfig {
|
pub struct BubbleConfig {
|
||||||
anchor: usize,
|
anchor: usize,
|
||||||
wrap: usize,
|
wrap: usize,
|
||||||
|
no_wrap: bool,
|
||||||
|
|
||||||
top: String,
|
top: String,
|
||||||
left: String,
|
left: String,
|
||||||
|
@ -19,7 +20,12 @@ pub struct BubbleConfig {
|
||||||
|
|
||||||
impl BubbleConfig {
|
impl BubbleConfig {
|
||||||
// assembles a config from critical information, attempting to use sensible defaults where possible
|
// assembles a config from critical information, attempting to use sensible defaults where possible
|
||||||
pub fn config_from_string(anchor: usize, wrap: usize, border: Option<String>) -> BubbleConfig {
|
pub fn config_from_string(
|
||||||
|
anchor: usize,
|
||||||
|
wrap: usize,
|
||||||
|
no_wrap: bool,
|
||||||
|
border: Option<String>,
|
||||||
|
) -> BubbleConfig {
|
||||||
if let Some(border) = border {
|
if let Some(border) = border {
|
||||||
let chars = split::graphemes(&border);
|
let chars = split::graphemes(&border);
|
||||||
let top = if let Some(item) = chars.get(0) {
|
let top = if let Some(item) = chars.get(0) {
|
||||||
|
@ -29,6 +35,7 @@ impl BubbleConfig {
|
||||||
return BubbleConfig {
|
return BubbleConfig {
|
||||||
anchor,
|
anchor,
|
||||||
wrap,
|
wrap,
|
||||||
|
no_wrap,
|
||||||
|
|
||||||
top: "_".to_string(),
|
top: "_".to_string(),
|
||||||
left: "<".to_string(),
|
left: "<".to_string(),
|
||||||
|
@ -91,6 +98,7 @@ impl BubbleConfig {
|
||||||
BubbleConfig {
|
BubbleConfig {
|
||||||
anchor,
|
anchor,
|
||||||
wrap,
|
wrap,
|
||||||
|
no_wrap,
|
||||||
|
|
||||||
top,
|
top,
|
||||||
left,
|
left,
|
||||||
|
@ -107,6 +115,7 @@ impl BubbleConfig {
|
||||||
BubbleConfig {
|
BubbleConfig {
|
||||||
anchor,
|
anchor,
|
||||||
wrap,
|
wrap,
|
||||||
|
no_wrap,
|
||||||
|
|
||||||
top: "_".to_string(),
|
top: "_".to_string(),
|
||||||
left: "<".to_string(),
|
left: "<".to_string(),
|
||||||
|
@ -124,8 +133,12 @@ impl BubbleConfig {
|
||||||
|
|
||||||
// front end to bubble_from_lines which takes normal text.
|
// front end to bubble_from_lines which takes normal text.
|
||||||
pub fn bubble_from_text(&self, text: &str) -> String {
|
pub fn bubble_from_text(&self, text: &str) -> String {
|
||||||
|
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))
|
self.bubble_from_lines(&wrap_block(text, self.wrap))
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// generates a bubble (doesn't end in newline) using a vector of strings as lines.
|
// generates a bubble (doesn't end in newline) using a vector of strings as lines.
|
||||||
fn bubble_from_lines(&self, lines: &Vec<String>) -> String {
|
fn bubble_from_lines(&self, lines: &Vec<String>) -> String {
|
||||||
|
@ -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<String>) {
|
fn wrap_once(text: &str, max_length: usize) -> (String, Option<String>) {
|
||||||
let whitespace_not_newline = |c: char| c.is_whitespace() && c != '\n';
|
let whitespace_not_newline = |c: char| c.is_whitespace() && c != '\n';
|
||||||
let mut length: usize = 0;
|
let mut length: usize = 0;
|
||||||
|
|
|
@ -54,6 +54,9 @@ struct Args {
|
||||||
#[clap(short = 'W', long)]
|
#[clap(short = 'W', long)]
|
||||||
pakala: Option<String>,
|
pakala: Option<String>,
|
||||||
|
|
||||||
|
#[clap(short = 'n', long)]
|
||||||
|
pakala_ala: bool,
|
||||||
|
|
||||||
#[clap(short = 'k', long)]
|
#[clap(short = 'k', long)]
|
||||||
kule: Vec<String>,
|
kule: Vec<String>,
|
||||||
|
|
||||||
|
@ -189,6 +192,7 @@ impl Args {
|
||||||
let bubble_config = BubbleConfig::config_from_string(
|
let bubble_config = BubbleConfig::config_from_string(
|
||||||
critter_config.template.anchor,
|
critter_config.template.anchor,
|
||||||
DEFAULT_MAXIMUM_LINE_LENGTH,
|
DEFAULT_MAXIMUM_LINE_LENGTH,
|
||||||
|
self.pakala_ala,
|
||||||
None,
|
None,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue