Skip to content

Add some vi-style navigation to the pager. #44

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 11 additions & 1 deletion src/rich_cli/pager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down