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 = {
|
special_keys = {
|
||||||
"\x1b": ..., # all prefixes of special keys must be entered as Ellipsis
|
"\x1b": ..., # all prefixes of special keys must be entered as Ellipsis
|
||||||
"\x1b[": ...,
|
"\x1b[": ...,
|
||||||
|
"\x1b[3": ...,
|
||||||
"\x1b[5": ...,
|
"\x1b[5": ...,
|
||||||
"\x1b[6": ...,
|
"\x1b[6": ...,
|
||||||
"\x1b[A": "KEY_UP",
|
"\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"))
|
# usb_cdc.data.write(f"{message}\r\n".encode("utf-8"))
|
||||||
|
|
||||||
INPUT_DISPLAY_REFRESH_COOLDOWN = 0.3 # s
|
INPUT_DISPLAY_REFRESH_COOLDOWN = 0.3 # s
|
||||||
|
SHOW_MEMFREE = False
|
||||||
|
|
||||||
|
|
||||||
class MaybeDisableReload:
|
class MaybeDisableReload:
|
||||||
|
|
@ -55,6 +56,7 @@ def os_exists(filename):
|
||||||
|
|
||||||
|
|
||||||
def gc_mem_free_hint():
|
def gc_mem_free_hint():
|
||||||
|
if not SHOW_MEMFREE:
|
||||||
return ""
|
return ""
|
||||||
if hasattr(gc, "mem_free"):
|
if hasattr(gc, "mem_free"):
|
||||||
gc.collect()
|
gc.collect()
|
||||||
|
|
@ -224,16 +226,12 @@ def editor(stdscr, filename, visible_cursor): # pylint: disable=too-many-branch
|
||||||
else:
|
else:
|
||||||
buffer = Buffer([""])
|
buffer = Buffer([""])
|
||||||
|
|
||||||
|
user_message = None
|
||||||
|
|
||||||
window = Window(curses.LINES - 1, curses.COLS - 1)
|
window = Window(curses.LINES - 1, curses.COLS - 1)
|
||||||
cursor = Cursor()
|
cursor = Cursor()
|
||||||
visible_cursor.text = buffer[0][0]
|
visible_cursor.text = buffer[0][0]
|
||||||
last_refresh_time = -1
|
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()
|
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):
|
for row in range(lastrow + 1, window.n_rows):
|
||||||
setline(row, "~~ EOF ~~")
|
setline(row, "~~ EOF ~~")
|
||||||
row = curses.LINES - 1
|
row = curses.LINES - 1
|
||||||
|
|
||||||
|
if user_message is None:
|
||||||
if util.readonly():
|
if util.readonly():
|
||||||
line = f"{filename:12} (*ro) | ^C: quit{gc_mem_free_hint()}"
|
line = f"{filename:12} (mnt RO ^W) | ^R run | ^C: quit{gc_mem_free_hint()}"
|
||||||
else:
|
else:
|
||||||
line = f"{filename:12} | ^X: write & exit | ^C: quit w/o save{gc_mem_free_hint()}"
|
line = f"{filename:12} (mnt RW ^W) | ^R run | ^S save | ^X: save & exit | ^C: exit no save{gc_mem_free_hint()}"
|
||||||
|
else:
|
||||||
|
line = user_message
|
||||||
|
user_message = None
|
||||||
setline(row, line)
|
setline(row, line)
|
||||||
|
|
||||||
stdscr.move(*window.translate(cursor))
|
stdscr.move(*window.translate(cursor))
|
||||||
|
|
@ -290,6 +293,7 @@ def editor(stdscr, filename, visible_cursor): # pylint: disable=too-many-branch
|
||||||
with open(filename, "w", encoding="utf-8") as f:
|
with open(filename, "w", encoding="utf-8") as f:
|
||||||
for row in buffer:
|
for row in buffer:
|
||||||
f.write(f"{row}\n")
|
f.write(f"{row}\n")
|
||||||
|
user_message = "Saved"
|
||||||
else:
|
else:
|
||||||
print("Unable to Save due to readonly mode!")
|
print("Unable to Save due to readonly mode!")
|
||||||
elif k == "\x11": # Ctrl-Q
|
elif k == "\x11": # Ctrl-Q
|
||||||
|
|
@ -344,7 +348,13 @@ def editor(stdscr, filename, visible_cursor): # pylint: disable=too-many-branch
|
||||||
right(window, buffer, cursor)
|
right(window, buffer, cursor)
|
||||||
elif k in ("KEY_DELETE", "\x04"):
|
elif k in ("KEY_DELETE", "\x04"):
|
||||||
print("delete")
|
print("delete")
|
||||||
|
if cursor.row < len(buffer.lines) - 1 or \
|
||||||
|
cursor.col < len(buffer.lines[cursor.row]):
|
||||||
buffer.delete(cursor)
|
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"):
|
elif k in ("KEY_BACKSPACE", "\x7f", "\x08"):
|
||||||
print(f"backspace {bytes(k, 'utf-8')}")
|
print(f"backspace {bytes(k, 'utf-8')}")
|
||||||
|
|
|
||||||
35
src/code.py
35
src/code.py
|
|
@ -15,11 +15,14 @@ import displayio
|
||||||
|
|
||||||
import supervisor
|
import supervisor
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
|
import terminalio
|
||||||
import usb
|
import usb
|
||||||
import adafruit_pathlib as pathlib
|
import adafruit_pathlib as pathlib
|
||||||
from adafruit_bitmap_font import bitmap_font
|
from adafruit_bitmap_font import bitmap_font
|
||||||
from adafruit_display_text.text_box import TextBox
|
from adafruit_display_text.text_box import TextBox
|
||||||
from adafruit_display_text.bitmap_label import Label
|
from adafruit_display_text.bitmap_label import Label
|
||||||
|
|
||||||
from adafruit_displayio_layout.layouts.grid_layout import GridLayout
|
from adafruit_displayio_layout.layouts.grid_layout import GridLayout
|
||||||
from adafruit_anchored_tilegrid import AnchoredTileGrid
|
from adafruit_anchored_tilegrid import AnchoredTileGrid
|
||||||
import adafruit_imageload
|
import adafruit_imageload
|
||||||
|
|
@ -63,14 +66,18 @@ if display.width > 360:
|
||||||
|
|
||||||
font_file = "/fonts/terminal.lvfontbin"
|
font_file = "/fonts/terminal.lvfontbin"
|
||||||
font = bitmap_font.load_font(font_file)
|
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
|
display.root_group = main_group
|
||||||
|
|
||||||
background_bmp = displayio.Bitmap(display.width, display.height, 1)
|
background_bmp = displayio.Bitmap(display.width, display.height, 1)
|
||||||
bg_palette = displayio.Palette(1)
|
bg_palette = displayio.Palette(1)
|
||||||
bg_palette[0] = 0x222222
|
bg_palette[0] = 0x222222
|
||||||
bg_tg = displayio.TileGrid(bitmap=background_bmp, pixel_shader=bg_palette)
|
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
|
# load the mouse cursor bitmap
|
||||||
mouse_bmp = displayio.OnDiskBitmap("launcher_assets/mouse_cursor.bmp")
|
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)
|
default_icon_palette.make_transparent(0)
|
||||||
menu_grid = GridLayout(x=40, y=16, width=WIDTH, height=HEIGHT, grid_size=(config["width"], config["height"]),
|
menu_grid = GridLayout(x=40, y=16, width=WIDTH, height=HEIGHT, grid_size=(config["width"], config["height"]),
|
||||||
divider_lines=False)
|
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 = Label(font, text="Fruit Jam OS")
|
||||||
menu_title_txt.anchor_point = (0.5, 0.5)
|
menu_title_txt.anchor_point = (0.5, 0.5)
|
||||||
menu_title_txt.anchored_position = (display.width // (2 * scale), 2)
|
menu_title_txt.anchored_position = (display.width // (2 * scale), 2)
|
||||||
main_group.append(menu_title_txt)
|
scaled_group.append(menu_title_txt)
|
||||||
|
|
||||||
app_titles = []
|
app_titles = []
|
||||||
apps = []
|
apps = []
|
||||||
|
|
@ -248,6 +255,7 @@ for path in app_path.iterdir():
|
||||||
"icon": str(icon_file.absolute()) if icon_file is not None else None,
|
"icon": str(icon_file.absolute()) if icon_file is not None else None,
|
||||||
"file": str(code_file.absolute())
|
"file": str(code_file.absolute())
|
||||||
})
|
})
|
||||||
|
|
||||||
i += 1
|
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)
|
right_tg.anchored_position = ((display.width // scale) - 4, (display.height // 2 // scale) - 2)
|
||||||
original_arrow_btn_color = left_palette[2]
|
original_arrow_btn_color = left_palette[2]
|
||||||
|
|
||||||
main_group.append(left_tg)
|
scaled_group.append(left_tg)
|
||||||
main_group.append(right_tg)
|
scaled_group.append(right_tg)
|
||||||
|
|
||||||
if len(apps) <= 6:
|
if len(apps) <= 6:
|
||||||
right_tg.hidden = True
|
right_tg.hidden = True
|
||||||
left_tg.hidden = True
|
left_tg.hidden = True
|
||||||
|
|
||||||
if mouse:
|
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():
|
def atexit_callback():
|
||||||
|
|
@ -534,6 +553,8 @@ while True:
|
||||||
|
|
||||||
editor_launch_file = "apps/editor/code.py"
|
editor_launch_file = "apps/editor/code.py"
|
||||||
write_argv(editor_launch_file, [apps[editor_index]["file"]])
|
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,
|
supervisor.set_next_code_file(editor_launch_file, sticky_on_reload=False, reload_on_error=True,
|
||||||
working_directory="/".join(editor_launch_file.split("/")[:-1]))
|
working_directory="/".join(editor_launch_file.split("/")[:-1]))
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue