From 42a1654e0ea47c1f678773d6f4eccf204e83dd87 Mon Sep 17 00:00:00 2001 From: Annika Hannig Date: Sat, 27 Aug 2022 12:15:43 +0000 Subject: [PATCH] updated example --- send_text/Cargo.lock | 8 -------- send_text/rustfmt.toml | 1 + send_text/src/main.rs | 27 +++++++++------------------ 3 files changed, 10 insertions(+), 26 deletions(-) create mode 100644 send_text/rustfmt.toml diff --git a/send_text/Cargo.lock b/send_text/Cargo.lock index 533c889..c385d4a 100644 --- a/send_text/Cargo.lock +++ b/send_text/Cargo.lock @@ -6,8 +6,6 @@ version = 3 name = "airportdisplay" version = "0.1.0" dependencies = [ - "anyhow", - "bytes", "codepage-437", ] @@ -29,12 +27,6 @@ dependencies = [ "serde", ] -[[package]] -name = "bytes" -version = "1.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ec8a7b6a70fde80372154c65702f00a0f56f3e1c36abbc6c440484be248856db" - [[package]] name = "codepage-437" version = "0.1.0" diff --git a/send_text/rustfmt.toml b/send_text/rustfmt.toml new file mode 100644 index 0000000..df99c69 --- /dev/null +++ b/send_text/rustfmt.toml @@ -0,0 +1 @@ +max_width = 80 diff --git a/send_text/src/main.rs b/send_text/src/main.rs index 0149c52..3146ea2 100644 --- a/send_text/src/main.rs +++ b/send_text/src/main.rs @@ -1,32 +1,23 @@ - use anyhow::Result; -use airportdisplay::{ - Display, - Command, - Text, - TextBuffer, -}; +use airportdisplay::{text::Buffer, Command, Display}; use std::io; +/// Send text read from stdio to the display fn main() -> Result<()> { - - // Read buffer - let mut buffer = String::new(); + // Read stdin into buffer + let mut text = String::new(); for line in io::stdin().lines() { - if let Ok(line) = line { - buffer.push_str(line.as_str()); - buffer.push('\n'); - } + text.push_str(line?.as_str()); + text.push('\n'); } + // Send content to display let display = Display::open("172.23.42.29:2342".into())?; - let cmd = Command::Text(Text::Buffer(TextBuffer::from(buffer))); - + display.send(Command::Clear)?; - display.send(cmd)?; + display.send(Buffer::from(text).into())?; Ok(()) } -