Skip to content

Commit 31b3998

Browse files
authored
Fix warnings and clippy lints (#943)
* Move InternalEventFilter into tests mod This is only used in test code, so should be defined there * Remove winapi feature flag checks These checks were impossible to trigger as there is no separate feature flag for winapi and crossterm_winapi. The windows feature flag automatically enables these dependencies. * Fix clippy lints for byte char slices https://rust-lang.github.io/rust-clippy/master/index.html\#byte_char_slices
1 parent 4549831 commit 31b3998

File tree

4 files changed

+38
-38
lines changed

4 files changed

+38
-38
lines changed

src/event/filter.rs

+10-10
Original file line numberDiff line numberDiff line change
@@ -61,23 +61,23 @@ impl Filter for EventFilter {
6161
}
6262
}
6363

64-
#[derive(Debug, Clone)]
65-
pub(crate) struct InternalEventFilter;
66-
67-
impl Filter for InternalEventFilter {
68-
fn eval(&self, _: &InternalEvent) -> bool {
69-
true
70-
}
71-
}
72-
7364
#[cfg(test)]
7465
#[cfg(unix)]
7566
mod tests {
7667
use super::{
7768
super::Event, CursorPositionFilter, EventFilter, Filter, InternalEvent,
78-
InternalEventFilter, KeyboardEnhancementFlagsFilter, PrimaryDeviceAttributesFilter,
69+
KeyboardEnhancementFlagsFilter, PrimaryDeviceAttributesFilter,
7970
};
8071

72+
#[derive(Debug, Clone)]
73+
pub(crate) struct InternalEventFilter;
74+
75+
impl Filter for InternalEventFilter {
76+
fn eval(&self, _: &InternalEvent) -> bool {
77+
true
78+
}
79+
}
80+
8181
#[test]
8282
fn test_cursor_position_filter_filters_cursor_position() {
8383
assert!(!CursorPositionFilter.eval(&InternalEvent::Event(Event::Resize(10, 10))));

src/event/read.rs

+10-4
Original file line numberDiff line numberDiff line change
@@ -132,10 +132,16 @@ mod tests {
132132

133133
#[cfg(unix)]
134134
use super::super::filter::CursorPositionFilter;
135-
use super::{
136-
super::{filter::InternalEventFilter, Event},
137-
EventSource, InternalEvent, InternalEventReader,
138-
};
135+
use super::{super::Event, EventSource, Filter, InternalEvent, InternalEventReader};
136+
137+
#[derive(Debug, Clone)]
138+
pub(crate) struct InternalEventFilter;
139+
140+
impl Filter for InternalEventFilter {
141+
fn eval(&self, _: &InternalEvent) -> bool {
142+
true
143+
}
144+
}
139145

140146
#[test]
141147
fn test_poll_fails_without_event_source() {

src/event/sys/unix/parse.rs

+18-18
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ fn char_code_to_event(code: KeyCode) -> KeyEvent {
135135
}
136136

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

723-
if !buffer.ends_with(&[b'm']) && !buffer.ends_with(&[b'M']) {
723+
if !buffer.ends_with(b"m") && !buffer.ends_with(b"M") {
724724
return Ok(None);
725725
}
726726

src/lib.rs

-6
Original file line numberDiff line numberDiff line change
@@ -252,9 +252,3 @@ pub(crate) mod macros;
252252

253253
#[cfg(all(windows, not(feature = "windows")))]
254254
compile_error!("Compiling on Windows with \"windows\" feature disabled. Feature \"windows\" should only be disabled when project will never be compiled on Windows.");
255-
256-
#[cfg(all(winapi, not(feature = "winapi")))]
257-
compile_error!("Compiling on Windows with \"winapi\" feature disabled. Feature \"winapi\" should only be disabled when project will never be compiled on Windows.");
258-
259-
#[cfg(all(crossterm_winapi, not(feature = "crossterm_winapi")))]
260-
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.");

0 commit comments

Comments
 (0)