diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e806d35..2cfe94b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -48,6 +48,7 @@ jobs: uses: actions-rs/cargo@v1 with: command: clippy + args: --all-targets --all-features -- -D warnings windows: name: Windows runs-on: windows-latest diff --git a/Makefile b/Makefile index 2a1e79e..ab680d9 100644 --- a/Makefile +++ b/Makefile @@ -52,7 +52,7 @@ fmt: ## Check the format of the source code .PHONY: clippy clippy: ## Check the style of the source code and catch common errors - $(CARGO) clippy --all-features + $(CARGO) clippy --all-targets --all-features -- -D warnings # ================================ Test ======================================= diff --git a/examples/block.rs b/examples/block.rs index 22b852e..4c9bed0 100644 --- a/examples/block.rs +++ b/examples/block.rs @@ -75,13 +75,10 @@ fn main() -> Result<(), Box> { } })?; - match events.next()? { - Event::Input(key) => { - if key == Key::Char('q') { - break; - } + if let Event::Input(key) = events.next()? { + if key == Key::Char('q') { + break; } - _ => {} } } Ok(()) diff --git a/examples/curses_demo.rs b/examples/curses_demo.rs index 93068ab..3dd4a8c 100644 --- a/examples/curses_demo.rs +++ b/examples/curses_demo.rs @@ -4,7 +4,6 @@ mod util; use crate::demo::{ui, App}; use argh::FromArgs; -use easycurses; use std::{ error::Error, io, @@ -26,7 +25,8 @@ struct Cli { fn main() -> Result<(), Box> { let cli: Cli = argh::from_env(); - let mut backend = CursesBackend::new().ok_or(io::Error::new(io::ErrorKind::Other, ""))?; + let mut backend = + CursesBackend::new().ok_or_else(|| io::Error::new(io::ErrorKind::Other, ""))?; let curses = backend.get_curses_mut(); curses.set_echo(false); curses.set_input_timeout(easycurses::TimeoutMode::WaitUpTo(50)); @@ -41,28 +41,25 @@ fn main() -> Result<(), Box> { let tick_rate = Duration::from_millis(cli.tick_rate); loop { terminal.draw(|mut f| ui::draw(&mut f, &mut app))?; - match terminal.backend_mut().get_curses_mut().get_input() { - Some(input) => { - match input { - easycurses::Input::Character(c) => { - app.on_key(c); - } - easycurses::Input::KeyUp => { - app.on_up(); - } - easycurses::Input::KeyDown => { - app.on_down(); - } - easycurses::Input::KeyLeft => { - app.on_left(); - } - easycurses::Input::KeyRight => { - app.on_right(); - } - _ => {} - }; - } - _ => {} + if let Some(input) = terminal.backend_mut().get_curses_mut().get_input() { + match input { + easycurses::Input::Character(c) => { + app.on_key(c); + } + easycurses::Input::KeyUp => { + app.on_up(); + } + easycurses::Input::KeyDown => { + app.on_down(); + } + easycurses::Input::KeyLeft => { + app.on_left(); + } + easycurses::Input::KeyRight => { + app.on_right(); + } + _ => {} + }; }; terminal.backend_mut().get_curses_mut().flush_input(); if last_tick.elapsed() > tick_rate { diff --git a/examples/custom_widget.rs b/examples/custom_widget.rs index 909f0df..b9dd7e3 100644 --- a/examples/custom_widget.rs +++ b/examples/custom_widget.rs @@ -48,13 +48,10 @@ fn main() -> Result<(), Box> { f.render_widget(label, size); })?; - match events.next()? { - Event::Input(key) => { - if key == Key::Char('q') { - break; - } + if let Event::Input(key) = events.next()? { + if key == Key::Char('q') { + break; } - _ => {} } } diff --git a/examples/demo/app.rs b/examples/demo/app.rs index 4f880c1..94ba869 100644 --- a/examples/demo/app.rs +++ b/examples/demo/app.rs @@ -1,12 +1,12 @@ use crate::util::{RandomSignal, SinSignal, StatefulList, TabsState}; -const TASKS: [&'static str; 24] = [ +const TASKS: [&str; 24] = [ "Item1", "Item2", "Item3", "Item4", "Item5", "Item6", "Item7", "Item8", "Item9", "Item10", "Item11", "Item12", "Item13", "Item14", "Item15", "Item16", "Item17", "Item18", "Item19", "Item20", "Item21", "Item22", "Item23", "Item24", ]; -const LOGS: [(&'static str, &'static str); 26] = [ +const LOGS: [(&str, &str); 26] = [ ("Event1", "INFO"), ("Event2", "INFO"), ("Event3", "CRITICAL"), @@ -35,7 +35,7 @@ const LOGS: [(&'static str, &'static str); 26] = [ ("Event26", "INFO"), ]; -const EVENTS: [(&'static str, u64); 24] = [ +const EVENTS: [(&str, u64); 24] = [ ("B1", 9), ("B2", 12), ("B3", 5), diff --git a/examples/layout.rs b/examples/layout.rs index b98d760..16b11b6 100644 --- a/examples/layout.rs +++ b/examples/layout.rs @@ -42,13 +42,10 @@ fn main() -> Result<(), Box> { f.render_widget(block, chunks[2]); })?; - match events.next()? { - Event::Input(input) => { - if let Key::Char('q') = input { - break; - } + if let Event::Input(input) = events.next()? { + if let Key::Char('q') = input { + break; } - _ => {} } } diff --git a/examples/paragraph.rs b/examples/paragraph.rs index c0fe5b3..89fb21a 100644 --- a/examples/paragraph.rs +++ b/examples/paragraph.rs @@ -94,13 +94,10 @@ fn main() -> Result<(), Box> { scroll += 1; scroll %= 10; - match events.next()? { - Event::Input(key) => { - if key == Key::Char('q') { - break; - } + if let Event::Input(key) = events.next()? { + if key == Key::Char('q') { + break; } - _ => {} } } Ok(()) diff --git a/examples/popup.rs b/examples/popup.rs index 3c12979..55504a8 100644 --- a/examples/popup.rs +++ b/examples/popup.rs @@ -97,13 +97,10 @@ fn main() -> Result<(), Box> { f.render_widget(block, area); })?; - match events.next()? { - Event::Input(input) => { - if let Key::Char('q') = input { - break; - } + if let Event::Input(input) = events.next()? { + if let Key::Char('q') = input { + break; } - _ => {} } } diff --git a/examples/rustbox_demo.rs b/examples/rustbox_demo.rs index 72d0601..d65d5b0 100644 --- a/examples/rustbox_demo.rs +++ b/examples/rustbox_demo.rs @@ -35,8 +35,10 @@ fn main() -> Result<(), Box> { let tick_rate = Duration::from_millis(cli.tick_rate); loop { terminal.draw(|mut f| ui::draw(&mut f, &mut app))?; - match terminal.backend().rustbox().peek_event(tick_rate, false) { - Ok(rustbox::Event::KeyEvent(key)) => match key { + if let Ok(rustbox::Event::KeyEvent(key)) = + terminal.backend().rustbox().peek_event(tick_rate, false) + { + match key { Key::Char(c) => { app.on_key(c); } @@ -53,8 +55,7 @@ fn main() -> Result<(), Box> { app.on_right(); } _ => {} - }, - _ => {} + } } if last_tick.elapsed() > tick_rate { app.on_tick(); diff --git a/examples/table.rs b/examples/table.rs index 13dbf17..6990407 100644 --- a/examples/table.rs +++ b/examples/table.rs @@ -100,7 +100,7 @@ fn main() -> Result<(), Box> { let rows = table .items .iter() - .map(|i| Row::StyledData(i.into_iter(), normal_style)); + .map(|i| Row::StyledData(i.iter(), normal_style)); let t = Table::new(header.iter(), rows) .block(Block::default().borders(Borders::ALL).title("Table")) .highlight_style(selected_style) @@ -113,8 +113,8 @@ fn main() -> Result<(), Box> { f.render_stateful_widget(t, rects[0], &mut table.state); })?; - match events.next()? { - Event::Input(key) => match key { + if let Event::Input(key) = events.next()? { + match key { Key::Char('q') => { break; } @@ -125,8 +125,7 @@ fn main() -> Result<(), Box> { table.previous(); } _ => {} - }, - _ => {} + } }; } diff --git a/examples/tabs.rs b/examples/tabs.rs index 4a1a02f..9bf97bf 100644 --- a/examples/tabs.rs +++ b/examples/tabs.rs @@ -64,16 +64,15 @@ fn main() -> Result<(), Box> { f.render_widget(inner, chunks[1]); })?; - match events.next()? { - Event::Input(input) => match input { + if let Event::Input(input) = events.next()? { + match input { Key::Char('q') => { break; } Key::Right => app.tabs.next(), Key::Left => app.tabs.previous(), _ => {} - }, - _ => {} + } } } Ok(()) diff --git a/examples/user_input.rs b/examples/user_input.rs index a639062..fb42bcf 100644 --- a/examples/user_input.rs +++ b/examples/user_input.rs @@ -118,8 +118,8 @@ fn main() -> Result<(), Box> { io::stdout().flush().ok(); // Handle input - match events.next()? { - Event::Input(input) => match app.input_mode { + if let Event::Input(input) = events.next()? { + match app.input_mode { InputMode::Normal => match input { Key::Char('e') => { app.input_mode = InputMode::Editing; @@ -146,8 +146,7 @@ fn main() -> Result<(), Box> { } _ => {} }, - }, - _ => {} + } } } Ok(()) diff --git a/examples/util/event.rs b/examples/util/event.rs index 5094c0a..536553e 100644 --- a/examples/util/event.rs +++ b/examples/util/event.rs @@ -53,28 +53,22 @@ impl Events { thread::spawn(move || { let stdin = io::stdin(); for evt in stdin.keys() { - match evt { - Ok(key) => { - if let Err(_) = tx.send(Event::Input(key)) { - return; - } - if !ignore_exit_key.load(Ordering::Relaxed) && key == config.exit_key { - return; - } + if let Ok(key) = evt { + if let Err(err) = tx.send(Event::Input(key)) { + eprintln!("{}", err); + return; + } + if !ignore_exit_key.load(Ordering::Relaxed) && key == config.exit_key { + return; } - Err(_) => {} } } }) }; let tick_handle = { - let tx = tx.clone(); - thread::spawn(move || { - let tx = tx.clone(); - loop { - tx.send(Event::Tick).unwrap(); - thread::sleep(config.tick_rate); - } + thread::spawn(move || loop { + tx.send(Event::Tick).unwrap(); + thread::sleep(config.tick_rate); }) }; Events { diff --git a/examples/util/mod.rs b/examples/util/mod.rs index 3167b05..c926b3a 100644 --- a/examples/util/mod.rs +++ b/examples/util/mod.rs @@ -93,7 +93,7 @@ impl StatefulList { pub fn with_items(items: Vec) -> StatefulList { StatefulList { state: ListState::default(), - items: items, + items, } } diff --git a/src/lib.rs b/src/lib.rs index cf9119d..8139ed1 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -145,8 +145,6 @@ //! you might need a blank space somewhere, try to pass an additional constraint and don't use the //! corresponding area. -#![deny(warnings)] - pub mod backend; pub mod buffer; pub mod layout; diff --git a/tests/chart.rs b/tests/chart.rs index ec083cf..53c8446 100644 --- a/tests/chart.rs +++ b/tests/chart.rs @@ -47,15 +47,15 @@ fn handles_overflow() { .marker(symbols::Marker::Braille) .style(Style::default().fg(Color::Magenta)) .data(&[ - (1588298471.0, 1.0), - (1588298473.0, 0.0), - (1588298496.0, 1.0), + (1_588_298_471.0, 1.0), + (1_588_298_473.0, 0.0), + (1_588_298_496.0, 1.0), ])]; let chart = Chart::default() .block(Block::default().title("Plot").borders(Borders::ALL)) .x_axis( Axis::default() - .bounds([1588298471.0, 1588992600.0]) + .bounds([1_588_298_471.0, 1_588_992_600.0]) .labels(&["1588298471.0", "1588992600.0"]), ) .y_axis(Axis::default().bounds([0.0, 1.0]).labels(&["0.0", "1.0"])) diff --git a/tests/list.rs b/tests/list.rs index 2dd5c02..98309f7 100644 --- a/tests/list.rs +++ b/tests/list.rs @@ -73,7 +73,7 @@ fn it_should_truncate_items() { let items = case.items.drain(..); terminal .draw(|mut f| { - let list = List::new(items.into_iter()) + let list = List::new(items) .block(Block::default().borders(Borders::RIGHT)) .highlight_symbol(">> "); f.render_stateful_widget(list, Rect::new(0, 0, 8, 2), &mut state);