import shutil
import sys
import termios
-
from collections import namedtuple
from io import UnsupportedOperation
# -------------------------------------------------------------------------
def __str__(self):
"""Typecasting into a string object."""
- msg = _("Cursor position:")
+ msg = _('Cursor position:')
msg += ' x = {x:3d}, y = {y:3d}'.format(x=self.x, y=self.y)
return msg
@classmethod
def cursor_position(cls):
"""
- Retrieves the current position of the terminal cursor.
+ Retrieve the current position of the terminal cursor.
It returns these position as a CursorPosition object.
A position of (-1, -1) means, the position could not be evaluated.
res = None
try:
- out = ""
- sys.stdout.write("\x1b[6n")
+ out = ''
+ sys.stdout.write('\x1b[6n')
sys.stdout.flush()
while not out.endswith('R'):
out += sys.stdin.read(1)
- res = re.match(r".*\[(?P<y>\d*);(?P<x>\d*)R", out)
+ res = re.match(r'.*\[(?P<y>\d*);(?P<x>\d*)R', out)
finally:
termios.tcsetattr(sys.stdin, termios.TCSAFLUSH, old_stdin_mode)
if res:
- return CursorPosition(int(res.group("x")), int(res.group("y")))
+ return CursorPosition(int(res.group('x')), int(res.group('y')))
return CursorPosition(-1, -1)