remove Window, fix examples, add logging
This commit is contained in:
parent
40de106f46
commit
27f891cd92
17 changed files with 707 additions and 61 deletions
|
@ -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();
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue