Fix LF line-endings (#3316)

This commit is contained in:
Charlie Groves 2022-08-03 12:53:57 +00:00 committed by GitHub
parent 6b244e2fef
commit 4b6c4ae6ee
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 818 additions and 818 deletions

File diff suppressed because it is too large Load Diff

View File

@ -1,153 +1,153 @@
use bitflags::bitflags; use bitflags::bitflags;
bitflags! { bitflags! {
/// Represents key modifiers (shift, control, alt). /// Represents key modifiers (shift, control, alt).
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct KeyModifiers: u8 { pub struct KeyModifiers: u8 {
const SHIFT = 0b0000_0001; const SHIFT = 0b0000_0001;
const CONTROL = 0b0000_0010; const CONTROL = 0b0000_0010;
const ALT = 0b0000_0100; const ALT = 0b0000_0100;
const NONE = 0b0000_0000; const NONE = 0b0000_0000;
} }
} }
#[cfg(feature = "term")] #[cfg(feature = "term")]
impl From<KeyModifiers> for crossterm::event::KeyModifiers { impl From<KeyModifiers> for crossterm::event::KeyModifiers {
fn from(key_modifiers: KeyModifiers) -> Self { fn from(key_modifiers: KeyModifiers) -> Self {
use crossterm::event::KeyModifiers as CKeyModifiers; use crossterm::event::KeyModifiers as CKeyModifiers;
let mut result = CKeyModifiers::NONE; let mut result = CKeyModifiers::NONE;
if key_modifiers.contains(KeyModifiers::SHIFT) { if key_modifiers.contains(KeyModifiers::SHIFT) {
result.insert(CKeyModifiers::SHIFT); result.insert(CKeyModifiers::SHIFT);
} }
if key_modifiers.contains(KeyModifiers::CONTROL) { if key_modifiers.contains(KeyModifiers::CONTROL) {
result.insert(CKeyModifiers::CONTROL); result.insert(CKeyModifiers::CONTROL);
} }
if key_modifiers.contains(KeyModifiers::ALT) { if key_modifiers.contains(KeyModifiers::ALT) {
result.insert(CKeyModifiers::ALT); result.insert(CKeyModifiers::ALT);
} }
result result
} }
} }
#[cfg(feature = "term")] #[cfg(feature = "term")]
impl From<crossterm::event::KeyModifiers> for KeyModifiers { impl From<crossterm::event::KeyModifiers> for KeyModifiers {
fn from(val: crossterm::event::KeyModifiers) -> Self { fn from(val: crossterm::event::KeyModifiers) -> Self {
use crossterm::event::KeyModifiers as CKeyModifiers; use crossterm::event::KeyModifiers as CKeyModifiers;
let mut result = KeyModifiers::NONE; let mut result = KeyModifiers::NONE;
if val.contains(CKeyModifiers::SHIFT) { if val.contains(CKeyModifiers::SHIFT) {
result.insert(KeyModifiers::SHIFT); result.insert(KeyModifiers::SHIFT);
} }
if val.contains(CKeyModifiers::CONTROL) { if val.contains(CKeyModifiers::CONTROL) {
result.insert(KeyModifiers::CONTROL); result.insert(KeyModifiers::CONTROL);
} }
if val.contains(CKeyModifiers::ALT) { if val.contains(CKeyModifiers::ALT) {
result.insert(KeyModifiers::ALT); result.insert(KeyModifiers::ALT);
} }
result result
} }
} }
/// Represents a key. /// Represents a key.
#[derive(Debug, PartialOrd, Ord, PartialEq, Eq, Clone, Copy, Hash)] #[derive(Debug, PartialOrd, Ord, PartialEq, Eq, Clone, Copy, Hash)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub enum KeyCode { pub enum KeyCode {
/// Backspace key. /// Backspace key.
Backspace, Backspace,
/// Enter key. /// Enter key.
Enter, Enter,
/// Left arrow key. /// Left arrow key.
Left, Left,
/// Right arrow key. /// Right arrow key.
Right, Right,
/// Up arrow key. /// Up arrow key.
Up, Up,
/// Down arrow key. /// Down arrow key.
Down, Down,
/// Home key. /// Home key.
Home, Home,
/// End key. /// End key.
End, End,
/// Page up key. /// Page up key.
PageUp, PageUp,
/// Page down key. /// Page down key.
PageDown, PageDown,
/// Tab key. /// Tab key.
Tab, Tab,
/// Delete key. /// Delete key.
Delete, Delete,
/// Insert key. /// Insert key.
Insert, Insert,
/// F key. /// F key.
/// ///
/// `KeyCode::F(1)` represents F1 key, etc. /// `KeyCode::F(1)` represents F1 key, etc.
F(u8), F(u8),
/// A character. /// A character.
/// ///
/// `KeyCode::Char('c')` represents `c` character, etc. /// `KeyCode::Char('c')` represents `c` character, etc.
Char(char), Char(char),
/// Null. /// Null.
Null, Null,
/// Escape key. /// Escape key.
Esc, Esc,
} }
#[cfg(feature = "term")] #[cfg(feature = "term")]
impl From<KeyCode> for crossterm::event::KeyCode { impl From<KeyCode> for crossterm::event::KeyCode {
fn from(key_code: KeyCode) -> Self { fn from(key_code: KeyCode) -> Self {
use crossterm::event::KeyCode as CKeyCode; use crossterm::event::KeyCode as CKeyCode;
match key_code { match key_code {
KeyCode::Backspace => CKeyCode::Backspace, KeyCode::Backspace => CKeyCode::Backspace,
KeyCode::Enter => CKeyCode::Enter, KeyCode::Enter => CKeyCode::Enter,
KeyCode::Left => CKeyCode::Left, KeyCode::Left => CKeyCode::Left,
KeyCode::Right => CKeyCode::Right, KeyCode::Right => CKeyCode::Right,
KeyCode::Up => CKeyCode::Up, KeyCode::Up => CKeyCode::Up,
KeyCode::Down => CKeyCode::Down, KeyCode::Down => CKeyCode::Down,
KeyCode::Home => CKeyCode::Home, KeyCode::Home => CKeyCode::Home,
KeyCode::End => CKeyCode::End, KeyCode::End => CKeyCode::End,
KeyCode::PageUp => CKeyCode::PageUp, KeyCode::PageUp => CKeyCode::PageUp,
KeyCode::PageDown => CKeyCode::PageDown, KeyCode::PageDown => CKeyCode::PageDown,
KeyCode::Tab => CKeyCode::Tab, KeyCode::Tab => CKeyCode::Tab,
KeyCode::Delete => CKeyCode::Delete, KeyCode::Delete => CKeyCode::Delete,
KeyCode::Insert => CKeyCode::Insert, KeyCode::Insert => CKeyCode::Insert,
KeyCode::F(f_number) => CKeyCode::F(f_number), KeyCode::F(f_number) => CKeyCode::F(f_number),
KeyCode::Char(character) => CKeyCode::Char(character), KeyCode::Char(character) => CKeyCode::Char(character),
KeyCode::Null => CKeyCode::Null, KeyCode::Null => CKeyCode::Null,
KeyCode::Esc => CKeyCode::Esc, KeyCode::Esc => CKeyCode::Esc,
} }
} }
} }
#[cfg(feature = "term")] #[cfg(feature = "term")]
impl From<crossterm::event::KeyCode> for KeyCode { impl From<crossterm::event::KeyCode> for KeyCode {
fn from(val: crossterm::event::KeyCode) -> Self { fn from(val: crossterm::event::KeyCode) -> Self {
use crossterm::event::KeyCode as CKeyCode; use crossterm::event::KeyCode as CKeyCode;
match val { match val {
CKeyCode::Backspace => KeyCode::Backspace, CKeyCode::Backspace => KeyCode::Backspace,
CKeyCode::Enter => KeyCode::Enter, CKeyCode::Enter => KeyCode::Enter,
CKeyCode::Left => KeyCode::Left, CKeyCode::Left => KeyCode::Left,
CKeyCode::Right => KeyCode::Right, CKeyCode::Right => KeyCode::Right,
CKeyCode::Up => KeyCode::Up, CKeyCode::Up => KeyCode::Up,
CKeyCode::Down => KeyCode::Down, CKeyCode::Down => KeyCode::Down,
CKeyCode::Home => KeyCode::Home, CKeyCode::Home => KeyCode::Home,
CKeyCode::End => KeyCode::End, CKeyCode::End => KeyCode::End,
CKeyCode::PageUp => KeyCode::PageUp, CKeyCode::PageUp => KeyCode::PageUp,
CKeyCode::PageDown => KeyCode::PageDown, CKeyCode::PageDown => KeyCode::PageDown,
CKeyCode::Tab => KeyCode::Tab, CKeyCode::Tab => KeyCode::Tab,
CKeyCode::BackTab => unreachable!("BackTab should have been handled on KeyEvent level"), CKeyCode::BackTab => unreachable!("BackTab should have been handled on KeyEvent level"),
CKeyCode::Delete => KeyCode::Delete, CKeyCode::Delete => KeyCode::Delete,
CKeyCode::Insert => KeyCode::Insert, CKeyCode::Insert => KeyCode::Insert,
CKeyCode::F(f_number) => KeyCode::F(f_number), CKeyCode::F(f_number) => KeyCode::F(f_number),
CKeyCode::Char(character) => KeyCode::Char(character), CKeyCode::Char(character) => KeyCode::Char(character),
CKeyCode::Null => KeyCode::Null, CKeyCode::Null => KeyCode::Null,
CKeyCode::Esc => KeyCode::Esc, CKeyCode::Esc => KeyCode::Esc,
} }
} }
} }