Add
{code} {code} == == * * _ _ [] * #

201

2017-01-12 15:43:41
/**
 * Makes ANSI escape seq for 256 color, each color comp is 0..5
 */
function tc2e($r, $g, $b) {
    return "\33[38;5;" . ($r * 36 + $g * 6 + $b + 16) . "m";
}

function c($s, $k) {
    $res = ["\r\33[2K"];
    foreach (str_split($s, floor(strlen($s) / 12) + 1) as $j => $chunk) {
        $res[] = tc2e(
            0,
            1 + abs(4 - (($k + $j) % 9)),
            0) . $chunk;
    }
    return implode('', $res);
}

if (!stream_set_blocking(STDIN, 0)) die("could not set stream to nonblocking\n");

proc_close(proc_open('stty -icanon -echo -echoe', array(STDIN, STDOUT, STDERR), $pp));

$i = 0;
$s = '';
while (true) {
    $c = fgets(STDIN);
    if (feof(STDIN)) break;
    if ($c !== false) {
        foreach (str_split($c) as $c) {
            if ($c === "\4" || $c == "\33") {
                break 2;
            } else if ($c == "\x7f") { /*backspace*/
                $s = substr($s, 0, -1);
            } else if ($c == "\n") {
                echo "\r\33[2K\33[0m$s\n";
                $s = '';
            } else {
                $s .= $c;
            }
        }
    }
    $i++;
    echo c($s, $i);
    usleep(100000);
}
proc_close(proc_open('stty sane', array(STDIN, STDOUT, STDERR), $pp));