Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
migrate from crossterm 0.13.3 to crossterm 0.14.0
- Loading branch information
Showing
12 changed files
with
139 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,54 @@ | ||
use crossterm::input::{InputEvent, KeyEvent, MouseButton, MouseEvent}; | ||
use crossterm; | ||
|
||
/// a valid user event | ||
#[derive(Debug, Clone)] | ||
pub enum Event { | ||
Key(KeyEvent), | ||
|
||
Key(crossterm::event::KeyEvent), | ||
|
||
Click(u16, u16), | ||
|
||
RightClick(u16, u16), | ||
|
||
DoubleClick(u16, u16), | ||
|
||
/// terminal was resized. Contains the new dimensions | ||
Resize(u16, u16), | ||
|
||
/// mouse wheel turns. contains -1 if up or 1 if down | ||
Wheel(i32), | ||
} | ||
|
||
impl Event { | ||
pub fn from_crossterm_event(crossterm_event: Option<InputEvent>) -> Option<Event> { | ||
/// convert a crossterm event into a termimad one. | ||
/// | ||
/// To get a double-click you'll either need to use a termimad event-source | ||
/// or to do the computation yourself. | ||
pub fn from_crossterm_event( | ||
crossterm_event: crossterm::Result<crossterm::event::Event> | ||
) -> Option<Event> { | ||
match crossterm_event { | ||
Some(InputEvent::Keyboard(key)) => Some(Event::Key(key)), | ||
Some(InputEvent::Mouse(MouseEvent::Release(x, y))) => Some(Event::Click(x, y)), | ||
Some(InputEvent::Mouse(MouseEvent::Press(MouseButton::WheelUp, _, _))) => { | ||
Ok(crossterm::event::Event::Key(key)) => { | ||
Some(Event::Key(key)) | ||
} | ||
Ok(crossterm::event::Event::Mouse(crossterm::event::MouseEvent::Up(button, x, y, ..))) => { | ||
match button { | ||
crossterm::event::MouseButton::Left => Some(Event::Click(x, y)), | ||
crossterm::event::MouseButton::Right => Some(Event::RightClick(x, y)), | ||
_ => None | ||
} | ||
} | ||
Ok(crossterm::event::Event::Resize(w, h)) => { | ||
Some(Event::Resize(w, h)) | ||
} | ||
Ok(crossterm::event::Event::Mouse(crossterm::event::MouseEvent::ScrollUp(..))) => { | ||
Some(Event::Wheel(-1)) | ||
} | ||
Some(InputEvent::Mouse(MouseEvent::Press(MouseButton::WheelDown, _, _))) => { | ||
Ok(crossterm::event::Event::Mouse(crossterm::event::MouseEvent::ScrollDown(..))) => { | ||
Some(Event::Wheel(1)) | ||
} | ||
_ => None, | ||
} | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -149,7 +149,6 @@ mod fit_tests { | |
Composite, | ||
}; | ||
use crate::{ | ||
MadSkin, | ||
Fitter, | ||
FmtComposite, | ||
}; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.