Skip to content

Commit

Permalink
Basic word wrapping
Browse files Browse the repository at this point in the history
  • Loading branch information
connorslade committed Dec 28, 2023
1 parent 143ed69 commit b446f98
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions printer/src/text.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<Vec<_>>();
let lines = if args.no_wrap {
text.lines()
.map(|l| truncate(l, 22).trim_end())
.collect::<Vec<_>>()
} 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::<Vec<_>>()
};

if args.preview {
for line in &lines {
Expand All @@ -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");
Expand Down

0 comments on commit b446f98

Please sign in to comment.