Skip to content

Commit

Permalink
Builtin apps enhancements (#106)
Browse files Browse the repository at this point in the history
* Fixed long lines freezing HyDE

* Open log.txt when run directly

* Add quit command to userinput
  • Loading branch information
echo-lalia authored Aug 24, 2024
1 parent 550eb86 commit 12a813e
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 21 deletions.
18 changes: 17 additions & 1 deletion src/launcher/HyDE.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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'):
Expand Down
30 changes: 10 additions & 20 deletions src/lib/userinput/userinput.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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)

0 comments on commit 12a813e

Please sign in to comment.