improve announce example

This commit is contained in:
Vinzenz Schroeter 2024-10-13 13:40:26 +02:00
parent dbbe631741
commit f7fddda8f1

View file

@ -6,16 +6,26 @@ use servicepoint::{CharGrid, Command, Connection, Cp437Grid, Origin};
#[derive(Parser, Debug)] #[derive(Parser, Debug)]
struct Cli { struct Cli {
#[arg(short, long, default_value = "localhost:2342")] #[arg(
short,
long,
default_value = "localhost:2342",
help = "Address of the display"
)]
destination: String, destination: String,
#[arg(short, long, num_args = 1.., value_delimiter = '\n')] #[arg(short, long, num_args = 1.., value_delimiter = '\n',
help = "Text to send - specify multiple times for multiple lines")]
text: Vec<String>, text: Vec<String>,
#[arg(short, long, default_value_t = true)] #[arg(
short,
long,
default_value_t = true,
help = "Clear screen before sending text"
)]
clear: bool, clear: bool,
} }
/// example: `cargo run -- --text "Hallo, /// example: `cargo run -- --text "Hallo" --text "CCCB"`
/// CCCB"`
fn main() { fn main() {
let mut cli = Cli::parse(); let mut cli = Cli::parse();
if cli.text.is_empty() { if cli.text.is_empty() {
@ -31,11 +41,7 @@ fn main() {
.expect("sending clear failed"); .expect("sending clear failed");
} }
let text = cli.text.iter().fold(String::new(), move |str, line| { let text = cli.text.join("\n");
let is_first = str.is_empty();
str + if is_first { "" } else { "\n" } + line
});
let grid = CharGrid::from(&*text); let grid = CharGrid::from(&*text);
let cp437_grid = Cp437Grid::from(&grid); let cp437_grid = Cp437Grid::from(&grid);