diff --git a/Cargo.toml b/Cargo.toml index 991799c..b0d2dbd 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,7 +7,7 @@ edition = "2021" [dependencies] tui = "0.19" -crossterm = "0.25" +crossterm = { version = "0.25", features = ["bracketed-paste"] } atty = "0.2.14" ansi4tui = {path = "./ansi4tui/"} anyhow = "1.0.66" diff --git a/src/main.rs b/src/main.rs index 5bfe67d..cfdec73 100644 --- a/src/main.rs +++ b/src/main.rs @@ -7,6 +7,8 @@ use ansi4tui::bytes_to_text; use anyhow::bail; use anyhow::Result; use command::CommandResult; +use crossterm::event::DisableBracketedPaste; +use crossterm::event::EnableBracketedPaste; use std::{ io::{self, Write}, process::{Command, Stdio}, @@ -170,7 +172,12 @@ fn main() -> Result<()> { enable_raw_mode()?; let mut stdout = io::stdout(); // execute!(stdout, EnterAlternateScreen, EnableMouseCapture)?; - execute!(stdout, EnterAlternateScreen)?; + execute!( + stdout, + EnterAlternateScreen, + // EnableMouseCapture, + EnableBracketedPaste, + )?; let backend = CrosstermBackend::new(stdout); let mut terminal = Terminal::new(backend)?; @@ -186,7 +193,8 @@ fn main() -> Result<()> { execute!( terminal.backend_mut(), LeaveAlternateScreen, - DisableMouseCapture + // DisableMouseCapture, + DisableBracketedPaste, )?; terminal.show_cursor()?; @@ -216,8 +224,8 @@ fn run_app( loop { terminal.draw(|f| ui(f, &app))?; - if let Event::Key(key) = event::read()? { - match key.code { + match event::read()? { + Event::Key(key) => match key.code { KeyCode::Esc => { // TODO: If there is any command line text, ask if the user is sure they want to quit return Ok(None); @@ -270,7 +278,17 @@ fn run_app( ); } _ => {} + }, + Event::Paste(data) => { + app.cmdline.insert_str(app.cmdline_position as usize, &data); + app.cmdline_position = app.cmdline_position.saturating_add(data.len() as u16); + + if app.autorun { + command::run(&mut app); + } } + + Event::FocusGained | Event::FocusLost | Event::Mouse(_) | Event::Resize(_, _) => {} } } } @@ -295,8 +313,13 @@ fn ui(f: &mut Frame, app: &App) { Paragraph::new(app.cmdline.as_ref()).block( Block::default() .title(format!( - "Cmdline ({} {})", + "Cmdline ({}{}{})", app.command, + if app.hidden_options.is_empty() { + "" + } else { + " " + }, app.hidden_options.join(" ") )) .borders(Borders::ALL),