Exemplo n.º 1
0
function main()
{
    if (!termbox_init()) {
        fwrite(STDERR, "termbox_init failed with error code " . termbox_last_error() . "\n");
        exit(1);
    }
    termbox_set_input_mode(TB_INPUT_ESC);
    termbox_clear();
    draw_keyboard();
    termbox_present();
    $ctrlxpressed = false;
    while (false !== ($ev = termbox_poll_event())) {
        switch ($ev['type']) {
            case TB_EVENT_KEY:
                if ($ev['key'] == TB_KEY_CTRL_Q && $ctrlxpressed) {
                    termbox_shutdown();
                    exit(0);
                } else {
                    if ($ev['key'] == TB_KEY_CTRL_C && $ctrlxpressed) {
                        $chmap = [0, 2, 1];
                        termbox_set_input_mode($chmap[termbox_get_input_mode()]);
                    }
                }
                $ctrlxpressed = $ev['key'] == TB_KEY_CTRL_X;
                termbox_clear();
                draw_keyboard();
                dispatch_press($ev);
                pretty_print_press($ev);
                termbox_present();
                break;
            case TB_EVENT_RESIZE:
                termbox_clear();
                draw_keyboard();
                pretty_print_resize($ev);
                termbox_present();
                break;
            default:
                break;
        }
    }
    termbox_shutdown();
}
Exemplo n.º 2
0
            pretty_print_press($event);
            $tb->present();
            break;
            // Did we resize the terminal?
        // Did we resize the terminal?
        case Constants::TB_EVENT_RESIZE:
            $tb->clear();
            draw_keyboard($tb);
            pretty_print_resize($event);
            $tb->present();
            break;
            // Did we jiggly the mouse?
        // Did we jiggly the mouse?
        case Constants::TB_EVENT_MOUSE:
            $tb->clear();
            draw_keyboard($tb);
            pretty_print_mouse($event);
            $tb->present();
            break;
        default:
            break;
    }
}
sleep(3);
exit;
function draw_keyboard(TermBox $tb)
{
    $tb->changeCell(0, 0, 0x250c, Constants::TB_WHITE | Constants::TB_BOLD, Constants::TB_DEFAULT);
    $tb->changeCell(79, 0, 0x2510, Constants::TB_WHITE | Constants::TB_BOLD, Constants::TB_DEFAULT);
    $tb->changeCell(0, 23, 0x2514, Constants::TB_WHITE | Constants::TB_BOLD, Constants::TB_DEFAULT);
    $tb->changeCell(79, 23, 0x2518, Constants::TB_WHITE | Constants::TB_BOLD, Constants::TB_DEFAULT);