Skip to main content

Terminal/console pager module for Python

Project description

Python module to page output to the screen, read keys and get console dimensions.

It was meant to be included in standard library http://bugs.python.org/issue8408

Author: anatoly techtonik <techtonik@gmail.com>
License: Public Domain (or MIT if a license is required)

Demo

# this runs manual tests that are also a showcase of
# module capabilities

python -m pager

Status

1.3 (stable)
  • Windows: Python 3 requires getwch()

  • Windows: fix ENTER LEFT UP RIGHT DOWN ESC key codes

1.2 (stable)
  • add names for ENTER LEFT UP RIGHT DOWN ESC keys

  • manual tests for getch() (fixes bug #4)

  • dumpkey() helper function to get hex dump of a value returned by getch()

1.1 (stable)
  • Python 3 compatibility

  • echo() helper function for unbuffered output (in Py3 output doesn’t appear immediately on screen unless it ends with newline)

1.0 (stable)
  • getch() now returns list of chars for special keys (fixes bug #1 when special key skipped several pages)

  • page() callbacks receive obligatory pagenumber param

  • default page() callback now shows page number

0.2 (stable)
  • do not insert blank line between pages

0.1 (stable)
  • shows content page by page

  • allows to get console/terminal dimensions

  • works on Windows

  • works on Linux

API

..function:: getwidth()

Return width of available window in characters. If detection fails, return value of standard width 80. Coordinate of the last character on a line is -1 from returned value.

..function:: getheight()

Return available window height in characters or 25 if detection fails. Coordinate of the last line is -1 from returned value.

..function:: getch()

Wait for keypress and return character or a list of characters. Arrows and special keys generate a sequence of characters, so if there are extra symbols in input buffer, this function returns list.

..function:: page(content, [pagecallback=prompt])

Output content iterable, calling pagecallback function after each page with page number as a parameter. Default prompt() callback shows page number with ‘Press any key … ‘ prompt and waits for keypress.

..function:: echo(msg)

Print msg to the screen without linefeed and flush the output.

..function:: dumpkey(key)

Return hexadecimal representation of a key value returned by getch().

References

Excellent tutorials for Win32 Console by Adrian Worley http://www.adrianxw.dk/SoftwareSite/index.html Console Reference on MSDN http://msdn.microsoft.com/en-us/library/ms682087%28VS.85%29.aspx

Public Domain Curses library maintained by William McBrine http://pdcurses.sourceforge.net/

Ioctl (input/output control) introduction from Wikipedia http://en.wikipedia.org/wiki/Ioctl Linux Programmer’s Manual - ioctls for terminals and serial lines http://www.kernel.org/doc/man-pages/online/pages/man4/tty_ioctl.4.html

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

pager-1.3.zip (9.9 kB view details)

Uploaded Source

File details

Details for the file pager-1.3.zip.

File metadata

  • Download URL: pager-1.3.zip
  • Upload date:
  • Size: 9.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for pager-1.3.zip
Algorithm Hash digest
SHA256 d9e28352ad83041f4dbb7bcde38087c57083b994c7ceee2836b33958ea6ce35c
MD5 279082a6cb927058c702c5b0e930d6b0
BLAKE2b-256 dd6aca7678630ff7fae2be951306eb931048b24fc66f33c36eacd6827ceb8a36

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page