aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/python/prompt-toolkit/py2/prompt_toolkit/terminal/vt100_input.py
diff options
context:
space:
mode:
authorNikita Slyusarev <nslus@yandex-team.com>2022-02-10 16:46:52 +0300
committerDaniil Cherednik <dcherednik@yandex-team.ru>2022-02-10 16:46:52 +0300
commitcd77cecfc03a3eaf87816af28a33067c4f0cdb59 (patch)
tree1308e0bae862d52e0020d881fe758080437fe389 /contrib/python/prompt-toolkit/py2/prompt_toolkit/terminal/vt100_input.py
parentcdae02d225fb5b3afbb28990e79a7ac6c9125327 (diff)
downloadydb-cd77cecfc03a3eaf87816af28a33067c4f0cdb59.tar.gz
Restoring authorship annotation for Nikita Slyusarev <nslus@yandex-team.com>. Commit 1 of 2.
Diffstat (limited to 'contrib/python/prompt-toolkit/py2/prompt_toolkit/terminal/vt100_input.py')
-rw-r--r--contrib/python/prompt-toolkit/py2/prompt_toolkit/terminal/vt100_input.py236
1 files changed, 118 insertions, 118 deletions
diff --git a/contrib/python/prompt-toolkit/py2/prompt_toolkit/terminal/vt100_input.py b/contrib/python/prompt-toolkit/py2/prompt_toolkit/terminal/vt100_input.py
index 74841312fad..a66afc28c69 100644
--- a/contrib/python/prompt-toolkit/py2/prompt_toolkit/terminal/vt100_input.py
+++ b/contrib/python/prompt-toolkit/py2/prompt_toolkit/terminal/vt100_input.py
@@ -9,8 +9,8 @@ import six
import termios
import tty
-from six.moves import range
-
+from six.moves import range
+
from ..keys import Keys
from ..key_binding.input_processor import KeyPress
@@ -93,7 +93,7 @@ ANSI_SEQUENCES = {
'\x1bOF': Keys.End,
'\x1b[3~': Keys.Delete,
'\x1b[3;2~': Keys.ShiftDelete, # xterm, gnome-terminal.
- '\x1b[3;5~': Keys.ControlDelete, # xterm, gnome-terminal.
+ '\x1b[3;5~': Keys.ControlDelete, # xterm, gnome-terminal.
'\x1b[1~': Keys.Home, # tmux
'\x1b[4~': Keys.End, # tmux
'\x1b[5~': Keys.PageUp,
@@ -107,11 +107,11 @@ ANSI_SEQUENCES = {
'\x1bOQ': Keys.F2,
'\x1bOR': Keys.F3,
'\x1bOS': Keys.F4,
- '\x1b[[A': Keys.F1, # Linux console.
- '\x1b[[B': Keys.F2, # Linux console.
- '\x1b[[C': Keys.F3, # Linux console.
- '\x1b[[D': Keys.F4, # Linux console.
- '\x1b[[E': Keys.F5, # Linux console.
+ '\x1b[[A': Keys.F1, # Linux console.
+ '\x1b[[B': Keys.F2, # Linux console.
+ '\x1b[[C': Keys.F3, # Linux console.
+ '\x1b[[D': Keys.F4, # Linux console.
+ '\x1b[[E': Keys.F5, # Linux console.
'\x1b[11~': Keys.F1, # rxvt-unicode
'\x1b[12~': Keys.F2, # rxvt-unicode
'\x1b[13~': Keys.F3, # rxvt-unicode
@@ -132,39 +132,39 @@ ANSI_SEQUENCES = {
'\x1b[32~': Keys.F18,
'\x1b[33~': Keys.F19,
'\x1b[34~': Keys.F20,
-
- # Xterm
- '\x1b[1;2P': Keys.F13,
- '\x1b[1;2Q': Keys.F14,
- # '\x1b[1;2R': Keys.F15, # Conflicts with CPR response.
- '\x1b[1;2S': Keys.F16,
- '\x1b[15;2~': Keys.F17,
- '\x1b[17;2~': Keys.F18,
- '\x1b[18;2~': Keys.F19,
- '\x1b[19;2~': Keys.F20,
- '\x1b[20;2~': Keys.F21,
- '\x1b[21;2~': Keys.F22,
- '\x1b[23;2~': Keys.F23,
- '\x1b[24;2~': Keys.F24,
-
+
+ # Xterm
+ '\x1b[1;2P': Keys.F13,
+ '\x1b[1;2Q': Keys.F14,
+ # '\x1b[1;2R': Keys.F15, # Conflicts with CPR response.
+ '\x1b[1;2S': Keys.F16,
+ '\x1b[15;2~': Keys.F17,
+ '\x1b[17;2~': Keys.F18,
+ '\x1b[18;2~': Keys.F19,
+ '\x1b[19;2~': Keys.F20,
+ '\x1b[20;2~': Keys.F21,
+ '\x1b[21;2~': Keys.F22,
+ '\x1b[23;2~': Keys.F23,
+ '\x1b[24;2~': Keys.F24,
+
'\x1b[1;5A': Keys.ControlUp, # Cursor Mode
'\x1b[1;5B': Keys.ControlDown, # Cursor Mode
'\x1b[1;5C': Keys.ControlRight, # Cursor Mode
'\x1b[1;5D': Keys.ControlLeft, # Cursor Mode
- '\x1b[1;2A': Keys.ShiftUp,
- '\x1b[1;2B': Keys.ShiftDown,
- '\x1b[1;2C': Keys.ShiftRight,
- '\x1b[1;2D': Keys.ShiftLeft,
-
- # Tmux sends following keystrokes when control+arrow is pressed, but for
- # Emacs ansi-term sends the same sequences for normal arrow keys. Consider
- # it a normal arrow press, because that's more important.
- '\x1bOA': Keys.Up,
- '\x1bOB': Keys.Down,
- '\x1bOC': Keys.Right,
- '\x1bOD': Keys.Left,
-
+ '\x1b[1;2A': Keys.ShiftUp,
+ '\x1b[1;2B': Keys.ShiftDown,
+ '\x1b[1;2C': Keys.ShiftRight,
+ '\x1b[1;2D': Keys.ShiftLeft,
+
+ # Tmux sends following keystrokes when control+arrow is pressed, but for
+ # Emacs ansi-term sends the same sequences for normal arrow keys. Consider
+ # it a normal arrow press, because that's more important.
+ '\x1bOA': Keys.Up,
+ '\x1bOB': Keys.Down,
+ '\x1bOC': Keys.Right,
+ '\x1bOD': Keys.Left,
+
'\x1b[5A': Keys.ControlUp,
'\x1b[5B': Keys.ControlDown,
'\x1b[5C': Keys.ControlRight,
@@ -188,11 +188,11 @@ ANSI_SEQUENCES = {
'\x1b[1;3C': (Keys.Escape, Keys.Right),
'\x1b[1;3A': (Keys.Escape, Keys.Up),
'\x1b[1;3B': (Keys.Escape, Keys.Down),
-
- # Sequences generated by numpad 5. Not sure what it means. (It doesn't
- # appear in 'infocmp'. Just ignore.
- '\x1b[E': Keys.Ignore, # Xterm.
- '\x1b[G': Keys.Ignore, # Linux console.
+
+ # Sequences generated by numpad 5. Not sure what it means. (It doesn't
+ # appear in 'infocmp'. Just ignore.
+ '\x1b[E': Keys.Ignore, # Xterm.
+ '\x1b[G': Keys.Ignore, # Linux console.
}
@@ -367,11 +367,11 @@ class InputStream(object):
# Quit bracketed paste mode and handle remaining input.
self._in_bracketed_paste = False
- remaining = self._paste_buffer[end_index + len(end_mark):]
+ remaining = self._paste_buffer[end_index + len(end_mark):]
self._paste_buffer = ''
- self.feed(remaining)
-
+ self.feed(remaining)
+
# Handle normal input character by character.
else:
for i, c in enumerate(data):
@@ -383,16 +383,16 @@ class InputStream(object):
else:
# Replace \r by \n. (Some clients send \r instead of \n
# when enter is pressed. E.g. telnet and some other
- # terminals.)
-
- # XXX: We should remove this in a future version. It *is*
- # now possible to recognise the difference.
- # (We remove ICRNL/INLCR/IGNCR below.)
- # However, this breaks IPython and maybe other applications,
- # because they bind ControlJ (\n) for handling the Enter key.
-
- # When this is removed, replace Enter=ControlJ by
- # Enter=ControlM in keys.py.
+ # terminals.)
+
+ # XXX: We should remove this in a future version. It *is*
+ # now possible to recognise the difference.
+ # (We remove ICRNL/INLCR/IGNCR below.)
+ # However, this breaks IPython and maybe other applications,
+ # because they bind ControlJ (\n) for handling the Enter key.
+
+ # When this is removed, replace Enter=ControlJ by
+ # Enter=ControlM in keys.py.
if c == '\r':
c = '\n'
self._input_parser.send(c)
@@ -425,40 +425,40 @@ class raw_mode(object):
with raw_mode(stdin):
''' the pseudo-terminal stdin is now used in raw mode '''
-
- We ignore errors when executing `tcgetattr` fails.
+
+ We ignore errors when executing `tcgetattr` fails.
"""
- # There are several reasons for ignoring errors:
- # 1. To avoid the "Inappropriate ioctl for device" crash if somebody would
- # execute this code (In a Python REPL, for instance):
- #
- # import os; f = open(os.devnull); os.dup2(f.fileno(), 0)
- #
- # The result is that the eventloop will stop correctly, because it has
- # to logic to quit when stdin is closed. However, we should not fail at
- # this point. See:
- # https://github.com/jonathanslenders/python-prompt-toolkit/pull/393
- # https://github.com/jonathanslenders/python-prompt-toolkit/issues/392
-
- # 2. Related, when stdin is an SSH pipe, and no full terminal was allocated.
- # See: https://github.com/jonathanslenders/python-prompt-toolkit/pull/165
+ # There are several reasons for ignoring errors:
+ # 1. To avoid the "Inappropriate ioctl for device" crash if somebody would
+ # execute this code (In a Python REPL, for instance):
+ #
+ # import os; f = open(os.devnull); os.dup2(f.fileno(), 0)
+ #
+ # The result is that the eventloop will stop correctly, because it has
+ # to logic to quit when stdin is closed. However, we should not fail at
+ # this point. See:
+ # https://github.com/jonathanslenders/python-prompt-toolkit/pull/393
+ # https://github.com/jonathanslenders/python-prompt-toolkit/issues/392
+
+ # 2. Related, when stdin is an SSH pipe, and no full terminal was allocated.
+ # See: https://github.com/jonathanslenders/python-prompt-toolkit/pull/165
def __init__(self, fileno):
self.fileno = fileno
- try:
- self.attrs_before = termios.tcgetattr(fileno)
- except termios.error:
- # Ignore attribute errors.
- self.attrs_before = None
+ try:
+ self.attrs_before = termios.tcgetattr(fileno)
+ except termios.error:
+ # Ignore attribute errors.
+ self.attrs_before = None
def __enter__(self):
# NOTE: On os X systems, using pty.setraw() fails. Therefor we are using this:
- try:
- newattr = termios.tcgetattr(self.fileno)
- except termios.error:
- pass
- else:
- newattr[tty.LFLAG] = self._patch_lflag(newattr[tty.LFLAG])
- newattr[tty.IFLAG] = self._patch_iflag(newattr[tty.IFLAG])
+ try:
+ newattr = termios.tcgetattr(self.fileno)
+ except termios.error:
+ pass
+ else:
+ newattr[tty.LFLAG] = self._patch_lflag(newattr[tty.LFLAG])
+ newattr[tty.IFLAG] = self._patch_iflag(newattr[tty.IFLAG])
# VMIN defines the number of characters read at a time in
# non-canonical mode. It seems to default to 1 on Linux, but on
@@ -467,54 +467,54 @@ class raw_mode(object):
# defaults to ASCII EOT = Ctrl-D = 4.)
newattr[tty.CC][termios.VMIN] = 1
- termios.tcsetattr(self.fileno, termios.TCSANOW, newattr)
+ termios.tcsetattr(self.fileno, termios.TCSANOW, newattr)
- # Put the terminal in cursor mode. (Instead of application mode.)
- os.write(self.fileno, b'\x1b[?1l')
+ # Put the terminal in cursor mode. (Instead of application mode.)
+ os.write(self.fileno, b'\x1b[?1l')
- @classmethod
- def _patch_lflag(cls, attrs):
+ @classmethod
+ def _patch_lflag(cls, attrs):
return attrs & ~(termios.ECHO | termios.ICANON | termios.IEXTEN | termios.ISIG)
- @classmethod
- def _patch_iflag(cls, attrs):
- return attrs & ~(
- # Disable XON/XOFF flow control on output and input.
- # (Don't capture Ctrl-S and Ctrl-Q.)
- # Like executing: "stty -ixon."
- termios.IXON | termios.IXOFF |
-
- # Don't translate carriage return into newline on input.
- termios.ICRNL | termios.INLCR | termios.IGNCR
- )
-
+ @classmethod
+ def _patch_iflag(cls, attrs):
+ return attrs & ~(
+ # Disable XON/XOFF flow control on output and input.
+ # (Don't capture Ctrl-S and Ctrl-Q.)
+ # Like executing: "stty -ixon."
+ termios.IXON | termios.IXOFF |
+
+ # Don't translate carriage return into newline on input.
+ termios.ICRNL | termios.INLCR | termios.IGNCR
+ )
+
def __exit__(self, *a, **kw):
- if self.attrs_before is not None:
- try:
- termios.tcsetattr(self.fileno, termios.TCSANOW, self.attrs_before)
- except termios.error:
- pass
+ if self.attrs_before is not None:
+ try:
+ termios.tcsetattr(self.fileno, termios.TCSANOW, self.attrs_before)
+ except termios.error:
+ pass
- # # Put the terminal in application mode.
- # self._stdout.write('\x1b[?1h')
+ # # Put the terminal in application mode.
+ # self._stdout.write('\x1b[?1h')
class cooked_mode(raw_mode):
"""
- The opposide of ``raw_mode``, used when we need cooked mode inside a
- `raw_mode` block. Used in `CommandLineInterface.run_in_terminal`.::
+ The opposide of ``raw_mode``, used when we need cooked mode inside a
+ `raw_mode` block. Used in `CommandLineInterface.run_in_terminal`.::
with cooked_mode(stdin):
''' the pseudo-terminal stdin is now used in cooked mode. '''
"""
- @classmethod
- def _patch_lflag(cls, attrs):
+ @classmethod
+ def _patch_lflag(cls, attrs):
return attrs | (termios.ECHO | termios.ICANON | termios.IEXTEN | termios.ISIG)
-
- @classmethod
- def _patch_iflag(cls, attrs):
- # Turn the ICRNL flag back on. (Without this, calling `input()` in
- # run_in_terminal doesn't work and displays ^M instead. Ptpython
- # evaluates commands using `run_in_terminal`, so it's important that
- # they translate ^M back into ^J.)
- return attrs | termios.ICRNL
+
+ @classmethod
+ def _patch_iflag(cls, attrs):
+ # Turn the ICRNL flag back on. (Without this, calling `input()` in
+ # run_in_terminal doesn't work and displays ^M instead. Ptpython
+ # evaluates commands using `run_in_terminal`, so it's important that
+ # they translate ^M back into ^J.)
+ return attrs | termios.ICRNL