Allow pasting
This commit is contained in:
parent
a3027a3d6d
commit
9b88539c50
@ -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"
|
||||
|
33
src/main.rs
33
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<B: Backend>(
|
||||
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,8 +278,18 @@ fn run_app<B: Backend>(
|
||||
);
|
||||
}
|
||||
_ => {}
|
||||
},
|
||||
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<B: Backend>(f: &mut Frame<B>, 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),
|
||||
|
Loading…
Reference in New Issue
Block a user