From 45badb7f38bc5996f7c9284a82348bee69e1c581 Mon Sep 17 00:00:00 2001 From: Pedro Burgos <43417195+druskus20@users.noreply.github.com> Date: Fri, 5 Nov 2021 12:37:37 +0100 Subject: [PATCH] Implement eww get command (#319) --- crates/eww/src/app.rs | 11 +++++++++++ crates/eww/src/main.rs | 10 ++++++++-- crates/eww/src/opts.rs | 13 ++++++++++--- 3 files changed, 29 insertions(+), 5 deletions(-) diff --git a/crates/eww/src/app.rs b/crates/eww/src/app.rs index e568593..7ac0802 100644 --- a/crates/eww/src/app.rs +++ b/crates/eww/src/app.rs @@ -53,6 +53,10 @@ pub enum DaemonCommand { all: bool, sender: DaemonResponseSender, }, + GetVar { + name: String, + sender: DaemonResponseSender, + }, PrintDebug(DaemonResponseSender), PrintWindows(DaemonResponseSender), } @@ -176,6 +180,13 @@ impl App { }; sender.send_success(output)? } + DaemonCommand::GetVar { name, sender } => { + let vars = self.eww_state.get_variables(); + match vars.get(name.as_str()) { + Some(x) => sender.send_success(x.to_string())?, + None => sender.send_failure(format!("Variable not found \"{}\"", name))?, + } + } DaemonCommand::PrintWindows(sender) => { let output = self .eww_config diff --git a/crates/eww/src/main.rs b/crates/eww/src/main.rs index 636cfa2..030e587 100644 --- a/crates/eww/src/main.rs +++ b/crates/eww/src/main.rs @@ -13,7 +13,7 @@ extern crate gtk; extern crate gtk_layer_shell as gtk_layer_shell; use anyhow::*; -use daemon_response::DaemonResponseReceiver; +use daemon_response::{DaemonResponse, DaemonResponseReceiver}; use opts::ActionWithServer; use std::{ os::unix::net, @@ -145,7 +145,13 @@ fn handle_server_command(paths: &EwwPaths, action: &ActionWithServer, connect_at log::debug!("Connected to Eww server ({}).", &paths.get_ipc_socket_file().display()); let response = client::do_server_call(&mut stream, action).context("Error while forwarding command to server")?; if let Some(response) = response { - println!("{}", response); + match response { + DaemonResponse::Success(x) => println!("{}", x), + DaemonResponse::Failure(x) => { + eprintln!("{}", x); + bail!("Error, server command failed"); + } + } } Ok(()) } diff --git a/crates/eww/src/opts.rs b/crates/eww/src/opts.rs index 1d51db0..9b6f70d 100644 --- a/crates/eww/src/opts.rs +++ b/crates/eww/src/opts.rs @@ -81,11 +81,11 @@ pub enum ActionWithServer { mappings: Vec<(VarName, DynVal)>, }, - // Open the GTK debugger + /// Open the GTK debugger #[structopt(name = "inspector", alias = "debugger")] OpenInspector, - /// open a window + /// Open a window #[structopt(name = "open", alias = "o")] OpenWindow { /// Name of the window you want to open. @@ -131,7 +131,7 @@ pub enum ActionWithServer { #[structopt(name = "reload", alias = "r")] Reload, - /// kill the eww daemon + /// Kill the eww daemon #[structopt(name = "kill", alias = "k")] KillServer, @@ -147,6 +147,10 @@ pub enum ActionWithServer { all: bool, }, + /// Get the value of a variable if defined + #[structopt(name = "get")] + GetVar { name: String }, + /// Print the names of all configured windows. Windows with a * in front of them are currently opened. #[structopt(name = "windows")] ShowWindows, @@ -219,6 +223,9 @@ impl ActionWithServer { ActionWithServer::ShowState { all } => { return with_response_channel(|sender| app::DaemonCommand::PrintState { all, sender }) } + ActionWithServer::GetVar { name } => { + return with_response_channel(|sender| app::DaemonCommand::GetVar { name, sender }) + } ActionWithServer::ShowDebug => return with_response_channel(app::DaemonCommand::PrintDebug), }; (command, None)