From b446f9815ba5e702504589a51f702dd50cb2a84e Mon Sep 17 00:00:00 2001 From: Connor Slade Date: Thu, 28 Dec 2023 01:31:28 -0500 Subject: [PATCH] Basic word wrapping --- printer/src/text.rs | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/printer/src/text.rs b/printer/src/text.rs index 632cc12..64ce03c 100644 --- a/printer/src/text.rs +++ b/printer/src/text.rs @@ -6,10 +6,24 @@ use crate::args::TextArgs; pub fn encode(args: TextArgs) -> Result<()> { let text = fs::read_to_string(args.input)?; - let lines = text - .lines() - .map(|l| truncate(l, 22).trim_end()) - .collect::>(); + let lines = if args.no_wrap { + text.lines() + .map(|l| truncate(l, 22).trim_end()) + .collect::>() + } else { + text.lines() + .map(|l| l.trim_end()) + .flat_map(|l| { + let mut lines = Vec::new(); + let mut i = 0; + while i < l.len() { + lines.push(truncate(&l[i..], 22)); + i += 22; + } + lines + }) + .collect::>() + }; if args.preview { for line in &lines { @@ -22,7 +36,6 @@ pub fn encode(args: TextArgs) -> Result<()> { } let mut prg = String::new(); - for line in lines { prg.push_str(&encode_string(line)); prg.push_str("AVIEW\n");