servicepoint-binding-uniffi/examples/announce/src/main.rs

49 lines
1.2 KiB
Rust
Raw Normal View History

2024-05-10 18:34:21 +02:00
use clap::Parser;
use servicepoint2::{ByteGrid, Command, Connection, Origin};
2024-05-10 18:34:21 +02:00
#[derive(Parser, Debug)]
struct Cli {
#[arg(short, long, default_value = "localhost:2342")]
destination: String,
#[arg(short, long, num_args = 1.., value_delimiter = '\n')]
text: Vec<String>,
#[arg(short, long, default_value_t = true)]
clear: bool,
2024-05-10 18:34:21 +02:00
}
2024-05-10 19:55:18 +02:00
/// example: `cargo run -- --text "Hallo,
/// CCCB"`
2024-05-10 18:34:21 +02:00
fn main() {
2024-05-12 13:51:41 +02:00
env_logger::init();
2024-05-10 18:34:21 +02:00
let cli = Cli::parse();
let connection = Connection::open(&cli.destination).unwrap();
if cli.clear {
connection.send(Command::Clear).unwrap();
}
2024-05-10 18:34:21 +02:00
let mut max_width = 0;
for l in cli.text.iter() {
if l.len() > max_width {
max_width = l.len()
}
}
let mut chars = ByteGrid::new(max_width, max_width * cli.text.len());
2024-05-10 18:34:21 +02:00
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());
2024-05-10 18:34:21 +02:00
}
}
2024-05-11 23:28:08 +02:00
connection
.send(Command::Cp437Data(Origin::top_left(), chars))
.unwrap();
2024-05-10 18:34:21 +02:00
}