diff --git a/src/launcher/HyDE.py b/src/launcher/HyDE.py index 45f86f5..76d8475 100644 --- a/src/launcher/HyDE.py +++ b/src/launcher/HyDE.py @@ -91,6 +91,9 @@ _TAB_INDENT = const(' ') +# lines longer than this skip the formatting step +_MAX_FORMATTED_LEN = const(200) + #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Global Objects: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ DISPLAY = display.Display() @@ -414,6 +417,10 @@ def segment_from_str(string:str, index:int) -> str: @micropython.native def draw_small_line(line,x,y,fade=0): """apply special styling to a small line and display it.""" + if len(line) > _MAX_FORMATTED_LEN: + DISPLAY.text(line, x, y, CONFIG.palette[6-fade]) + return + line = format_display_line(line) is_comment = False string_char = None @@ -479,10 +486,19 @@ def draw_fancy_line(line, x, y, highlight=False, trim=True): 'False','Finally','for','from','global','if','import','in','is','lambda','None', 'nonlocal','not','or','pass','raise','return','True','try','while','with','yield')) _OPERATORS = const("<>,|[]{}()*^%!=-+/:;&@") + + # skip formatting on long lines + if len(line) > _MAX_FORMATTED_LEN: + DISPLAY.text(line, x, y, CONFIG.palette[8], font=font) + return # TODO: I worry this may be extremely unoptomized. Should maybe be tested/optimized further. # It might be worth it to try pre-processing lines into a colored # format so that we dont need to redo this between frames + # And reworking this to split lines into tokens first, rather than drawing them character-by-character, + # would also probably be a lot faster. + # Finally, only rerunning the formatting on pre-processed lines if they have been modified, should certainly + # Speed things up a ton. line = format_display_line(line) # trim right part of line to speed up styling @@ -961,7 +977,7 @@ def main_loop(): target_file = RTC.memory().decode() # TESTING: if target_file == "": - target_file = "/misc_tdeck/testkb.py" + target_file = "/log.txt" # remove syntax hilighting for plain txt files. if target_file.endswith('.txt'): diff --git a/src/lib/userinput/userinput.py b/src/lib/userinput/userinput.py index 5dd598a..5f77e15 100644 --- a/src/lib/userinput/userinput.py +++ b/src/lib/userinput/userinput.py @@ -12,17 +12,10 @@ import time from lib.hydra.config import Config from lib.display import Display - -try: - from . import _keys -except ImportError: - from lib.userinput import _keys +from . import _keys # mh_if touchscreen: -try: - from . import _touch -except ImportError: - from lib.userinput import _touch +from . import _touch # mh_end_if @@ -250,14 +243,18 @@ def system_commands(self, keylist): keylist.remove('m') # vol up - if ';' in keylist: + if 'UP' in keylist: self.config['volume'] = (self.config['volume'] + 1) % 11 - keylist.remove(';') + keylist.remove('UP') # vol down - elif '.' in keylist: + elif 'DOWN' in keylist: self.config['volume'] = (self.config['volume'] - 1) % 11 - keylist.remove('.') + keylist.remove('DOWN') + + if "q" in keylist: + machine.RTC().memory("") + machine.reset() # mh_if kb_light: if "b" in keylist: @@ -293,10 +290,3 @@ def _locked_keys_overlay(self, display): display.text(key_txt, x, _PADDING + 2, display.palette[txt_clr]) width = x - _RADIUS - _PADDING - - -if __name__ == "__main__": - user_input = UserInput(locking_keys=True) - while True: - print(user_input.get_new_keys() + user_input.get_touch_events()) - time.sleep_ms(30) \ No newline at end of file