about summary refs log tree commit diff stats
path: root/pkgs/by-name/ts/tskm/src/rofi/mod.rs
diff options
context:
space:
mode:
authorBenedikt Peetz <benedikt.peetz@b-peetz.de>2025-04-04 11:48:44 +0200
committerBenedikt Peetz <benedikt.peetz@b-peetz.de>2025-04-04 11:48:44 +0200
commit135d09bfb305d54cac1ba1fb9861d5b9309a7b3a (patch)
tree459109a40320530993ae560f55a730a72df31416 /pkgs/by-name/ts/tskm/src/rofi/mod.rs
parentrefactor(modules/legacy/firefox): Move to by-name (diff)
downloadnixos-config-135d09bfb305d54cac1ba1fb9861d5b9309a7b3a.zip
feat(pkgs/neorg): Rewrite in rust
This improves upon neorg by integrating it better into the system
context.
Diffstat (limited to '')
-rw-r--r--pkgs/by-name/ts/tskm/src/rofi/mod.rs37
1 files changed, 37 insertions, 0 deletions
diff --git a/pkgs/by-name/ts/tskm/src/rofi/mod.rs b/pkgs/by-name/ts/tskm/src/rofi/mod.rs
new file mode 100644
index 00000000..a0591b7f
--- /dev/null
+++ b/pkgs/by-name/ts/tskm/src/rofi/mod.rs
@@ -0,0 +1,37 @@
+use std::{
+    io::Write,
+    process::{Command, Stdio},
+};
+
+use anyhow::{Context, Result};
+
+pub fn select(options: &[String]) -> Result<String> {
+    let mut child = Command::new("rofi")
+        .args(["-sep", "\n", "-dmenu"])
+        .stdin(Stdio::piped())
+        .stdout(Stdio::piped())
+        .spawn()
+        .context("Failed to spawn rofi")?;
+
+    let mut stdin = child
+        .stdin
+        .take()
+        .expect("We piped this, so should be available");
+
+    stdin
+        .write_all(options.join("\n").as_bytes())
+        .context("Failed to write to rofi's stdin")?;
+
+    let output = child
+        .wait_with_output()
+        .context("Failed to wait for rofi's output")?;
+
+    let selected = String::from_utf8(output.stdout.clone()).with_context(|| {
+        format!(
+            "Failed to decode '{}' as utf8",
+            String::from_utf8_lossy(&output.stdout)
+        )
+    })?;
+
+    Ok(selected.trim_end().to_owned())
+}