remove Window, fix examples, add logging

This commit is contained in:
Vinzenz Schroeter 2024-05-11 14:41:09 +02:00
parent 40de106f46
commit 27f891cd92
17 changed files with 707 additions and 61 deletions

View file

@ -123,6 +123,12 @@ version = "1.70.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f8478577c03552c21db0e2724ffb8986a5ce7af88107e6be5d2ee6e158c12800"
[[package]]
name = "log"
version = "0.4.21"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "90ed8c1e510134f979dbc4f070f87d4313098b704861a105fe34231c70a3901c"
[[package]]
name = "num"
version = "0.4.3"
@ -229,6 +235,7 @@ dependencies = [
name = "servicepoint2"
version = "0.1.0"
dependencies = [
"log",
"num",
"num-derive",
"num-traits",

View file

@ -6,3 +6,5 @@ edition = "2021"
[dependencies]
clap = { version = "4.5.4", features = ["derive"] }
servicepoint2 = { path = "../.." }
log = "0.4.21"
env_logger = "0.11.3"

View file

@ -1,5 +1,5 @@
use clap::Parser;
use servicepoint2::{Command, Connection, Origin, Size, Window};
use servicepoint2::{ByteGrid, Command, Connection, Origin};
#[derive(Parser, Debug)]
struct Cli {
@ -7,16 +7,23 @@ struct Cli {
destination: String,
#[arg(short, long, num_args = 1.., value_delimiter = '\n')]
text: Vec<String>,
#[arg(short, long, default_value_t = true)]
clear: bool,
}
/// example: `cargo run -- --text "Hallo,
/// CCCB"`
fn main() {
env_logger::builder()
.filter_level(log::LevelFilter::Debug)
.init();
let cli = Cli::parse();
println!("starting with args: {:?}", &cli);
let connection = Connection::open(&cli.destination).unwrap();
if cli.clear {
connection.send(Command::Clear).unwrap();
}
let mut max_width = 0;
for l in cli.text.iter() {
@ -25,7 +32,7 @@ fn main() {
}
}
let mut data = vec!(0; max_width * cli.text.len());
let mut chars = ByteGrid::new(max_width, max_width * cli.text.len());
for y in 0..cli.text.len() {
let row = &cli.text[y];
for x in 0..max_width {
@ -33,13 +40,9 @@ fn main() {
continue;
}
data[x + y * max_width] = row.chars().nth(x).unwrap().try_into().unwrap();
chars.set(x, y, row.chars().nth(x).unwrap().try_into().unwrap());
}
}
let window = Window(Origin(0, 0), Size(max_width as u16, cli.text.len() as u16));
let command = Command::Cp437Data(window, data);
connection.send(Command::Clear).unwrap();
connection.send(command).unwrap()
connection.send(Command::Cp437Data(Origin::top_left(), chars)).unwrap();
}