Skip to main content

pypager

Build Status Latest Version License

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()

Metadata

Release files for pypager 3.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pypager 3.0.1
File Size Uploaded
pypager-3.0.1.tar.gz 17.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pypager 3.0.1
File Interpreter ABI Platform
pypager-3.0.1-py3-none-any.whl Python 3 none any Details

Total release size: 36.3 kB

Release files / pypager-3.0.1.tar.gz

Download URL pypager-3.0.1.tar.gz
Size 17.2 kB
Tags Source
SHA-256 checksum
How to use checksums
79c1fc8c4f2c9749dd58e5b29bfce48ca864a24898d1a1e0df1e7fe82d86ab44
BLAKE2b-256 checksum
How to use checksums
a294fb3cf81608d8a5aaf5bbac7e8f331e1ccc4501d7351957b72f0a8eb0d9f5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.13

Release files / pypager-3.0.1-py3-none-any.whl

Download URL pypager-3.0.1-py3-none-any.whl
Size 19.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f5169242fa7e46f5ffec225a667af664f8adf31616c84d99bf7ed8e898433930
BLAKE2b-256 checksum
How to use checksums
91a000480b4dd4e88a8833a691d219f1ad550d385ed898f0af7564486d5a62c0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.13

Release history Release notifications | RSS feed

This release

3.0.1 This release

2 release files

3.0.0

2 release files

0.5

2 release files

0.4

2 release files

0.3

2 release files

0.2

3 release files

0.1

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page