Code Monkey home page Code Monkey logo

purdy's Introduction

Purdy

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 takes one of a Python program, a Python REPL console file or a Bash console file. Source code is 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 "?".

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.
  • pat -- "purdy cat", prints ANSI colourized source.
  • prat -- "purdy RTF cat", prints colourized source in RTF document format. Particularly useful for copying to a clipboard and pasting full colourized source into a document. On OS X prat <filename> | pbcopy will put the output directly to the clipboard.
  • subpurdy -- Full set of commands to control Purdy. Sub-commands dictate behaviour. Does 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:

  • ? -- 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:

  • S -- go to the next section, skipping any animation.
  • <TAB> -- focus next window area in a multi Screen display
  • <SHIFT><TAB> -- focus previous window area in a multi Screen display

Additionally the s, 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. You can create more complex animations by writing programs using the purdy library. Custom programs can have split screens, highlighting lines, 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.7. Terminal control is done with the Urwid library. Parsing and tokenization is done through Pygments. Both libraries are execellent and I'm grateful they're publically available.

Docs & Source

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

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

purdy's People

Contributors

cltrudeau avatar johanvergeer avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

purdy's Issues

bug in HighlightChain

Looks like the last item in HighlightChain stays highlighted after the chain runs

no typewriter on comments

In REPL mode, when a REPL line is only a comment, skip the typewriter animation

(Maybe make this an option?)

escape sequence

Add escape sequence for controlling of animation or presentation

Example use cases:

  • presenting in a certain format foreign to the context
  • Generic highlighting (colour sequencing) for things that don't have parsers
  • Timing of animation (insert pauses between response lines for things like terminal commands that take time)
  • Animation sequences (progress bars)

Chaining sequences

HighlightChain and any other chaining sequences should use tuples instead of strings for mutli-sets

Should also support *args instead of needing a list

mixed context

Some sort of file format that allows for mixing context highlighting

Single presentation for going from BASH to REPL and back again

Hot reloading

While writing the script and rehearsing, I have to change small pieces of the script now and then, but still restart the entire script and go though the whole thing again.

Therefore it would be quite a timesaver when hot reloading could be added to Purdy.

animation speed

Add ability to change animation speed (command line arg? key press?)

partial actions

Add ability to do an action to just part of a Code object. Example AppendTypewriter(line_start=3, line_end=15).

rename py console lexer

py console lexer should be look for ".repl" extensions and be called "repl"

"con" should be used for "bash" as that is the file extension

add pauses in output

Add a parameter to Append() and its siblings that allows you to insert pauses between output lines

Possible example:

Append(box, code, pauses=[Pause(3, 1.5), Pause(4, 1.5)])

Where 3 is the line to pause after, 1.5 the amount of time

title

allow for a title bar

have a fixed mode that stays at top during scroll?

debugger animation

A new animation class that takes a chunk of code, debug line numbers, a chunk of text, and pause points in the output.

The code is displayed in one box while the output is displayed in the other. Each "breakpoint" in the code is matched to a pause in the output, and as you proceed through the animation it shows the next chunk of output. Kind of like highlight chain but looking like there is a debugger.

ActionsBuilder class

Hi @cltrudeau,

In order to have a bit shorter syntax when working with Purdy, I created a class to create all actions:

class ActionsBuilder(Iterable):
    def __init__(self, code_box, lexer_name: str) -> None:
        self.__code_box = code_box
        self.__lexer_name = lexer_name
        self.__actions = []

    def __iter__(self):
        return iter(self.__actions)

    def append_typewriter(self, text: str = "", filename: str = "") -> "ActionsBuilder":
        self.__actions.append(
            AppendTypewriter(
                self.__code_box,
                Code(filename=filename, text=text, lexer_name=self.__lexer_name),
            )
        )
        return self

    def append(self, text: str = "", filename: str = "") -> "ActionsBuilder":
        self.__actions.append(
            Append(
                self.__code_box,
                Code(filename=filename, text=text, lexer_name=self.__lexer_name),
            )
        )
        return self

    def suffix(self, position, source) -> "ActionsBuilder":
        self.__actions.append(Suffix(self.__code_box, position, source))
        return self

    def wait(self) -> "ActionsBuilder":
        self.__actions.append(Wait())
        return self

    def clear(self) -> "ActionsBuilder":
        self.__actions.append(Clear(self.__code_box))
        return self

This class allows me to create a set of actions like this:

screen = SimpleScreen(starting_line_number=-1, settings=settings)
code_box = screen.code_box

actions = (
    ActionsBuilder(code_box, lexer_name="bash")
    .append_typewriter("$ pyenv versions")
    .append("* system\n  3.9.0\n  3.9.1")
    .append_typewriter("$ pyenv global 3.9.1")
    .append_typewriter("$ python -V")
    .append("Python 3.9.0")
    .append_typewriter("$ pyenv global system")
    .append_typewriter("$ python -V")
    .append("Python 2.7.16")
    .append_typewriter("$ ")
)

screen.run(actions)

Would you like to add this class to be added to Purdy? If so, I'm more than happy to create a PR for you. ๐Ÿ˜ƒ

go-to action

Add action that causes screen to scroll to a given line number

Support -1 for bottom

Two modes? Skip straight and animated scrolling?

Fold: bigger picture

Should fold be an action? Should it be something done on a Code item instead?

Consequences: how do line numbers behave if so, sometimes want folding with removal, sometimes don't.

Think about this when dealing with the re-design of Code and its ability to show parts.

Add lexer that does no lexing

For anything that doesn't require highlighting, a lexer that has no colouring might be useful. (Requested by Leodanis)

Add "none" as a supported value for the "-l" option

line removal

Add a chaining method so that sets of lines can be trimmed at the same time -- makes it easier to figure out based on original file line numbers instead of the edit of an edit.

dbash lexer doesn't tokenize the prompt

Using typewriter mode on a dbash based lexer uses the typewriter animation to show the prompt.

Either the prompt isn't being treated as a whole token

or there is a bug in the animation sequence.

chained subset

Add ability to do multiple calls to Code.subset() in a single call to split up a document

Maybe has two versions, one that just takes the starting line numbers of chunks and one that specifies a sequence of start-end specifiers

Code.subset()

Either completely re-think how this works (some sort of generator so that actions can advance part-way through blocks), or add ability to specify end=-1

bug / optimization in Transition

Looks like the transition wipe is processing the entire file instead of optimizing for what is shown on screen. Longer files have a delay before the transition starts if you're scrolled down.

Mixed line plus suffix

Often end up doing a "prompt" line in output. Want to be able to do:

Name: John

Where name is spit out, while "John" is typed

Currently done with multiple Appends and SuffixTypewriter commands, could be mixed into one.

"none" lexer single line bug

Using the "none" lexer seems to not split things on multiple lines, or somehow the lines can't highlight correctly

See RP 039_jinja/demo and try to highlight some of the template code lines

screen transition

Can't currently do a Transition animation on the whole screen. Use case: TwinRowBoxes, want to clear both of them. Maybe provide initial state new box.

Could also re-examine how Transition works -- maybe it is just an animated clear, with the next action populating the new view. Transition-in and Transition-out being separate animations.

Fold lines behaviour

folded lines don't respect the line number display --> it is a simple replace, rather than a fold

typewriter on indent

Currently indent spaces are treated as characters in typewriter mode. The animation should be smarter and go directly to the code part of the line.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.