Skip to main content

Terminal based code snippet display tool

Project description

During talks or screencasts I don’t want to be typing code, it is too error prone and too likely to mess up my speaking flow. Purdy is both a set of programs and a library to display colourized code in a series of animations.

The purdy command displays your program or data to screen with colourization. It supports a number of syntax highlighters including Python, Python REPL, Bash console and more. Source code can be presented to the screen as if typing. For console files, the typing pauses at a prompt, waiting for interaction. Prompts are:

  • >>> or ... for Python REPL

  • $ for Bash console

If the program is paused at a prompt, pressing the right arrow will continue. Typing animation can be skipped over by pressing the letter “s” instead. Animation can be undone by pressing the left arrow. More info on keys can be found in the help dialog, viewed by pressing “h”.

Example Usage:

$ purdy code-snippet.py

The result looks like this:

screenshot.gif

Once the code has been displayed, further key presses are ignored. At any time you can press “q” to quit.

Purdy Programs

The following programs come with the purdy library:

  • purdy – Animated display that looks like a program is being typed to the screen.

  • subpurdy – Full set of commands to control Purdy. Sub-commands dictate behaviour, doing a variety of code presentation. Includes ANSI, RTF, HTML output as well as the typewriter animations.

More information can be found in the Command Line Program Documentation.

Purdy TUI Controls

The following keys help you to control the TUI purdy programs:

  • h – Help screen

  • <RIGHT> – next animation step

  • <LEFT> – previous animation step

  • s – go to the next step, skipping any animation

For custom made code using the purdy library, the following controls will also work:

  • <TAB> – focus next window area in a multi Screen display

  • <SHIFT><TAB> – focus previous window area in a multi Screen display

Additionally the s, and <LEFT> commands all support skipping multiple steps by specifying a number first. For example the sequence 12s would skip past the next 12 steps.

Purdy Library

The purdy script is fairly simple, but you can create more complex animations by writing programs using the purdy library. Custom programs can have split screens, highlight lines, do slide transitions, and more. More information can be found in the Library Documentation.

Installation

$ pip install purdy

Supports

Purdy has been tested with Python 3.13. Terminal control is done with the Textual library. Parsing and tokenization is done through Pygments. Both libraries are excellent and I’m grateful they’re publicly available.

Purdy was re-written from the ground up for version 2, moving to Textual and doing an API redesign based on pain points over the years. Version 2 is not compatible with version 1 which was based on Urwid. For the deprecated version see the purdy 1 branch or pip install purdy==1.14.1.

Docs & Source

Docs: http://purdy.readthedocs.io/en/latest/

Source: https://github.com/cltrudeau/purdy

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

purdy-2.3.1.tar.gz (53.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

purdy-2.3.1-py3-none-any.whl (51.6 kB view details)

Uploaded Python 3

File details

Details for the file purdy-2.3.1.tar.gz.

File metadata

  • Download URL: purdy-2.3.1.tar.gz
  • Upload date:
  • Size: 53.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.2

File hashes

Hashes for purdy-2.3.1.tar.gz
Algorithm Hash digest
SHA256 c72d19036d9930af565273ceedbf32a200436972d56ff288f7b418b640249791
MD5 fba11e6983f6cec2ed2f9efaa29bbe79
BLAKE2b-256 3402e5042ea0c3c69df7cc44dbff5fa66b9e82a007a8099e1be5c09fac923a86

See more details on using hashes here.

File details

Details for the file purdy-2.3.1-py3-none-any.whl.

File metadata

  • Download URL: purdy-2.3.1-py3-none-any.whl
  • Upload date:
  • Size: 51.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.2

File hashes

Hashes for purdy-2.3.1-py3-none-any.whl
Algorithm Hash digest
SHA256 e7bbba3b4aece3aa032a6b2264d80a7eed1b36b3c1572e057f84f4da4c200024
MD5 bcb728d80507778cd4a3ab890165f0af
BLAKE2b-256 34e6b578a4e42da6d0aa68beb35b7b3ac2e4a9f2c3b4c58218b5f00ea074c6e9

See more details on using hashes here.

Supported by

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