1
0
зеркало из https://github.com/glebtv/tui-textarea.git synced 2026-08-28 11:36:17 +03:00
Files
tui-textarea/examples/termion.rs
srothgan 56f531a73f chore: migrate to Rust 2024 edition and bump to v0.9.2 (#12)
* 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
2026-02-20 03:38:50 +10:00

70 строки
1.9 KiB
Rust

use ratatui::Terminal;
use ratatui::backend::TermionBackend;
use ratatui::widgets::{Block, Borders};
use std::error::Error;
use std::io;
use std::sync::mpsc;
use std::thread;
use std::time::Duration;
use termion::event::Event as TermEvent;
use termion::input::{MouseTerminal, TermRead};
use termion::raw::IntoRawMode;
use termion::screen::IntoAlternateScreen;
use tui_textarea::{Input, Key, TextArea};
enum Event {
Term(TermEvent),
Tick,
}
fn main() -> Result<(), Box<dyn Error>> {
let stdout = io::stdout().into_raw_mode()?.into_alternate_screen()?;
let stdout = MouseTerminal::from(stdout);
let backend = TermionBackend::new(stdout);
let mut term = Terminal::new(backend)?;
let events = {
let events = io::stdin().events();
let (tx, rx) = mpsc::channel();
let keys_tx = tx.clone();
thread::spawn(move || {
for event in events.flatten() {
keys_tx.send(Event::Term(event)).unwrap();
}
});
thread::spawn(move || {
loop {
tx.send(Event::Tick).unwrap();
thread::sleep(Duration::from_millis(100));
}
});
rx
};
let mut textarea = TextArea::default();
textarea.set_block(
Block::default()
.borders(Borders::ALL)
.title("Termion Minimal Example"),
);
loop {
match events.recv()? {
Event::Term(event) => match event.into() {
Input { key: Key::Esc, .. } => break,
input => {
textarea.input(input);
}
},
Event::Tick => {}
}
term.draw(|f| {
f.render_widget(&textarea, f.area());
})?;
}
drop(term); // Leave terminal raw mode to print the following line
println!("Lines: {:?}", textarea.lines());
Ok(())
}