From febbb88e0712c501c8878a3133e53c23b90ba94e Mon Sep 17 00:00:00 2001 From: rybarczykj Date: Wed, 1 Jul 2020 15:42:32 -0500 Subject: [PATCH 1/4] Added functionality for full-width character input - Works with normal input and stdin input - There still are issues with line wrapping when using full-width chars --- bpython/curtsiesfrontend/repl.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/bpython/curtsiesfrontend/repl.py b/bpython/curtsiesfrontend/repl.py index 9bccca5fe..f1915390c 100644 --- a/bpython/curtsiesfrontend/repl.py +++ b/bpython/curtsiesfrontend/repl.py @@ -19,6 +19,8 @@ from bpython._py3compat import PythonLexer from pygments.formatters import TerminalFormatter +from wcwidth import wcswidth + import blessings import curtsies @@ -1556,7 +1558,8 @@ def move_screen_up(current_line_start_row): if self.stdin.has_focus: cursor_row, cursor_column = divmod( - len(self.current_stdouterr_line) + self.stdin.cursor_offset, + len(self.current_stdouterr_line) + + wcswidth(self.stdin.current_line[: self.stdin.cursor_offset]), width, ) assert cursor_column >= 0, cursor_column @@ -1577,9 +1580,9 @@ def move_screen_up(current_line_start_row): else: cursor_row, cursor_column = divmod( ( - len(self.current_cursor_line_without_suggestion) - - len(self.current_line) - + self.cursor_offset + self.current_cursor_line_without_suggestion.width + - wcswidth(self.current_line) + + wcswidth(self.current_line[: self.cursor_offset]) ), width, ) From bc496d63f390f12620c0eab890d063634872ebf3 Mon Sep 17 00:00:00 2001 From: rybarczykj Date: Mon, 6 Jul 2020 12:59:14 -0500 Subject: [PATCH 2/4] Update minimum curtsies version requirement from 0.1.18 to 0.2.0 so as to allow .width --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 24ec50055..45f991728 100755 --- a/setup.py +++ b/setup.py @@ -225,7 +225,7 @@ def initialize_options(self): install_requires = [ "pygments", "requests", - "curtsies >=0.1.18", + "curtsies >=0.2.0", "greenlet", "six >=1.5", ] From 9e38030bbd2b2896a77dae5c9363741c8b761131 Mon Sep 17 00:00:00 2001 From: rybarczykj Date: Thu, 9 Jul 2020 09:51:26 -0500 Subject: [PATCH 3/4] Fix wide chars on input('...') --- bpython/curtsiesfrontend/repl.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bpython/curtsiesfrontend/repl.py b/bpython/curtsiesfrontend/repl.py index f1915390c..ecd65909e 100644 --- a/bpython/curtsiesfrontend/repl.py +++ b/bpython/curtsiesfrontend/repl.py @@ -1558,7 +1558,7 @@ def move_screen_up(current_line_start_row): if self.stdin.has_focus: cursor_row, cursor_column = divmod( - len(self.current_stdouterr_line) + wcswidth(self.current_stdouterr_line) + wcswidth(self.stdin.current_line[: self.stdin.cursor_offset]), width, ) From 143915ed25cf0460b58d0517ee9e8dead040b027 Mon Sep 17 00:00:00 2001 From: rybarczykj Date: Mon, 13 Jul 2020 11:52:35 -0500 Subject: [PATCH 4/4] Avoid upgrading minimum curtsies version - Use wcswidth(FmtStr.s) instead of FmtStr.width --- bpython/curtsiesfrontend/repl.py | 10 +++++++--- setup.py | 3 ++- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/bpython/curtsiesfrontend/repl.py b/bpython/curtsiesfrontend/repl.py index ecd65909e..1e0c89ac0 100644 --- a/bpython/curtsiesfrontend/repl.py +++ b/bpython/curtsiesfrontend/repl.py @@ -1361,7 +1361,11 @@ def display_line_with_prompt(self): @property def current_cursor_line_without_suggestion(self): - """Current line, either output/input or Python prompt + code""" + """ + Current line, either output/input or Python prompt + code + + :returns: FmtStr + """ value = self.current_output_line + ( "" if self.coderunner.running else self.display_line_with_prompt ) @@ -1577,10 +1581,10 @@ def move_screen_up(current_line_start_row): len(self.current_line), self.cursor_offset, ) - else: + else: # Common case for determining cursor position cursor_row, cursor_column = divmod( ( - self.current_cursor_line_without_suggestion.width + wcswidth(self.current_cursor_line_without_suggestion.s) - wcswidth(self.current_line) + wcswidth(self.current_line[: self.cursor_offset]) ), diff --git a/setup.py b/setup.py index 45f991728..92365e442 100755 --- a/setup.py +++ b/setup.py @@ -225,9 +225,10 @@ def initialize_options(self): install_requires = [ "pygments", "requests", - "curtsies >=0.2.0", + "curtsies >=0.1.18", "greenlet", "six >=1.5", + "wcwidth" ] extras_require = {