add help text to launcher, add other hotkeys to editor bar, fix del key functionality
This commit is contained in:
parent
5dcf983bb4
commit
b9f9f8e1b8
3 changed files with 53 additions and 21 deletions
|
|
@ -42,6 +42,7 @@ COLS = 120
|
|||
special_keys = {
|
||||
"\x1b": ..., # all prefixes of special keys must be entered as Ellipsis
|
||||
"\x1b[": ...,
|
||||
"\x1b[3": ...,
|
||||
"\x1b[5": ...,
|
||||
"\x1b[6": ...,
|
||||
"\x1b[A": "KEY_UP",
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@ from argv_file_helper import argv_filename
|
|||
# usb_cdc.data.write(f"{message}\r\n".encode("utf-8"))
|
||||
|
||||
INPUT_DISPLAY_REFRESH_COOLDOWN = 0.3 # s
|
||||
SHOW_MEMFREE = False
|
||||
|
||||
|
||||
class MaybeDisableReload:
|
||||
|
|
@ -55,7 +56,8 @@ def os_exists(filename):
|
|||
|
||||
|
||||
def gc_mem_free_hint():
|
||||
return ""
|
||||
if not SHOW_MEMFREE:
|
||||
return ""
|
||||
if hasattr(gc, "mem_free"):
|
||||
gc.collect()
|
||||
return f" | free: {gc.mem_free()}"
|
||||
|
|
@ -224,16 +226,12 @@ def editor(stdscr, filename, visible_cursor): # pylint: disable=too-many-branch
|
|||
else:
|
||||
buffer = Buffer([""])
|
||||
|
||||
user_message = None
|
||||
|
||||
window = Window(curses.LINES - 1, curses.COLS - 1)
|
||||
cursor = Cursor()
|
||||
visible_cursor.text = buffer[0][0]
|
||||
last_refresh_time = -1
|
||||
# print("updating visible cursor")
|
||||
# visible_cursor.anchored_position = ((0 * 6) - 1, (0 * 12) + 20)
|
||||
# try:
|
||||
# visible_cursor.text = buffer.lines[0][0]
|
||||
# except IndexError:
|
||||
# visible_cursor.text = " "
|
||||
|
||||
stdscr.erase()
|
||||
|
||||
|
|
@ -258,10 +256,15 @@ def editor(stdscr, filename, visible_cursor): # pylint: disable=too-many-branch
|
|||
for row in range(lastrow + 1, window.n_rows):
|
||||
setline(row, "~~ EOF ~~")
|
||||
row = curses.LINES - 1
|
||||
if util.readonly():
|
||||
line = f"{filename:12} (*ro) | ^C: quit{gc_mem_free_hint()}"
|
||||
|
||||
if user_message is None:
|
||||
if util.readonly():
|
||||
line = f"{filename:12} (mnt RO ^W) | ^R run | ^C: quit{gc_mem_free_hint()}"
|
||||
else:
|
||||
line = f"{filename:12} (mnt RW ^W) | ^R run | ^S save | ^X: save & exit | ^C: exit no save{gc_mem_free_hint()}"
|
||||
else:
|
||||
line = f"{filename:12} | ^X: write & exit | ^C: quit w/o save{gc_mem_free_hint()}"
|
||||
line = user_message
|
||||
user_message = None
|
||||
setline(row, line)
|
||||
|
||||
stdscr.move(*window.translate(cursor))
|
||||
|
|
@ -285,23 +288,24 @@ def editor(stdscr, filename, visible_cursor): # pylint: disable=too-many-branch
|
|||
for row in buffer:
|
||||
print(row)
|
||||
print("---- end file contents ----")
|
||||
elif k == "\x13": # Ctrl-S
|
||||
elif k == "\x13": # Ctrl-S
|
||||
if not util.readonly():
|
||||
with open(filename, "w", encoding="utf-8") as f:
|
||||
for row in buffer:
|
||||
f.write(f"{row}\n")
|
||||
user_message = "Saved"
|
||||
else:
|
||||
print("Unable to Save due to readonly mode!")
|
||||
elif k == "\x11": # Ctrl-Q
|
||||
print("ctrl-Q")
|
||||
for row in buffer:
|
||||
print(row)
|
||||
elif k == "\x17": # Ctrl-W
|
||||
elif k == "\x17": # Ctrl-W
|
||||
boot_args_file = argv_filename("/boot.py")
|
||||
with open(boot_args_file, "w") as f:
|
||||
f.write(json.dumps([not util.readonly(), "/apps/editor/code.py", Path(filename).absolute()]))
|
||||
microcontroller.reset()
|
||||
elif k == "\x12": # Ctrl-R
|
||||
elif k == "\x12": # Ctrl-R
|
||||
print(f"Run: {filename}")
|
||||
|
||||
launcher_code_args_file = argv_filename("/code.py")
|
||||
|
|
@ -344,7 +348,13 @@ def editor(stdscr, filename, visible_cursor): # pylint: disable=too-many-branch
|
|||
right(window, buffer, cursor)
|
||||
elif k in ("KEY_DELETE", "\x04"):
|
||||
print("delete")
|
||||
buffer.delete(cursor)
|
||||
if cursor.row < len(buffer.lines) - 1 or \
|
||||
cursor.col < len(buffer.lines[cursor.row]):
|
||||
buffer.delete(cursor)
|
||||
try:
|
||||
visible_cursor.text = buffer.lines[cursor.row][cursor.col]
|
||||
except IndexError:
|
||||
visible_cursor.text = " "
|
||||
|
||||
elif k in ("KEY_BACKSPACE", "\x7f", "\x08"):
|
||||
print(f"backspace {bytes(k, 'utf-8')}")
|
||||
|
|
|
|||
35
src/code.py
35
src/code.py
|
|
@ -15,11 +15,14 @@ import displayio
|
|||
|
||||
import supervisor
|
||||
import sys
|
||||
|
||||
import terminalio
|
||||
import usb
|
||||
import adafruit_pathlib as pathlib
|
||||
from adafruit_bitmap_font import bitmap_font
|
||||
from adafruit_display_text.text_box import TextBox
|
||||
from adafruit_display_text.bitmap_label import Label
|
||||
|
||||
from adafruit_displayio_layout.layouts.grid_layout import GridLayout
|
||||
from adafruit_anchored_tilegrid import AnchoredTileGrid
|
||||
import adafruit_imageload
|
||||
|
|
@ -63,14 +66,18 @@ if display.width > 360:
|
|||
|
||||
font_file = "/fonts/terminal.lvfontbin"
|
||||
font = bitmap_font.load_font(font_file)
|
||||
main_group = displayio.Group(scale=scale)
|
||||
scaled_group = displayio.Group(scale=scale)
|
||||
|
||||
main_group = displayio.Group()
|
||||
main_group.append(scaled_group)
|
||||
|
||||
display.root_group = main_group
|
||||
|
||||
background_bmp = displayio.Bitmap(display.width, display.height, 1)
|
||||
bg_palette = displayio.Palette(1)
|
||||
bg_palette[0] = 0x222222
|
||||
bg_tg = displayio.TileGrid(bitmap=background_bmp, pixel_shader=bg_palette)
|
||||
main_group.append(bg_tg)
|
||||
scaled_group.append(bg_tg)
|
||||
|
||||
# load the mouse cursor bitmap
|
||||
mouse_bmp = displayio.OnDiskBitmap("launcher_assets/mouse_cursor.bmp")
|
||||
|
|
@ -199,12 +206,12 @@ default_icon_bmp, default_icon_palette = adafruit_imageload.load("launcher_asset
|
|||
default_icon_palette.make_transparent(0)
|
||||
menu_grid = GridLayout(x=40, y=16, width=WIDTH, height=HEIGHT, grid_size=(config["width"], config["height"]),
|
||||
divider_lines=False)
|
||||
main_group.append(menu_grid)
|
||||
scaled_group.append(menu_grid)
|
||||
|
||||
menu_title_txt = Label(font, text="Fruit Jam OS")
|
||||
menu_title_txt.anchor_point = (0.5, 0.5)
|
||||
menu_title_txt.anchored_position = (display.width // (2 * scale), 2)
|
||||
main_group.append(menu_title_txt)
|
||||
scaled_group.append(menu_title_txt)
|
||||
|
||||
app_titles = []
|
||||
apps = []
|
||||
|
|
@ -248,6 +255,7 @@ for path in app_path.iterdir():
|
|||
"icon": str(icon_file.absolute()) if icon_file is not None else None,
|
||||
"file": str(code_file.absolute())
|
||||
})
|
||||
|
||||
i += 1
|
||||
|
||||
|
||||
|
|
@ -356,15 +364,26 @@ right_tg.anchor_point = (1.0, 0.5)
|
|||
right_tg.anchored_position = ((display.width // scale) - 4, (display.height // 2 // scale) - 2)
|
||||
original_arrow_btn_color = left_palette[2]
|
||||
|
||||
main_group.append(left_tg)
|
||||
main_group.append(right_tg)
|
||||
scaled_group.append(left_tg)
|
||||
scaled_group.append(right_tg)
|
||||
|
||||
if len(apps) <= 6:
|
||||
right_tg.hidden = True
|
||||
left_tg.hidden = True
|
||||
|
||||
if mouse:
|
||||
main_group.append(mouse_tg)
|
||||
scaled_group.append(mouse_tg)
|
||||
|
||||
|
||||
help_txt = Label(terminalio.FONT, text="[Arrow]: Move\n[E]: Edit\n[Enter]: Run")
|
||||
# help_txt = TextBox(terminalio.FONT, width=88, height=30, align=TextBox.ALIGN_RIGHT, background_color=0x008800, text="[E]: Edit\n[Enter]: Run")
|
||||
help_txt.anchor_point = (0, 0)
|
||||
|
||||
help_txt.anchored_position = (2, 2)
|
||||
# help_txt.anchored_position = (display.width - 89, 1)
|
||||
|
||||
print(help_txt.bounding_box)
|
||||
main_group.append(help_txt)
|
||||
|
||||
|
||||
def atexit_callback():
|
||||
|
|
@ -534,6 +553,8 @@ while True:
|
|||
|
||||
editor_launch_file = "apps/editor/code.py"
|
||||
write_argv(editor_launch_file, [apps[editor_index]["file"]])
|
||||
# with open(argv_filename(launch_file), "w") as f:
|
||||
# f.write(json.dumps([apps[editor_index]["file"]]))
|
||||
|
||||
supervisor.set_next_code_file(editor_launch_file, sticky_on_reload=False, reload_on_error=True,
|
||||
working_directory="/".join(editor_launch_file.split("/")[:-1]))
|
||||
|
|
|
|||
Loading…
Reference in a new issue