From 83f6780fc986651fdd212b5ca049ecab93428859 Mon Sep 17 00:00:00 2001 From: jsbautista Date: Mon, 29 Jul 2024 01:21:35 -0500 Subject: [PATCH 01/30] First commit to fix TQDM --- qtconsole/ansi_code_processor.py | 11 +++++++++++ qtconsole/console_widget.py | 5 +++++ 2 files changed, 16 insertions(+) diff --git a/qtconsole/ansi_code_processor.py b/qtconsole/ansi_code_processor.py index 8ebe5c92..18278e22 100644 --- a/qtconsole/ansi_code_processor.py +++ b/qtconsole/ansi_code_processor.py @@ -185,6 +185,17 @@ def set_csi_code(self, command, params=[]): count = params[0] if params else 1 self.actions.append(ScrollAction('scroll', dir, 'line', count)) + elif (command == 'A'): # Move N lines Up + dir = 'up' + count = params[0] if params else 1 + self.actions.append(MoveAction('move', dir, 'line', count)) + elif (command == 'F'): # Goes back to the begining of the n-th previous line + dir = 'up' + count = params[0] if params else 1 + self.actions.append(MoveAction('move', dir, 'line', count)) + self.actions.append(CarriageReturnAction('carriage-return')) + + def set_osc_code(self, params): """ Set attributes based on OSC (Operating System Command) parameters. diff --git a/qtconsole/console_widget.py b/qtconsole/console_widget.py index 62d20377..d748d90e 100644 --- a/qtconsole/console_widget.py +++ b/qtconsole/console_widget.py @@ -2154,6 +2154,11 @@ def _insert_plain_text(self, cursor, text, flush=False): cursor.select(QtGui.QTextCursor.Document) cursor.removeSelectedText() + elif act.action == 'move' and act.unit == 'line' and act.dir == 'up': + for i in range(act.count): + cursor.movePosition( + QtGui.QTextCursor.Up) + elif act.action == 'carriage-return': cursor.movePosition( QtGui.QTextCursor.StartOfLine, From 95f24983ed83c226f8ad3ddd884d55eae724c2e1 Mon Sep 17 00:00:00 2001 From: jsbautista Date: Mon, 29 Jul 2024 22:55:28 -0500 Subject: [PATCH 02/30] Fix command F --- qtconsole/ansi_code_processor.py | 3 +-- qtconsole/console_widget.py | 14 +++++++++++--- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/qtconsole/ansi_code_processor.py b/qtconsole/ansi_code_processor.py index 18278e22..36969a4a 100644 --- a/qtconsole/ansi_code_processor.py +++ b/qtconsole/ansi_code_processor.py @@ -190,10 +190,9 @@ def set_csi_code(self, command, params=[]): count = params[0] if params else 1 self.actions.append(MoveAction('move', dir, 'line', count)) elif (command == 'F'): # Goes back to the begining of the n-th previous line - dir = 'up' + dir = 'leftup' count = params[0] if params else 1 self.actions.append(MoveAction('move', dir, 'line', count)) - self.actions.append(CarriageReturnAction('carriage-return')) def set_osc_code(self, params): diff --git a/qtconsole/console_widget.py b/qtconsole/console_widget.py index d748d90e..1a696b68 100644 --- a/qtconsole/console_widget.py +++ b/qtconsole/console_widget.py @@ -2154,10 +2154,18 @@ def _insert_plain_text(self, cursor, text, flush=False): cursor.select(QtGui.QTextCursor.Document) cursor.removeSelectedText() - elif act.action == 'move' and act.unit == 'line' and act.dir == 'up': - for i in range(act.count): + elif act.action == 'move' and act.unit == 'line': + if act.dir == 'up': + for i in range(act.count): + cursor.movePosition( + QtGui.QTextCursor.Up) + elif act.dir == 'leftup': + for i in range(act.count): + cursor.movePosition( + QtGui.QTextCursor.Up) cursor.movePosition( - QtGui.QTextCursor.Up) + QtGui.QTextCursor.StartOfLine, + QtGui.QTextCursor.MoveAnchor) elif act.action == 'carriage-return': cursor.movePosition( From a711809828364f9afa383724dddb94f47bf744d5 Mon Sep 17 00:00:00 2001 From: jsbautista Date: Mon, 5 Aug 2024 13:39:00 -0500 Subject: [PATCH 03/30] add Test to moveCursor --- qtconsole/tests/test_ansi_code_processor.py | 38 +++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/qtconsole/tests/test_ansi_code_processor.py b/qtconsole/tests/test_ansi_code_processor.py index 2b7dd71f..83dc8275 100644 --- a/qtconsole/tests/test_ansi_code_processor.py +++ b/qtconsole/tests/test_ansi_code_processor.py @@ -182,6 +182,44 @@ def test_combined(self): self.assertEqual(splits, ['abc', None, 'def', None]) self.assertEqual(actions, [[], ['carriage-return'], [], ['backspace']]) + def test_move_cursor_up(self): + """ Do control sequences for scrolling the buffer work? + """ + string = '\x1b[A\x1b[5A\x1b[F\x1b[5F' + i = -1 + for i, substring in enumerate(self.processor.split_string(string)): + if i == 0: + self.assertEqual(len(self.processor.actions), 1) + action = self.processor.actions[0] + self.assertEqual(action.action, 'move') + self.assertEqual(action.dir, 'up') + self.assertEqual(action.unit, 'line') + self.assertEqual(action.count, 1) + elif i == 1: + self.assertEqual(len(self.processor.actions), 1) + action = self.processor.actions[0] + self.assertEqual(action.action, 'move') + self.assertEqual(action.dir, 'up') + self.assertEqual(action.unit, 'line') + self.assertEqual(action.count, 5) + elif i == 2: + self.assertEqual(len(self.processor.actions), 1) + action = self.processor.actions[0] + self.assertEqual(action.action, 'move') + self.assertEqual(action.dir, 'leftup') + self.assertEqual(action.unit, 'line') + self.assertEqual(action.count, 1) + elif i == 3: + self.assertEqual(len(self.processor.actions), 1) + action = self.processor.actions[0] + self.assertEqual(action.action, 'move') + self.assertEqual(action.dir, 'leftup') + self.assertEqual(action.unit, 'line') + self.assertEqual(action.count, 5) + else: + self.fail('Too many substrings.') + self.assertEqual(i, 1, 'Too few substrings.') + if __name__ == '__main__': unittest.main() From be2f61954a3b01abe81b493e3b393c79a5d49b02 Mon Sep 17 00:00:00 2001 From: jsbautista Date: Mon, 5 Aug 2024 13:42:35 -0500 Subject: [PATCH 04/30] Fix Test to moveCursor --- qtconsole/tests/test_ansi_code_processor.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/qtconsole/tests/test_ansi_code_processor.py b/qtconsole/tests/test_ansi_code_processor.py index 83dc8275..a696cd61 100644 --- a/qtconsole/tests/test_ansi_code_processor.py +++ b/qtconsole/tests/test_ansi_code_processor.py @@ -218,7 +218,7 @@ def test_move_cursor_up(self): self.assertEqual(action.count, 5) else: self.fail('Too many substrings.') - self.assertEqual(i, 1, 'Too few substrings.') + self.assertEqual(i, 3, 'Too few substrings.') if __name__ == '__main__': From 548c65fb183ef882b62ca1136195cbf33a8f059d Mon Sep 17 00:00:00 2001 From: jsbautista Date: Mon, 5 Aug 2024 13:50:38 -0500 Subject: [PATCH 05/30] Fix Test to moveCursor --- qtconsole/tests/test_ansi_code_processor.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/qtconsole/tests/test_ansi_code_processor.py b/qtconsole/tests/test_ansi_code_processor.py index a696cd61..e20bf28f 100644 --- a/qtconsole/tests/test_ansi_code_processor.py +++ b/qtconsole/tests/test_ansi_code_processor.py @@ -183,8 +183,6 @@ def test_combined(self): self.assertEqual(actions, [[], ['carriage-return'], [], ['backspace']]) def test_move_cursor_up(self): - """ Do control sequences for scrolling the buffer work? - """ string = '\x1b[A\x1b[5A\x1b[F\x1b[5F' i = -1 for i, substring in enumerate(self.processor.split_string(string)): From dea62c7a9fc17c33e2b893e67d9f2f29694a9edb Mon Sep 17 00:00:00 2001 From: jsbautista Date: Mon, 19 Aug 2024 20:10:44 -0500 Subject: [PATCH 06/30] Add down line action --- qtconsole/console_widget.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/qtconsole/console_widget.py b/qtconsole/console_widget.py index 1a696b68..5870f33d 100644 --- a/qtconsole/console_widget.py +++ b/qtconsole/console_widget.py @@ -2159,6 +2159,10 @@ def _insert_plain_text(self, cursor, text, flush=False): for i in range(act.count): cursor.movePosition( QtGui.QTextCursor.Up) + elif act.dir == 'down': + for i in range(act.count): + cursor.movePosition( + QtGui.QTextCursor.Down) elif act.dir == 'leftup': for i in range(act.count): cursor.movePosition( From d54f69b382018abf942af3f417652ab7cc7360e8 Mon Sep 17 00:00:00 2001 From: jsbautista Date: Mon, 26 Aug 2024 21:41:01 -0500 Subject: [PATCH 07/30] Add action move down AnsiCodeProcessor --- qtconsole/ansi_code_processor.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/qtconsole/ansi_code_processor.py b/qtconsole/ansi_code_processor.py index 09a7940a..bca4d2c6 100644 --- a/qtconsole/ansi_code_processor.py +++ b/qtconsole/ansi_code_processor.py @@ -189,6 +189,10 @@ def set_csi_code(self, command, params=[]): dir = 'up' count = params[0] if params else 1 self.actions.append(MoveAction('move', dir, 'line', count)) + elif (command == 'B'): # Move N lines Down + dir = 'down' + count = params[0] if params else 1 + self.actions.append(MoveAction('move', dir, 'line', count)) elif (command == 'F'): # Goes back to the begining of the n-th previous line dir = 'leftup' count = params[0] if params else 1 From b4929201c45b9691e62063e31c53537785a26f48 Mon Sep 17 00:00:00 2001 From: jsbautista Date: Mon, 26 Aug 2024 22:53:31 -0500 Subject: [PATCH 08/30] Add new behavior to \n --- qtconsole/console_widget.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/qtconsole/console_widget.py b/qtconsole/console_widget.py index efa78a8d..16455146 100644 --- a/qtconsole/console_widget.py +++ b/qtconsole/console_widget.py @@ -2220,7 +2220,9 @@ def _insert_plain_text(self, cursor, text, flush=False): QtGui.QTextCursor.MoveAnchor) elif act.action == 'newline': - cursor.movePosition(QtGui.QTextCursor.EndOfLine) + if not cursor.movePosition(QtGui.QTextCursor.NextBlock): + cursor.movePosition(QtGui.QTextCursor.EndOfLine) + cursor.insertText('\n') # simulate replacement mode if substring is not None: From 6044edc470a4cb4e2150efe9d472e63995394f8b Mon Sep 17 00:00:00 2001 From: jsbautista Date: Mon, 26 Aug 2024 22:53:48 -0500 Subject: [PATCH 09/30] Add new behavior to \n --- qtconsole/ansi_code_processor.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/qtconsole/ansi_code_processor.py b/qtconsole/ansi_code_processor.py index bca4d2c6..c5492a7c 100644 --- a/qtconsole/ansi_code_processor.py +++ b/qtconsole/ansi_code_processor.py @@ -122,7 +122,7 @@ def split_string(self, string): self.actions = [] elif g0 == '\n' or g0 == '\r\n': self.actions.append(NewLineAction('newline')) - yield g0 + yield None self.actions = [] else: params = [ param for param in groups[1].split(';') if param ] From 461a8d4fd1bbd41cbfdbdb70dc2d33d10e8ef151 Mon Sep 17 00:00:00 2001 From: jsbautista Date: Tue, 27 Aug 2024 13:00:32 -0500 Subject: [PATCH 10/30] fixTests --- qtconsole/tests/test_ansi_code_processor.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/qtconsole/tests/test_ansi_code_processor.py b/qtconsole/tests/test_ansi_code_processor.py index e20bf28f..07481238 100644 --- a/qtconsole/tests/test_ansi_code_processor.py +++ b/qtconsole/tests/test_ansi_code_processor.py @@ -139,7 +139,7 @@ def test_carriage_return_newline(self): for split in self.processor.split_string(string): splits.append(split) actions.append([action.action for action in self.processor.actions]) - self.assertEqual(splits, ['foo', None, 'bar', '\r\n', 'cat', '\r\n', '\n']) + self.assertEqual(splits, ['foo', None, 'bar',None, 'cat', None, None]) self.assertEqual(actions, [[], ['carriage-return'], [], ['newline'], [], ['newline'], ['newline']]) def test_beep(self): From 83e2f1d2f873a6da8da7af62c1ecf7b73d30bae0 Mon Sep 17 00:00:00 2001 From: jsbautista Date: Tue, 27 Aug 2024 13:17:15 -0500 Subject: [PATCH 11/30] fixTests --- qtconsole/tests/test_ansi_code_processor.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/qtconsole/tests/test_ansi_code_processor.py b/qtconsole/tests/test_ansi_code_processor.py index 07481238..74a4a4f8 100644 --- a/qtconsole/tests/test_ansi_code_processor.py +++ b/qtconsole/tests/test_ansi_code_processor.py @@ -139,7 +139,7 @@ def test_carriage_return_newline(self): for split in self.processor.split_string(string): splits.append(split) actions.append([action.action for action in self.processor.actions]) - self.assertEqual(splits, ['foo', None, 'bar',None, 'cat', None, None]) + self.assertEqual(splits, ['foo', None, 'bar',None, 'cat', None, '\n']) self.assertEqual(actions, [[], ['carriage-return'], [], ['newline'], [], ['newline'], ['newline']]) def test_beep(self): From 3b23c097a4438d7098584e9535a18b027a6fe4fd Mon Sep 17 00:00:00 2001 From: jsbautista Date: Tue, 27 Aug 2024 13:19:10 -0500 Subject: [PATCH 12/30] Add new behavior to \n --- qtconsole/ansi_code_processor.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/qtconsole/ansi_code_processor.py b/qtconsole/ansi_code_processor.py index c5492a7c..8fc8a795 100644 --- a/qtconsole/ansi_code_processor.py +++ b/qtconsole/ansi_code_processor.py @@ -147,7 +147,7 @@ def split_string(self, string): if last_char is not None: self.actions.append(NewLineAction('newline')) - yield last_char + yield None def set_csi_code(self, command, params=[]): """ Set attributes based on CSI (Control Sequence Introducer) code. From 152740a3f74363b8fe5125543d9bcfc589abadfa Mon Sep 17 00:00:00 2001 From: jsbautista Date: Tue, 27 Aug 2024 13:19:29 -0500 Subject: [PATCH 13/30] fixTests --- qtconsole/tests/test_ansi_code_processor.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/qtconsole/tests/test_ansi_code_processor.py b/qtconsole/tests/test_ansi_code_processor.py index 74a4a4f8..07481238 100644 --- a/qtconsole/tests/test_ansi_code_processor.py +++ b/qtconsole/tests/test_ansi_code_processor.py @@ -139,7 +139,7 @@ def test_carriage_return_newline(self): for split in self.processor.split_string(string): splits.append(split) actions.append([action.action for action in self.processor.actions]) - self.assertEqual(splits, ['foo', None, 'bar',None, 'cat', None, '\n']) + self.assertEqual(splits, ['foo', None, 'bar',None, 'cat', None, None]) self.assertEqual(actions, [[], ['carriage-return'], [], ['newline'], [], ['newline'], ['newline']]) def test_beep(self): From 75a53bf03e745ba27a0b84bcacb7ea859a42155b Mon Sep 17 00:00:00 2001 From: jsbautista Date: Tue, 27 Aug 2024 13:42:23 -0500 Subject: [PATCH 14/30] fix behavior to \n --- qtconsole/console_widget.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/qtconsole/console_widget.py b/qtconsole/console_widget.py index 16455146..4fd46aa7 100644 --- a/qtconsole/console_widget.py +++ b/qtconsole/console_widget.py @@ -2220,9 +2220,9 @@ def _insert_plain_text(self, cursor, text, flush=False): QtGui.QTextCursor.MoveAnchor) elif act.action == 'newline': - if not cursor.movePosition(QtGui.QTextCursor.NextBlock): - cursor.movePosition(QtGui.QTextCursor.EndOfLine) + if not cursor.movePosition(QtGui.QTextCursor.NextBlock): cursor.insertText('\n') + cursor.movePosition(QtGui.QTextCursor.EndOfLine) # simulate replacement mode if substring is not None: From c198d204dfe3d265778d6c2e03d66e23cfbe6ffa Mon Sep 17 00:00:00 2001 From: jsbautista Date: Tue, 27 Aug 2024 14:18:44 -0500 Subject: [PATCH 15/30] fix behavior to \n --- qtconsole/ansi_code_processor.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/qtconsole/ansi_code_processor.py b/qtconsole/ansi_code_processor.py index 8fc8a795..c5492a7c 100644 --- a/qtconsole/ansi_code_processor.py +++ b/qtconsole/ansi_code_processor.py @@ -147,7 +147,7 @@ def split_string(self, string): if last_char is not None: self.actions.append(NewLineAction('newline')) - yield None + yield last_char def set_csi_code(self, command, params=[]): """ Set attributes based on CSI (Control Sequence Introducer) code. From 380e56cfda310460def7c4855bb50cabb3a9b29c Mon Sep 17 00:00:00 2001 From: jsbautista Date: Tue, 27 Aug 2024 14:18:49 -0500 Subject: [PATCH 16/30] fixTests --- qtconsole/tests/test_ansi_code_processor.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/qtconsole/tests/test_ansi_code_processor.py b/qtconsole/tests/test_ansi_code_processor.py index 07481238..74a4a4f8 100644 --- a/qtconsole/tests/test_ansi_code_processor.py +++ b/qtconsole/tests/test_ansi_code_processor.py @@ -139,7 +139,7 @@ def test_carriage_return_newline(self): for split in self.processor.split_string(string): splits.append(split) actions.append([action.action for action in self.processor.actions]) - self.assertEqual(splits, ['foo', None, 'bar',None, 'cat', None, None]) + self.assertEqual(splits, ['foo', None, 'bar',None, 'cat', None, '\n']) self.assertEqual(actions, [[], ['carriage-return'], [], ['newline'], [], ['newline'], ['newline']]) def test_beep(self): From 03e83dc0f8dae40c80b6351175ecf5d31e42ad28 Mon Sep 17 00:00:00 2001 From: jsbautista Date: Sun, 1 Sep 2024 20:55:58 -0500 Subject: [PATCH 17/30] fix behavior to \n --- qtconsole/ansi_code_processor.py | 2 +- qtconsole/console_widget.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/qtconsole/ansi_code_processor.py b/qtconsole/ansi_code_processor.py index c5492a7c..8fc8a795 100644 --- a/qtconsole/ansi_code_processor.py +++ b/qtconsole/ansi_code_processor.py @@ -147,7 +147,7 @@ def split_string(self, string): if last_char is not None: self.actions.append(NewLineAction('newline')) - yield last_char + yield None def set_csi_code(self, command, params=[]): """ Set attributes based on CSI (Control Sequence Introducer) code. diff --git a/qtconsole/console_widget.py b/qtconsole/console_widget.py index 4fd46aa7..a3052aed 100644 --- a/qtconsole/console_widget.py +++ b/qtconsole/console_widget.py @@ -2221,8 +2221,8 @@ def _insert_plain_text(self, cursor, text, flush=False): elif act.action == 'newline': if not cursor.movePosition(QtGui.QTextCursor.NextBlock): - cursor.insertText('\n') cursor.movePosition(QtGui.QTextCursor.EndOfLine) + cursor.insertText('\n') # simulate replacement mode if substring is not None: From 6aa21d615372ef23c82b3139aedff52b0b7c9e53 Mon Sep 17 00:00:00 2001 From: jsbautista Date: Sun, 1 Sep 2024 21:00:37 -0500 Subject: [PATCH 18/30] fixTests --- qtconsole/tests/test_ansi_code_processor.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/qtconsole/tests/test_ansi_code_processor.py b/qtconsole/tests/test_ansi_code_processor.py index 74a4a4f8..07481238 100644 --- a/qtconsole/tests/test_ansi_code_processor.py +++ b/qtconsole/tests/test_ansi_code_processor.py @@ -139,7 +139,7 @@ def test_carriage_return_newline(self): for split in self.processor.split_string(string): splits.append(split) actions.append([action.action for action in self.processor.actions]) - self.assertEqual(splits, ['foo', None, 'bar',None, 'cat', None, '\n']) + self.assertEqual(splits, ['foo', None, 'bar',None, 'cat', None, None]) self.assertEqual(actions, [[], ['carriage-return'], [], ['newline'], [], ['newline'], ['newline']]) def test_beep(self): From 46aa854e727dec88bab71faf2913a3856d51aa62 Mon Sep 17 00:00:00 2001 From: jsbautista Date: Sun, 1 Sep 2024 22:31:37 -0500 Subject: [PATCH 19/30] fix behavior to \n --- qtconsole/ansi_code_processor.py | 2 +- qtconsole/console_widget.py | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/qtconsole/ansi_code_processor.py b/qtconsole/ansi_code_processor.py index 8fc8a795..8c3d3303 100644 --- a/qtconsole/ansi_code_processor.py +++ b/qtconsole/ansi_code_processor.py @@ -95,7 +95,7 @@ def split_string(self, string): # strings ending with \r are assumed to be ending in \r\n since # \n is appended to output strings automatically. Accounting # for that, here. - last_char = '\n' if len(string) > 0 and string[-1] == '\n' else None + last_char = None#'\n' if len(string) > 0 and string[-1] == '\n' else None string = string[:-1] if last_char is not None else string for match in ANSI_OR_SPECIAL_PATTERN.finditer(string): diff --git a/qtconsole/console_widget.py b/qtconsole/console_widget.py index a3052aed..643539ab 100644 --- a/qtconsole/console_widget.py +++ b/qtconsole/console_widget.py @@ -2221,7 +2221,8 @@ def _insert_plain_text(self, cursor, text, flush=False): elif act.action == 'newline': if not cursor.movePosition(QtGui.QTextCursor.NextBlock): - cursor.movePosition(QtGui.QTextCursor.EndOfLine) + cursor.movePosition(QtGui.QTextCursor.EndOfLine, + QtGui.QTextCursor.MoveAnchor) cursor.insertText('\n') # simulate replacement mode From 7aff3b063184b97852b0700ade4ee62532c6328c Mon Sep 17 00:00:00 2001 From: jsbautista Date: Sun, 1 Sep 2024 22:52:39 -0500 Subject: [PATCH 20/30] fixTests --- qtconsole/tests/test_00_console_widget.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/qtconsole/tests/test_00_console_widget.py b/qtconsole/tests/test_00_console_widget.py index c9b571e8..ed30122c 100644 --- a/qtconsole/tests/test_00_console_widget.py +++ b/qtconsole/tests/test_00_console_widget.py @@ -394,7 +394,7 @@ def test_print_carriage_return(self): w._append_plain_text(text, before_prompt=True) w._flush_pending_stream() # emulate text being flushed - self.assert_text_equal(w._get_cursor(), + self.assert_text_equal(w._get_line_start_cursor(), "Hello\u20290123456789\u2029\u2029prompt>") # Print after prompt From 918902381213fc7412210f8b380c434b35d75f95 Mon Sep 17 00:00:00 2001 From: jsbautista Date: Sun, 1 Sep 2024 22:59:31 -0500 Subject: [PATCH 21/30] fixTests --- qtconsole/tests/test_00_console_widget.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/qtconsole/tests/test_00_console_widget.py b/qtconsole/tests/test_00_console_widget.py index ed30122c..0ab3bc90 100644 --- a/qtconsole/tests/test_00_console_widget.py +++ b/qtconsole/tests/test_00_console_widget.py @@ -392,9 +392,9 @@ def test_print_carriage_return(self): for text in test_inputs: w._append_plain_text(text, before_prompt=True) - w._flush_pending_stream() # emulate text being flushed + #w._flush_pending_stream() # emulate text being flushed - self.assert_text_equal(w._get_line_start_cursor(), + self.assert_text_equal(w._get_cursor(), "Hello\u20290123456789\u2029\u2029prompt>") # Print after prompt From 7591edd25b8b66a9c0149e1a46f935fb3c3bcf95 Mon Sep 17 00:00:00 2001 From: jsbautista Date: Mon, 2 Sep 2024 11:44:07 -0500 Subject: [PATCH 22/30] fixTests --- qtconsole/console_widget.py | 5 ++++- qtconsole/tests/test_00_console_widget.py | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/qtconsole/console_widget.py b/qtconsole/console_widget.py index 643539ab..79f9d1d1 100644 --- a/qtconsole/console_widget.py +++ b/qtconsole/console_widget.py @@ -2220,7 +2220,10 @@ def _insert_plain_text(self, cursor, text, flush=False): QtGui.QTextCursor.MoveAnchor) elif act.action == 'newline': - if not cursor.movePosition(QtGui.QTextCursor.NextBlock): + self.log.debug(self._prompt) + if cursor.block() != cursor.document().lastBlock(): + cursor.movePosition(QtGui.QTextCursor.NextBlock) + else: cursor.movePosition(QtGui.QTextCursor.EndOfLine, QtGui.QTextCursor.MoveAnchor) cursor.insertText('\n') diff --git a/qtconsole/tests/test_00_console_widget.py b/qtconsole/tests/test_00_console_widget.py index 0ab3bc90..c9b571e8 100644 --- a/qtconsole/tests/test_00_console_widget.py +++ b/qtconsole/tests/test_00_console_widget.py @@ -392,7 +392,7 @@ def test_print_carriage_return(self): for text in test_inputs: w._append_plain_text(text, before_prompt=True) - #w._flush_pending_stream() # emulate text being flushed + w._flush_pending_stream() # emulate text being flushed self.assert_text_equal(w._get_cursor(), "Hello\u20290123456789\u2029\u2029prompt>") From 41ea37e9ab2b1537138ee8288fbe5f8a1e97c34d Mon Sep 17 00:00:00 2001 From: jsbautista <42411448+jsbautista@users.noreply.github.com> Date: Sun, 8 Sep 2024 23:01:13 -0500 Subject: [PATCH 23/30] Update qtconsole/console_widget.py MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Daniel Althviz Moré <16781833+dalthviz@users.noreply.github.com> --- qtconsole/console_widget.py | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/qtconsole/console_widget.py b/qtconsole/console_widget.py index 79f9d1d1..495b3409 100644 --- a/qtconsole/console_widget.py +++ b/qtconsole/console_widget.py @@ -2220,13 +2220,19 @@ def _insert_plain_text(self, cursor, text, flush=False): QtGui.QTextCursor.MoveAnchor) elif act.action == 'newline': - self.log.debug(self._prompt) - if cursor.block() != cursor.document().lastBlock(): + if ( + cursor.block() != cursor.document().lastBlock() + and not cursor.document() + .toPlainText() + .endswith(self._prompt) + ): cursor.movePosition(QtGui.QTextCursor.NextBlock) else: - cursor.movePosition(QtGui.QTextCursor.EndOfLine, - QtGui.QTextCursor.MoveAnchor) - cursor.insertText('\n') + cursor.movePosition( + QtGui.QTextCursor.EndOfLine, + QtGui.QTextCursor.MoveAnchor, + ) + cursor.insertText("\n") # simulate replacement mode if substring is not None: From cb7bcaaaa1a34d62518ce76e6386b16b002dcf34 Mon Sep 17 00:00:00 2001 From: jsbautista Date: Mon, 16 Sep 2024 13:57:21 -0500 Subject: [PATCH 24/30] Clean code --- qtconsole/ansi_code_processor.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/qtconsole/ansi_code_processor.py b/qtconsole/ansi_code_processor.py index 8c3d3303..8dfdcf50 100644 --- a/qtconsole/ansi_code_processor.py +++ b/qtconsole/ansi_code_processor.py @@ -95,7 +95,7 @@ def split_string(self, string): # strings ending with \r are assumed to be ending in \r\n since # \n is appended to output strings automatically. Accounting # for that, here. - last_char = None#'\n' if len(string) > 0 and string[-1] == '\n' else None + last_char = None string = string[:-1] if last_char is not None else string for match in ANSI_OR_SPECIAL_PATTERN.finditer(string): From 7aaff636c2cfedc819fff00b4abcb5ec6060486d Mon Sep 17 00:00:00 2001 From: jsbautista <42411448+jsbautista@users.noreply.github.com> Date: Tue, 24 Sep 2024 14:03:44 -0500 Subject: [PATCH 25/30] Update qtconsole/tests/test_ansi_code_processor.py MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Daniel Althviz Moré <16781833+dalthviz@users.noreply.github.com> --- qtconsole/tests/test_ansi_code_processor.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/qtconsole/tests/test_ansi_code_processor.py b/qtconsole/tests/test_ansi_code_processor.py index 07481238..7ca00002 100644 --- a/qtconsole/tests/test_ansi_code_processor.py +++ b/qtconsole/tests/test_ansi_code_processor.py @@ -139,7 +139,7 @@ def test_carriage_return_newline(self): for split in self.processor.split_string(string): splits.append(split) actions.append([action.action for action in self.processor.actions]) - self.assertEqual(splits, ['foo', None, 'bar',None, 'cat', None, None]) + self.assertEqual(splits, ['foo', None, 'bar', None, 'cat', None, None]) self.assertEqual(actions, [[], ['carriage-return'], [], ['newline'], [], ['newline'], ['newline']]) def test_beep(self): From 42cc43192318520352c83f9be300ddf2f2c8eeda Mon Sep 17 00:00:00 2001 From: jsbautista Date: Tue, 8 Oct 2024 09:38:53 -0500 Subject: [PATCH 26/30] Clean Code --- qtconsole/ansi_code_processor.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/qtconsole/ansi_code_processor.py b/qtconsole/ansi_code_processor.py index 8dfdcf50..3875c23d 100644 --- a/qtconsole/ansi_code_processor.py +++ b/qtconsole/ansi_code_processor.py @@ -92,9 +92,6 @@ def split_string(self, string): self.actions = [] start = 0 - # strings ending with \r are assumed to be ending in \r\n since - # \n is appended to output strings automatically. Accounting - # for that, here. last_char = None string = string[:-1] if last_char is not None else string From ddf5a1d341b694256f0dc3e551a1848ced820f65 Mon Sep 17 00:00:00 2001 From: jsbautista <42411448+jsbautista@users.noreply.github.com> Date: Thu, 17 Oct 2024 09:29:22 -0500 Subject: [PATCH 27/30] Apply suggestions from code review Co-authored-by: Carlos Cordoba --- qtconsole/ansi_code_processor.py | 8 +++++--- qtconsole/console_widget.py | 14 +++++++++----- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/qtconsole/ansi_code_processor.py b/qtconsole/ansi_code_processor.py index 3875c23d..16f2ddde 100644 --- a/qtconsole/ansi_code_processor.py +++ b/qtconsole/ansi_code_processor.py @@ -182,15 +182,17 @@ def set_csi_code(self, command, params=[]): count = params[0] if params else 1 self.actions.append(ScrollAction('scroll', dir, 'line', count)) - elif (command == 'A'): # Move N lines Up + elif command == 'A': # Move N lines Up dir = 'up' count = params[0] if params else 1 self.actions.append(MoveAction('move', dir, 'line', count)) - elif (command == 'B'): # Move N lines Down + + elif command == 'B': # Move N lines Down dir = 'down' count = params[0] if params else 1 self.actions.append(MoveAction('move', dir, 'line', count)) - elif (command == 'F'): # Goes back to the begining of the n-th previous line + + elif command == 'F': # Goes back to the begining of the n-th previous line dir = 'leftup' count = params[0] if params else 1 self.actions.append(MoveAction('move', dir, 'line', count)) diff --git a/qtconsole/console_widget.py b/qtconsole/console_widget.py index 495b3409..aa492baf 100644 --- a/qtconsole/console_widget.py +++ b/qtconsole/console_widget.py @@ -2192,18 +2192,22 @@ def _insert_plain_text(self, cursor, text, flush=False): if act.dir == 'up': for i in range(act.count): cursor.movePosition( - QtGui.QTextCursor.Up) + QtGui.QTextCursor.Up + ) elif act.dir == 'down': for i in range(act.count): cursor.movePosition( - QtGui.QTextCursor.Down) + QtGui.QTextCursor.Down + ) elif act.dir == 'leftup': for i in range(act.count): cursor.movePosition( - QtGui.QTextCursor.Up) + QtGui.QTextCursor.Up + ) cursor.movePosition( - QtGui.QTextCursor.StartOfLine, - QtGui.QTextCursor.MoveAnchor) + QtGui.QTextCursor.StartOfLine, + QtGui.QTextCursor.MoveAnchor + ) elif act.action == 'carriage-return': cursor.movePosition( From a7b4c10f2dfdf6b8f7804479fd2108e1242b71f2 Mon Sep 17 00:00:00 2001 From: jsbautista Date: Thu, 17 Oct 2024 14:14:28 -0500 Subject: [PATCH 28/30] add coment to test --- qtconsole/tests/test_ansi_code_processor.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/qtconsole/tests/test_ansi_code_processor.py b/qtconsole/tests/test_ansi_code_processor.py index 7ca00002..48909b62 100644 --- a/qtconsole/tests/test_ansi_code_processor.py +++ b/qtconsole/tests/test_ansi_code_processor.py @@ -183,6 +183,9 @@ def test_combined(self): self.assertEqual(actions, [[], ['carriage-return'], [], ['backspace']]) def test_move_cursor_up(self): + """Are the ANSI commands for the cursor movement actions + (movement up and to the beginning of the line) processed correctly? + """ string = '\x1b[A\x1b[5A\x1b[F\x1b[5F' i = -1 for i, substring in enumerate(self.processor.split_string(string)): From e56dd6032c461c91b7dd7cf055365af7746dc99e Mon Sep 17 00:00:00 2001 From: jsbautista Date: Mon, 21 Oct 2024 08:23:39 -0500 Subject: [PATCH 29/30] add comment to test --- qtconsole/tests/test_ansi_code_processor.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/qtconsole/tests/test_ansi_code_processor.py b/qtconsole/tests/test_ansi_code_processor.py index 48909b62..11d0a200 100644 --- a/qtconsole/tests/test_ansi_code_processor.py +++ b/qtconsole/tests/test_ansi_code_processor.py @@ -186,6 +186,10 @@ def test_move_cursor_up(self): """Are the ANSI commands for the cursor movement actions (movement up and to the beginning of the line) processed correctly? """ + #This line moves the cursor up once, then moves it up five more lines. + #Next, it moves the cursor to the beginning of the previous line, and + #finally moves it to the beginning of the fifth line above the current + #position string = '\x1b[A\x1b[5A\x1b[F\x1b[5F' i = -1 for i, substring in enumerate(self.processor.split_string(string)): From a7ee27f63f966d819e1105be3c7e54d58f96ffcd Mon Sep 17 00:00:00 2001 From: jsbautista <42411448+jsbautista@users.noreply.github.com> Date: Mon, 21 Oct 2024 14:07:09 -0500 Subject: [PATCH 30/30] Update qtconsole/tests/test_ansi_code_processor.py MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Daniel Althviz Moré <16781833+dalthviz@users.noreply.github.com> --- qtconsole/tests/test_ansi_code_processor.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/qtconsole/tests/test_ansi_code_processor.py b/qtconsole/tests/test_ansi_code_processor.py index 11d0a200..ed00d631 100644 --- a/qtconsole/tests/test_ansi_code_processor.py +++ b/qtconsole/tests/test_ansi_code_processor.py @@ -186,10 +186,10 @@ def test_move_cursor_up(self): """Are the ANSI commands for the cursor movement actions (movement up and to the beginning of the line) processed correctly? """ - #This line moves the cursor up once, then moves it up five more lines. - #Next, it moves the cursor to the beginning of the previous line, and - #finally moves it to the beginning of the fifth line above the current - #position + # This line moves the cursor up once, then moves it up five more lines. + # Next, it moves the cursor to the beginning of the previous line, and + # finally moves it to the beginning of the fifth line above the current + # position string = '\x1b[A\x1b[5A\x1b[F\x1b[5F' i = -1 for i, substring in enumerate(self.processor.split_string(string)):