Skip to content

Commit 44be7ab

Browse files
committed
Line editor: adding pure_ascii property
1 parent 28fe37b commit 44be7ab

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed

Changelog

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
2019-10-23 s-n-g
2+
* Handling CJK presentation on station and playlist window
3+
14
2019-10-20 s-n-g
25
* Version 0.8.2
36
* Fixing chars H,L,M rejected by line editor

pyradio/radio.py

+1
Original file line numberDiff line numberDiff line change
@@ -613,6 +613,7 @@ def _give_me_a_search_class(self, operation_mode):
613613
edit_color = curses.color_pair(5),
614614
cursor_color = curses.color_pair(8))
615615
self.search = self._search_classes[self._mode_to_search[operation_mode]]
616+
#self.search.pure_ascii = True
616617
if self.ws.previous_operation_mode == self.ws.CONFIG_MODE:
617618
self.search.box_color = curses.color_pair(3)
618619
else:

pyradio/simple_curses_widgets.py

+15-1
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,9 @@ class SimpleCursesLineEdit(object):
107107
'[', ']', '{', '}', '|', '\\', '/',
108108
)
109109

110+
""" Set to True to restringt accepted characters to ASCII only """
111+
_pure_ascii = False
112+
110113
""" True if backlash has been pressed """
111114
_backslash = False
112115

@@ -227,6 +230,14 @@ def show_help_with_backslash(self):
227230
def show_help_with_backslash(self, val):
228231
self._show_help_with_backslash = val
229232

233+
@property
234+
def pure_ascii(self):
235+
return self.pure_ascii
236+
237+
@pure_ascii.setter
238+
def pure_ascii(self, val):
239+
self._pure_ascii = val
240+
230241
def _is_cjk(self):
231242
""" Check if string contains CJK characters.
232243
If string is empty reset history index """
@@ -930,7 +941,7 @@ def keypress(self, win, char):
930941
logger.debug('action: add-character')
931942
if self.log is not None:
932943
self.log('====================\n')
933-
if version_info < (3, 0):
944+
if version_info < (3, 0) or (self._pure_ascii and not platform.startswith('win')):
934945
if 32 <= char < 127:
935946
# accept only ascii characters
936947
if len(self._string) == self._first + self._curs_pos:
@@ -949,6 +960,9 @@ def keypress(self, win, char):
949960
char = chr(char)
950961
else:
951962
char = self._get_char(win, char)
963+
if self._pure_ascii:
964+
if ord(char) > 127:
965+
return 1
952966
#if len(self._string) == self._first + self._curs_pos:
953967
if self._at_end_of_sting():
954968
self._string += char

0 commit comments

Comments
 (0)