Search in sources :

Example 1 with KeyPress

use of org.apache.hadoop.hbase.hbtop.terminal.KeyPress in project hbase by apache.

the class TestKeyPress method main.

public static void main(String[] args) throws Exception {
    try (Terminal terminal = new TerminalImpl()) {
        terminal.hideCursor();
        terminal.refresh();
        while (true) {
            KeyPress keyPress = terminal.pollKeyPress();
            if (keyPress == null) {
                TimeUnit.MILLISECONDS.sleep(100);
                continue;
            }
            terminal.getTerminalPrinter(0).print(keyPress.toString()).endOfLine();
            terminal.refresh();
            if (keyPress.getType() == KeyPress.Type.F12) {
                break;
            }
        }
    }
}
Also used : KeyPress(org.apache.hadoop.hbase.hbtop.terminal.KeyPress) Terminal(org.apache.hadoop.hbase.hbtop.terminal.Terminal)

Example 2 with KeyPress

use of org.apache.hadoop.hbase.hbtop.terminal.KeyPress in project hbase by apache.

the class KeyPressGenerator method ctrlAltAndCharacter.

private void ctrlAltAndCharacter(char ch) {
    char ctrlCode;
    switch(ch) {
        case 0:
            ctrlCode = ' ';
            break;
        case 28:
            ctrlCode = '\\';
            break;
        case 29:
            ctrlCode = ']';
            break;
        case 30:
            ctrlCode = '^';
            break;
        case 31:
            ctrlCode = '_';
            break;
        default:
            ctrlCode = (char) ('a' - 1 + ch);
            break;
    }
    offer(new KeyPress(KeyPress.Type.Character, ctrlCode, true, true, false));
}
Also used : KeyPress(org.apache.hadoop.hbase.hbtop.terminal.KeyPress)

Example 3 with KeyPress

use of org.apache.hadoop.hbase.hbtop.terminal.KeyPress in project hbase by apache.

the class KeyPressGenerator method generatorThread.

private void generatorThread() {
    while (!stopThreads.get()) {
        Character ch;
        try {
            ch = inputCharacterQueue.poll(100, TimeUnit.MILLISECONDS);
        } catch (InterruptedException ignored) {
            continue;
        }
        if (ch == null) {
            if (parseState == ParseState.ESCAPE) {
                offer(new KeyPress(KeyPress.Type.Escape, null, false, false, false));
                initState();
            } else if (parseState != ParseState.START) {
                offer(new KeyPress(KeyPress.Type.Unknown, null, false, false, false));
                initState();
            }
            continue;
        }
        if (parseState == ParseState.START) {
            if (ch == 0x1B) {
                parseState = ParseState.ESCAPE;
                continue;
            }
            switch(ch) {
                case '\n':
                case '\r':
                    offer(new KeyPress(KeyPress.Type.Enter, '\n', false, false, false));
                    continue;
                case 0x08:
                case 0x7F:
                    offer(new KeyPress(KeyPress.Type.Backspace, '\b', false, false, false));
                    continue;
                case '\t':
                    offer(new KeyPress(KeyPress.Type.Tab, '\t', false, false, false));
                    continue;
                default:
                    // Do nothing
                    break;
            }
            if (ch < 32) {
                ctrlAndCharacter(ch);
                continue;
            }
            if (isPrintableChar(ch)) {
                // Normal character
                offer(new KeyPress(KeyPress.Type.Character, ch, false, false, false));
                continue;
            }
            offer(new KeyPress(KeyPress.Type.Unknown, null, false, false, false));
            continue;
        }
        if (parseState == ParseState.ESCAPE) {
            if (ch == 0x1B) {
                offer(new KeyPress(KeyPress.Type.Escape, null, false, false, false));
                continue;
            }
            if (ch < 32 && ch != 0x08) {
                ctrlAltAndCharacter(ch);
                initState();
                continue;
            } else if (ch == 0x7F || ch == 0x08) {
                offer(new KeyPress(KeyPress.Type.Backspace, '\b', false, false, false));
                initState();
                continue;
            }
            if (ch == '[' || ch == 'O') {
                parseState = ParseState.ESCAPE_SEQUENCE_PARAM1;
                continue;
            }
            if (isPrintableChar(ch)) {
                // Alt and character
                offer(new KeyPress(KeyPress.Type.Character, ch, true, false, false));
                initState();
                continue;
            }
            offer(new KeyPress(KeyPress.Type.Escape, null, false, false, false));
            offer(new KeyPress(KeyPress.Type.Unknown, null, false, false, false));
            initState();
            continue;
        }
        escapeSequenceCharacter(ch);
    }
}
Also used : KeyPress(org.apache.hadoop.hbase.hbtop.terminal.KeyPress)

