~ireas/rusty-man

730bca7a9e354bfec542cd678dd67a66bb0e454b — Robin Krahl 3 months ago 7f7d85f
Scroll by page on PageUp/PageDown in tui viewer

Previosuly, we would always scroll by five lines if the PageUp or
PageDown button is hit in the tui viewer.  With this patch, we customize
the scroll speed to one page (minus one line).
2 files changed, 27 insertions(+), 3 deletions(-)

M CHANGELOG.md
M src/viewer/tui/mod.rs
M CHANGELOG.md => CHANGELOG.md +1 -0
@@ 7,6 7,7 @@ SPDX-License-Identifier: MIT

## Unreleased

- Scroll by page on PageUp/PageDown in tui viewer.
- Bump MSRV to 1.45.0.

## v0.4.3 (2021-06-19)

M src/viewer/tui/mod.rs => src/viewer/tui/mod.rs +26 -3
@@ 7,7 7,7 @@ use std::convert;

use anyhow::Context as _;
use cursive::view::{Resizable as _, Scrollable as _};
use cursive::views::{Dialog, EditView, LinearLayout, PaddedView, Panel, SelectView, TextView};
use cursive::views::{Dialog, EditView, LinearLayout, OnEventView, PaddedView, Panel, SelectView, TextView};
use cursive::{event, theme, utils::markup};
use cursive_markup::MarkupView;



@@ 119,9 119,32 @@ impl<'s> TuiManRenderer<'s> {
    }

    fn into_view(self) -> impl cursive::View {
        use cursive::With as _;
        use cursive::view::scroll::Scroller as _;

        let title = format!("{} {}", self.doc_ty.name(), self.doc_name);
        let scroll = self.layout.scrollable().full_screen();
        Panel::new(scroll).title(title)
        let scroll = self.layout.scrollable();
        let wrapper = scroll
            .wrap_with(OnEventView::new)
            .on_pre_event_inner(event::Key::PageUp, |v, _| {
                let scroller = v.get_scroller_mut();
                if scroller.can_scroll_up() {
                    scroller.scroll_up(
                        scroller.last_outer_size().y.saturating_sub(1),
                    );
                }
                Some(event::EventResult::Consumed(None))
            })
            .on_pre_event_inner(event::Key::PageDown, |v, _| {
                let scroller = v.get_scroller_mut();
                if scroller.can_scroll_down() {
                    scroller.scroll_down(
                        scroller.last_outer_size().y.saturating_sub(1),
                    );
                }
                Some(event::EventResult::Consumed(None))
            });
        Panel::new(wrapper.full_screen()).title(title)
    }
}