From cb6f3def3c5f92bc3f02bc2b838456bfb4f3e311 Mon Sep 17 00:00:00 2001 From: Austen Adler Date: Tue, 27 Dec 2022 23:22:56 -0500 Subject: [PATCH] Allow moving stdout to stdin with ctrl+p --- src/main.rs | 20 +++++++++++++++++++- src/ui.rs | 5 ++--- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/src/main.rs b/src/main.rs index 268cc56..c1973df 100644 --- a/src/main.rs +++ b/src/main.rs @@ -18,6 +18,8 @@ use crossbeam::channel::Receiver; use crossbeam::channel::Sender; use crossterm::event::DisableBracketedPaste; use crossterm::event::EnableBracketedPaste; +use crossterm::event::KeyEvent; +use crossterm::event::KeyModifiers; use event::EventMessage; use parking_lot::RwLock; use ropey::Rope; @@ -315,7 +317,7 @@ fn init_message_passing() -> (Receiver, Sender) { #[allow(clippy::too_many_lines)] #[cfg_attr(debug_assertions, instrument(skip(terminal, app)))] -fn run_app(terminal: &mut Terminal, app: App) -> Result> { +fn run_app(terminal: &mut Terminal, mut app: App) -> Result> { // When starting the app, ensure the command runs at least once { let mut command_options = app.command_options.write(); @@ -343,6 +345,22 @@ fn run_app(terminal: &mut Terminal, app: App) -> Result { + // Move stdout to stdin + if let Some(result) = &command_options.command_result { + app.text_orig = Arc::new(Some(result.stdout.to_string())); + app.text_orig_rope = Some(result.stdout.clone()); + command_options.cmdline = String::new(); + command_options.cmdline_position = 0; + if command_options.autorun { + app.run_command()?; + } + } + } Event::Key(key) => match key.code { KeyCode::Esc => { return Ok(None); diff --git a/src/ui.rs b/src/ui.rs index 43b2bfb..9d8ccaa 100644 --- a/src/ui.rs +++ b/src/ui.rs @@ -88,9 +88,8 @@ pub fn draw(f: &mut Frame, app: &App) { ui_output(f, chunks[1], &mut render_states, command_result); } else { f.render_widget( - Block::default().title("Output") - .borders(Borders::ALL), - chunks[1] + Block::default().title("Output").borders(Borders::ALL), + chunks[1], ) }