• Stars
    star
    161
  • Rank 233,470 (Top 5 %)
  • Language
    Python
  • License
    GNU General Publi...
  • Created almost 10 years ago
  • Updated almost 7 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

undo in any program that uses readline

Build Status

rlundo

rlundo grants interactive interpreters magical undo powers!

rlundo preview example

For a long read about the motivation for such a tool, see this blog post

A patched version of readline is used to fork an interpreter at each prompt. If the user enters undo then that child process dies and execution is resume. rlundo also removes the terminal output that occurred in the recently-deceased child process, restoring the terminal to its previous state.

The goal is for this to work with any interpreter:

$ python rlundo irb

The name rlundo is modeled off of rlwrap, which wraps interactive command line interfaces with the readline editing interface. Like that command, rlundo wraps other interactive interfaces. To make the analogy work better it probably should have been called undowrap, or rlundowrap to suggest that the way undo is implemented uses readline.


Using a patched version of the readline library only works for interactive interpreters that dynamically link readline. To address this, this project includes shims for various interpreters that implement undo via fork in a less general way in /rlundo/interps/. Compiling the patched readline library is not required for interpreters implemented this way. Add your favorite!

$ python rlundo python

(python seems to usually statically link readline)

Modified Readline library

rlundoable is a patched version of the gnu readline library with the following modifications:

  • calling readline causes the process to fork
  • the user entering "undo" causes the process to die
  • tcp socket connections are made when the process forks or dies to notify a listener that might be recording terminal state

To build this patched readline library:

cd rlundoable
make -f Makefileosx

Read more about the patched readline library in that readme.

The library substitution works more reliably for me on linux right now. Maybe this is because homebrew more often links readline statically? That's just speculation. Writing workarounds for common interpreters or digging into how to make readline hijacking more reliable would both be really helpful!

Rewriting terminal state

In order to restore prior terminal state on undo, interpreters are run in a pseudo terminal that takes snapshots of terminal state when the interpreter forks and restores previous terminal state when an interpreter process dies.

try it with

$ python rewrite.py

and then in another terminal run

nc -U path/to/tmp/unix/socket/*save

to save terminal states, and

nc -U path/tmp/tmp/unix/socket/*save; nc -U path/to/tmp/unix/socket/*restore;

to restore previous terminal states. Restore always goes back two state, so it is necessary to call save before restore as shown above to restore the previous save. Ordinarily these signals are sent by the modified interpreter (or the patched readline it calls) after printing the prompt but before the user types anything. Since you'll be sending the commands manually in the above demo, the > prompt will not reappear after undo.

Running the tests

  • clone the repo, create a virtual environment
  • pip install nose
  • install tmux 1.9a or 2.1 or later. 1.8 is too early, 2.0 has a regression.
  • nosetests test in the root directory
  • or try RLUNDO_USE_EXISTING_TMUX_SESSION=1 nosetests test while you have a tmux session open to watch the tests which use tmux run

Thanks to

  • John Hergenroeder for help with fixing race conditions with terminal rewriting
  • John Connor for discussion and Python 3 fixes
  • AgustΓ­n Benassi for ipython support, improved terminal rewriting, memory monitoring work and much more
  • Joe Jean for work on Travis tests
  • Madelyn Freed for work on the executable rlundo script

License

Copyright 2015 Thomas Ballinger

Released under GPL3, like GNU readline.

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.


$ python rlundo ipython

undo with ctrl+c

More Repositories

1

dalsegno

Repeat from the sign
JavaScript
79
star
2

observable-jupyter

Embed visualizations and code from Observable notebooks in Jupyter
Jupyter Notebook
55
star
3

lazyload

hack for causing Python modules to be loaded lazily
Python
52
star
4

endless-web

A fork of Endless Sky for playing in a browser: try it at https://play-endless-web.com/
C++
20
star
5

talkingtoothercomputers

Jupyter Notebook
19
star
6

observable-jupyter-widget

Python
17
star
7

convex-clerk-users-table

TypeScript
13
star
8

pythonquiz

Python
12
star
9

hs

Haskell
11
star
10

potrace-python

Python
9
star
11

bittorrent

Python
8
star
12

regressiontrees

Python
5
star
13

hotswapping-js-interp

Sandboxed JavaScript interpreter with function hot-swapping
JavaScript
5
star
14

scottwasright

curses-like interface that doesn't mess with scrolling
Python
4
star
15

raytracing

Python raycaster
Python
4
star
16

beazley-wasm

Web Assembly VM from David Beazley's PyCon India keynote (https://www.youtube.com/watch?v=VUT386_GKI8)
Python
4
star
17

simplerepl

Python
4
star
18

shiplang

a language you might use on a ship
TypeScript
4
star
19

remoteFreesurfer

Spins up amazon ec2 instances and runs freesurfer recon-all on them.
Python
4
star
20

trellocardupdate

Update trello cards
Python
4
star
21

vim

vim folder, I symlink to the vimrc inside
Vim Script
3
star
22

evoImage

JavaScript
3
star
23

jsrisk

Risk webapp using javascript
JavaScript
3
star
24

hsrepl

Haskell REPL with a few bpython-like features
Haskell
3
star
25

fmtstr

temporary name, this term is overloaded
Python
3
star
26

bphython

bpython for hy
Python
3
star
27

endless-sky-vscode

Endless Sky data language VSCode support
TypeScript
3
star
28

your-party-is-full

TypeScript
3
star
29

regex-parser

Python
2
star
30

Utok

Risk clone with flask and redis
Python
2
star
31

embind-ES6-for-node-and-browser

Makefile
2
star
32

bpython-cheat-sheet

2
star
33

loveinthetimeoftetris

Elm
2
star
34

convex-html-email-example

TypeScript
2
star
35

btgames

Performance testing infrastructure for bittorrent clients
Python
2
star
36

endless-sky-bindings-python

Python
1
star
37

calc

A calculator that gets stretched into a language
Python
1
star
38

ipythonturtle

Python
1
star
39

2or3

Uses heuristics to classify a Python file as Python 2 or 3. Prefers 3 if unclear.
Python
1
star
40

regexfun

Python
1
star
41

dast

dynamic ast, live code reloading experiment
Python
1
star
42

music

Boston Hack Day 2011 - lolartist: pastes lolcat translations of popular tracks by an artist on an image of that artist, powered by the Echonest
Python
1
star
43

zuliptrack

Python
1
star
44

youtube-podcast

A node.js server that converts YouTube Channels to Podcast RSS Feeds
JavaScript
1
star
45

WWFplayer

Suggests words with friends (scrabble-like) moves
Python
1
star
46

networkhangman

Python
1
star
47

old-bpython-with-hy-support

A bpython repo for the curtsies frontend and hy integration for collaboration with git users
Python
1
star
48

ballingercalendar

Automatically exported from code.google.com/p/ballingercalendar
Python
1
star
49

accountibot

Zulip bot for RC
Python
1
star
50

anotherexampletictactoe

Python
1
star
51

ball-shoot

TypeScript
1
star
52

androidtetris

Java
1
star
53

anothertest

1
star
54

tetrisai

Python
1
star
55

terminals-talk

JavaScript
1
star
56

pyconcat

Concatenates python scripts into one ugly behemoth
Python
1
star
57

posts

published posts appearing at http://ballingt.com/blog
1
star
58

smv

Python library for Slicer3 for scripting camera movements and taking screenshots to stitch together to make movies
Python
1
star