Allow moving stdout to stdin with ctrl+p
This commit is contained in:
parent
f5e9fe8584
commit
cb6f3def3c
20
src/main.rs
20
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<EventMessage>, Sender<CommandRequest>) {
|
||||
|
||||
#[allow(clippy::too_many_lines)]
|
||||
#[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
|
||||
{
|
||||
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();
|
||||
|
||||
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 {
|
||||
KeyCode::Esc => {
|
||||
return Ok(None);
|
||||
|
@ -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);
|
||||
} else {
|
||||
f.render_widget(
|
||||
Block::default().title("Output")
|
||||
.borders(Borders::ALL),
|
||||
chunks[1]
|
||||
Block::default().title("Output").borders(Borders::ALL),
|
||||
chunks[1],
|
||||
)
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user