3232import usb_cdc
3333import ansi_escape_code as terminal
3434
35- __version__ = "0 .0.0-auto.0"
35+ __version__ = "1 .0.0-auto.0"
3636__repo__ = "https://github.com/s-light/CircuitPython_nonblocking_serialinput.git"
3737
3838# pylint: disable=too-many-instance-attributes
@@ -142,7 +142,7 @@ def _statusline_fn_default():
142142
143143 def _statusline_update_check_intervall (self ):
144144 """Update the Statusline if intervall is over."""
145- if self .statusline_next_update <= time .monotonic ():
145+ if self .statusline and self . statusline_next_update <= time .monotonic ():
146146 self .statusline_next_update = time .monotonic () + self .statusline_intervall
147147 self .print (content = None )
148148
@@ -190,8 +190,8 @@ def print(self, *args, content=True):
190190 move += terminal .ANSIControl .cursor .previous_line (1 )
191191 # earease statusline
192192 move += terminal .ANSIControl .erase_line (2 )
193- if self .echo :
194- move += terminal .ANSIControl .cursor .next_line (1 )
193+ # if self.echo:
194+ # move += terminal.ANSIControl.cursor.next_line(1)
195195 # move += terminal.ANSIControl.cursor.position("1, 1")
196196 move += terminal .ANSIControl .cursor .horizontal_absolute (1 )
197197 # print("\n\n\n{}\n\n\n".format(repr(move)))
@@ -205,9 +205,13 @@ def print(self, *args, content=True):
205205 # print statement is finished.
206206 # now we have to reprint echo & statusline
207207 if self .statusline :
208- print (self ._get_statusline (), end = "" )
209- # print(terminal.ANSIControl.cursor.next_line(1), end="")
208+ if self .echo :
209+ print (self ._get_statusline ())
210+ else :
211+ print (self ._get_statusline (), end = "" )
212+ # print(terminal.ANSIControl.cursor.next_line(1), end="")
210213 if self .echo :
214+ print (terminal .ANSIControl .cursor .horizontal_absolute (1 ), end = "" )
211215 print (self ._get_echo_line (), end = "" )
212216 # print(self._get_echo_line())
213217 # if not self.echo and not self.statusline:
@@ -284,7 +288,10 @@ def input(self):
284288 """
285289 try :
286290 result = self .input_list .pop (0 )
287- self .print (result )
291+ if self .echo :
292+ self .print (self .echo_pre_text , result )
293+ else :
294+ self .print (result )
288295 if self .verbose :
289296 self .print ("result: {}" .format (repr (result )))
290297 except IndexError :
@@ -294,8 +301,7 @@ def input(self):
294301 ##########################################
295302 # main handling
296303
297- def update (self ):
298- """Main update funciton. please call as often as possible."""
304+ def _handle_input (self ):
299305 if self .serial .connected :
300306 available = self .serial .in_waiting
301307 while available :
@@ -311,21 +317,34 @@ def update(self):
311317 # errors="strict",
312318 self ._buffer_check_and_handle_line_ends ()
313319 available = self .serial .in_waiting
320+
321+ def _handle_input_handling_fn (self ):
314322 parsed_input = False
315323 if self .input_handling_fn :
316324 while self .input_list :
317325 # first in first out
318326 oldest_input = self .input_list .pop (0 )
319- self .print (oldest_input )
327+ text = oldest_input
328+ # isprintable is not implemented in CP
329+ # if not text.isprintable():
330+ # text = repr(text)
331+ if len (text ) == 0 :
332+ text = repr (text )
333+ if self .echo :
334+ text = self .echo_pre_text + text
335+ self .print (text )
320336 self .input_handling_fn (oldest_input )
321337 parsed_input = True
322338 if parsed_input and self .print_help_fn :
323339 self .print_help_fn ()
324- if self .echo :
325- # self.echo_print()
326- self .print ()
327- if self .statusline :
328- self ._statusline_update_check_intervall ()
340+ if self .echo or self .statusline :
341+ self .print (content = None )
342+
343+ def update (self ):
344+ """Main update funciton. please call as often as possible."""
345+ self ._handle_input ()
346+ self ._handle_input_handling_fn ()
347+ self ._statusline_update_check_intervall ()
329348
330349
331350##########################################
0 commit comments