Allow pasting
This commit is contained in:
parent
a3027a3d6d
commit
9b88539c50
@ -7,7 +7,7 @@ edition = "2021"
|
|||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
tui = "0.19"
|
tui = "0.19"
|
||||||
crossterm = "0.25"
|
crossterm = { version = "0.25", features = ["bracketed-paste"] }
|
||||||
atty = "0.2.14"
|
atty = "0.2.14"
|
||||||
ansi4tui = {path = "./ansi4tui/"}
|
ansi4tui = {path = "./ansi4tui/"}
|
||||||
anyhow = "1.0.66"
|
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::bail;
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use command::CommandResult;
|
use command::CommandResult;
|
||||||
|
use crossterm::event::DisableBracketedPaste;
|
||||||
|
use crossterm::event::EnableBracketedPaste;
|
||||||
use std::{
|
use std::{
|
||||||
io::{self, Write},
|
io::{self, Write},
|
||||||
process::{Command, Stdio},
|
process::{Command, Stdio},
|
||||||
@ -170,7 +172,12 @@ fn main() -> Result<()> {
|
|||||||
enable_raw_mode()?;
|
enable_raw_mode()?;
|
||||||
let mut stdout = io::stdout();
|
let mut stdout = io::stdout();
|
||||||
// execute!(stdout, EnterAlternateScreen, EnableMouseCapture)?;
|
// execute!(stdout, EnterAlternateScreen, EnableMouseCapture)?;
|
||||||
execute!(stdout, EnterAlternateScreen)?;
|
execute!(
|
||||||
|
stdout,
|
||||||
|
EnterAlternateScreen,
|
||||||
|
// EnableMouseCapture,
|
||||||
|
EnableBracketedPaste,
|
||||||
|
)?;
|
||||||
let backend = CrosstermBackend::new(stdout);
|
let backend = CrosstermBackend::new(stdout);
|
||||||
let mut terminal = Terminal::new(backend)?;
|
let mut terminal = Terminal::new(backend)?;
|
||||||
|
|
||||||
@ -186,7 +193,8 @@ fn main() -> Result<()> {
|
|||||||
execute!(
|
execute!(
|
||||||
terminal.backend_mut(),
|
terminal.backend_mut(),
|
||||||
LeaveAlternateScreen,
|
LeaveAlternateScreen,
|
||||||
DisableMouseCapture
|
// DisableMouseCapture,
|
||||||
|
DisableBracketedPaste,
|
||||||
)?;
|
)?;
|
||||||
terminal.show_cursor()?;
|
terminal.show_cursor()?;
|
||||||
|
|
||||||
@ -216,8 +224,8 @@ fn run_app<B: Backend>(
|
|||||||
loop {
|
loop {
|
||||||
terminal.draw(|f| ui(f, &app))?;
|
terminal.draw(|f| ui(f, &app))?;
|
||||||
|
|
||||||
if let Event::Key(key) = event::read()? {
|
match event::read()? {
|
||||||
match key.code {
|
Event::Key(key) => match key.code {
|
||||||
KeyCode::Esc => {
|
KeyCode::Esc => {
|
||||||
// TODO: If there is any command line text, ask if the user is sure they want to quit
|
// TODO: If there is any command line text, ask if the user is sure they want to quit
|
||||||
return Ok(None);
|
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(
|
Paragraph::new(app.cmdline.as_ref()).block(
|
||||||
Block::default()
|
Block::default()
|
||||||
.title(format!(
|
.title(format!(
|
||||||
"Cmdline ({} {})",
|
"Cmdline ({}{}{})",
|
||||||
app.command,
|
app.command,
|
||||||
|
if app.hidden_options.is_empty() {
|
||||||
|
""
|
||||||
|
} else {
|
||||||
|
" "
|
||||||
|
},
|
||||||
app.hidden_options.join(" ")
|
app.hidden_options.join(" ")
|
||||||
))
|
))
|
||||||
.borders(Borders::ALL),
|
.borders(Borders::ALL),
|
||||||
|
Loading…
Reference in New Issue
Block a user