diff --git a/README.md b/README.md index d5297ed..0761abd 100644 --- a/README.md +++ b/README.md @@ -147,7 +147,7 @@ rich "Hello [b]World[/b]!" --rule --rule-style "red" --rule-char "=" Add `--pager` to display the content with a built in pager application. -Scroll the pager with cursor keys, page up/down, home, end. Alternatively use the scrollbar which will be visible to the right of the terminal. +Scroll the pager with cursor keys, page up/down, home, end. Alternatively use the scrollbar which will be visible to the right of the terminal. Or use the vi navigation (j, k, ctrl_d, ctrl-u). ``` rich __main__.py -n -g --theme monokai --pager diff --git a/src/rich_cli/pager.py b/src/rich_cli/pager.py index 53d4ce3..419d3a0 100644 --- a/src/rich_cli/pager.py +++ b/src/rich_cli/pager.py @@ -59,8 +59,18 @@ async def on_load(self, event: events.Load) -> None: await self.bind("q", "quit", "Quit") async def on_key(self, event: events.Key) -> None: - if event.key == " ": + if event.key == "j": + self.body.scroll_up() + elif event.key == "k": + self.body.scroll_down() + elif event.key == " ": self.body.page_down() + elif event.key == "ctrl+u": + self.body.target_y -= self.body.size.height // 2 + self.body.animate("y", self.body.target_y, easing="out_cubic") + elif event.key == "ctrl+d": + self.body.target_y += self.body.size.height // 2 + self.body.animate("y", self.body.target_y, easing="out_cubic") async def on_mount(self, event: events.Mount) -> None: self.body = body = ScrollView(auto_width=True)