@@ -107,6 +107,9 @@ class SimpleCursesLineEdit(object):
107
107
'[' , ']' , '{' , '}' , '|' , '\\ ' , '/' ,
108
108
)
109
109
110
+ """ Set to True to restringt accepted characters to ASCII only """
111
+ _pure_ascii = False
112
+
110
113
""" True if backlash has been pressed """
111
114
_backslash = False
112
115
@@ -227,6 +230,14 @@ def show_help_with_backslash(self):
227
230
def show_help_with_backslash (self , val ):
228
231
self ._show_help_with_backslash = val
229
232
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
+
230
241
def _is_cjk (self ):
231
242
""" Check if string contains CJK characters.
232
243
If string is empty reset history index """
@@ -930,7 +941,7 @@ def keypress(self, win, char):
930
941
logger .debug ('action: add-character' )
931
942
if self .log is not None :
932
943
self .log ('====================\n ' )
933
- if version_info < (3 , 0 ):
944
+ if version_info < (3 , 0 ) or ( self . _pure_ascii and not platform . startswith ( 'win' )) :
934
945
if 32 <= char < 127 :
935
946
# accept only ascii characters
936
947
if len (self ._string ) == self ._first + self ._curs_pos :
@@ -949,6 +960,9 @@ def keypress(self, win, char):
949
960
char = chr (char )
950
961
else :
951
962
char = self ._get_char (win , char )
963
+ if self ._pure_ascii :
964
+ if ord (char ) > 127 :
965
+ return 1
952
966
#if len(self._string) == self._first + self._curs_pos:
953
967
if self ._at_end_of_sting ():
954
968
self ._string += char
0 commit comments