From e4cd68a4ebb59a3a6776f60f65c34609333e7b4c Mon Sep 17 00:00:00 2001 From: Alexandre Bury Date: Sat, 30 Dec 2017 23:03:42 +0100 Subject: [PATCH] Rustfmt --- examples/edit.rs | 7 +- examples/key_codes.rs | 1 - examples/list_view.rs | 20 +- examples/mines/main.rs | 1 - examples/slider.rs | 7 +- examples/terminal_default.rs | 2 - src/backend/blt.rs | 199 ++++++------- src/backend/curses/n.rs | 107 ++++--- src/backend/curses/pan.rs | 528 ++++++++++++++++++----------------- src/backend/termion.rs | 8 +- src/cursive.rs | 1 - src/direction.rs | 8 +- src/event.rs | 1 - src/lib.rs | 5 +- src/menu.rs | 9 +- src/printer.rs | 1 - src/theme.rs | 8 +- src/utils/lines_iterator.rs | 2 - src/utils/reader.rs | 1 - src/vec.rs | 1 - src/view/mod.rs | 18 +- src/view/scroll.rs | 3 - src/view/size_constraint.rs | 6 +- src/view/view_wrapper.rs | 12 +- src/views/button.rs | 2 - src/views/canvas.rs | 1 - src/views/checkbox.rs | 15 +- src/views/dialog.rs | 8 +- src/views/edit_view.rs | 14 +- src/views/linear_layout.rs | 7 +- src/views/list_view.rs | 8 +- src/views/menu_popup.rs | 21 +- src/views/mod.rs | 4 +- src/views/panel.rs | 1 - src/views/progress_bar.rs | 3 - src/views/radio.rs | 15 +- src/views/select_view.rs | 1 - src/views/stack_view.rs | 15 +- src/views/text_area.rs | 9 +- src/views/text_view.rs | 2 + src/with.rs | 1 - 41 files changed, 526 insertions(+), 557 deletions(-) diff --git a/examples/edit.rs b/examples/edit.rs index 92a1495..bd95b22 100644 --- a/examples/edit.rs +++ b/examples/edit.rs @@ -21,10 +21,9 @@ fn main() { .fixed_width(20), ) .button("Ok", |s| { - let name = s.call_on_id( - "name", - |view: &mut EditView| view.get_content(), - ).unwrap(); + let name = s.call_on_id("name", |view: &mut EditView| { + view.get_content() + }).unwrap(); show_popup(s, &name); }), ); diff --git a/examples/key_codes.rs b/examples/key_codes.rs index 7ea8f65..83c3032 100644 --- a/examples/key_codes.rs +++ b/examples/key_codes.rs @@ -4,7 +4,6 @@ use cursive::{Cursive, Printer}; use cursive::event::{Event, EventResult}; use cursive::traits::*; - fn main() { let mut siv = Cursive::new(); diff --git a/examples/list_view.rs b/examples/list_view.rs index a4e074a..ed70491 100644 --- a/examples/list_view.rs +++ b/examples/list_view.rs @@ -17,16 +17,16 @@ fn main() { .child("Name", EditView::new().fixed_width(10)) .child( "Receive spam?", - Checkbox::new().on_change( - |s, checked| for name in &["email1", "email2"] { + Checkbox::new().on_change(|s, checked| { + for name in &["email1", "email2"] { s.call_on_id(name, |view: &mut EditView| { view.set_enabled(checked) }); if checked { s.focus_id("email1").unwrap(); } - }, - ), + } + }), ) .child( "Email", @@ -55,11 +55,13 @@ fn main() { .item_str("31-40") .item_str("41+"), ) - .with(|list| for i in 0..50 { - list.add_child( - &format!("Item {}", i), - EditView::new(), - ); + .with(|list| { + for i in 0..50 { + list.add_child( + &format!("Item {}", i), + EditView::new(), + ); + } }), ), ); diff --git a/examples/mines/main.rs b/examples/mines/main.rs index 63eeb68..b797495 100644 --- a/examples/mines/main.rs +++ b/examples/mines/main.rs @@ -31,7 +31,6 @@ fn main() { siv.run(); } - fn show_options(siv: &mut Cursive) { siv.add_layer( Dialog::new() diff --git a/examples/slider.rs b/examples/slider.rs index b4b0d78..305a981 100644 --- a/examples/slider.rs +++ b/examples/slider.rs @@ -16,10 +16,9 @@ fn main() { .value(7) .on_change(|s, v| { let title = format!("[ {} ]", v); - s.call_on_id( - "dialog", - |view: &mut Dialog| view.set_title(title), - ); + s.call_on_id("dialog", |view: &mut Dialog| { + view.set_title(title) + }); }) .on_enter(|s, v| { s.pop_layer(); diff --git a/examples/terminal_default.rs b/examples/terminal_default.rs index 2da9ac6..40ce736 100644 --- a/examples/terminal_default.rs +++ b/examples/terminal_default.rs @@ -1,11 +1,9 @@ extern crate cursive; - use cursive::Cursive; use cursive::theme::{Color, Theme}; use cursive::views::TextView; - fn custom_theme_from_cursive(siv: &Cursive) -> Theme { let mut theme = siv.current_theme().clone(); theme.colors.background = Color::TerminalDefault; diff --git a/src/backend/blt.rs b/src/backend/blt.rs index e246138..e3f2fbb 100644 --- a/src/backend/blt.rs +++ b/src/backend/blt.rs @@ -25,45 +25,45 @@ impl Concrete { &mut self, kc: KeyCode, shift: bool, ctrl: bool ) -> Event { match kc { - KeyCode::F1 | - KeyCode::F2 | - KeyCode::F3 | - KeyCode::F4 | - KeyCode::F5 | - KeyCode::F6 | - KeyCode::F7 | - KeyCode::F8 | - KeyCode::F9 | - KeyCode::F10 | - KeyCode::F11 | - KeyCode::F12 | - KeyCode::NumEnter | - KeyCode::Enter | - KeyCode::Escape | - KeyCode::Backspace | - KeyCode::Tab | - KeyCode::Pause | - KeyCode::Insert | - KeyCode::Home | - KeyCode::PageUp | - KeyCode::Delete | - KeyCode::End | - KeyCode::PageDown | - KeyCode::Right | - KeyCode::Left | - KeyCode::Down | - KeyCode::Up => match (shift, ctrl) { + KeyCode::F1 + | KeyCode::F2 + | KeyCode::F3 + | KeyCode::F4 + | KeyCode::F5 + | KeyCode::F6 + | KeyCode::F7 + | KeyCode::F8 + | KeyCode::F9 + | KeyCode::F10 + | KeyCode::F11 + | KeyCode::F12 + | KeyCode::NumEnter + | KeyCode::Enter + | KeyCode::Escape + | KeyCode::Backspace + | KeyCode::Tab + | KeyCode::Pause + | KeyCode::Insert + | KeyCode::Home + | KeyCode::PageUp + | KeyCode::Delete + | KeyCode::End + | KeyCode::PageDown + | KeyCode::Right + | KeyCode::Left + | KeyCode::Down + | KeyCode::Up => match (shift, ctrl) { (true, true) => Event::CtrlShift(blt_keycode_to_key(kc)), (true, false) => Event::Shift(blt_keycode_to_key(kc)), (false, true) => Event::Ctrl(blt_keycode_to_key(kc)), (false, false) => Event::Key(blt_keycode_to_key(kc)), }, // TODO: mouse support - KeyCode::MouseLeft | - KeyCode::MouseRight | - KeyCode::MouseMiddle | - KeyCode::MouseFourth | - KeyCode::MouseFifth => blt_keycode_to_mouse_button(kc) + KeyCode::MouseLeft + | KeyCode::MouseRight + | KeyCode::MouseMiddle + | KeyCode::MouseFourth + | KeyCode::MouseFifth => blt_keycode_to_mouse_button(kc) .map(|btn| { self.buttons_pressed.insert(btn); Event::Mouse { @@ -73,69 +73,69 @@ impl Concrete { } }) .unwrap_or(Event::Unknown(vec![])), - KeyCode::A | - KeyCode::B | - KeyCode::C | - KeyCode::D | - KeyCode::E | - KeyCode::F | - KeyCode::G | - KeyCode::H | - KeyCode::I | - KeyCode::J | - KeyCode::K | - KeyCode::L | - KeyCode::M | - KeyCode::N | - KeyCode::O | - KeyCode::P | - KeyCode::Q | - KeyCode::R | - KeyCode::S | - KeyCode::T | - KeyCode::U | - KeyCode::V | - KeyCode::W | - KeyCode::X | - KeyCode::Y | - KeyCode::Z | - KeyCode::Row1 | - KeyCode::Row2 | - KeyCode::Row3 | - KeyCode::Row4 | - KeyCode::Row5 | - KeyCode::Row6 | - KeyCode::Row7 | - KeyCode::Row8 | - KeyCode::Row9 | - KeyCode::Row0 | - KeyCode::Grave | - KeyCode::Minus | - KeyCode::Equals | - KeyCode::LeftBracket | - KeyCode::RightBracket | - KeyCode::Backslash | - KeyCode::Semicolon | - KeyCode::Apostrophe | - KeyCode::Comma | - KeyCode::Period | - KeyCode::Slash | - KeyCode::Space | - KeyCode::NumDivide | - KeyCode::NumMultiply | - KeyCode::NumMinus | - KeyCode::NumPlus | - KeyCode::NumPeriod | - KeyCode::Num1 | - KeyCode::Num2 | - KeyCode::Num3 | - KeyCode::Num4 | - KeyCode::Num5 | - KeyCode::Num6 | - KeyCode::Num7 | - KeyCode::Num8 | - KeyCode::Num9 | - KeyCode::Num0 => if ctrl { + KeyCode::A + | KeyCode::B + | KeyCode::C + | KeyCode::D + | KeyCode::E + | KeyCode::F + | KeyCode::G + | KeyCode::H + | KeyCode::I + | KeyCode::J + | KeyCode::K + | KeyCode::L + | KeyCode::M + | KeyCode::N + | KeyCode::O + | KeyCode::P + | KeyCode::Q + | KeyCode::R + | KeyCode::S + | KeyCode::T + | KeyCode::U + | KeyCode::V + | KeyCode::W + | KeyCode::X + | KeyCode::Y + | KeyCode::Z + | KeyCode::Row1 + | KeyCode::Row2 + | KeyCode::Row3 + | KeyCode::Row4 + | KeyCode::Row5 + | KeyCode::Row6 + | KeyCode::Row7 + | KeyCode::Row8 + | KeyCode::Row9 + | KeyCode::Row0 + | KeyCode::Grave + | KeyCode::Minus + | KeyCode::Equals + | KeyCode::LeftBracket + | KeyCode::RightBracket + | KeyCode::Backslash + | KeyCode::Semicolon + | KeyCode::Apostrophe + | KeyCode::Comma + | KeyCode::Period + | KeyCode::Slash + | KeyCode::Space + | KeyCode::NumDivide + | KeyCode::NumMultiply + | KeyCode::NumMinus + | KeyCode::NumPlus + | KeyCode::NumPeriod + | KeyCode::Num1 + | KeyCode::Num2 + | KeyCode::Num3 + | KeyCode::Num4 + | KeyCode::Num5 + | KeyCode::Num6 + | KeyCode::Num7 + | KeyCode::Num8 + | KeyCode::Num9 + | KeyCode::Num0 => if ctrl { Event::CtrlChar(blt_keycode_to_char(kc, shift)) } else { Event::Char(blt_keycode_to_char(kc, shift)) @@ -200,9 +200,10 @@ impl backend::Backend for Concrete { } fn clear(&self, color: Color) { - terminal::set_background( - colour_to_blt_colour(color, ColorRole::Background), - ); + terminal::set_background(colour_to_blt_colour( + color, + ColorRole::Background, + )); terminal::clear(None); } diff --git a/src/backend/curses/n.rs b/src/backend/curses/n.rs index adbca5d..6af47af 100644 --- a/src/backend/curses/n.rs +++ b/src/backend/curses/n.rs @@ -89,12 +89,10 @@ impl Concrete { | ncurses::BUTTON_CTRL) as mmask_t; - let make_event = |event| { - Event::Mouse { - offset: Vec2::zero(), - position: Vec2::new(mevent.x as usize, mevent.y as usize), - event: event, - } + let make_event = |event| Event::Mouse { + offset: Vec2::zero(), + position: Vec2::new(mevent.x as usize, mevent.y as usize), + event: event, }; if mevent.bstate == ncurses::REPORT_MOUSE_POSITION as mmask_t { @@ -214,7 +212,6 @@ impl backend::Backend for Concrete { ncurses::endwin(); } - fn with_color(&self, colors: ColorPair, f: F) { let current = self.current_style.get(); if current != colors { @@ -284,31 +281,31 @@ impl backend::Backend for Concrete { /// Returns the Key enum corresponding to the given ncurses event. fn get_mouse_button(bare_event: i32) -> MouseButton { match bare_event { - ncurses::BUTTON1_RELEASED | - ncurses::BUTTON1_PRESSED | - ncurses::BUTTON1_CLICKED | - ncurses::BUTTON1_DOUBLE_CLICKED | - ncurses::BUTTON1_TRIPLE_CLICKED => MouseButton::Left, - ncurses::BUTTON2_RELEASED | - ncurses::BUTTON2_PRESSED | - ncurses::BUTTON2_CLICKED | - ncurses::BUTTON2_DOUBLE_CLICKED | - ncurses::BUTTON2_TRIPLE_CLICKED => MouseButton::Middle, - ncurses::BUTTON3_RELEASED | - ncurses::BUTTON3_PRESSED | - ncurses::BUTTON3_CLICKED | - ncurses::BUTTON3_DOUBLE_CLICKED | - ncurses::BUTTON3_TRIPLE_CLICKED => MouseButton::Right, - ncurses::BUTTON4_RELEASED | - ncurses::BUTTON4_PRESSED | - ncurses::BUTTON4_CLICKED | - ncurses::BUTTON4_DOUBLE_CLICKED | - ncurses::BUTTON4_TRIPLE_CLICKED => MouseButton::Button4, - ncurses::BUTTON5_RELEASED | - ncurses::BUTTON5_PRESSED | - ncurses::BUTTON5_CLICKED | - ncurses::BUTTON5_DOUBLE_CLICKED | - ncurses::BUTTON5_TRIPLE_CLICKED => MouseButton::Button5, + ncurses::BUTTON1_RELEASED + | ncurses::BUTTON1_PRESSED + | ncurses::BUTTON1_CLICKED + | ncurses::BUTTON1_DOUBLE_CLICKED + | ncurses::BUTTON1_TRIPLE_CLICKED => MouseButton::Left, + ncurses::BUTTON2_RELEASED + | ncurses::BUTTON2_PRESSED + | ncurses::BUTTON2_CLICKED + | ncurses::BUTTON2_DOUBLE_CLICKED + | ncurses::BUTTON2_TRIPLE_CLICKED => MouseButton::Middle, + ncurses::BUTTON3_RELEASED + | ncurses::BUTTON3_PRESSED + | ncurses::BUTTON3_CLICKED + | ncurses::BUTTON3_DOUBLE_CLICKED + | ncurses::BUTTON3_TRIPLE_CLICKED => MouseButton::Right, + ncurses::BUTTON4_RELEASED + | ncurses::BUTTON4_PRESSED + | ncurses::BUTTON4_CLICKED + | ncurses::BUTTON4_DOUBLE_CLICKED + | ncurses::BUTTON4_TRIPLE_CLICKED => MouseButton::Button4, + ncurses::BUTTON5_RELEASED + | ncurses::BUTTON5_PRESSED + | ncurses::BUTTON5_CLICKED + | ncurses::BUTTON5_DOUBLE_CLICKED + | ncurses::BUTTON5_TRIPLE_CLICKED => MouseButton::Button5, _ => MouseButton::Other, } } @@ -328,36 +325,36 @@ where match bare_event { ncurses::BUTTON4_PRESSED => f(MouseEvent::WheelUp), ncurses::BUTTON5_PRESSED => f(MouseEvent::WheelDown), - ncurses::BUTTON1_RELEASED | - ncurses::BUTTON2_RELEASED | - ncurses::BUTTON3_RELEASED | - ncurses::BUTTON4_RELEASED | - ncurses::BUTTON5_RELEASED => f(MouseEvent::Release(button)), - ncurses::BUTTON1_PRESSED | - ncurses::BUTTON2_PRESSED | - ncurses::BUTTON3_PRESSED => f(MouseEvent::Press(button)), - ncurses::BUTTON1_CLICKED | - ncurses::BUTTON2_CLICKED | - ncurses::BUTTON3_CLICKED | - ncurses::BUTTON4_CLICKED | - ncurses::BUTTON5_CLICKED => { + ncurses::BUTTON1_RELEASED + | ncurses::BUTTON2_RELEASED + | ncurses::BUTTON3_RELEASED + | ncurses::BUTTON4_RELEASED + | ncurses::BUTTON5_RELEASED => f(MouseEvent::Release(button)), + ncurses::BUTTON1_PRESSED + | ncurses::BUTTON2_PRESSED + | ncurses::BUTTON3_PRESSED => f(MouseEvent::Press(button)), + ncurses::BUTTON1_CLICKED + | ncurses::BUTTON2_CLICKED + | ncurses::BUTTON3_CLICKED + | ncurses::BUTTON4_CLICKED + | ncurses::BUTTON5_CLICKED => { f(MouseEvent::Press(button)); f(MouseEvent::Release(button)); } // Well, we disabled click detection - ncurses::BUTTON1_DOUBLE_CLICKED | - ncurses::BUTTON2_DOUBLE_CLICKED | - ncurses::BUTTON3_DOUBLE_CLICKED | - ncurses::BUTTON4_DOUBLE_CLICKED | - ncurses::BUTTON5_DOUBLE_CLICKED => for _ in 0..2 { + ncurses::BUTTON1_DOUBLE_CLICKED + | ncurses::BUTTON2_DOUBLE_CLICKED + | ncurses::BUTTON3_DOUBLE_CLICKED + | ncurses::BUTTON4_DOUBLE_CLICKED + | ncurses::BUTTON5_DOUBLE_CLICKED => for _ in 0..2 { f(MouseEvent::Press(button)); f(MouseEvent::Release(button)); }, - ncurses::BUTTON1_TRIPLE_CLICKED | - ncurses::BUTTON2_TRIPLE_CLICKED | - ncurses::BUTTON3_TRIPLE_CLICKED | - ncurses::BUTTON4_TRIPLE_CLICKED | - ncurses::BUTTON5_TRIPLE_CLICKED => for _ in 0..3 { + ncurses::BUTTON1_TRIPLE_CLICKED + | ncurses::BUTTON2_TRIPLE_CLICKED + | ncurses::BUTTON3_TRIPLE_CLICKED + | ncurses::BUTTON4_TRIPLE_CLICKED + | ncurses::BUTTON5_TRIPLE_CLICKED => for _ in 0..3 { f(MouseEvent::Press(button)); f(MouseEvent::Release(button)); }, diff --git a/src/backend/curses/pan.rs b/src/backend/curses/pan.rs index 2c4499a..0040ca0 100644 --- a/src/backend/curses/pan.rs +++ b/src/backend/curses/pan.rs @@ -73,27 +73,20 @@ impl Concrete { Ok(event) => event, }; - let _shift = - (mevent.bstate & pancurses::BUTTON_SHIFT as mmask_t) != 0; - let _alt = - (mevent.bstate & pancurses::BUTTON_ALT as mmask_t) != 0; - let _ctrl = - (mevent.bstate & pancurses::BUTTON_CTRL as mmask_t) != 0; + let _shift = (mevent.bstate & pancurses::BUTTON_SHIFT as mmask_t) != 0; + let _alt = (mevent.bstate & pancurses::BUTTON_ALT as mmask_t) != 0; + let _ctrl = (mevent.bstate & pancurses::BUTTON_CTRL as mmask_t) != 0; mevent.bstate &= !(pancurses::BUTTON_SHIFT | pancurses::BUTTON_ALT - | pancurses::BUTTON_CTRL) - as mmask_t; + | pancurses::BUTTON_CTRL) as mmask_t; - let make_event = |event| { - Event::Mouse { - offset: Vec2::zero(), - position: Vec2::new(mevent.x as usize, mevent.y as usize), - event: event, - } + let make_event = |event| Event::Mouse { + offset: Vec2::zero(), + position: Vec2::new(mevent.x as usize, mevent.y as usize), + event: event, }; - if mevent.bstate == pancurses::REPORT_MOUSE_POSITION as mmask_t - { + if mevent.bstate == pancurses::REPORT_MOUSE_POSITION as mmask_t { // The event is either a mouse drag event, // or a weird double-release event. :S self.last_mouse_button @@ -221,206 +214,216 @@ impl backend::Backend for Concrete { fn poll_event(&mut self) -> Event { self.event_queue.pop().unwrap_or_else(|| { - if let Some(ev) = self.window.getch() { - match ev { - pancurses::Input::Character('\n') => Event::Key(Key::Enter), - // TODO: wait for a very short delay. If more keys are - // pipelined, it may be an escape sequence. - pancurses::Input::Character('\u{7f}') | - pancurses::Input::Character('\u{8}') => { - Event::Key(Key::Backspace) - } - pancurses::Input::Character('\u{9}') => Event::Key(Key::Tab), - pancurses::Input::Character('\u{1b}') => Event::Key(Key::Esc), - pancurses::Input::Character(c) - if 32 <= (c as u32) && (c as u32) <= 255 => - { - Event::Char( - utf8::read_char(c as u8, || { - self.window.getch().and_then(|i| match i { - pancurses::Input::Character(c) => { - Some(c as u8) - } - _ => None, - }) - }).unwrap(), - ) - } - pancurses::Input::Character(c) if (c as u32) <= 26 => { - Event::CtrlChar((b'a' - 1 + c as u8) as char) - } - pancurses::Input::Character(c) => { - let mut bytes = [0u8; 4]; - Event::Unknown( - c.encode_utf8(&mut bytes).as_bytes().to_vec(), - ) - } - // TODO: Some key combos are not recognized by pancurses, - // but are sent as Unknown. We could still parse them here. - pancurses::Input::Unknown(code) => match code { - 220 => Event::Ctrl(Key::Del), - - 224 => Event::Alt(Key::Down), - 225 => Event::AltShift(Key::Down), - 226 => Event::Ctrl(Key::Down), - 227 => Event::CtrlShift(Key::Down), - - 229 => Event::Alt(Key::End), - 230 => Event::AltShift(Key::End), - 231 => Event::Ctrl(Key::End), - 232 => Event::CtrlShift(Key::End), - - 235 => Event::Alt(Key::Home), - 236 => Event::AltShift(Key::Home), - 237 => Event::Ctrl(Key::Home), - 238 => Event::CtrlShift(Key::Home), - - 246 => Event::Alt(Key::Left), - 247 => Event::AltShift(Key::Left), - 248 => Event::Ctrl(Key::Left), - 249 => Event::CtrlShift(Key::Left), - - 251 => Event::Alt(Key::PageDown), - 252 => Event::AltShift(Key::PageDown), - 253 => Event::Ctrl(Key::PageDown), - 254 => Event::CtrlShift(Key::PageDown), - - 256 => Event::Alt(Key::PageUp), - 257 => Event::AltShift(Key::PageUp), - 258 => Event::Ctrl(Key::PageUp), - 259 => Event::CtrlShift(Key::PageUp), - - 261 => Event::Alt(Key::Right), - 262 => Event::AltShift(Key::Right), - 263 => Event::Ctrl(Key::Right), - 264 => Event::CtrlShift(Key::Right), - - 267 => Event::Alt(Key::Up), - 268 => Event::AltShift(Key::Up), - 269 => Event::Ctrl(Key::Up), - 270 => Event::CtrlShift(Key::Up), - other => { - warn!("Unknown: {}", other); - Event::Unknown(split_i32(other)) + if let Some(ev) = self.window.getch() { + match ev { + pancurses::Input::Character('\n') => { + Event::Key(Key::Enter) } - }, - // TODO: I honestly have no fucking idea what KeyCodeYes is - pancurses::Input::KeyCodeYes => Event::Refresh, - pancurses::Input::KeyBreak => Event::Key(Key::PauseBreak), - pancurses::Input::KeyDown => Event::Key(Key::Down), - pancurses::Input::KeyUp => Event::Key(Key::Up), - pancurses::Input::KeyLeft => Event::Key(Key::Left), - pancurses::Input::KeyRight => Event::Key(Key::Right), - pancurses::Input::KeyHome => Event::Key(Key::Home), - pancurses::Input::KeyBackspace => Event::Key(Key::Backspace), - pancurses::Input::KeyF0 => Event::Key(Key::F0), - pancurses::Input::KeyF1 => Event::Key(Key::F1), - pancurses::Input::KeyF2 => Event::Key(Key::F2), - pancurses::Input::KeyF3 => Event::Key(Key::F3), - pancurses::Input::KeyF4 => Event::Key(Key::F4), - pancurses::Input::KeyF5 => Event::Key(Key::F5), - pancurses::Input::KeyF6 => Event::Key(Key::F6), - pancurses::Input::KeyF7 => Event::Key(Key::F7), - pancurses::Input::KeyF8 => Event::Key(Key::F8), - pancurses::Input::KeyF9 => Event::Key(Key::F9), - pancurses::Input::KeyF10 => Event::Key(Key::F10), - pancurses::Input::KeyF11 => Event::Key(Key::F11), - pancurses::Input::KeyF12 => Event::Key(Key::F12), - pancurses::Input::KeyF13 => Event::Shift(Key::F1), - pancurses::Input::KeyF14 => Event::Shift(Key::F2), - pancurses::Input::KeyF15 => Event::Shift(Key::F3), - pancurses::Input::KeyDL => Event::Refresh, - pancurses::Input::KeyIL => Event::Refresh, - pancurses::Input::KeyDC => Event::Key(Key::Del), - pancurses::Input::KeyIC => Event::Key(Key::Ins), - pancurses::Input::KeyEIC => Event::Refresh, - pancurses::Input::KeyClear => Event::Refresh, - pancurses::Input::KeyEOS => Event::Refresh, - pancurses::Input::KeyEOL => Event::Refresh, - pancurses::Input::KeySF => Event::Shift(Key::Down), - pancurses::Input::KeySR => Event::Shift(Key::Up), - pancurses::Input::KeyNPage => Event::Key(Key::PageDown), - pancurses::Input::KeyPPage => Event::Key(Key::PageUp), - pancurses::Input::KeySTab => Event::Shift(Key::Tab), - pancurses::Input::KeyCTab => Event::Ctrl(Key::Tab), - pancurses::Input::KeyCATab => Event::CtrlAlt(Key::Tab), - pancurses::Input::KeyEnter => Event::Key(Key::Enter), - pancurses::Input::KeySReset => Event::Refresh, - pancurses::Input::KeyReset => Event::Refresh, - pancurses::Input::KeyPrint => Event::Refresh, - pancurses::Input::KeyLL => Event::Refresh, - pancurses::Input::KeyAbort => Event::Refresh, - pancurses::Input::KeySHelp => Event::Refresh, - pancurses::Input::KeyLHelp => Event::Refresh, - pancurses::Input::KeyBTab => Event::Shift(Key::Tab), - pancurses::Input::KeyBeg => Event::Refresh, - pancurses::Input::KeyCancel => Event::Refresh, - pancurses::Input::KeyClose => Event::Refresh, - pancurses::Input::KeyCommand => Event::Refresh, - pancurses::Input::KeyCopy => Event::Refresh, - pancurses::Input::KeyCreate => Event::Refresh, - pancurses::Input::KeyEnd => Event::Key(Key::End), - pancurses::Input::KeyExit => Event::Refresh, - pancurses::Input::KeyFind => Event::Refresh, - pancurses::Input::KeyHelp => Event::Refresh, - pancurses::Input::KeyMark => Event::Refresh, - pancurses::Input::KeyMessage => Event::Refresh, - pancurses::Input::KeyMove => Event::Refresh, - pancurses::Input::KeyNext => Event::Refresh, - pancurses::Input::KeyOpen => Event::Refresh, - pancurses::Input::KeyOptions => Event::Refresh, - pancurses::Input::KeyPrevious => Event::Refresh, - pancurses::Input::KeyRedo => Event::Refresh, - pancurses::Input::KeyReference => Event::Refresh, - pancurses::Input::KeyRefresh => Event::Refresh, - pancurses::Input::KeyReplace => Event::Refresh, - pancurses::Input::KeyRestart => Event::Refresh, - pancurses::Input::KeyResume => Event::Refresh, - pancurses::Input::KeySave => Event::Refresh, - pancurses::Input::KeySBeg => Event::Refresh, - pancurses::Input::KeySCancel => Event::Refresh, - pancurses::Input::KeySCommand => Event::Refresh, - pancurses::Input::KeySCopy => Event::Refresh, - pancurses::Input::KeySCreate => Event::Refresh, - pancurses::Input::KeySDC => Event::Shift(Key::Del), - pancurses::Input::KeySDL => Event::Refresh, - pancurses::Input::KeySelect => Event::Refresh, - pancurses::Input::KeySEnd => Event::Shift(Key::End), - pancurses::Input::KeySEOL => Event::Refresh, - pancurses::Input::KeySExit => Event::Refresh, - pancurses::Input::KeySFind => Event::Refresh, - pancurses::Input::KeySHome => Event::Shift(Key::Home), - pancurses::Input::KeySIC => Event::Shift(Key::Ins), - pancurses::Input::KeySLeft => Event::Shift(Key::Left), - pancurses::Input::KeySMessage => Event::Refresh, - pancurses::Input::KeySMove => Event::Refresh, - pancurses::Input::KeySNext => Event::Shift(Key::PageDown), - pancurses::Input::KeySOptions => Event::Refresh, - pancurses::Input::KeySPrevious => Event::Shift(Key::PageUp), - pancurses::Input::KeySPrint => Event::Refresh, - pancurses::Input::KeySRedo => Event::Refresh, - pancurses::Input::KeySReplace => Event::Refresh, - pancurses::Input::KeySRight => Event::Shift(Key::Right), - pancurses::Input::KeySResume => Event::Refresh, - pancurses::Input::KeySSave => Event::Refresh, - pancurses::Input::KeySSuspend => Event::Refresh, - pancurses::Input::KeySUndo => Event::Refresh, - pancurses::Input::KeySuspend => Event::Refresh, - pancurses::Input::KeyUndo => Event::Refresh, - pancurses::Input::KeyResize => Event::WindowResize, - pancurses::Input::KeyEvent => Event::Refresh, - // TODO: mouse support - pancurses::Input::KeyMouse => self.parse_mouse_event(), - pancurses::Input::KeyA1 => Event::Refresh, - pancurses::Input::KeyA3 => Event::Refresh, - pancurses::Input::KeyB2 => Event::Key(Key::NumpadCenter), - pancurses::Input::KeyC1 => Event::Refresh, - pancurses::Input::KeyC3 => Event::Refresh, + // TODO: wait for a very short delay. If more keys are + // pipelined, it may be an escape sequence. + pancurses::Input::Character('\u{7f}') + | pancurses::Input::Character('\u{8}') => { + Event::Key(Key::Backspace) + } + pancurses::Input::Character('\u{9}') => { + Event::Key(Key::Tab) + } + pancurses::Input::Character('\u{1b}') => { + Event::Key(Key::Esc) + } + pancurses::Input::Character(c) + if 32 <= (c as u32) && (c as u32) <= 255 => + { + Event::Char( + utf8::read_char(c as u8, || { + self.window.getch().and_then(|i| match i { + pancurses::Input::Character(c) => { + Some(c as u8) + } + _ => None, + }) + }).unwrap(), + ) + } + pancurses::Input::Character(c) if (c as u32) <= 26 => { + Event::CtrlChar((b'a' - 1 + c as u8) as char) + } + pancurses::Input::Character(c) => { + let mut bytes = [0u8; 4]; + Event::Unknown( + c.encode_utf8(&mut bytes).as_bytes().to_vec(), + ) + } + // TODO: Some key combos are not recognized by pancurses, + // but are sent as Unknown. We could still parse them here. + pancurses::Input::Unknown(code) => match code { + 220 => Event::Ctrl(Key::Del), + + 224 => Event::Alt(Key::Down), + 225 => Event::AltShift(Key::Down), + 226 => Event::Ctrl(Key::Down), + 227 => Event::CtrlShift(Key::Down), + + 229 => Event::Alt(Key::End), + 230 => Event::AltShift(Key::End), + 231 => Event::Ctrl(Key::End), + 232 => Event::CtrlShift(Key::End), + + 235 => Event::Alt(Key::Home), + 236 => Event::AltShift(Key::Home), + 237 => Event::Ctrl(Key::Home), + 238 => Event::CtrlShift(Key::Home), + + 246 => Event::Alt(Key::Left), + 247 => Event::AltShift(Key::Left), + 248 => Event::Ctrl(Key::Left), + 249 => Event::CtrlShift(Key::Left), + + 251 => Event::Alt(Key::PageDown), + 252 => Event::AltShift(Key::PageDown), + 253 => Event::Ctrl(Key::PageDown), + 254 => Event::CtrlShift(Key::PageDown), + + 256 => Event::Alt(Key::PageUp), + 257 => Event::AltShift(Key::PageUp), + 258 => Event::Ctrl(Key::PageUp), + 259 => Event::CtrlShift(Key::PageUp), + + 261 => Event::Alt(Key::Right), + 262 => Event::AltShift(Key::Right), + 263 => Event::Ctrl(Key::Right), + 264 => Event::CtrlShift(Key::Right), + + 267 => Event::Alt(Key::Up), + 268 => Event::AltShift(Key::Up), + 269 => Event::Ctrl(Key::Up), + 270 => Event::CtrlShift(Key::Up), + other => { + warn!("Unknown: {}", other); + Event::Unknown(split_i32(other)) + } + }, + // TODO: I honestly have no fucking idea what KeyCodeYes is + pancurses::Input::KeyCodeYes => Event::Refresh, + pancurses::Input::KeyBreak => Event::Key(Key::PauseBreak), + pancurses::Input::KeyDown => Event::Key(Key::Down), + pancurses::Input::KeyUp => Event::Key(Key::Up), + pancurses::Input::KeyLeft => Event::Key(Key::Left), + pancurses::Input::KeyRight => Event::Key(Key::Right), + pancurses::Input::KeyHome => Event::Key(Key::Home), + pancurses::Input::KeyBackspace => { + Event::Key(Key::Backspace) + } + pancurses::Input::KeyF0 => Event::Key(Key::F0), + pancurses::Input::KeyF1 => Event::Key(Key::F1), + pancurses::Input::KeyF2 => Event::Key(Key::F2), + pancurses::Input::KeyF3 => Event::Key(Key::F3), + pancurses::Input::KeyF4 => Event::Key(Key::F4), + pancurses::Input::KeyF5 => Event::Key(Key::F5), + pancurses::Input::KeyF6 => Event::Key(Key::F6), + pancurses::Input::KeyF7 => Event::Key(Key::F7), + pancurses::Input::KeyF8 => Event::Key(Key::F8), + pancurses::Input::KeyF9 => Event::Key(Key::F9), + pancurses::Input::KeyF10 => Event::Key(Key::F10), + pancurses::Input::KeyF11 => Event::Key(Key::F11), + pancurses::Input::KeyF12 => Event::Key(Key::F12), + pancurses::Input::KeyF13 => Event::Shift(Key::F1), + pancurses::Input::KeyF14 => Event::Shift(Key::F2), + pancurses::Input::KeyF15 => Event::Shift(Key::F3), + pancurses::Input::KeyDL => Event::Refresh, + pancurses::Input::KeyIL => Event::Refresh, + pancurses::Input::KeyDC => Event::Key(Key::Del), + pancurses::Input::KeyIC => Event::Key(Key::Ins), + pancurses::Input::KeyEIC => Event::Refresh, + pancurses::Input::KeyClear => Event::Refresh, + pancurses::Input::KeyEOS => Event::Refresh, + pancurses::Input::KeyEOL => Event::Refresh, + pancurses::Input::KeySF => Event::Shift(Key::Down), + pancurses::Input::KeySR => Event::Shift(Key::Up), + pancurses::Input::KeyNPage => Event::Key(Key::PageDown), + pancurses::Input::KeyPPage => Event::Key(Key::PageUp), + pancurses::Input::KeySTab => Event::Shift(Key::Tab), + pancurses::Input::KeyCTab => Event::Ctrl(Key::Tab), + pancurses::Input::KeyCATab => Event::CtrlAlt(Key::Tab), + pancurses::Input::KeyEnter => Event::Key(Key::Enter), + pancurses::Input::KeySReset => Event::Refresh, + pancurses::Input::KeyReset => Event::Refresh, + pancurses::Input::KeyPrint => Event::Refresh, + pancurses::Input::KeyLL => Event::Refresh, + pancurses::Input::KeyAbort => Event::Refresh, + pancurses::Input::KeySHelp => Event::Refresh, + pancurses::Input::KeyLHelp => Event::Refresh, + pancurses::Input::KeyBTab => Event::Shift(Key::Tab), + pancurses::Input::KeyBeg => Event::Refresh, + pancurses::Input::KeyCancel => Event::Refresh, + pancurses::Input::KeyClose => Event::Refresh, + pancurses::Input::KeyCommand => Event::Refresh, + pancurses::Input::KeyCopy => Event::Refresh, + pancurses::Input::KeyCreate => Event::Refresh, + pancurses::Input::KeyEnd => Event::Key(Key::End), + pancurses::Input::KeyExit => Event::Refresh, + pancurses::Input::KeyFind => Event::Refresh, + pancurses::Input::KeyHelp => Event::Refresh, + pancurses::Input::KeyMark => Event::Refresh, + pancurses::Input::KeyMessage => Event::Refresh, + pancurses::Input::KeyMove => Event::Refresh, + pancurses::Input::KeyNext => Event::Refresh, + pancurses::Input::KeyOpen => Event::Refresh, + pancurses::Input::KeyOptions => Event::Refresh, + pancurses::Input::KeyPrevious => Event::Refresh, + pancurses::Input::KeyRedo => Event::Refresh, + pancurses::Input::KeyReference => Event::Refresh, + pancurses::Input::KeyRefresh => Event::Refresh, + pancurses::Input::KeyReplace => Event::Refresh, + pancurses::Input::KeyRestart => Event::Refresh, + pancurses::Input::KeyResume => Event::Refresh, + pancurses::Input::KeySave => Event::Refresh, + pancurses::Input::KeySBeg => Event::Refresh, + pancurses::Input::KeySCancel => Event::Refresh, + pancurses::Input::KeySCommand => Event::Refresh, + pancurses::Input::KeySCopy => Event::Refresh, + pancurses::Input::KeySCreate => Event::Refresh, + pancurses::Input::KeySDC => Event::Shift(Key::Del), + pancurses::Input::KeySDL => Event::Refresh, + pancurses::Input::KeySelect => Event::Refresh, + pancurses::Input::KeySEnd => Event::Shift(Key::End), + pancurses::Input::KeySEOL => Event::Refresh, + pancurses::Input::KeySExit => Event::Refresh, + pancurses::Input::KeySFind => Event::Refresh, + pancurses::Input::KeySHome => Event::Shift(Key::Home), + pancurses::Input::KeySIC => Event::Shift(Key::Ins), + pancurses::Input::KeySLeft => Event::Shift(Key::Left), + pancurses::Input::KeySMessage => Event::Refresh, + pancurses::Input::KeySMove => Event::Refresh, + pancurses::Input::KeySNext => Event::Shift(Key::PageDown), + pancurses::Input::KeySOptions => Event::Refresh, + pancurses::Input::KeySPrevious => { + Event::Shift(Key::PageUp) + } + pancurses::Input::KeySPrint => Event::Refresh, + pancurses::Input::KeySRedo => Event::Refresh, + pancurses::Input::KeySReplace => Event::Refresh, + pancurses::Input::KeySRight => Event::Shift(Key::Right), + pancurses::Input::KeySResume => Event::Refresh, + pancurses::Input::KeySSave => Event::Refresh, + pancurses::Input::KeySSuspend => Event::Refresh, + pancurses::Input::KeySUndo => Event::Refresh, + pancurses::Input::KeySuspend => Event::Refresh, + pancurses::Input::KeyUndo => Event::Refresh, + pancurses::Input::KeyResize => Event::WindowResize, + pancurses::Input::KeyEvent => Event::Refresh, + // TODO: mouse support + pancurses::Input::KeyMouse => self.parse_mouse_event(), + pancurses::Input::KeyA1 => Event::Refresh, + pancurses::Input::KeyA3 => Event::Refresh, + pancurses::Input::KeyB2 => Event::Key(Key::NumpadCenter), + pancurses::Input::KeyC1 => Event::Refresh, + pancurses::Input::KeyC3 => Event::Refresh, + } + } else { + Event::Refresh } - } else { - Event::Refresh - } - }) + }) } fn set_refresh_rate(&mut self, fps: u32) { @@ -447,36 +450,36 @@ where match bare_event { pancurses::BUTTON4_PRESSED => f(MouseEvent::WheelUp), pancurses::BUTTON5_PRESSED => f(MouseEvent::WheelDown), - pancurses::BUTTON1_RELEASED | - pancurses::BUTTON2_RELEASED | - pancurses::BUTTON3_RELEASED | - pancurses::BUTTON4_RELEASED | - pancurses::BUTTON5_RELEASED => f(MouseEvent::Release(button)), - pancurses::BUTTON1_PRESSED | - pancurses::BUTTON2_PRESSED | - pancurses::BUTTON3_PRESSED => f(MouseEvent::Press(button)), - pancurses::BUTTON1_CLICKED | - pancurses::BUTTON2_CLICKED | - pancurses::BUTTON3_CLICKED | - pancurses::BUTTON4_CLICKED | - pancurses::BUTTON5_CLICKED => { + pancurses::BUTTON1_RELEASED + | pancurses::BUTTON2_RELEASED + | pancurses::BUTTON3_RELEASED + | pancurses::BUTTON4_RELEASED + | pancurses::BUTTON5_RELEASED => f(MouseEvent::Release(button)), + pancurses::BUTTON1_PRESSED + | pancurses::BUTTON2_PRESSED + | pancurses::BUTTON3_PRESSED => f(MouseEvent::Press(button)), + pancurses::BUTTON1_CLICKED + | pancurses::BUTTON2_CLICKED + | pancurses::BUTTON3_CLICKED + | pancurses::BUTTON4_CLICKED + | pancurses::BUTTON5_CLICKED => { f(MouseEvent::Press(button)); f(MouseEvent::Release(button)); } // Well, we disabled click detection - pancurses::BUTTON1_DOUBLE_CLICKED | - pancurses::BUTTON2_DOUBLE_CLICKED | - pancurses::BUTTON3_DOUBLE_CLICKED | - pancurses::BUTTON4_DOUBLE_CLICKED | - pancurses::BUTTON5_DOUBLE_CLICKED => for _ in 0..2 { + pancurses::BUTTON1_DOUBLE_CLICKED + | pancurses::BUTTON2_DOUBLE_CLICKED + | pancurses::BUTTON3_DOUBLE_CLICKED + | pancurses::BUTTON4_DOUBLE_CLICKED + | pancurses::BUTTON5_DOUBLE_CLICKED => for _ in 0..2 { f(MouseEvent::Press(button)); f(MouseEvent::Release(button)); }, - pancurses::BUTTON1_TRIPLE_CLICKED | - pancurses::BUTTON2_TRIPLE_CLICKED | - pancurses::BUTTON3_TRIPLE_CLICKED | - pancurses::BUTTON4_TRIPLE_CLICKED | - pancurses::BUTTON5_TRIPLE_CLICKED => for _ in 0..3 { + pancurses::BUTTON1_TRIPLE_CLICKED + | pancurses::BUTTON2_TRIPLE_CLICKED + | pancurses::BUTTON3_TRIPLE_CLICKED + | pancurses::BUTTON4_TRIPLE_CLICKED + | pancurses::BUTTON5_TRIPLE_CLICKED => for _ in 0..3 { f(MouseEvent::Press(button)); f(MouseEvent::Release(button)); }, @@ -487,32 +490,31 @@ where /// Returns the Key enum corresponding to the given pancurses event. fn get_mouse_button(bare_event: mmask_t) -> MouseButton { match bare_event { - pancurses::BUTTON1_RELEASED | - pancurses::BUTTON1_PRESSED | - pancurses::BUTTON1_CLICKED | - pancurses::BUTTON1_DOUBLE_CLICKED | - pancurses::BUTTON1_TRIPLE_CLICKED => MouseButton::Left, - pancurses::BUTTON2_RELEASED | - pancurses::BUTTON2_PRESSED | - pancurses::BUTTON2_CLICKED | - pancurses::BUTTON2_DOUBLE_CLICKED | - pancurses::BUTTON2_TRIPLE_CLICKED => MouseButton::Middle, - pancurses::BUTTON3_RELEASED | - pancurses::BUTTON3_PRESSED | - pancurses::BUTTON3_CLICKED | - pancurses::BUTTON3_DOUBLE_CLICKED | - pancurses::BUTTON3_TRIPLE_CLICKED => MouseButton::Right, - pancurses::BUTTON4_RELEASED | - pancurses::BUTTON4_PRESSED | - pancurses::BUTTON4_CLICKED | - pancurses::BUTTON4_DOUBLE_CLICKED | - pancurses::BUTTON4_TRIPLE_CLICKED => MouseButton::Button4, - pancurses::BUTTON5_RELEASED | - pancurses::BUTTON5_PRESSED | - pancurses::BUTTON5_CLICKED | - pancurses::BUTTON5_DOUBLE_CLICKED | - pancurses::BUTTON5_TRIPLE_CLICKED => MouseButton::Button5, + pancurses::BUTTON1_RELEASED + | pancurses::BUTTON1_PRESSED + | pancurses::BUTTON1_CLICKED + | pancurses::BUTTON1_DOUBLE_CLICKED + | pancurses::BUTTON1_TRIPLE_CLICKED => MouseButton::Left, + pancurses::BUTTON2_RELEASED + | pancurses::BUTTON2_PRESSED + | pancurses::BUTTON2_CLICKED + | pancurses::BUTTON2_DOUBLE_CLICKED + | pancurses::BUTTON2_TRIPLE_CLICKED => MouseButton::Middle, + pancurses::BUTTON3_RELEASED + | pancurses::BUTTON3_PRESSED + | pancurses::BUTTON3_CLICKED + | pancurses::BUTTON3_DOUBLE_CLICKED + | pancurses::BUTTON3_TRIPLE_CLICKED => MouseButton::Right, + pancurses::BUTTON4_RELEASED + | pancurses::BUTTON4_PRESSED + | pancurses::BUTTON4_CLICKED + | pancurses::BUTTON4_DOUBLE_CLICKED + | pancurses::BUTTON4_TRIPLE_CLICKED => MouseButton::Button4, + pancurses::BUTTON5_RELEASED + | pancurses::BUTTON5_PRESSED + | pancurses::BUTTON5_CLICKED + | pancurses::BUTTON5_DOUBLE_CLICKED + | pancurses::BUTTON5_TRIPLE_CLICKED => MouseButton::Button5, _ => MouseButton::Other, } } - diff --git a/src/backend/termion.rs b/src/backend/termion.rs index bfeac22..7ecf2e1 100644 --- a/src/backend/termion.rs +++ b/src/backend/termion.rs @@ -143,9 +143,11 @@ impl backend::Backend for Concrete { let (sender, receiver) = chan::async(); - thread::spawn(move || for key in ::std::io::stdin().events() { - if let Ok(key) = key { - sender.send(key) + thread::spawn(move || { + for key in ::std::io::stdin().events() { + if let Ok(key) = key { + sender.send(key) + } } }); diff --git a/src/cursive.rs b/src/cursive.rs index f86e102..36eb92d 100644 --- a/src/cursive.rs +++ b/src/cursive.rs @@ -464,7 +464,6 @@ impl Cursive { self.running } - /// Runs the event loop. /// /// It will wait for user input (key presses) diff --git a/src/direction.rs b/src/direction.rs index 1fdf36d..55f71fa 100644 --- a/src/direction.rs +++ b/src/direction.rs @@ -198,10 +198,10 @@ impl Absolute { /// orientation (ex: `Left` and `Vertical`). pub fn relative(self, orientation: Orientation) -> Option { match (orientation, self) { - (Orientation::Horizontal, Absolute::Left) | - (Orientation::Vertical, Absolute::Up) => Some(Relative::Front), - (Orientation::Horizontal, Absolute::Right) | - (Orientation::Vertical, Absolute::Down) => Some(Relative::Back), + (Orientation::Horizontal, Absolute::Left) + | (Orientation::Vertical, Absolute::Up) => Some(Relative::Front), + (Orientation::Horizontal, Absolute::Right) + | (Orientation::Vertical, Absolute::Down) => Some(Relative::Back), _ => None, } } diff --git a/src/event.rs b/src/event.rs index e0d8314..3dce04b 100644 --- a/src/event.rs +++ b/src/event.rs @@ -13,7 +13,6 @@ //! [global callback](../struct.Cursive.html#method.add_global_callback) //! table is checked. - use Cursive; use std::ops::Deref; use std::rc::Rc; diff --git a/src/lib.rs b/src/lib.rs index ef30853..1536244 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -59,10 +59,10 @@ //! Or you can use gdb as usual. #![deny(missing_docs)] -#[macro_use] -extern crate maplit; #[macro_use] extern crate log; +#[macro_use] +extern crate maplit; extern crate num; extern crate owning_ref; extern crate toml; @@ -109,7 +109,6 @@ mod utf8; #[doc(hidden)] pub mod backend; - pub use cursive::{Cursive, ScreenId}; pub use printer::Printer; pub use with::With; diff --git a/src/menu.rs b/src/menu.rs index 6cd04c2..7dac3b7 100644 --- a/src/menu.rs +++ b/src/menu.rs @@ -113,7 +113,6 @@ impl MenuTree { .insert(i, MenuItem::Leaf(title, Callback::from_fn(cb))); } - /// Adds a actionnable leaf to the end of this tree - chainable variant. pub fn leaf(self, title: S, cb: F) -> Self where @@ -173,13 +172,13 @@ impl MenuTree { /// Returns `None` if the given title was not found, /// or if it wasn't a subtree. pub fn find_subtree(&mut self, title: &str) -> Option<&mut MenuTree> { - self.find_item(title).and_then( - |item| if let MenuItem::Subtree(_, ref mut tree) = *item { + self.find_item(title).and_then(|item| { + if let MenuItem::Subtree(_, ref mut tree) = *item { Some(Rc::make_mut(tree)) } else { None - }, - ) + } + }) } /// Removes the item at the given position. diff --git a/src/printer.rs b/src/printer.rs index 0eaa642..c2537c2 100644 --- a/src/printer.rs +++ b/src/printer.rs @@ -1,6 +1,5 @@ //! Makes drawing on ncurses windows easier. - use backend::{self, Backend}; use std::cell::Cell; use std::cmp::min; diff --git a/src/theme.rs b/src/theme.rs index e74400c..357cb3f 100644 --- a/src/theme.rs +++ b/src/theme.rs @@ -517,9 +517,11 @@ impl Color { let rgb: Vec<_> = value.chars().map(|c| c as i16 - '0' as i16).collect(); if rgb.iter().all(|&i| i >= 0 && i < 6) { - Some( - Color::RgbLowRes(rgb[0] as u8, rgb[1] as u8, rgb[2] as u8), - ) + Some(Color::RgbLowRes( + rgb[0] as u8, + rgb[1] as u8, + rgb[2] as u8, + )) } else { None } diff --git a/src/utils/lines_iterator.rs b/src/utils/lines_iterator.rs index ccf7090..1441b1b 100644 --- a/src/utils/lines_iterator.rs +++ b/src/utils/lines_iterator.rs @@ -1,5 +1,3 @@ - - use With; use unicode_segmentation::UnicodeSegmentation; use unicode_width::UnicodeWidthStr; diff --git a/src/utils/reader.rs b/src/utils/reader.rs index 07a5b11..056ccea 100644 --- a/src/utils/reader.rs +++ b/src/utils/reader.rs @@ -10,7 +10,6 @@ pub struct ProgressReader { counter: Counter, } - impl ProgressReader { /// Creates a new `ProgressReader` around `reader`. /// diff --git a/src/vec.rs b/src/vec.rs index e7bcb1d..9e5e605 100644 --- a/src/vec.rs +++ b/src/vec.rs @@ -320,7 +320,6 @@ impl> Sub for Vec4 { } } - impl Div for Vec4 { type Output = Vec4; diff --git a/src/view/mod.rs b/src/view/mod.rs index e804a2f..76fd604 100644 --- a/src/view/mod.rs +++ b/src/view/mod.rs @@ -49,7 +49,6 @@ mod scroll; mod identifiable; mod boxable; - pub use self::boxable::Boxable; pub use self::identifiable::Identifiable; pub use self::position::{Offset, Position}; @@ -182,14 +181,15 @@ impl Finder for T { let result_ref = &mut result; let mut callback = Some(callback); - let callback = |v: &mut Any| if let Some(callback) = - callback.take() - { - if v.is::() { - *result_ref = v.downcast_mut::().map(|v| callback(v)); - } else if v.is::>() { - *result_ref = v.downcast_mut::>() - .and_then(|v| v.with_view_mut(callback)); + let callback = |v: &mut Any| { + if let Some(callback) = callback.take() { + if v.is::() { + *result_ref = + v.downcast_mut::().map(|v| callback(v)); + } else if v.is::>() { + *result_ref = v.downcast_mut::>() + .and_then(|v| v.with_view_mut(callback)); + } } }; self.call_on_any(sel, Box::new(callback)); diff --git a/src/view/scroll.rs b/src/view/scroll.rs index dc882fb..55c701c 100644 --- a/src/view/scroll.rs +++ b/src/view/scroll.rs @@ -178,7 +178,6 @@ impl ScrollBase { return false; } - // Now, did we hit the thumb? Or should we direct-jump? let height = self.scrollbar_thumb_height(); let thumb_y = self.scrollbar_thumb_y(height); @@ -218,7 +217,6 @@ impl ScrollBase { self.thumb_grab = None; } - /// Draws the scroll bar and the content using the given drawer. /// /// `line_drawer` will be called once for each line that needs to be drawn. @@ -269,7 +267,6 @@ impl ScrollBase { ); } - // And draw the scrollbar if needed if self.view_height < self.content_height { // We directly compute the size of the scrollbar diff --git a/src/view/size_constraint.rs b/src/view/size_constraint.rs index 3461776..569c025 100644 --- a/src/view/size_constraint.rs +++ b/src/view/size_constraint.rs @@ -25,9 +25,9 @@ impl SizeConstraint { /// When `available` is offered to the `BoxView`. pub fn available(self, available: usize) -> usize { match self { - SizeConstraint::Free | - SizeConstraint::Full | - SizeConstraint::AtLeast(_) => available, + SizeConstraint::Free + | SizeConstraint::Full + | SizeConstraint::AtLeast(_) => available, // If the available space is too small, always give in. SizeConstraint::Fixed(value) | SizeConstraint::AtMost(value) => { min(value, available) diff --git a/src/view/view_wrapper.rs b/src/view/view_wrapper.rs index 0426e5b..91f1dbd 100644 --- a/src/view/view_wrapper.rs +++ b/src/view/view_wrapper.rs @@ -34,7 +34,6 @@ pub trait ViewWrapper: 'static { where F: FnOnce(&mut Self::V) -> R; - /// Attempts to retrieve the inner view. fn into_inner(self) -> Result where @@ -74,9 +73,7 @@ pub trait ViewWrapper: 'static { /// Wraps the `find` method. fn wrap_call_on_any<'a>( - &mut self, - selector: &Selector, - callback: Box, + &mut self, selector: &Selector, callback: Box ) { self.with_view_mut(|v| v.call_on_any(selector, callback)); } @@ -96,7 +93,8 @@ pub trait ViewWrapper: 'static { // Some types easily implement ViewWrapper. // This includes Box use std::ops::{Deref, DerefMut}; -impl + DerefMut + 'static> ViewWrapper for T { +impl + DerefMut + 'static> ViewWrapper + for T { type V = U; fn with_view(&self, f: F) -> Option @@ -137,9 +135,7 @@ impl View for T { } fn call_on_any<'a>( - &mut self, - selector: &Selector, - callback: Box, + &mut self, selector: &Selector, callback: Box ) { self.wrap_call_on_any(selector, callback) } diff --git a/src/views/button.rs b/src/views/button.rs index 5cf4258..6d087b3 100644 --- a/src/views/button.rs +++ b/src/views/button.rs @@ -1,5 +1,3 @@ - - use {Cursive, Printer, With}; use align::HAlign; use direction::Direction; diff --git a/src/views/canvas.rs b/src/views/canvas.rs index 63788ca..8d5d7af 100644 --- a/src/views/canvas.rs +++ b/src/views/canvas.rs @@ -161,7 +161,6 @@ impl Canvas { self.needs_relayout = Box::new(f); } - /// Sets the closure for `needs_relayout()`. /// /// Chainable variant. diff --git a/src/views/checkbox.rs b/src/views/checkbox.rs index 282bb64..8f4a4d9 100644 --- a/src/views/checkbox.rs +++ b/src/views/checkbox.rs @@ -8,7 +8,6 @@ use theme::ColorStyle; use vec::Vec2; use view::View; - /// Checkable box. pub struct Checkbox { checked: bool, @@ -116,15 +115,13 @@ impl View for Checkbox { fn draw(&self, printer: &Printer) { if self.enabled { - printer.with_selection( - printer.focused, - |printer| self.draw_internal(printer), - ); + printer.with_selection(printer.focused, |printer| { + self.draw_internal(printer) + }); } else { - printer.with_color( - ColorStyle::Secondary, - |printer| self.draw_internal(printer), - ); + printer.with_color(ColorStyle::Secondary, |printer| { + self.draw_internal(printer) + }); } } diff --git a/src/views/dialog.rs b/src/views/dialog.rs index e656e1a..63a610b 100644 --- a/src/views/dialog.rs +++ b/src/views/dialog.rs @@ -216,7 +216,6 @@ impl Dialog { self } - // Private methods // An event is received while the content is in focus @@ -373,10 +372,9 @@ impl Dialog { printer.print((x + len, 0), " ├"); }); - printer.with_color( - ColorStyle::TitlePrimary, - |p| p.print((x, 0), &self.title), - ); + printer.with_color(ColorStyle::TitlePrimary, |p| { + p.print((x, 0), &self.title) + }); } } diff --git a/src/views/edit_view.rs b/src/views/edit_view.rs index 06e1a94..8e47d08 100644 --- a/src/views/edit_view.rs +++ b/src/views/edit_view.rs @@ -1,5 +1,3 @@ - - use {Cursive, Printer, With}; use direction::Direction; use event::{Callback, Event, EventResult, Key, MouseEvent}; @@ -188,7 +186,6 @@ impl EditView { self.style = style; } - /// Sets the style used for this view. /// /// When the view is enabled, the style will be reversed. @@ -278,11 +275,11 @@ impl EditView { // Instead, have some generic function immutify() // or something that wraps a FnMut closure. let callback = RefCell::new(callback); - self.set_on_submit( - move |s, text| if let Ok(mut f) = callback.try_borrow_mut() { + self.set_on_submit(move |s, text| { + if let Ok(mut f) = callback.try_borrow_mut() { (&mut *f)(s, text); - }, - ); + } + }); } /// Sets a callback to be called when `` is pressed. @@ -516,8 +513,7 @@ impl View for EditView { .next() .expect(&format!( "Found no char at cursor {} in {}", - self.cursor, - &self.content + self.cursor, &self.content )); if self.secret { make_small_stars(selected.width()) diff --git a/src/views/linear_layout.rs b/src/views/linear_layout.rs index aaf1a4d..22fa701 100644 --- a/src/views/linear_layout.rs +++ b/src/views/linear_layout.rs @@ -192,7 +192,11 @@ impl LinearLayout { ) -> Box + 'a> { match source { direction::Relative::Front => { - let start = if from_focus { self.focus } else { 0 }; + let start = if from_focus { + self.focus + } else { + 0 + }; Box::new(self.children.iter_mut().enumerate().skip(start)) } @@ -347,7 +351,6 @@ impl View for LinearLayout { let ideal = self.orientation.stack(ideal_sizes.iter()); debug!("Ideal result: {:?}", ideal); - // Does it fit? if ideal.fits_in(req) { // Champagne! diff --git a/src/views/list_view.rs b/src/views/list_view.rs index 05d68e4..8c60b56 100644 --- a/src/views/list_view.rs +++ b/src/views/list_view.rs @@ -73,7 +73,6 @@ impl ListView { self.children.is_empty() } - /// Returns a reference to the children pub fn children(&self) -> &[ListChild] { &self.children[..] @@ -155,7 +154,11 @@ impl ListView { ) -> Box + 'a> { match source { direction::Relative::Front => { - let start = if from_focus { self.focus } else { 0 }; + let start = if from_focus { + self.focus + } else { + 0 + }; Box::new(self.children.iter_mut().enumerate().skip(start)) } @@ -365,7 +368,6 @@ impl View for ListView { _ => (), } - // Then: some events can move the focus around. self.check_focus_grab(&event); diff --git a/src/views/menu_popup.rs b/src/views/menu_popup.rs index d31bfad..365ec13 100644 --- a/src/views/menu_popup.rs +++ b/src/views/menu_popup.rs @@ -87,7 +87,6 @@ impl MenuPopup { } } - /// Sets the alignment for this view. /// /// Chainable variant. @@ -152,8 +151,8 @@ impl MenuPopup { let action_cb = action_cb.clone(); s.screen_mut().add_layer_at( Position::parent(offset), - OnEventView::new( - MenuPopup::new(Rc::clone(&tree)).on_action(move |s| { + OnEventView::new(MenuPopup::new(Rc::clone(&tree)).on_action( + move |s| { // This will happen when the subtree popup // activates something; // First, remove ourselve. @@ -161,8 +160,8 @@ impl MenuPopup { if let Some(ref action_cb) = action_cb { action_cb.clone()(s); } - }), - ).on_event(Key::Left, |s| s.pop_layer()), + }, + )).on_event(Key::Left, |s| s.pop_layer()), ); }) } @@ -258,7 +257,6 @@ impl View for MenuPopup { .unwrap_or(1); let h = 2 + self.menu.children.len(); - let scrolling = req.y < h; let w = if scrolling { w + 1 } else { w }; @@ -346,10 +344,13 @@ impl View for MenuPopup { position.checked_sub(offset + (1, 1)).map( // `position` is not relative to the content // (It's inside the border) - |position| if position < inner_size { - let focus = position.y + self.scrollbase.start_line; - if !self.menu.children[focus].is_delimiter() { - self.focus = focus; + |position| { + if position < inner_size { + let focus = + position.y + self.scrollbase.start_line; + if !self.menu.children[focus].is_delimiter() { + self.focus = focus; + } } }, ); diff --git a/src/views/mod.rs b/src/views/mod.rs index 8d0a358..ec9372c 100644 --- a/src/views/mod.rs +++ b/src/views/mod.rs @@ -82,7 +82,7 @@ pub use self::select_view::SelectView; pub use self::shadow_view::ShadowView; pub use self::sized_view::SizedView; pub use self::slider_view::SliderView; -pub use self::stack_view::{StackView, LayerPosition}; +pub use self::stack_view::{LayerPosition, StackView}; pub use self::text_area::TextArea; -pub use self::text_view::{TextView, TextContent, TextContentRef}; +pub use self::text_view::{TextContent, TextContentRef, TextView}; pub use self::tracked_view::TrackedView; diff --git a/src/views/panel.rs b/src/views/panel.rs index d75a97c..8ef9b04 100644 --- a/src/views/panel.rs +++ b/src/views/panel.rs @@ -16,7 +16,6 @@ impl Panel { } } - impl ViewWrapper for Panel { wrap_impl!(self.view: V); diff --git a/src/views/progress_bar.rs b/src/views/progress_bar.rs index ea7fde9..3ba06b5 100644 --- a/src/views/progress_bar.rs +++ b/src/views/progress_bar.rs @@ -1,5 +1,3 @@ - - use Printer; use align::HAlign; use std::cmp; @@ -68,7 +66,6 @@ pub struct ProgressBar { label_maker: Box String>, } - fn make_percentage(value: usize, (min, max): (usize, usize)) -> String { if value < min { // ?? Negative progress? diff --git a/src/views/radio.rs b/src/views/radio.rs index 6c975cc..dacd009 100644 --- a/src/views/radio.rs +++ b/src/views/radio.rs @@ -100,7 +100,6 @@ pub struct RadioButton { label: String, } - impl RadioButton { impl_enabled!(self.enabled); @@ -165,15 +164,13 @@ impl View for RadioButton { fn draw(&self, printer: &Printer) { if self.enabled { - printer.with_selection( - printer.focused, - |printer| self.draw_internal(printer), - ); + printer.with_selection(printer.focused, |printer| { + self.draw_internal(printer) + }); } else { - printer.with_color( - ColorStyle::Secondary, - |printer| self.draw_internal(printer), - ); + printer.with_color(ColorStyle::Secondary, |printer| { + self.draw_internal(printer) + }); } } diff --git a/src/views/select_view.rs b/src/views/select_view.rs index 7c106ef..942f4a7 100644 --- a/src/views/select_view.rs +++ b/src/views/select_view.rs @@ -175,7 +175,6 @@ impl SelectView { self.with(|s| s.set_on_submit(cb)) } - /// Sets the alignment for this view. pub fn align(mut self, align: Align) -> Self { self.align = align; diff --git a/src/views/stack_view.rs b/src/views/stack_view.rs index fbf84a5..72adb2e 100644 --- a/src/views/stack_view.rs +++ b/src/views/stack_view.rs @@ -255,7 +255,7 @@ impl StackView { } /// Moves a layer to a new position in the stack. - /// + /// /// This only affects the elevation of a layer (whether it is drawn over /// or under other views). pub fn move_layer(&mut self, from: LayerPosition, to: LayerPosition) { @@ -266,11 +266,7 @@ impl StackView { let removed = self.layers.remove(from_i); // Shift the position if needed - let to_i = if to_i > from_i { - to_i - 1 - } else { - to_i - }; + let to_i = if to_i > from_i { to_i - 1 } else { to_i }; self.layers.insert(to_i, removed); } @@ -333,8 +329,11 @@ impl View for StackView { StackPositionIterator::new(self.layers.iter(), printer.size) .enumerate() { - v.view - .draw(&printer.sub_printer(offset, v.size, i + 1 == last)); + v.view.draw(&printer.sub_printer( + offset, + v.size, + i + 1 == last, + )); } }); } diff --git a/src/views/text_area.rs b/src/views/text_area.rs index 61ade0f..6eb730e 100644 --- a/src/views/text_area.rs +++ b/src/views/text_area.rs @@ -423,12 +423,11 @@ impl View for TextArea { } else { printer.size.x }; - printer.with_effect( - effect, - |printer| for y in 0..printer.size.y { + printer.with_effect(effect, |printer| { + for y in 0..printer.size.y { printer.print_hline((0, y), w, " "); - }, - ); + } + }); debug!("Content: `{}`", &self.content); self.scrollbase.draw(printer, |printer, i| { diff --git a/src/views/text_view.rs b/src/views/text_view.rs index 4430c2f..3752b4b 100644 --- a/src/views/text_view.rs +++ b/src/views/text_view.rs @@ -33,6 +33,8 @@ impl TextContent { /// A reference to the text content. /// +/// It implements `Deref`. +/// /// This keeps the content locked. Do not store this! pub struct TextContentRef { handle: OwningHandle< diff --git a/src/with.rs b/src/with.rs index dcb1b47..da86497 100644 --- a/src/with.rs +++ b/src/with.rs @@ -1,4 +1,3 @@ - /// Generic trait to enable chainable API pub trait With: Sized { /// Calls the given closure on `self`.