Skip to content

Commit

Permalink
fix warnings & lints
Browse files Browse the repository at this point in the history
  • Loading branch information
wfraser committed Jan 5, 2021
1 parent ee464d7 commit 1ee57ce
Show file tree
Hide file tree
Showing 10 changed files with 39 additions and 36 deletions.
10 changes: 2 additions & 8 deletions examples/newdemo.rs
Expand Up @@ -151,10 +151,7 @@ fn main() {
let char_index = visbuf_i as i32 - i;
let ch = if char_index >= 0 && char_index < message.len() as i32 {
let char_index = char_index as usize;
match message[char_index..char_index + 1].chars().next() {
Some(c) => c,
None => ' ',
}
message[char_index..char_index + 1].chars().next().unwrap_or(' ')
} else {
' '
};
Expand Down Expand Up @@ -237,10 +234,7 @@ fn wait_for_user(main_window: &Window) -> bool {
nocbreak(); // Reset the halfdelay() value
cbreak();

match ch {
Some(Input::Character('\x1B')) => true,
_ => false,
}
matches!(ch, Some(Input::Character('\x1B')))
}

fn sub_win_test(main_window: &Window, win: &Window) -> Result<(), i32> {
Expand Down
2 changes: 1 addition & 1 deletion examples/newtest.rs
Expand Up @@ -22,7 +22,7 @@ fn main() {

set_title("NewTest: tests various pancurses features");

mousemask(ALL_MOUSE_EVENTS, std::ptr::null_mut());
mousemask(ALL_MOUSE_EVENTS, None);

window.attrset(COLOR_PAIR(1));

Expand Down
2 changes: 2 additions & 0 deletions examples/rain.rs
@@ -1,3 +1,5 @@
#![allow(clippy::many_single_char_names)]

/// **************************************************************************
/// Copyright (c) 2002 Free Software Foundation, Inc. *
/// *
Expand Down
6 changes: 5 additions & 1 deletion src/attributes.rs
Expand Up @@ -72,6 +72,7 @@ impl Attributes {
}
attribute_setter!(set_dim, A_DIM);

#[cfg_attr(unix, allow(clippy::bad_bit_mask))]
pub fn is_leftline(&self) -> bool {
(self.raw & A_LEFTLINE) > 0
}
Expand All @@ -94,6 +95,7 @@ impl Attributes {
self.raw = 0
}

#[cfg_attr(unix, allow(clippy::bad_bit_mask))]
pub fn is_overline(&self) -> bool {
(self.raw & A_OVERLINE) > 0
}
Expand All @@ -104,11 +106,13 @@ impl Attributes {
}
attribute_setter!(set_reverse, A_REVERSE);

#[cfg_attr(unix, allow(clippy::bad_bit_mask))]
pub fn is_rightline(&self) -> bool {
(self.raw & A_RIGHTLINE) > 0
}
attribute_setter!(set_rightline, A_RIGHTLINE);

#[cfg_attr(unix, allow(clippy::bad_bit_mask))]
pub fn is_strikeout(&self) -> bool {
(self.raw & A_STRIKEOUT) > 0
}
Expand All @@ -124,7 +128,7 @@ impl Attributes {
}
pub fn set_color_pair(&mut self, color_pair: ColorPair) {
let color_chtype: chtype = color_pair.into();
self.raw = self.raw | color_chtype;
self.raw |= color_chtype;
self.color_pair = color_pair;
}
}
Expand Down
5 changes: 3 additions & 2 deletions src/lib.rs
Expand Up @@ -278,8 +278,9 @@ pub fn mouseinterval(interval: i32) -> i32 {
///
/// As a side effect, setting a zero mousemask may turn off the mouse pointer; setting a nonzero
/// mask may turn it on. Whether this happens is device-dependent.
pub fn mousemask(newmask: mmask_t, oldmask: *mut mmask_t) -> mmask_t {
unsafe { curses::mousemask(newmask, oldmask) }
pub fn mousemask(newmask: mmask_t, oldmask: Option<&mut mmask_t>) -> mmask_t {
let oldmask_ptr = oldmask.map(|x| x as *mut _).unwrap_or(std::ptr::null_mut());
unsafe { curses::mousemask(newmask, oldmask_ptr) }
}

/// Returns a character string corresponding to the key `code`.
Expand Down
14 changes: 7 additions & 7 deletions src/unix/constants.rs
Expand Up @@ -67,28 +67,28 @@ pub const COLOR_CYAN: i16 = 6;
pub const COLOR_WHITE: i16 = 7;

pub const A_ALTCHARSET: attr_t = (1u32 << (14u32 + NCURSES_ATTR_SHIFT)) as attr_t;
pub const A_ATTRIBUTES: attr_t = (!0u32 << (0u32 + NCURSES_ATTR_SHIFT)) as attr_t;
pub const A_ATTRIBUTES: attr_t = (!0u32 << NCURSES_ATTR_SHIFT) as attr_t;
pub const A_BLINK: attr_t = (1u32 << (11u32 + NCURSES_ATTR_SHIFT)) as attr_t;
pub const A_BOLD: attr_t = (1u32 << (13u32 + NCURSES_ATTR_SHIFT)) as attr_t;
pub const A_CHARTEXT: attr_t = (1u32 << (0u32 + NCURSES_ATTR_SHIFT)) as attr_t;
pub const A_COLOR: attr_t = ((((1u32) << 8) - 1u32) << (0u32 + NCURSES_ATTR_SHIFT)) as attr_t;
pub const A_CHARTEXT: attr_t = (1u32 << NCURSES_ATTR_SHIFT) as attr_t;
pub const A_COLOR: attr_t = ((((1u32) << 8) - 1u32) << NCURSES_ATTR_SHIFT) as attr_t;
pub const A_DIM: attr_t = (1u32 << (12u32 + NCURSES_ATTR_SHIFT)) as attr_t;
pub const A_ITALIC: attr_t = (1u32 << (23 + NCURSES_ATTR_SHIFT)) as attr_t;
pub const A_INVIS: attr_t = (1u32 << (15u32 + NCURSES_ATTR_SHIFT)) as attr_t;
pub const A_LEFTLINE: attr_t = 0; // Not supported on ncurses
pub const A_NORMAL: attr_t = 0u32 as attr_t;
pub const A_NORMAL: attr_t = 0;
pub const A_OVERLINE: attr_t = 0; // Not supported on ncurses
pub const A_REVERSE: attr_t = (1u32 << (10 + NCURSES_ATTR_SHIFT)) as attr_t;
pub const A_RIGHTLINE: attr_t = 0; // Not supported on ncurses
pub const A_STANDOUT: attr_t = (1u32 << (8 + NCURSES_ATTR_SHIFT)) as attr_t;
pub const A_STRIKEOUT: attr_t = 0; // Not supported on ncurses
pub const A_UNDERLINE: attr_t = (1u32 << (9 + NCURSES_ATTR_SHIFT)) as attr_t;

pub const KEY_RESIZE: i32 = 0632;
pub const KEY_RESIZE: i32 = 0o632;

pub const KEY_OFFSET: i32 = 0o0400;
pub const KEY_F15: i32 = (KEY_OFFSET + 0x17);
pub const KEY_EVENT: i32 = (KEY_OFFSET + 0o633);
pub const KEY_F15: i32 = KEY_OFFSET + 0x17;
pub const KEY_EVENT: i32 = KEY_OFFSET + 0o633;

pub const SPECIAL_KEY_CODES: [Input; 108] = [
Input::KeyCodeYes,
Expand Down
10 changes: 5 additions & 5 deletions src/unix/mod.rs
Expand Up @@ -92,14 +92,14 @@ pub fn _ungetch(input: &Input) -> i32 {
let mut utf8_buffer = [0; 4];
c.encode_utf8(&mut utf8_buffer)
.as_bytes()
.into_iter()
.iter()
.rev()
.map(|x| unsafe { ungetch(*x as c_int) })
.fold(0, |res, x| i32::min(res, x))
.fold(0, |res, x| res.min(x))
}
Input::Unknown(i) => unsafe { ungetch(i) },
specialKeyCode => {
for (i, skc) in SPECIAL_KEY_CODES.into_iter().enumerate() {
for (i, skc) in SPECIAL_KEY_CODES.iter().enumerate() {
if *skc == specialKeyCode {
let result = i as c_int + KEY_OFFSET;
if result <= KEY_F15 {
Expand Down Expand Up @@ -177,12 +177,12 @@ mod tests {
'ე', 'პ', 'ხ', 'இ', 'ங', 'க', 'ಬ', 'ಇ', 'ಲ', 'ಸ',
];

chars.into_iter().for_each(|c| {
chars.iter().for_each(|c| {
_ungetch(&Input::Character(*c));
assert_eq!(_wgetch(w).unwrap(), Input::Character(*c));
});

SPECIAL_KEY_CODES.into_iter().for_each(|i| {
SPECIAL_KEY_CODES.iter().for_each(|i| {
_ungetch(i);
assert_eq!(_wgetch(w).unwrap(), *i);
});
Expand Down
2 changes: 2 additions & 0 deletions src/window.rs
Expand Up @@ -95,6 +95,7 @@ impl Window {
}

/// Draw a border around the edges of the window.
#[allow(clippy::too_many_arguments)]
pub fn border<T: ToChtype>(
&self,
left_side: T,
Expand Down Expand Up @@ -164,6 +165,7 @@ impl Window {
/// "overlay", if TRUE, indicates that the copy is done non-destructively (as in overlay());
/// blanks in the source window are not copied to the destination window. When overlay is
/// FALSE, blanks are copied.
#[allow(clippy::too_many_arguments)]
pub fn copywin(
&self,
destination_window: &Window,
Expand Down
8 changes: 4 additions & 4 deletions src/windows/constants.rs
Expand Up @@ -35,10 +35,10 @@ pub const A_STRIKEOUT: chtype = 0x200 << PDC_CHARTEXT_BITS;
pub const A_UNDERLINE: chtype = 0x010 << PDC_CHARTEXT_BITS;

pub const KEY_OFFSET: i32 = 0xec00;
pub const KEY_F15: i32 = (KEY_OFFSET + 0x17);
pub const KEY_UNDO: i32 = (KEY_OFFSET + 0x96);
pub const KEY_RESIZE: i32 = (KEY_OFFSET + 0x122);
pub const KEY_MOUSE: i32 = (KEY_OFFSET + 0x11b);
pub const KEY_F15: i32 = KEY_OFFSET + 0x17;
pub const KEY_UNDO: i32 = KEY_OFFSET + 0x96;
pub const KEY_RESIZE: i32 = KEY_OFFSET + 0x122;
pub const KEY_MOUSE: i32 = KEY_OFFSET + 0x11b;

pub const KEY_NUMPAD_UP: i32 = 60610;
pub const KEY_NUMPAD_DOWN: i32 = 60616;
Expand Down
16 changes: 8 additions & 8 deletions src/windows/mod.rs
Expand Up @@ -151,13 +151,13 @@ pub fn _wgetch(w: *mut WINDOW) -> Option<Input> {
decode_utf16(iter::once(i as u16))
.map(|result| {
result
.map(|c| Input::Character(c))
.map(Input::Character)
.unwrap_or_else(|first_error| {
let trailing = unsafe { wgetch(w) };
let data = [i as u16, trailing as u16];
decode_utf16(data.into_iter().cloned())
decode_utf16(data.iter().cloned())
.map(|result| {
result.map(|c| Input::Character(c)).unwrap_or_else(
result.map(Input::Character).unwrap_or_else(
|second_error| {
warn!("Decoding input as UTF-16 failed. The two values that could not be decoded were {} and {}.", first_error.unpaired_surrogate(), second_error.unpaired_surrogate());
Input::Unknown(second_error.unpaired_surrogate() as i32)
Expand All @@ -180,16 +180,16 @@ pub fn _ungetch(input: &Input) -> i32 {
// Need to convert to UTF-16 since Rust chars are UTF-8 while PDCurses deals with UTF-16
let mut utf16_buffer = [0; 2];
c.encode_utf16(&mut utf16_buffer)
.into_iter()
.iter_mut()
.rev()
.map(|x| unsafe { PDC_ungetch(*x as c_int) })
.fold(0, |res, x| cmp::min(res, x))
.fold(0, cmp::min)
}
Input::Unknown(i) => unsafe { PDC_ungetch(i) },
Input::KeyResize => unsafe { PDC_ungetch(KEY_RESIZE) },
Input::KeyMouse => unsafe { PDC_ungetch(KEY_MOUSE) },
specialKeyCode => {
for (i, skc) in SPECIAL_KEY_CODES.into_iter().enumerate() {
for (i, skc) in SPECIAL_KEY_CODES.iter().enumerate() {
if *skc == specialKeyCode {
let result = i as c_int + KEY_OFFSET;
if result <= KEY_F15 {
Expand Down Expand Up @@ -237,12 +237,12 @@ mod tests {
'ე', 'პ', 'ხ', 'இ', 'ங', 'க', 'ಬ', 'ಇ', 'ಲ', 'ಸ',
];

chars.into_iter().for_each(|c| {
chars.iter().for_each(|c| {
_ungetch(&Input::Character(*c));
assert_eq!(_wgetch(w).unwrap(), Input::Character(*c));
});

SPECIAL_KEY_CODES.into_iter().for_each(|i| {
SPECIAL_KEY_CODES.iter().for_each(|i| {
_ungetch(i);
assert_eq!(_wgetch(w).unwrap(), *i);
});
Expand Down

0 comments on commit 1ee57ce

Please sign in to comment.