Python prompt_toolkit.keys.Keys.Down() Examples

The following are 2 code examples of prompt_toolkit.keys.Keys.Down(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module prompt_toolkit.keys.Keys , or try the search function .
Example #1
Source File: key_mappings.py    From pymux with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def prompt_toolkit_key_to_vt100_key(key, application_mode=False):
    """
    Turn a prompt toolkit key. (E.g Keys.ControlB) into a Vt100 key sequence.
    (E.g. \x1b[A.)
    """
    application_mode_keys = {
        Keys.Up: '\x1bOA',
        Keys.Left: '\x1bOD',
        Keys.Right: '\x1bOC',
        Keys.Down: '\x1bOB',
    }

    if key == Keys.ControlJ:
        # Required for redis-cli. This can be removed when prompt_toolkit stops
        # replacing \r by \n.
        return '\r'

    if key == '\n':
        return '\r'

    elif application_mode and key in application_mode_keys:
        return application_mode_keys.get(key)
    else:
        return _PROMPT_TOOLKIT_KEY_TO_VT100.get(key, key) 
Example #2
Source File: test_inputstream.py    From python-prompt-toolkit with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def test_arrows(processor, stream):
    stream.feed("\x1b[A\x1b[B\x1b[C\x1b[D")

    assert len(processor.keys) == 4
    assert processor.keys[0].key == Keys.Up
    assert processor.keys[1].key == Keys.Down
    assert processor.keys[2].key == Keys.Right
    assert processor.keys[3].key == Keys.Left
    assert processor.keys[0].data == "\x1b[A"
    assert processor.keys[1].data == "\x1b[B"
    assert processor.keys[2].data == "\x1b[C"
    assert processor.keys[3].data == "\x1b[D"