1
0
зеркало из https://github.com/glebtv/tui-textarea.git synced 2026-09-03 14:26:17 +03:00

use the same version of termion as tui's dependency for tuirs-termion feature

Этот коммит содержится в:
rhysd
2024-08-08 23:01:57 +09:00
родитель 8d2c201aff
Коммит 3fb0a78a4c
7 изменённых файлов: 49 добавлений и 6 удалений

Просмотреть файл

@@ -27,7 +27,7 @@ no-backend = ["ratatui"]
# Features to use tui-rs
tuirs = ["dep:tui"]
tuirs-crossterm = ["tuirs", "dep:crossterm-025", "tui/crossterm"]
tuirs-termion = ["tuirs", "dep:termion", "tui/termion"]
tuirs-termion = ["tuirs", "dep:termion-15", "tui/termion"]
tuirs-no-backend = ["tuirs"]
# Other optional features
search = ["dep:regex"]
@@ -40,6 +40,7 @@ crossterm-025 = { package = "crossterm", version = "0.25", optional = true }
ratatui = { version = "0.28", default-features = false, optional = true }
regex = { version = "1", optional = true }
termion = { version = "4.0", optional = true }
termion-15 = { package = "termion", version = "1.5", optional = true }
termwiz = { version = "0.22.0", optional = true }
tui = { version = "0.19", default-features = false, optional = true }
unicode-width = "0.1.11"

Просмотреть файл

@@ -192,8 +192,9 @@ Note that [ratatui][] support and [tui-rs][] support are exclusive. When you use
[ratatui][] support by `default-features = false`.
In addition to above dependencies, you also need to install [crossterm][] or [termion][] or [termwiz][] to initialize
your application and to receive key inputs. Note that version of [crossterm][] crate is different between [ratatui][]
and [tui-rs][]. Please select the correct version.
your application and to receive key inputs. Note that version of [crossterm][] crate and [termion][] crate are different
between [ratatui][] and [tui-rs][]. Please select the same dependency version. For example, [tui-rs][] depends on
[crossterm][] v0.2.5 or [termion][] v1.5 where both crates are older than [ratatui][]'s dependencies.
## Minimal Usage

Просмотреть файл

@@ -1,3 +1,4 @@
// Use `crossterm` v0.25 for `tui` backend.
use crossterm_025 as crossterm;
use crossterm::event::{DisableMouseCapture, EnableMouseCapture};

Просмотреть файл

@@ -1,3 +1,4 @@
// Use `crossterm` v0.25 for `tui` backend.
use crossterm_025 as crossterm;
use crossterm::event::{DisableMouseCapture, EnableMouseCapture};

Просмотреть файл

@@ -1,3 +1,6 @@
// Use `termion` v1.5 for `tui` backend.
use termion_15 as termion;
use std::error::Error;
use std::io;
use std::sync::mpsc;
@@ -6,7 +9,7 @@ use std::time::Duration;
use termion::event::Event as TermEvent;
use termion::input::{MouseTerminal, TermRead};
use termion::raw::IntoRawMode;
use termion::screen::IntoAlternateScreen;
use termion::screen::AlternateScreen;
use tui::backend::TermionBackend;
use tui::widgets::{Block, Borders};
use tui::Terminal;
@@ -18,8 +21,9 @@ enum Event {
}
fn main() -> Result<(), Box<dyn Error>> {
let stdout = io::stdout().into_raw_mode()?.into_alternate_screen()?;
let stdout = io::stdout().into_raw_mode()?;
let stdout = MouseTerminal::from(stdout);
let stdout = AlternateScreen::from(stdout);
let backend = TermionBackend::new(stdout);
let mut term = Terminal::new(backend)?;

Просмотреть файл

@@ -1,5 +1,5 @@
use super::{Input, Key};
use termion::event::{Event, Key as KeyEvent, MouseButton, MouseEvent};
use crate::termion::event::{Event, Key as KeyEvent, MouseButton, MouseEvent};
impl From<Event> for Input {
/// Convert [`termion::event::Event`] into [`Input`].
@@ -22,6 +22,7 @@ impl From<KeyEvent> for Input {
/// So the `shift` field of the returned `Input` instance is always `false` except for combinations with arrow keys.
/// For example, `termion::event::Key::Char('A')` is converted to `Input { key: Key::Char('A'), shift: false, .. }`.
fn from(key: KeyEvent) -> Self {
#[cfg(feature = "termion")]
let (ctrl, alt, shift) = match key {
KeyEvent::Ctrl(_)
| KeyEvent::CtrlUp
@@ -42,6 +43,14 @@ impl From<KeyEvent> for Input {
_ => (false, false, false),
};
#[cfg(feature = "tuirs-termion")]
let (ctrl, alt, shift) = match key {
KeyEvent::Ctrl(_) => (true, false, false),
KeyEvent::Alt(_) => (false, true, false),
_ => (false, false, false),
};
#[cfg(feature = "termion")]
let key = match key {
KeyEvent::Char('\n' | '\r') => Key::Enter,
KeyEvent::Char(c) | KeyEvent::Ctrl(c) | KeyEvent::Alt(c) => Key::Char(c),
@@ -67,6 +76,26 @@ impl From<KeyEvent> for Input {
_ => Key::Null,
};
#[cfg(feature = "tuirs-termion")]
let key = match key {
KeyEvent::Char('\n' | '\r') => Key::Enter,
KeyEvent::Char(c) | KeyEvent::Ctrl(c) | KeyEvent::Alt(c) => Key::Char(c),
KeyEvent::Backspace => Key::Backspace,
KeyEvent::Left => Key::Left,
KeyEvent::Right => Key::Right,
KeyEvent::Up => Key::Up,
KeyEvent::Down => Key::Down,
KeyEvent::Home => Key::Home,
KeyEvent::End => Key::End,
KeyEvent::PageUp => Key::PageUp,
KeyEvent::PageDown => Key::PageDown,
KeyEvent::BackTab => Key::Tab,
KeyEvent::Delete => Key::Delete,
KeyEvent::Esc => Key::Esc,
KeyEvent::F(x) => Key::F(x),
_ => Key::Null,
};
Input {
key,
ctrl,

Просмотреть файл

@@ -31,6 +31,12 @@ use crossterm;
#[cfg(feature = "tuirs-crossterm")]
use crossterm_025 as crossterm;
#[cfg(feature = "termion")]
#[allow(clippy::single_component_path_imports)]
use termion;
#[cfg(feature = "tuirs-termion")]
use termion_15 as termion;
pub use cursor::CursorMove;
pub use input::{Input, Key};
pub use scroll::Scrolling;