mirror of
https://github.com/crossterm-rs/crossterm.git
synced 2025-09-26 20:40:47 +00:00
fix: clippy lints (#1000)
This commit is contained in:
parent
d5b0e07007
commit
41bcd3b783
@ -12,21 +12,21 @@ fn match_event(event: Event) {
|
||||
code,
|
||||
..
|
||||
} => {
|
||||
println!("Control + {:?}", code);
|
||||
println!("Control + {code:?}");
|
||||
}
|
||||
KeyEvent {
|
||||
modifiers: KeyModifiers::SHIFT,
|
||||
code,
|
||||
..
|
||||
} => {
|
||||
println!("Shift + {:?}", code);
|
||||
println!("Shift + {code:?}");
|
||||
}
|
||||
KeyEvent {
|
||||
modifiers: KeyModifiers::ALT,
|
||||
code,
|
||||
..
|
||||
} => {
|
||||
println!("Alt + {:?}", code);
|
||||
println!("Alt + {code:?}");
|
||||
}
|
||||
|
||||
// Match on multiple modifiers:
|
||||
@ -34,9 +34,9 @@ fn match_event(event: Event) {
|
||||
code, modifiers, ..
|
||||
} => {
|
||||
if modifiers == (KeyModifiers::ALT | KeyModifiers::SHIFT) {
|
||||
println!("Alt + Shift {:?}", code);
|
||||
println!("Alt + Shift {code:?}");
|
||||
} else {
|
||||
println!("({:?}) with key: {:?}", modifiers, code)
|
||||
println!("({modifiers:?}) with key: {code:?}")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -25,7 +25,7 @@ fn print_events() -> io::Result<()> {
|
||||
// It's guaranteed that read() won't block if `poll` returns `Ok(true)`
|
||||
let event = read()?;
|
||||
|
||||
println!("Event::{:?}\r", event);
|
||||
println!("Event::{event:?}\r");
|
||||
|
||||
if event == Event::Key(KeyCode::Char('c').into()) {
|
||||
println!("Cursor position: {:?}\r", position());
|
||||
@ -44,7 +44,7 @@ fn print_events() -> io::Result<()> {
|
||||
}
|
||||
|
||||
fn main() -> io::Result<()> {
|
||||
println!("{}", HELP);
|
||||
println!("{HELP}");
|
||||
|
||||
enable_raw_mode()?;
|
||||
|
||||
@ -52,7 +52,7 @@ fn main() -> io::Result<()> {
|
||||
execute!(stdout, EnableMouseCapture)?;
|
||||
|
||||
if let Err(e) = print_events() {
|
||||
println!("Error: {:?}\r", e);
|
||||
println!("Error: {e:?}\r");
|
||||
}
|
||||
|
||||
execute!(stdout, DisableMouseCapture)?;
|
||||
|
@ -29,7 +29,7 @@ fn print_events() -> io::Result<()> {
|
||||
// Blocking read
|
||||
let event = read()?;
|
||||
|
||||
println!("Event: {:?}\r", event);
|
||||
println!("Event: {event:?}\r");
|
||||
|
||||
if event == Event::Key(KeyCode::Char('c').into()) {
|
||||
println!("Cursor position: {:?}\r", position());
|
||||
@ -37,7 +37,7 @@ fn print_events() -> io::Result<()> {
|
||||
|
||||
if let Event::Resize(x, y) = event {
|
||||
let (original_size, new_size) = flush_resize_events((x, y));
|
||||
println!("Resize from: {:?}, to: {:?}\r", original_size, new_size);
|
||||
println!("Resize from: {original_size:?}, to: {new_size:?}\r");
|
||||
}
|
||||
|
||||
if event == Event::Key(KeyCode::Esc.into()) {
|
||||
@ -63,7 +63,7 @@ fn flush_resize_events(first_resize: (u16, u16)) -> ((u16, u16), (u16, u16)) {
|
||||
}
|
||||
|
||||
fn main() -> io::Result<()> {
|
||||
println!("{}", HELP);
|
||||
println!("{HELP}");
|
||||
|
||||
enable_raw_mode()?;
|
||||
|
||||
@ -94,7 +94,7 @@ fn main() -> io::Result<()> {
|
||||
)?;
|
||||
|
||||
if let Err(e) = print_events() {
|
||||
println!("Error: {:?}\r", e);
|
||||
println!("Error: {e:?}\r");
|
||||
}
|
||||
|
||||
if supports_keyboard_enhancement {
|
||||
|
@ -33,7 +33,7 @@ async fn print_events() {
|
||||
maybe_event = event => {
|
||||
match maybe_event {
|
||||
Some(Ok(event)) => {
|
||||
println!("Event::{:?}\r", event);
|
||||
println!("Event::{event:?}\r");
|
||||
|
||||
if event == Event::Key(KeyCode::Char('c').into()) {
|
||||
println!("Cursor position: {:?}\r", position());
|
||||
@ -43,7 +43,7 @@ async fn print_events() {
|
||||
break;
|
||||
}
|
||||
}
|
||||
Some(Err(e)) => println!("Error: {:?}\r", e),
|
||||
Some(Err(e)) => println!("Error: {e:?}\r"),
|
||||
None => break,
|
||||
}
|
||||
}
|
||||
@ -52,7 +52,7 @@ async fn print_events() {
|
||||
}
|
||||
|
||||
fn main() -> std::io::Result<()> {
|
||||
println!("{}", HELP);
|
||||
println!("{HELP}");
|
||||
|
||||
enable_raw_mode()?;
|
||||
|
||||
|
@ -33,7 +33,7 @@ async fn print_events() {
|
||||
maybe_event = event => {
|
||||
match maybe_event {
|
||||
Some(Ok(event)) => {
|
||||
println!("Event::{:?}\r", event);
|
||||
println!("Event::{event:?}\r");
|
||||
|
||||
if event == Event::Key(KeyCode::Char('c').into()) {
|
||||
println!("Cursor position: {:?}\r", position());
|
||||
@ -43,7 +43,7 @@ async fn print_events() {
|
||||
break;
|
||||
}
|
||||
}
|
||||
Some(Err(e)) => println!("Error: {:?}\r", e),
|
||||
Some(Err(e)) => println!("Error: {e:?}\r"),
|
||||
None => break,
|
||||
}
|
||||
}
|
||||
@ -53,7 +53,7 @@ async fn print_events() {
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() -> std::io::Result<()> {
|
||||
println!("{}", HELP);
|
||||
println!("{HELP}");
|
||||
|
||||
enable_raw_mode()?;
|
||||
|
||||
|
@ -19,10 +19,10 @@ const HELP: &str = r#"Key display
|
||||
"#;
|
||||
|
||||
fn main() -> io::Result<()> {
|
||||
println!("{}", HELP);
|
||||
println!("{HELP}");
|
||||
enable_raw_mode()?;
|
||||
if let Err(e) = print_events() {
|
||||
println!("Error: {:?}\r", e);
|
||||
println!("Error: {e:?}\r");
|
||||
}
|
||||
disable_raw_mode()?;
|
||||
Ok(())
|
||||
|
@ -90,6 +90,6 @@ fn main() {
|
||||
'1' => print!(".."),
|
||||
'2' => print!("/"),
|
||||
'3' => print!("~"),
|
||||
_ => println!("{}", TEXT),
|
||||
_ => println!("{TEXT}"),
|
||||
}
|
||||
}
|
||||
|
52
src/event.rs
52
src/event.rs
@ -1446,11 +1446,11 @@ impl Display for KeyCode {
|
||||
KeyCode::Tab => write!(f, "Tab"),
|
||||
KeyCode::BackTab => write!(f, "Back Tab"),
|
||||
KeyCode::Insert => write!(f, "Insert"),
|
||||
KeyCode::F(n) => write!(f, "F{}", n),
|
||||
KeyCode::F(n) => write!(f, "F{n}"),
|
||||
KeyCode::Char(c) => match c {
|
||||
// special case for non-visible characters
|
||||
' ' => write!(f, "Space"),
|
||||
c => write!(f, "{}", c),
|
||||
c => write!(f, "{c}"),
|
||||
},
|
||||
KeyCode::Null => write!(f, "Null"),
|
||||
KeyCode::Esc => write!(f, "Esc"),
|
||||
@ -1461,8 +1461,8 @@ impl Display for KeyCode {
|
||||
KeyCode::Pause => write!(f, "Pause"),
|
||||
KeyCode::Menu => write!(f, "Menu"),
|
||||
KeyCode::KeypadBegin => write!(f, "Begin"),
|
||||
KeyCode::Media(media) => write!(f, "{}", media),
|
||||
KeyCode::Modifier(modifier) => write!(f, "{}", modifier),
|
||||
KeyCode::Media(media) => write!(f, "{media}"),
|
||||
KeyCode::Modifier(modifier) => write!(f, "{modifier}"),
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1530,9 +1530,9 @@ mod tests {
|
||||
fn keycode_display() {
|
||||
#[cfg(target_os = "macos")]
|
||||
{
|
||||
assert_eq!(format!("{}", Backspace), "Delete");
|
||||
assert_eq!(format!("{}", Delete), "Fwd Del");
|
||||
assert_eq!(format!("{}", Enter), "Return");
|
||||
assert_eq!(format!("{Backspace}"), "Delete");
|
||||
assert_eq!(format!("{Delete}"), "Fwd Del");
|
||||
assert_eq!(format!("{Enter}"), "Return");
|
||||
}
|
||||
#[cfg(not(target_os = "macos"))]
|
||||
{
|
||||
@ -1540,28 +1540,28 @@ mod tests {
|
||||
assert_eq!(format!("{}", Delete), "Del");
|
||||
assert_eq!(format!("{}", Enter), "Enter");
|
||||
}
|
||||
assert_eq!(format!("{}", Left), "Left");
|
||||
assert_eq!(format!("{}", Right), "Right");
|
||||
assert_eq!(format!("{}", Up), "Up");
|
||||
assert_eq!(format!("{}", Down), "Down");
|
||||
assert_eq!(format!("{}", Home), "Home");
|
||||
assert_eq!(format!("{}", End), "End");
|
||||
assert_eq!(format!("{}", PageUp), "Page Up");
|
||||
assert_eq!(format!("{}", PageDown), "Page Down");
|
||||
assert_eq!(format!("{}", Tab), "Tab");
|
||||
assert_eq!(format!("{}", BackTab), "Back Tab");
|
||||
assert_eq!(format!("{}", Insert), "Insert");
|
||||
assert_eq!(format!("{Left}"), "Left");
|
||||
assert_eq!(format!("{Right}"), "Right");
|
||||
assert_eq!(format!("{Up}"), "Up");
|
||||
assert_eq!(format!("{Down}"), "Down");
|
||||
assert_eq!(format!("{Home}"), "Home");
|
||||
assert_eq!(format!("{End}"), "End");
|
||||
assert_eq!(format!("{PageUp}"), "Page Up");
|
||||
assert_eq!(format!("{PageDown}"), "Page Down");
|
||||
assert_eq!(format!("{Tab}"), "Tab");
|
||||
assert_eq!(format!("{BackTab}"), "Back Tab");
|
||||
assert_eq!(format!("{Insert}"), "Insert");
|
||||
assert_eq!(format!("{}", F(1)), "F1");
|
||||
assert_eq!(format!("{}", Char('a')), "a");
|
||||
assert_eq!(format!("{}", Null), "Null");
|
||||
assert_eq!(format!("{}", Esc), "Esc");
|
||||
assert_eq!(format!("{}", CapsLock), "Caps Lock");
|
||||
assert_eq!(format!("{}", ScrollLock), "Scroll Lock");
|
||||
assert_eq!(format!("{}", NumLock), "Num Lock");
|
||||
assert_eq!(format!("{}", PrintScreen), "Print Screen");
|
||||
assert_eq!(format!("{Null}"), "Null");
|
||||
assert_eq!(format!("{Esc}"), "Esc");
|
||||
assert_eq!(format!("{CapsLock}"), "Caps Lock");
|
||||
assert_eq!(format!("{ScrollLock}"), "Scroll Lock");
|
||||
assert_eq!(format!("{NumLock}"), "Num Lock");
|
||||
assert_eq!(format!("{PrintScreen}"), "Print Screen");
|
||||
assert_eq!(format!("{}", KeyCode::Pause), "Pause");
|
||||
assert_eq!(format!("{}", Menu), "Menu");
|
||||
assert_eq!(format!("{}", KeypadBegin), "Begin");
|
||||
assert_eq!(format!("{Menu}"), "Menu");
|
||||
assert_eq!(format!("{KeypadBegin}"), "Begin");
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -139,7 +139,7 @@ impl EventSource for UnixInternalEventSource {
|
||||
Err(e) => {
|
||||
return Err(std::io::Error::new(
|
||||
std::io::ErrorKind::Other,
|
||||
format!("got unexpected error while polling: {:?}", e),
|
||||
format!("got unexpected error while polling: {e:?}"),
|
||||
))
|
||||
}
|
||||
Ok(_) => (),
|
||||
|
@ -67,7 +67,7 @@
|
||||
//! - Alternate screen - [`EnterAlternateScreen`](terminal/struct.EnterAlternateScreen.html),
|
||||
//! [`LeaveAlternateScreen`](terminal/struct.LeaveAlternateScreen.html)
|
||||
//! - Module [`clipboard`](clipboard/index.html) (requires
|
||||
//! [`feature = "osc52"`](#optional-features))
|
||||
//! [`feature = "osc52"`](#optional-features))
|
||||
//! - Clipboard - [`CopyToClipboard`](clipboard/struct.CopyToClipboard.html)
|
||||
//!
|
||||
//! ### Command Execution
|
||||
|
@ -246,10 +246,8 @@ impl serde::ser::Serialize for Color {
|
||||
|
||||
if str.is_empty() {
|
||||
match *self {
|
||||
Color::AnsiValue(value) => serializer.serialize_str(&format!("ansi_({})", value)),
|
||||
Color::Rgb { r, g, b } => {
|
||||
serializer.serialize_str(&format!("rgb_({},{},{})", r, g, b))
|
||||
}
|
||||
Color::AnsiValue(value) => serializer.serialize_str(&format!("ansi_({value})")),
|
||||
Color::Rgb { r, g, b } => serializer.serialize_str(&format!("rgb_({r},{g},{b})")),
|
||||
_ => Err(serde::ser::Error::custom("Could not serialize enum type")),
|
||||
}
|
||||
} else {
|
||||
|
Loading…
x
Reference in New Issue
Block a user