1 | #!/usr/bin/env bash
|
2 | #
|
3 | # Usage:
|
4 | # ./tty.sh <function name>
|
5 |
|
6 | set -o nounset
|
7 | set -o pipefail
|
8 | set -o errexit
|
9 |
|
10 | # makes a file called ttyrecord. Has TIMING info.
|
11 | ttyrec-demo() {
|
12 | ttyrec -e demo/pyreadline.py
|
13 | }
|
14 |
|
15 | play() {
|
16 | ttyplay ttyrecord
|
17 | }
|
18 |
|
19 | # makes a file called 'typescript'
|
20 | script-demo() {
|
21 | script -c demo/pyreadline.py "$@"
|
22 | }
|
23 |
|
24 | # TODO: Can we see how efficient it is?
|
25 | show-script() {
|
26 | #od -c typescript
|
27 | cat typescript
|
28 | }
|
29 |
|
30 | # Conclusion: readline is smart enough not to redraw the entire line when you
|
31 | # use set_completer_delims('')! So you should do that!
|
32 | #
|
33 | # You can see this by using -W -- it deletes stuff.
|
34 |
|
35 | readonly FIFO=_tmp/script-fifo
|
36 |
|
37 | record-to-fifo() {
|
38 | local cmd=${1:-demo/pyreadline.py} # e.g. try zsh or bash
|
39 | mkfifo $FIFO || true
|
40 | script --flush --command "$cmd" $FIFO
|
41 | }
|
42 |
|
43 | # in another window. This shows control codes.
|
44 | # Honestly this could use a Python version using repr().
|
45 |
|
46 | # Recording fish is interesting. It apparently does React-like diffing.
|
47 | # It optimizes the control codes when you navigate the file list.
|
48 | #
|
49 | # Elvish doesn't do this! It draws the whole thing each time!
|
50 |
|
51 | play-fifo() {
|
52 | cat -A $FIFO
|
53 | }
|
54 |
|
55 | # Cool program!
|
56 | # https://github.com/haberman/vtparse
|
57 | vtparse-fifo() {
|
58 | ~/git/languages/vtparse/test < $FIFO
|
59 | }
|
60 |
|
61 | "$@"
|