From 312fff95b3a788a8e5db080f50752453f21be88b Mon Sep 17 00:00:00 2001 From: Vinzenz Schroeter Date: Fri, 17 May 2024 23:05:52 +0200 Subject: [PATCH] improve text example, fix example in README --- README.md | 2 +- examples/announce/src/main.rs | 20 ++++++++------------ 2 files changed, 9 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index a12082a..511a9f8 100644 --- a/README.md +++ b/README.md @@ -33,7 +33,7 @@ fn main() { .expect("connection failed"); // clear screen content - connection.send(servicepoint2::Command::Clear) + connection.send(servicepoint2::Command::Clear.into()) .expect("send failed"); } ``` diff --git a/examples/announce/src/main.rs b/examples/announce/src/main.rs index ff604af..2916f50 100644 --- a/examples/announce/src/main.rs +++ b/examples/announce/src/main.rs @@ -24,22 +24,18 @@ fn main() { connection.send(Command::Clear.into()).unwrap(); } - let mut max_width = 0; - for l in cli.text.iter() { - if l.len() > max_width { - max_width = l.len() - } - } + let max_width = cli.text.iter() + .map(|t| t.len()) + .max() + .unwrap(); - let mut chars = ByteGrid::new(max_width, max_width * cli.text.len()); + let mut chars = ByteGrid::new(max_width, cli.text.len()); for y in 0..cli.text.len() { let row = &cli.text[y]; - for x in 0..max_width { - if x >= row.len() { - continue; - } - chars.set(x, y, row.chars().nth(x).unwrap().try_into().unwrap()); + for (x, char) in row.chars().enumerate() { + let char = char.try_into().expect("invalid input char"); + chars.set(x, y, char); } }