Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix warnings and clippy lints #943

Merged
merged 3 commits into from
Nov 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions src/event/filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,23 +61,23 @@ impl Filter for EventFilter {
}
}

#[derive(Debug, Clone)]
pub(crate) struct InternalEventFilter;

impl Filter for InternalEventFilter {
fn eval(&self, _: &InternalEvent) -> bool {
true
}
}

#[cfg(test)]
#[cfg(unix)]
mod tests {
use super::{
super::Event, CursorPositionFilter, EventFilter, Filter, InternalEvent,
InternalEventFilter, KeyboardEnhancementFlagsFilter, PrimaryDeviceAttributesFilter,
KeyboardEnhancementFlagsFilter, PrimaryDeviceAttributesFilter,
};

#[derive(Debug, Clone)]
pub(crate) struct InternalEventFilter;

impl Filter for InternalEventFilter {
fn eval(&self, _: &InternalEvent) -> bool {
true
}
}

#[test]
fn test_cursor_position_filter_filters_cursor_position() {
assert!(!CursorPositionFilter.eval(&InternalEvent::Event(Event::Resize(10, 10))));
Expand Down
14 changes: 10 additions & 4 deletions src/event/read.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,10 +132,16 @@ mod tests {

#[cfg(unix)]
use super::super::filter::CursorPositionFilter;
use super::{
super::{filter::InternalEventFilter, Event},
EventSource, InternalEvent, InternalEventReader,
};
use super::{super::Event, EventSource, Filter, InternalEvent, InternalEventReader};

#[derive(Debug, Clone)]
pub(crate) struct InternalEventFilter;

impl Filter for InternalEventFilter {
fn eval(&self, _: &InternalEvent) -> bool {
true
}
}

#[test]
fn test_poll_fails_without_event_source() {
Expand Down
36 changes: 18 additions & 18 deletions src/event/sys/unix/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ fn char_code_to_event(code: KeyCode) -> KeyEvent {
}

pub(crate) fn parse_csi(buffer: &[u8]) -> io::Result<Option<InternalEvent>> {
assert!(buffer.starts_with(&[b'\x1B', b'['])); // ESC [
assert!(buffer.starts_with(b"\x1B[")); // ESC [

if buffer.len() == 2 {
return Ok(None);
Expand Down Expand Up @@ -242,8 +242,8 @@ pub(crate) fn parse_csi_cursor_position(buffer: &[u8]) -> io::Result<Option<Inte
// ESC [ Cy ; Cx R
// Cy - cursor row number (starting from 1)
// Cx - cursor column number (starting from 1)
assert!(buffer.starts_with(&[b'\x1B', b'['])); // ESC [
assert!(buffer.ends_with(&[b'R']));
assert!(buffer.starts_with(b"\x1B[")); // ESC [
assert!(buffer.ends_with(b"R"));

let s = std::str::from_utf8(&buffer[2..buffer.len() - 1])
.map_err(|_| could_not_parse_event_error())?;
Expand All @@ -258,8 +258,8 @@ pub(crate) fn parse_csi_cursor_position(buffer: &[u8]) -> io::Result<Option<Inte

fn parse_csi_keyboard_enhancement_flags(buffer: &[u8]) -> io::Result<Option<InternalEvent>> {
// ESC [ ? flags u
assert!(buffer.starts_with(&[b'\x1B', b'[', b'?'])); // ESC [ ?
assert!(buffer.ends_with(&[b'u']));
assert!(buffer.starts_with(b"\x1B[?")); // ESC [ ?
assert!(buffer.ends_with(b"u"));

if buffer.len() < 5 {
return Ok(None);
Expand Down Expand Up @@ -290,8 +290,8 @@ fn parse_csi_keyboard_enhancement_flags(buffer: &[u8]) -> io::Result<Option<Inte

fn parse_csi_primary_device_attributes(buffer: &[u8]) -> io::Result<Option<InternalEvent>> {
// ESC [ 64 ; attr1 ; attr2 ; ... ; attrn ; c
assert!(buffer.starts_with(&[b'\x1B', b'[', b'?']));
assert!(buffer.ends_with(&[b'c']));
assert!(buffer.starts_with(b"\x1B[?"));
assert!(buffer.ends_with(b"c"));

// This is a stub for parsing the primary device attributes. This response is not
// exposed in the crossterm API so we don't need to parse the individual attributes yet.
Expand Down Expand Up @@ -346,8 +346,8 @@ fn parse_key_event_kind(kind: u8) -> KeyEventKind {
}

pub(crate) fn parse_csi_modifier_key_code(buffer: &[u8]) -> io::Result<Option<InternalEvent>> {
assert!(buffer.starts_with(&[b'\x1B', b'['])); // ESC [
//
assert!(buffer.starts_with(b"\x1B[")); // ESC [
//
let s = std::str::from_utf8(&buffer[2..buffer.len() - 1])
.map_err(|_| could_not_parse_event_error())?;
let mut split = s.split(';');
Expand Down Expand Up @@ -495,8 +495,8 @@ fn translate_functional_key_code(codepoint: u32) -> Option<(KeyCode, KeyEventSta
}

pub(crate) fn parse_csi_u_encoded_key_code(buffer: &[u8]) -> io::Result<Option<InternalEvent>> {
assert!(buffer.starts_with(&[b'\x1B', b'['])); // ESC [
assert!(buffer.ends_with(&[b'u']));
assert!(buffer.starts_with(b"\x1B[")); // ESC [
assert!(buffer.ends_with(b"u"));

// This function parses `CSI … u` sequences. These are sequences defined in either
// the `CSI u` (a.k.a. "Fix Keyboard Input on Terminals - Please", https://www.leonerd.org.uk/hacks/fixterms/)
Expand Down Expand Up @@ -617,8 +617,8 @@ pub(crate) fn parse_csi_u_encoded_key_code(buffer: &[u8]) -> io::Result<Option<I
}

pub(crate) fn parse_csi_special_key_code(buffer: &[u8]) -> io::Result<Option<InternalEvent>> {
assert!(buffer.starts_with(&[b'\x1B', b'['])); // ESC [
assert!(buffer.ends_with(&[b'~']));
assert!(buffer.starts_with(b"\x1B[")); // ESC [
assert!(buffer.ends_with(b"~"));

let s = std::str::from_utf8(&buffer[2..buffer.len() - 1])
.map_err(|_| could_not_parse_event_error())?;
Expand Down Expand Up @@ -664,8 +664,8 @@ pub(crate) fn parse_csi_rxvt_mouse(buffer: &[u8]) -> io::Result<Option<InternalE
// rxvt mouse encoding:
// ESC [ Cb ; Cx ; Cy ; M

assert!(buffer.starts_with(&[b'\x1B', b'['])); // ESC [
assert!(buffer.ends_with(&[b'M']));
assert!(buffer.starts_with(b"\x1B[")); // ESC [
assert!(buffer.ends_with(b"M"));

let s = std::str::from_utf8(&buffer[2..buffer.len() - 1])
.map_err(|_| could_not_parse_event_error())?;
Expand All @@ -690,7 +690,7 @@ pub(crate) fn parse_csi_rxvt_mouse(buffer: &[u8]) -> io::Result<Option<InternalE
pub(crate) fn parse_csi_normal_mouse(buffer: &[u8]) -> io::Result<Option<InternalEvent>> {
// Normal mouse encoding: ESC [ M CB Cx Cy (6 characters only).

assert!(buffer.starts_with(&[b'\x1B', b'[', b'M'])); // ESC [ M
assert!(buffer.starts_with(b"\x1B[M")); // ESC [ M

if buffer.len() < 6 {
return Ok(None);
Expand Down Expand Up @@ -718,9 +718,9 @@ pub(crate) fn parse_csi_normal_mouse(buffer: &[u8]) -> io::Result<Option<Interna
pub(crate) fn parse_csi_sgr_mouse(buffer: &[u8]) -> io::Result<Option<InternalEvent>> {
// ESC [ < Cb ; Cx ; Cy (;) (M or m)

assert!(buffer.starts_with(&[b'\x1B', b'[', b'<'])); // ESC [ <
assert!(buffer.starts_with(b"\x1B[<")); // ESC [ <

if !buffer.ends_with(&[b'm']) && !buffer.ends_with(&[b'M']) {
if !buffer.ends_with(b"m") && !buffer.ends_with(b"M") {
return Ok(None);
}

Expand Down
6 changes: 0 additions & 6 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -252,9 +252,3 @@ pub(crate) mod macros;

#[cfg(all(windows, not(feature = "windows")))]
compile_error!("Compiling on Windows with \"windows\" feature disabled. Feature \"windows\" should only be disabled when project will never be compiled on Windows.");

#[cfg(all(winapi, not(feature = "winapi")))]
joshka marked this conversation as resolved.
Show resolved Hide resolved
compile_error!("Compiling on Windows with \"winapi\" feature disabled. Feature \"winapi\" should only be disabled when project will never be compiled on Windows.");

#[cfg(all(crossterm_winapi, not(feature = "crossterm_winapi")))]
compile_error!("Compiling on Windows with \"crossterm_winapi\" feature disabled. Feature \"crossterm_winapi\" should only be disabled when project will never be compiled on Windows.");
Loading