зеркало из
https://github.com/glebtv/tui-textarea.git
synced 2026-09-04 23:05:50 +03:00
prefer Into::into to From::from
Этот коммит содержится в:
10
README.md
10
README.md
@@ -366,7 +366,7 @@ loop {
|
|||||||
|
|
||||||
// Using `Input` is not mandatory, but it's useful for pattern match
|
// Using `Input` is not mandatory, but it's useful for pattern match
|
||||||
// Ignore Ctrl+m and Enter. Otherwise handle keys as usual
|
// Ignore Ctrl+m and Enter. Otherwise handle keys as usual
|
||||||
match Input::from(read()?) {
|
match read()?.into() {
|
||||||
Input { key: Key::Char('m'), ctrl: true, alt: false }
|
Input { key: Key::Char('m'), ctrl: true, alt: false }
|
||||||
| Input { key: Key::Enter, .. } => continue,
|
| Input { key: Key::Enter, .. } => continue,
|
||||||
input => {
|
input => {
|
||||||
@@ -436,7 +436,7 @@ loop {
|
|||||||
// ...
|
// ...
|
||||||
|
|
||||||
match mode {
|
match mode {
|
||||||
Mode::Normal => match Input::from(read()?) {
|
Mode::Normal => match read()?.into() {
|
||||||
Input { key: Key::Char('h'), .. } => textarea.move_cursor(CursorMove::Back),
|
Input { key: Key::Char('h'), .. } => textarea.move_cursor(CursorMove::Back),
|
||||||
Input { key: Key::Char('j'), .. } => textarea.move_cursor(CursorMove::Down),
|
Input { key: Key::Char('j'), .. } => textarea.move_cursor(CursorMove::Down),
|
||||||
Input { key: Key::Char('k'), .. } => textarea.move_cursor(CursorMove::Up),
|
Input { key: Key::Char('k'), .. } => textarea.move_cursor(CursorMove::Up),
|
||||||
@@ -460,7 +460,7 @@ loop {
|
|||||||
}
|
}
|
||||||
_ => {},
|
_ => {},
|
||||||
},
|
},
|
||||||
Mode::Insert => match Input::from(read()?) {
|
Mode::Insert => match read()?.into() {
|
||||||
Input { key: Key::Esc, .. } => {
|
Input { key: Key::Esc, .. } => {
|
||||||
mode = Mode::Normal;
|
mode = Mode::Normal;
|
||||||
}
|
}
|
||||||
@@ -477,7 +477,7 @@ If you don't want to use default key mappings, `TextArea::input_without_shortcut
|
|||||||
newlines.
|
newlines.
|
||||||
|
|
||||||
```rust
|
```rust
|
||||||
match Input::from(read()?) {
|
match read()?.into() {
|
||||||
// Handle your own key mappings here
|
// Handle your own key mappings here
|
||||||
// ...
|
// ...
|
||||||
input => textarea.input_without_shortcuts(input),
|
input => textarea.input_without_shortcuts(input),
|
||||||
@@ -583,7 +583,7 @@ loop {
|
|||||||
}
|
}
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
match Input::from(read()?) {
|
match read()?.into() {
|
||||||
// Switch focused textarea by Ctrl+S
|
// Switch focused textarea by Ctrl+S
|
||||||
Input { key: Key::Char('s'), ctrl: true, .. } => focused = (focused + 1) % 2;
|
Input { key: Key::Char('s'), ctrl: true, .. } => focused = (focused + 1) % 2;
|
||||||
// Handle input by the focused editor
|
// Handle input by the focused editor
|
||||||
|
|||||||
@@ -260,7 +260,7 @@ impl<'a> Editor<'a> {
|
|||||||
|
|
||||||
if search_height > 0 {
|
if search_height > 0 {
|
||||||
let textarea = &mut self.buffers[self.current].textarea;
|
let textarea = &mut self.buffers[self.current].textarea;
|
||||||
match Input::from(crossterm::event::read()?) {
|
match crossterm::event::read()?.into() {
|
||||||
Input {
|
Input {
|
||||||
key: Key::Char('g' | 'n'),
|
key: Key::Char('g' | 'n'),
|
||||||
ctrl: true,
|
ctrl: true,
|
||||||
@@ -307,7 +307,7 @@ impl<'a> Editor<'a> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
match Input::from(crossterm::event::read()?) {
|
match crossterm::event::read()?.into() {
|
||||||
Input {
|
Input {
|
||||||
key: Key::Char('q'),
|
key: Key::Char('q'),
|
||||||
ctrl: true,
|
ctrl: true,
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ fn main() -> io::Result<()> {
|
|||||||
term.draw(|f| {
|
term.draw(|f| {
|
||||||
f.render_widget(textarea.widget(), f.size());
|
f.render_widget(textarea.widget(), f.size());
|
||||||
})?;
|
})?;
|
||||||
match Input::from(crossterm::event::read()?) {
|
match crossterm::event::read()?.into() {
|
||||||
Input { key: Key::Esc, .. } => break,
|
Input { key: Key::Esc, .. } => break,
|
||||||
input => {
|
input => {
|
||||||
textarea.input(input);
|
textarea.input(input);
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ fn main() -> io::Result<()> {
|
|||||||
f.render_widget(widget, chunks[0]);
|
f.render_widget(widget, chunks[0]);
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
match Input::from(crossterm::event::read()?) {
|
match crossterm::event::read()?.into() {
|
||||||
Input { key: Key::Esc, .. } => break,
|
Input { key: Key::Esc, .. } => break,
|
||||||
Input {
|
Input {
|
||||||
key: Key::Enter, ..
|
key: Key::Enter, ..
|
||||||
|
|||||||
@@ -59,7 +59,7 @@ fn main() -> io::Result<()> {
|
|||||||
f.render_widget(widget, chunk);
|
f.render_widget(widget, chunk);
|
||||||
}
|
}
|
||||||
})?;
|
})?;
|
||||||
match Input::from(crossterm::event::read()?) {
|
match crossterm::event::read()?.into() {
|
||||||
Input { key: Key::Esc, .. } => break,
|
Input { key: Key::Esc, .. } => break,
|
||||||
Input {
|
Input {
|
||||||
key: Key::Char('x'),
|
key: Key::Char('x'),
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ fn main() -> io::Result<()> {
|
|||||||
.split(f.size());
|
.split(f.size());
|
||||||
f.render_widget(textarea.widget(), chunks[0]);
|
f.render_widget(textarea.widget(), chunks[0]);
|
||||||
})?;
|
})?;
|
||||||
match Input::from(crossterm::event::read()?) {
|
match crossterm::event::read()?.into() {
|
||||||
Input { key: Key::Esc, .. } => break,
|
Input { key: Key::Esc, .. } => break,
|
||||||
input => {
|
input => {
|
||||||
textarea.input(input);
|
textarea.input(input);
|
||||||
|
|||||||
@@ -36,9 +36,14 @@ pub enum Key {
|
|||||||
/// use crossterm::event::{Event, read};
|
/// use crossterm::event::{Event, read};
|
||||||
///
|
///
|
||||||
/// let event = read().unwrap();
|
/// let event = read().unwrap();
|
||||||
|
///
|
||||||
|
/// // `Input::from` can convert backend-native event into `Input`
|
||||||
/// let input = Input::from(event);
|
/// let input = Input::from(event);
|
||||||
|
/// // or `Into::into`
|
||||||
|
/// let input: Input = event.into();
|
||||||
|
/// // Conversion from `KeyEvent` value is also available
|
||||||
/// if let Event::Key(key) = event {
|
/// if let Event::Key(key) = event {
|
||||||
/// let input = Input::from(key); // Conversion from `KeyEvent` value is also available
|
/// let input = Input::from(key);
|
||||||
/// }
|
/// }
|
||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user