Skip to content

Commit

Permalink
Merge pull request #44 from VPerrollaz/add-vi-move
Browse files Browse the repository at this point in the history
Add some vi-style navigation to the pager.
  • Loading branch information
willmcgugan authored Apr 30, 2022
2 parents b2d8dda + 45fe8e6 commit 996596c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
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

0 comments on commit 996596c

Please sign in to comment.