git.lucas.co / cce-color-editor
color picker and palette editor
git clone https://git.lucas.co/cce-color-editor.git

commitc8f1e7e8a46570f7155e832e5ac9259d6340c37e
parentd7b5dbdc5a
authorLucas Galante <[email protected]>
date2026-07-24 14:45
feat: --stream mode — print every color change live

With --stream each change prints (flushed) as the user picks, so the
launching widget can apply it while the picker stays open; Cancel
prints 'cancel' so the caller restores its launch value. Batch
consumers reading stdout after exit still see the final line last.

Co-Authored-By: Claude Fable 5 <[email protected]>

 src/main.rs | 28 +++++++++++++++++++++++++++-
 1 file changed, 27 insertions(+), 1 deletion(-)

diff --git a/src/main.rs b/src/main.rs
index 29642e0..9721a90 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -344,6 +344,11 @@ struct ColorApp {
     alpha: f32,
     with_alpha: bool,
     expecting_output: bool,
+    // --stream: print every color change (flushed) so the launching widget
+    // applies it live while this picker stays open; Cancel prints `cancel`
+    // so the caller can restore the launch value.
+    stream: bool,
+    last_streamed: String,
 
     cursor_x: f32,
     cursor_y: f32,
@@ -602,10 +607,13 @@ impl Application for ColorApp {
     fn new(_qh: &QueueHandle<EngineState<Self>>, _sender: calloop::channel::Sender<Self::Message>) -> Self {
         let args: Vec<String> = std::env::args().collect();
         let mut with_alpha = false;
+        let mut stream = false;
         let mut hex_arg = None;
         for arg in args.iter().skip(1) {
             if arg == "--alpha" || arg == "-a" {
                 with_alpha = true;
+            } else if arg == "--stream" {
+                stream = true;
             } else {
                 hex_arg = Some(arg.as_str());
             }
@@ -673,6 +681,8 @@ impl Application for ColorApp {
             alpha: a,
             with_alpha,
             expecting_output,
+            stream,
+            last_streamed: String::new(),
             cursor_x: 0.0,
             cursor_y: 0.0,
             width: initial_w,
@@ -713,12 +723,28 @@ impl Application for ColorApp {
                 *exit = true;
             }
             Message::Cancel => {
+                if self.stream {
+                    use std::io::Write;
+                    println!("cancel");
+                    let _ = std::io::stdout().flush();
+                }
                 *exit = true;
             }
         }
     }
 
-    fn tick(&mut self, _dt: f32, _needs_rebuild: &mut bool) {}
+    fn tick(&mut self, _dt: f32, _needs_rebuild: &mut bool) {
+        // Stream the live color to the launching widget on every change.
+        if self.stream {
+            let hex = self.hex();
+            if hex != self.last_streamed {
+                use std::io::Write;
+                println!("{}", hex);
+                let _ = std::io::stdout().flush();
+                self.last_streamed = hex;
+            }
+        }
+    }
 
     fn handle_mouse_wheel(&mut self, delta: &MouseScrollDelta, pos: LogicalPosition, needs_rebuild: &mut bool) {
         let px = pos.x;