Skip to content

Commit

Permalink
fix windows double character
Browse files Browse the repository at this point in the history
  • Loading branch information
pm100 committed May 5, 2023
1 parent 959be77 commit 60ce814
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 4 deletions.
4 changes: 4 additions & 0 deletions Cargo.toml
Expand Up @@ -42,6 +42,7 @@ tui = { version = "0.19", default-features = false, optional = true }
arbitrary = { version = "1", features = ["derive"], optional = true }
crossterm-026 = { package = "crossterm", version = "0.26", optional = true }
ratatui = { version = "0.20.1", default-features = false, optional = true }
log = "0.4.17"

[[example]]
name = "minimal"
Expand Down Expand Up @@ -91,6 +92,9 @@ members = [
[profile.bench]
lto = "thin"

[dev-dependencies]
simplelog = "0.12.1"

[package.metadata.docs.rs]
all-features = true
rustdoc-args = ["--cfg", "docsrs"]
7 changes: 7 additions & 0 deletions examples/minimal.rs
Expand Up @@ -2,13 +2,20 @@ use crossterm::event::{DisableMouseCapture, EnableMouseCapture};
use crossterm::terminal::{
disable_raw_mode, enable_raw_mode, EnterAlternateScreen, LeaveAlternateScreen,
};
use simplelog::{Config, LevelFilter, WriteLogger};
use std::fs::File;
use std::io;
use tui::backend::CrosstermBackend;
use tui::widgets::{Block, Borders};
use tui::Terminal;
use tui_textarea::{Input, Key, TextArea};

fn main() -> io::Result<()> {
let _ = WriteLogger::init(
LevelFilter::Trace,
Config::default(),
File::create("textarea.log").unwrap(),
);
let stdout = io::stdout();
let mut stdout = stdout.lock();

Expand Down
8 changes: 7 additions & 1 deletion examples/ratatui_minimal.rs
Expand Up @@ -7,10 +7,16 @@ use crossterm::terminal::{
use ratatui::backend::CrosstermBackend;
use ratatui::widgets::{Block, Borders};
use ratatui::Terminal;
use simplelog::{Config, LevelFilter, WriteLogger};
use std::fs::File;
use std::io;
use tui_textarea::{Input, Key, TextArea};

fn main() -> io::Result<()> {
let _ = WriteLogger::init(
LevelFilter::Trace,
Config::default(),
File::create("textarea.log").unwrap(),
);
let stdout = io::stdout();
let mut stdout = stdout.lock();

Expand Down
9 changes: 6 additions & 3 deletions src/input.rs
@@ -1,10 +1,12 @@
#[cfg(any(feature = "crossterm", feature = "ratatui-crossterm"))]
use crate::crossterm::event::{
Event as CrosstermEvent, KeyCode, KeyEvent, KeyModifiers, MouseEvent as CrosstermMouseEvent,
MouseEventKind as CrosstermMouseEventKind,
Event as CrosstermEvent, KeyCode, KeyEvent, KeyEventKind, KeyModifiers,
MouseEvent as CrosstermMouseEvent, MouseEventKind as CrosstermMouseEventKind,
};
#[cfg(feature = "arbitrary")]
use arbitrary::Arbitrary;
#[cfg(any(feature = "crossterm", feature = "ratatui-crossterm"))]
use log::trace;
#[cfg(any(feature = "termion", feature = "ratatui-termion"))]
use termion::event::{Event as TermionEvent, Key as TermionKey, MouseEvent as TermionMouseEvent};

Expand Down Expand Up @@ -99,8 +101,9 @@ impl Default for Input {
impl From<CrosstermEvent> for Input {
/// Convert [`crossterm::event::Event`] to [`Input`].
fn from(event: CrosstermEvent) -> Self {
trace!("Cross Event:{:?}", event);
match event {
CrosstermEvent::Key(key) => Self::from(key),
CrosstermEvent::Key(key) if key.kind == KeyEventKind::Press => Self::from(key),
CrosstermEvent::Mouse(mouse) => Self::from(mouse),
_ => Self::default(),
}
Expand Down

0 comments on commit 60ce814

Please sign in to comment.