зеркало из
https://github.com/glebtv/tui-textarea.git
synced 2026-09-08 00:15:50 +03:00
use the same version of termion as tui's dependency for tuirs-termion feature
Этот коммит содержится в:
@@ -27,7 +27,7 @@ no-backend = ["ratatui"]
|
|||||||
# Features to use tui-rs
|
# Features to use tui-rs
|
||||||
tuirs = ["dep:tui"]
|
tuirs = ["dep:tui"]
|
||||||
tuirs-crossterm = ["tuirs", "dep:crossterm-025", "tui/crossterm"]
|
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"]
|
tuirs-no-backend = ["tuirs"]
|
||||||
# Other optional features
|
# Other optional features
|
||||||
search = ["dep:regex"]
|
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 }
|
ratatui = { version = "0.28", default-features = false, optional = true }
|
||||||
regex = { version = "1", optional = true }
|
regex = { version = "1", optional = true }
|
||||||
termion = { version = "4.0", optional = true }
|
termion = { version = "4.0", optional = true }
|
||||||
|
termion-15 = { package = "termion", version = "1.5", optional = true }
|
||||||
termwiz = { version = "0.22.0", optional = true }
|
termwiz = { version = "0.22.0", optional = true }
|
||||||
tui = { version = "0.19", default-features = false, optional = true }
|
tui = { version = "0.19", default-features = false, optional = true }
|
||||||
unicode-width = "0.1.11"
|
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`.
|
[ratatui][] support by `default-features = false`.
|
||||||
|
|
||||||
In addition to above dependencies, you also need to install [crossterm][] or [termion][] or [termwiz][] to initialize
|
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][]
|
your application and to receive key inputs. Note that version of [crossterm][] crate and [termion][] crate are different
|
||||||
and [tui-rs][]. Please select the correct version.
|
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
|
## Minimal Usage
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
// Use `crossterm` v0.25 for `tui` backend.
|
||||||
use crossterm_025 as crossterm;
|
use crossterm_025 as crossterm;
|
||||||
|
|
||||||
use crossterm::event::{DisableMouseCapture, EnableMouseCapture};
|
use crossterm::event::{DisableMouseCapture, EnableMouseCapture};
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
// Use `crossterm` v0.25 for `tui` backend.
|
||||||
use crossterm_025 as crossterm;
|
use crossterm_025 as crossterm;
|
||||||
|
|
||||||
use crossterm::event::{DisableMouseCapture, EnableMouseCapture};
|
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::error::Error;
|
||||||
use std::io;
|
use std::io;
|
||||||
use std::sync::mpsc;
|
use std::sync::mpsc;
|
||||||
@@ -6,7 +9,7 @@ use std::time::Duration;
|
|||||||
use termion::event::Event as TermEvent;
|
use termion::event::Event as TermEvent;
|
||||||
use termion::input::{MouseTerminal, TermRead};
|
use termion::input::{MouseTerminal, TermRead};
|
||||||
use termion::raw::IntoRawMode;
|
use termion::raw::IntoRawMode;
|
||||||
use termion::screen::IntoAlternateScreen;
|
use termion::screen::AlternateScreen;
|
||||||
use tui::backend::TermionBackend;
|
use tui::backend::TermionBackend;
|
||||||
use tui::widgets::{Block, Borders};
|
use tui::widgets::{Block, Borders};
|
||||||
use tui::Terminal;
|
use tui::Terminal;
|
||||||
@@ -18,8 +21,9 @@ enum Event {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn main() -> Result<(), Box<dyn Error>> {
|
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 = MouseTerminal::from(stdout);
|
||||||
|
let stdout = AlternateScreen::from(stdout);
|
||||||
let backend = TermionBackend::new(stdout);
|
let backend = TermionBackend::new(stdout);
|
||||||
let mut term = Terminal::new(backend)?;
|
let mut term = Terminal::new(backend)?;
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
use super::{Input, Key};
|
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 {
|
impl From<Event> for Input {
|
||||||
/// Convert [`termion::event::Event`] into [`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.
|
/// 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, .. }`.
|
/// For example, `termion::event::Key::Char('A')` is converted to `Input { key: Key::Char('A'), shift: false, .. }`.
|
||||||
fn from(key: KeyEvent) -> Self {
|
fn from(key: KeyEvent) -> Self {
|
||||||
|
#[cfg(feature = "termion")]
|
||||||
let (ctrl, alt, shift) = match key {
|
let (ctrl, alt, shift) = match key {
|
||||||
KeyEvent::Ctrl(_)
|
KeyEvent::Ctrl(_)
|
||||||
| KeyEvent::CtrlUp
|
| KeyEvent::CtrlUp
|
||||||
@@ -42,6 +43,14 @@ impl From<KeyEvent> for Input {
|
|||||||
_ => (false, false, false),
|
_ => (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 {
|
let key = match key {
|
||||||
KeyEvent::Char('\n' | '\r') => Key::Enter,
|
KeyEvent::Char('\n' | '\r') => Key::Enter,
|
||||||
KeyEvent::Char(c) | KeyEvent::Ctrl(c) | KeyEvent::Alt(c) => Key::Char(c),
|
KeyEvent::Char(c) | KeyEvent::Ctrl(c) | KeyEvent::Alt(c) => Key::Char(c),
|
||||||
@@ -67,6 +76,26 @@ impl From<KeyEvent> for Input {
|
|||||||
_ => Key::Null,
|
_ => 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 {
|
Input {
|
||||||
key,
|
key,
|
||||||
ctrl,
|
ctrl,
|
||||||
|
|||||||
@@ -31,6 +31,12 @@ use crossterm;
|
|||||||
#[cfg(feature = "tuirs-crossterm")]
|
#[cfg(feature = "tuirs-crossterm")]
|
||||||
use crossterm_025 as 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 cursor::CursorMove;
|
||||||
pub use input::{Input, Key};
|
pub use input::{Input, Key};
|
||||||
pub use scroll::Scrolling;
|
pub use scroll::Scrolling;
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user