Pure Python pager (like "more" and "less").
Project description
A $PAGER in pure Python
pip install pypager
Pypager can be used as a stand-alone application, or as a library.
What is a pager?
A pager is a terminal program that can be used to view the content of a file, or the output stream from another application.
For instance, when we run man vim, the actual content is displayed in a pager, according to the $PAGER environment variable.
Important for a pager is that the input can be streamed. For instance when we execute find / | pypager; we don’t want to wait for the whole file system to be traversed, before displaying anything. Data is only read from the input pipe, when it needs to be displayed.
Popular pager applications are more, less and most.
Features
Highlighting of text [0].
Searching.
Many key bindings from less are implemented.
[0] (It understands the output of man pages, ANSI escape codes and further, it can use Pygments to highlight about any file.)
Usage
# Install it.
pip install pypager
# Tell the environment to use this pager. Put the following line in
# ~/.bashrc if you like.
export PAGER=pypager
# Following commands, and many others should pick up the pager.
man vim
git diff
# View a file, using this pager.
pypager some_source_code.py
As a library
from pypager.source import GeneratorSource
from pypager.pager import Pager
def generate_a_lot_of_content():
"""
This is a function that generates content on the fly.
It's called when the pager needs to display more content.
This should yield prompt_toolkit `(style_string, text)` tuples.
"""
counter = 0
while True:
yield [("", 'line: %i\n' % counter)]
counter += 1
if __name__ == '__main__':
p = Pager()
p.add_source(GeneratorSource(generate_a_lot_of_content())
p.run()
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file pypager-3.0.1.tar.gz
.
File metadata
- Download URL: pypager-3.0.1.tar.gz
- Upload date:
- Size: 17.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.13
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 79c1fc8c4f2c9749dd58e5b29bfce48ca864a24898d1a1e0df1e7fe82d86ab44 |
|
MD5 | 6c8b49ea9fe3d1d05bafab2da7bd0e5c |
|
BLAKE2b-256 | a294fb3cf81608d8a5aaf5bbac7e8f331e1ccc4501d7351957b72f0a8eb0d9f5 |
File details
Details for the file pypager-3.0.1-py3-none-any.whl
.
File metadata
- Download URL: pypager-3.0.1-py3-none-any.whl
- Upload date:
- Size: 19.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.13
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f5169242fa7e46f5ffec225a667af664f8adf31616c84d99bf7ed8e898433930 |
|
MD5 | 5cd8604b7527bf2210d5dcdf75d77c7b |
|
BLAKE2b-256 | 91a000480b4dd4e88a8833a691d219f1ad550d385ed898f0af7564486d5a62c0 |