diff --git a/Cargo.lock b/Cargo.lock index 0245850..182cf4d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -154,6 +154,7 @@ version = "0.1.0" dependencies = [ "chrono", "clap 4.3.3", + "const_format", "criterion", "env_logger 0.10.0", "lazy_static", @@ -331,6 +332,26 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "acbf1af155f9b9ef647e42cdc158db4b64a1b61f743629225fde6f3e0be2a7c7" +[[package]] +name = "const_format" +version = "0.2.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c990efc7a285731f9a4378d81aff2f0e85a2c8781a05ef0f8baa8dac54d0ff48" +dependencies = [ + "const_format_proc_macros", +] + +[[package]] +name = "const_format_proc_macros" +version = "0.2.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e026b6ce194a874cb9cf32cd5772d1ef9767cc8fcb5765948d74f37a9d8b2bf6" +dependencies = [ + "proc-macro2", + "quote", + "unicode-xid", +] + [[package]] name = "core-foundation-sys" version = "0.8.4" @@ -755,9 +776,9 @@ dependencies = [ [[package]] name = "log" -version = "0.4.18" +version = "0.4.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "518ef76f2f87365916b142844c16d8fefd85039bc5699050210a7778ee1cd1de" +checksum = "b06a4cde4c0f271a446782e3eff8de789548ce57dbc8eca9292c27f4a42004b4" [[package]] name = "memchr" @@ -1059,9 +1080,9 @@ dependencies = [ [[package]] name = "rustix" -version = "0.37.19" +version = "0.37.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "acf8729d8542766f1b2cf77eb034d52f40d375bb8b615d0b147089946e16613d" +checksum = "b96e891d04aa506a6d1f318d2771bcb1c7dfda84e126660ace067c9b474bb2c0" dependencies = [ "bitflags", "errno", @@ -1418,6 +1439,12 @@ version = "0.1.10" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c0edd1e5b14653f783770bce4a4dabb4a5108a5370a5f5d8cfe8710c361f6c8b" +[[package]] +name = "unicode-xid" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f962df74c8c05a667b5ee8bcf162993134c104e96440b663c8daa176dc772d8c" + [[package]] name = "url" version = "2.4.0" diff --git a/Cargo.toml b/Cargo.toml index cd01eb9..223f951 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,6 +4,8 @@ version = "0.1.0" edition = "2021" [dependencies] +chrono = "0.4" +const_format = "0.2" clap = { version = "4.3", features = ["derive"] } rusttype = "0.9" number_prefix = "0.4" @@ -17,7 +19,6 @@ simple_moving_average = "0.1" thread-priority = "0.13" tokio = { version = "1.28", features = ["fs", "rt-multi-thread", "net", "io-util", "macros", "process", "signal", "sync", "time"] } vncserver = { version ="0.2", optional = true} -chrono = "0.4.26" [dev-dependencies] criterion = {version = "0.5", features = ["async_tokio"]} diff --git a/src/parser.rs b/src/parser.rs index ec36a45..7b4c375 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -1,21 +1,26 @@ +use crate::framebuffer::FrameBuffer; +use const_format::formatcp; use std::sync::Arc; - use tokio::io::AsyncWriteExt; -use crate::framebuffer::FrameBuffer; - pub const PARSER_LOOKAHEAD: usize = "PX 1234 1234 rrggbbaa\n".len(); // Longest possible command -pub const HELP_TEXT: &[u8] = "\ +pub const HELP_TEXT: &[u8] = formatcp!("\ Pixelflut server powered by breakwater https://github.com/sbernauer/breakwater Available commands: HELP: Show this help PX x y rrggbb: Color the pixel (x,y) with the given hexadecimal color rrggbb -PX x y rrggbbaa: Color the pixel (x,y) with the given hexadecimal color rrggbb (alpha channel is ignored by default, unless breakwater is compiled with \"--feature alpha\". This is for performance reasons) +{} PX x y gg: Color the pixel (x,y) with the hexadecimal color gggggg. Basically this is the same as the other commands, but is a more efficient way of filling white, black or gray areas PX x y: Get the color value of the pixel (x,y) SIZE: Get the size of the drawing surface, e.g. `SIZE 1920 1080` OFFSET x y: Apply offset (x,y) to all further pixel draws on this connection. This can e.g. be used to pre-calculate an image/animation and simply use the OFFSET command to move it around the screen without the need to re-calculate it -".as_bytes(); +", +if cfg!(feature = "alpha") { + "PX x y rrggbbaa: Color the pixel (x,y) with the given hexadecimal color rrggbb and a transparency of aa, where ff means draw normally on top of the existing pixel and 00 means fully transparent (no change at all)" +} else { + "PX x y rrggbbaa: Color the pixel (x,y) with the given hexadecimal color rrggbb. The alpha part is discarded for performance reasons, as breakwater was compiled without the alpha feature" +} +).as_bytes(); #[derive(Clone, Default, Debug)] pub struct ParserState {