From 7b4c6bff1baf9bdebbc239f81236a14fd012cdfe Mon Sep 17 00:00:00 2001 From: Rushmore75 Date: Tue, 3 Feb 2026 12:29:01 -0700 Subject: [PATCH] add wrapper script --- src/main.rs | 13 ++++++++++--- wrapper.sh | 15 +++++++++++++++ 2 files changed, 25 insertions(+), 3 deletions(-) create mode 100755 wrapper.sh diff --git a/src/main.rs b/src/main.rs index 21c2d48..f7b4bb3 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,11 +1,10 @@ -use std::{env::args, io::{self, BufRead, Read, stdin}}; +use std::{env::args, fs::OpenOptions, io::{self, Read, Write}}; use ratatui::{ DefaultTerminal, Frame, crossterm::event::{self, Event}, layout::{self, Constraint, Layout}, style::{Style, palette::material::{BLACK, WHITE}}, widgets::{Block, BorderType, Paragraph} }; fn main() -> Result<(), std::io::Error> { - // let mut buffer = Vec::new(); let mut buffer = String::new(); let stdin = io::stdin(); let mut handle = stdin.lock(); @@ -19,7 +18,15 @@ fn main() -> Result<(), std::io::Error> { ratatui::restore(); let v = &app.options[app.index]; - println!("{}", v); + + let args = args(); + // gets the last arg + let path = args.skip(1).fold(String::new(), |_last, next| next); + if let Ok(mut file) = OpenOptions::new().write(true).create(false).open(&path) { + file.write_all(v.as_bytes()).expect("Could not write all bytes"); + } else { + println!("{v}"); + } return res; } diff --git a/wrapper.sh b/wrapper.sh new file mode 100755 index 0000000..bbd1bc9 --- /dev/null +++ b/wrapper.sh @@ -0,0 +1,15 @@ +#!/bin/bash + +# Make a buffered FIFO queue +mkfifo /tmp/fifo 2> /dev/null +exec 4<> /tmp/fifo + +# Put the output to fd 4 and put the TUI to 2, since pipes redirect 1 by default +cat /dev/stdin | ./target/release/select_option /proc/self/fd/4 1>&2 + +read -r VAL < /proc/self/fd/4 + +echo $VAL + +rm /tmp/fifo +