Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion qtconsole/ansi_code_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
# Constants and datatypes
#-----------------------------------------------------------------------------

# An action for cursor visibility requests
CursorVisibilityAction = namedtuple('CursorVisibilityAction', ['action', 'visible'])

# An action for erase requests (ED and EL commands).
EraseAction = namedtuple('EraseAction', ['action', 'area', 'erase_to'])

Expand All @@ -42,7 +45,7 @@
BackSpaceAction = namedtuple('BackSpaceAction', ['action'])

# Regular expressions.
CSI_COMMANDS = 'ABCDEFGHJKSTfmnsu'
CSI_COMMANDS = 'ABCDEFGHJKSTfmnsuhl'
CSI_SUBPATTERN = '\\[(.*?)([%s])' % CSI_COMMANDS
OSC_SUBPATTERN = '\\](.*?)[\x07\x1b]'
ANSI_PATTERN = ('\x01?\x1b(%s|%s)\x02?' % \
Expand Down Expand Up @@ -157,6 +160,13 @@ def set_csi_code(self, command, params=[]):
params : sequence of integers, optional
The parameter codes for the command.
"""

if command in ('h', 'l'):
if params == [25]:
visible = (command == 'h')
self.actions.append(
CursorVisibilityAction('cursor-visibility', visible)
)
if command == 'm': # SGR - Select Graphic Rendition
if params:
self.set_sgr_code(params)
Expand Down
24 changes: 24 additions & 0 deletions qtconsole/tests/test_ansi_code_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,31 @@ def test_move_cursor_up(self):
else:
self.fail('Too many substrings.')
self.assertEqual(i, 3, 'Too few substrings.')

def test_cursor_visibility(self):
"""Test for the ANSI commands for cursor visibility (?25h / ?25l)
"""
# This line hides the cursor, then shows it again.
string = '\x1b[?25l\x1b[?25h'
i = -1

for i, substring in enumerate(self.processor.split_string(string)):
# No text should be produced
self.assertIsNone(substring)

self.assertEqual(len(self.processor.actions), 1)
action = self.processor.actions[0]

self.assertEqual(action.action, 'cursor-visibility')

if i == 0:
self.assertFalse(action.visible)
elif i == 1:
self.assertTrue(action.visible)
else:
self.fail('Too many substrings.')

self.assertEqual(i, 1, 'Too few substrings.')

if __name__ == '__main__':
unittest.main()
Loading