diff --git a/Cargo.lock b/Cargo.lock index 19e255f..8ca5e46 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -315,6 +315,7 @@ dependencies = [ "anyhow", "clap", "color-eyre", + "html-escape", "reqwest", "serde", "serde_json", @@ -346,6 +347,15 @@ dependencies = [ "libc", ] +[[package]] +name = "html-escape" +version = "0.2.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "816ea801a95538fc5f53c836697b3f8b64a9d664c4f0b91efe1fe7c92e4dbcb7" +dependencies = [ + "utf8-width", +] + [[package]] name = "http" version = "0.2.5" @@ -1203,6 +1213,12 @@ dependencies = [ "percent-encoding", ] +[[package]] +name = "utf8-width" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7cf7d77f457ef8dfa11e4cd5933c5ddb5dc52a94664071951219a97710f0a32b" + [[package]] name = "vcpkg" version = "0.2.15" diff --git a/Cargo.toml b/Cargo.toml index 9ef9d59..f36762e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,6 +9,7 @@ edition = "2021" anyhow = "1.0.52" clap = "3.0.0-beta.2" color-eyre = "0.6.0" +html-escape = "0.2.9" reqwest = { version = "0.11.4", features = ["blocking", "json"] } serde = { version = "1.0.126", features = ["derive"] } serde_json = "1.0.64" diff --git a/flake.nix b/flake.nix index 572c326..da26a0f 100644 --- a/flake.nix +++ b/flake.nix @@ -55,7 +55,7 @@ devShell = with pkgs; mkShell { inherit buildInputs; - nativeBuildInputs = [ cargo-edit cargo-expand cargo-diet cargo-feature cargo-outdated pre-commit jq ] ++ nativeBuildInputs; + nativeBuildInputs = [ cargo-edit cargo-expand cargo-diet cargo-feature cargo-outdated rust-analyzer pre-commit jq ] ++ nativeBuildInputs; }; }); diff --git a/src/main.rs b/src/main.rs index 6281ae3..8ad6095 100644 --- a/src/main.rs +++ b/src/main.rs @@ -158,14 +158,12 @@ fn get_now_playing(host: String, entity: String, insecure: bool, token: String) format!("{volume}{artist} - {title}") }; - println!("{}", now_playing); + println!("{}", html_escape::encode_text(&now_playing)); } else { - println!( - "Sonos {}", - response["state"] - .as_str() - .map_or("state unknown", |state| state) - ); + let state = response["state"] + .as_str() + .map_or("State unknown", |state| state); + println!("Sonos {}", html_escape::encode_text(state)); } Ok(())