summaryrefslogtreecommitdiffstats
path: root/cholerab
diff options
context:
space:
mode:
authortv <tv@also>2011-07-21 00:19:52 +0200
committertv <tv@also>2011-07-21 00:19:52 +0200
commit8f55d7b86a5fea0e121780ddcd4b4dc46da50980 (patch)
tree9887cff051c8e829b39c09c3e641be5cba13624e /cholerab
parent0e70e8089e8452fcd0fd2a0cdf8b935844f2c725 (diff)
cholerab live.sh: initial commit
Diffstat (limited to 'cholerab')
-rwxr-xr-xcholerab/live.sh76
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 8" >&2
+ echo -n "7state=$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 8" >&2
+ echo -n "7state=$state8" >&2
+ char="`dd bs=1 count=1 2>/dev/null`"
+ odchar="`echo -n "$char" | od -An -tx | tr -d "[$IFS]"`"
+ history="$odchar ${history-}"
+ echo -n "7 8" >&2
+ echo -n "7 8" >&2
+ echo -n "7`echo -n "$history"`8" >&2
+}
+
+
+S() {
+ state S
+ case "$char" in
+ () ESC "$char";;
+ () echo -n ' '; S;;
+ (*)
+ echo -n "$char"
+ S
+ ;;
+ esac
+}
+
+ESC() {
+ state ESC
+ case "$char" in
+ ('[') ESC_OSQRB "$1$char";;
+ (*)
+ echo -n '^['
+ 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 '^[['
+ S
+ ;;
+ esac
+}
+
+ESC_OSQRB2() {
+ state ESC_OSQRB2
+ case "$char" in
+ (A|B|C|D) echo -n "$1$char"; S;;
+ (*)
+ echo -n '^[[['
+ S
+ ;;
+ esac
+}
+
+
+echo -n 'c'
+S