Example 4 with KeyPress

use of org.apache.hadoop.hbase.hbtop.terminal.KeyPress in project hbase by apache.

the class TestCursor method main.

public static void main(String[] args) throws Exception {
    try (Terminal terminal = new TerminalImpl()) {
        terminal.refresh();
        terminal.setCursorPosition(0, 0);
        terminal.getTerminalPrinter(0).print("aaa").endOfLine();
        terminal.refresh();
        TimeUnit.SECONDS.sleep(1);
        terminal.getTerminalPrinter(0).print("bbb").endOfLine();
        terminal.refresh();
        TimeUnit.SECONDS.sleep(1);
        terminal.setCursorPosition(1, 0);
        terminal.refresh();
        TimeUnit.SECONDS.sleep(1);
        terminal.setCursorPosition(2, 0);
        terminal.refresh();
        TimeUnit.SECONDS.sleep(1);
        terminal.setCursorPosition(3, 0);
        terminal.refresh();
        TimeUnit.SECONDS.sleep(1);
        terminal.setCursorPosition(0, 1);
        terminal.refresh();
        TimeUnit.SECONDS.sleep(1);
        terminal.getTerminalPrinter(1).print("ccc").endOfLine();
        terminal.refresh();
        TimeUnit.SECONDS.sleep(1);
        terminal.getTerminalPrinter(3).print("Press any key to finish").endOfLine();
        terminal.refresh();
        while (true) {
            KeyPress keyPress = terminal.pollKeyPress();
            if (keyPress == null) {
                TimeUnit.MILLISECONDS.sleep(100);
                continue;
            }
            break;
        }
    }
}
Also used : KeyPress(org.apache.hadoop.hbase.hbtop.terminal.KeyPress) Terminal(org.apache.hadoop.hbase.hbtop.terminal.Terminal)

Example 5 with KeyPress

use of org.apache.hadoop.hbase.hbtop.terminal.KeyPress in project hbase by apache.

the class Screen method run.

public void run() {
    currentScreenView.init();
    while (true) {
        try {
            KeyPress keyPress = terminal.pollKeyPress();
            ScreenView nextScreenView;
            if (keyPress != null) {
                // Dispatch the key press to the current screen
                nextScreenView = currentScreenView.handleKeyPress(keyPress);
            } else {
                if (timerTimestamp != null) {
                    long now = EnvironmentEdgeManager.currentTime();
                    if (timerTimestamp <= now) {
                        // Dispatch the timer to the current screen
                        timerTimestamp = null;
                        nextScreenView = currentScreenView.handleTimer();
                    } else {
                        TimeUnit.MILLISECONDS.sleep(Math.min(timerTimestamp - now, SLEEP_TIMEOUT_MILLISECONDS));
                        continue;
                    }
                } else {
                    TimeUnit.MILLISECONDS.sleep(SLEEP_TIMEOUT_MILLISECONDS);
                    continue;
                }
            }
            // If the next screen is null, then exit
            if (nextScreenView == null) {
                return;
            }
            // If the next screen is not the previous, then go to the next screen
            if (nextScreenView != currentScreenView) {
                currentScreenView = nextScreenView;
                currentScreenView.init();
            }
        } catch (Exception e) {
            LOGGER.error("Caught an exception", e);
        }
    }
}
Also used : KeyPress(org.apache.hadoop.hbase.hbtop.terminal.KeyPress) TopScreenView(org.apache.hadoop.hbase.hbtop.screen.top.TopScreenView) IOException(java.io.IOException)

Aggregations

KeyPress (org.apache.hadoop.hbase.hbtop.terminal.KeyPress)8 Terminal (org.apache.hadoop.hbase.hbtop.terminal.Terminal)3 IOException (java.io.IOException)1 TopScreenView (org.apache.hadoop.hbase.hbtop.screen.top.TopScreenView)1 TerminalPrinter (org.apache.hadoop.hbase.hbtop.terminal.TerminalPrinter)1