diff options
author | tv <tv@also> | 2011-07-21 00:19:52 +0200 |
---|---|---|
committer | tv <tv@also> | 2011-07-21 00:19:52 +0200 |
commit | 4d241a5df909730d7366f30697cb3c00b8e826aa (patch) | |
tree | edf218cbda8c1faa686af8cfd506dc877b01cbf0 /cholerab/live.sh | |
parent | a404187f63c0bc183ce8170b5b652e45babbb884 (diff) |
cholerab live.sh: initial commit
Diffstat (limited to 'cholerab/live.sh')
-rwxr-xr-x | cholerab/live.sh | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/cholerab/live.sh b/cholerab/live.sh new file mode 100755 index 00000000..8328ea07 --- /dev/null +++ b/cholerab/live.sh @@ -0,0 +1,76 @@ +#! /bin/sh +set -euf +stty cbreak -echo + +getc() { + echo -n "7[1;70H 8" >&2 + echo -n "7[1;70Hstate=$state8" >&2 + set -- "`dd bs=1 count=1 2>/dev/null`" + set -- "$1" "`echo -n "$1" | od -An -tx | tr -d "[$IFS]"`" + char="$1" + odchar="$2" + echo -n "$1" +} + +state() { + state="$1" + echo -n "7[1;70H 8" >&2 + echo -n "7[1;70Hstate=$state8" >&2 + char="`dd bs=1 count=1 2>/dev/null`" + odchar="`echo -n "$char" | od -An -tx | tr -d "[$IFS]"`" + history="$odchar [10D[B${history-}" + echo -n "7[2;70H 8" >&2 + echo -n "7[3;70H 8" >&2 + echo -n "7[4;70H`echo -n "$history"`8" >&2 +} + + +S() { + state S + case "$char" in + () ESC "$char";; + () echo -n '[D [D'; S;; + (*) + echo -n "$char" + S + ;; + esac +} + +ESC() { + state ESC + case "$char" in + ('[') ESC_OSQRB "$1$char";; + (*) + echo -n '[35m^[[m' + S + ;; + esac +} + +ESC_OSQRB() { + state ESC_OSQRB + case "$char" in + (A|B|C|D) echo -n "$1$char"; S;; + ('[') ESC_OSQRB2 "$1$char";; + (*) + echo -n '[35m^[[m[' + S + ;; + esac +} + +ESC_OSQRB2() { + state ESC_OSQRB2 + case "$char" in + (A|B|C|D) echo -n "$1$char"; S;; + (*) + echo -n '[35m^[[m[[' + S + ;; + esac +} + + +echo -n 'c' +S |