Skip to content

Commit ef404f1

Browse files
committed
New implementation for BaseTextBox.get_input, reindent some code.
1 parent 7f81e52 commit ef404f1

File tree

2 files changed

+40
-43
lines changed

2 files changed

+40
-43
lines changed

visualdialog/box.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,10 @@ def __init__(
111111
self.downtime_chars = downtime_chars
112112
self.downtime_chars_delay = downtime_chars_delay
113113

114-
#: Keystroke acquisition mode for the TextBox.get_input method.
115-
self.key_detection_mode: Literal["key", "code"] = "key"
114+
#: Keystroke acquisition curses method for BaseTextBox.get_input.
115+
self.key_detection: Literal["getkey",
116+
"getch",
117+
"get_wch"] = "getkey"
116118

117119
#: List of accepted key to skip dialog.
118120
#: This defaults to a list contains " ".
@@ -200,10 +202,7 @@ def get_input(self, win: CursesWindow):
200202
curses.flushinp()
201203

202204
while 1:
203-
key = win.getch()
204-
205-
if self.key_detection_mode == "key":
206-
key = chr(key)
205+
key = getattr(win, self.key_detection)()
207206

208207
if key in self.confirm_keys:
209208
break

visualdialog/dialog.py

Lines changed: 35 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,11 @@ def __enter__(self):
7171
def __exit__(self, type, value, traceback):
7272
pass
7373

74-
def _display_end_indicator(
75-
self,
76-
win: CursesWindow,
77-
text_attr: CursesTextAttributes= (curses.A_BOLD,
78-
curses.A_BLINK)):
74+
def _display_end_indicator(self,
75+
win: CursesWindow,
76+
text_attr: CursesTextAttributes = (
77+
curses.A_BOLD,
78+
curses.A_BLINK)):
7979
"""Displays an end indicator in the lower right corner of
8080
textbox.
8181
@@ -202,22 +202,21 @@ def _one_by_one(self,
202202
self._display_end_indicator(win)
203203
self.get_input(win)
204204

205-
def char_by_char(
206-
self,
207-
win: CursesWindow,
208-
text: str,
209-
colors_pair_nb: int = 0,
210-
text_attr: Union[CursesTextAttribute,
211-
CursesTextAttributes] = (),
212-
words_attr: Mapping[Sequence[str],
213-
Union[CursesTextAttribute,
214-
CursesTextAttributes]] = {},
215-
word_delimiter: str = " ",
216-
flash_screen: bool = False,
217-
delay: int = 40,
218-
random_delay: Sequence[int] = (0, 0),
219-
callback: Callable = lambda: None,
220-
cargs: Sequence = ()):
205+
def char_by_char(self,
206+
win: CursesWindow,
207+
text: str,
208+
colors_pair_nb: int = 0,
209+
text_attr: Union[CursesTextAttribute,
210+
CursesTextAttributes] = (),
211+
words_attr: Mapping[Sequence[str],
212+
Union[CursesTextAttribute,
213+
CursesTextAttributes]] = {},
214+
word_delimiter: str = " ",
215+
flash_screen: bool = False,
216+
delay: int = 40,
217+
random_delay: Sequence[int] = (0, 0),
218+
callback: Callable = lambda: None,
219+
cargs: Sequence = ()):
221220
"""Write the given text character by character.
222221
223222
:param win: ``curses`` window object on which the method will
@@ -304,22 +303,21 @@ def char_by_char(
304303
callback,
305304
cargs)
306305

307-
def word_by_word(
308-
self,
309-
win: CursesWindow,
310-
text: str,
311-
colors_pair_nb: int = 0,
312-
text_attr: Union[CursesTextAttribute,
313-
CursesTextAttributes] = (),
314-
words_attr: Mapping[Sequence[str],
315-
Union[CursesTextAttribute,
316-
CursesTextAttributes]] = {},
317-
word_delimiter: str = " ",
318-
flash_screen: bool = False,
319-
delay: int = 150,
320-
random_delay: Sequence[int] = (0, 0),
321-
callback: Callable = lambda: None,
322-
cargs: Sequence = ()):
306+
def word_by_word(self,
307+
win: CursesWindow,
308+
text: str,
309+
colors_pair_nb: int = 0,
310+
text_attr: Union[CursesTextAttribute,
311+
CursesTextAttributes] = (),
312+
words_attr: Mapping[Sequence[str],
313+
Union[CursesTextAttribute,
314+
CursesTextAttributes]] = {},
315+
word_delimiter: str = " ",
316+
flash_screen: bool = False,
317+
delay: int = 150,
318+
random_delay: Sequence[int] = (0, 0),
319+
callback: Callable = lambda: None,
320+
cargs: Sequence = ()):
323321
"""Write the given text word by word.
324322
325323
:param win: ``curses`` window object on which the method will

0 commit comments

Comments
 (0)