Skip to content

Add GNU "less" style navigation shortcuts to --pager view #102

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
27 changes: 27 additions & 0 deletions src/rich_cli/pager.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,33 @@ async def on_key(self, event: events.Key) -> None:
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")
elif event.key == "f":
# page down
self.body.target_y += self.body.size.height
self.body.y = self.body.target_y
elif event.key == "b":
# page up
self.body.target_y -= self.body.size.height
self.body.y = self.body.target_y
elif event.key == "d":
# half page-down
self.body.target_y += self.body.size.height // 2
self.body.y = self.body.target_y
elif event.key == "u":
# half page-up
self.body.target_y -= self.body.size.height // 2
self.body.y = self.body.target_y
elif event.key == "g" or event.key == "1" :
# jump to first line
# "g" is the "less" version; "1" is a shorthand for the "vi" command "1 -> Shift+G"
self.body.target_x = self.body.target_y = 0
self.body.x = self.body.y = 0
elif event.key == "G":
# jump to last line
# Same shortcut in both "less" and "vi"
self.body.target_x = 0
self.body.target_y = self.body.window.virtual_size.height - self.body.size.height
self.body.x, self.body.y = self.body.target_x, self.body.target_y

async def on_mount(self, event: events.Mount) -> None:
self.body = body = ScrollView(auto_width=True)
Expand Down