Allow moving stdout to stdin with ctrl+p
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/tag Build is passing

This commit is contained in:
Austen Adler 2022-12-27 23:22:56 -05:00
parent f5e9fe8584
commit cb6f3def3c
2 changed files with 21 additions and 4 deletions

View File

@ -18,6 +18,8 @@ use crossbeam::channel::Receiver;
use crossbeam::channel::Sender; use crossbeam::channel::Sender;
use crossterm::event::DisableBracketedPaste; use crossterm::event::DisableBracketedPaste;
use crossterm::event::EnableBracketedPaste; use crossterm::event::EnableBracketedPaste;
use crossterm::event::KeyEvent;
use crossterm::event::KeyModifiers;
use event::EventMessage; use event::EventMessage;
use parking_lot::RwLock; use parking_lot::RwLock;
use ropey::Rope; use ropey::Rope;
@ -315,7 +317,7 @@ fn init_message_passing() -> (Receiver<EventMessage>, Sender<CommandRequest>) {
#[allow(clippy::too_many_lines)] #[allow(clippy::too_many_lines)]
#[cfg_attr(debug_assertions, instrument(skip(terminal, app)))] #[cfg_attr(debug_assertions, instrument(skip(terminal, app)))]
fn run_app<B: Backend>(terminal: &mut Terminal<B>, app: App) -> Result<Option<String>> { fn run_app<B: Backend>(terminal: &mut Terminal<B>, mut app: App) -> Result<Option<String>> {
// When starting the app, ensure the command runs at least once // When starting the app, ensure the command runs at least once
{ {
let mut command_options = app.command_options.write(); let mut command_options = app.command_options.write();
@ -343,6 +345,22 @@ fn run_app<B: Backend>(terminal: &mut Terminal<B>, app: App) -> Result<Option<St
let mut command_options = app.command_options.write(); let mut command_options = app.command_options.write();
match crossterm_event { match crossterm_event {
Event::Key(KeyEvent {
code: KeyCode::Char('p'),
modifiers: KeyModifiers::CONTROL,
..
}) => {
// 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 { Event::Key(key) => match key.code {
KeyCode::Esc => { KeyCode::Esc => {
return Ok(None); return Ok(None);

View File

@ -88,9 +88,8 @@ pub fn draw<B: Backend>(f: &mut Frame<B>, app: &App) {
ui_output(f, chunks[1], &mut render_states, command_result); ui_output(f, chunks[1], &mut render_states, command_result);
} else { } else {
f.render_widget( f.render_widget(
Block::default().title("Output") Block::default().title("Output").borders(Borders::ALL),
.borders(Borders::ALL), chunks[1],
chunks[1]
) )
} }