зеркало из
https://github.com/glebtv/tui-textarea.git
synced 2026-08-28 11:36:17 +03:00
* chore: migrate to Rust 2024 edition and bump to v0.9.2 - Bump edition to 2024 and rust-version to 1.85.0 - Replace f64::log10 with usize::ilog10 in num_digits - Fix clippy lints surfaced by edition bump: repeat_n, derived Default, then_some - Expand watch-check and watch-test aliases to cover all feature paths (crossterm_0_28, no-backend, tuirs variants, serde, arbitrary) - Expand CI test and clippy workflows to full 6/8-entry feature matrices including termion on Ubuntu - Apply rustfmt import reordering from edition 2024 rules * fix: revert turis linux checks
56 строки
1.5 KiB
Rust
56 строки
1.5 KiB
Rust
use ratatui::Terminal;
|
|
use ratatui::backend::TermwizBackend;
|
|
use ratatui::widgets::{Block, Borders};
|
|
use std::error::Error;
|
|
use std::time::Duration;
|
|
use termwiz::input::InputEvent;
|
|
use termwiz::terminal::Terminal as _;
|
|
use tui_textarea::{Input, Key, TextArea};
|
|
|
|
fn main() -> Result<(), Box<dyn Error>> {
|
|
let backend = TermwizBackend::new()?;
|
|
let mut term = Terminal::new(backend)?;
|
|
term.hide_cursor()?;
|
|
|
|
let mut textarea = TextArea::default();
|
|
textarea.set_block(
|
|
Block::default()
|
|
.borders(Borders::ALL)
|
|
.title("Termwiz Minimal Example"),
|
|
);
|
|
|
|
// The event loop
|
|
loop {
|
|
term.draw(|f| {
|
|
f.render_widget(&textarea, f.area());
|
|
})?;
|
|
|
|
if let Some(input) = term
|
|
.backend_mut()
|
|
.buffered_terminal_mut()
|
|
.terminal()
|
|
.poll_input(Some(Duration::from_millis(100)))?
|
|
{
|
|
if let InputEvent::Resized { cols, rows } = input {
|
|
term.backend_mut()
|
|
.buffered_terminal_mut()
|
|
.resize(cols, rows);
|
|
} else {
|
|
match input.into() {
|
|
Input { key: Key::Esc, .. } => break,
|
|
input => {
|
|
textarea.input(input);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
term.show_cursor()?;
|
|
term.flush()?;
|
|
drop(term); // Leave terminal raw mode to print the following line
|
|
|
|
println!("Lines: {:?}", textarea.lines());
|
|
Ok(())
|
|
}
|