# GUIDE # type freely! CTRL+D clears the text. # backspace, space, and return function as expected. # keys not recognised WILL print "UNKNOWN 0x??", but this is useful for extra key scans # # WORK IN PROGRESS # CTRL + S to save text to the SD Card # CTRL + O to open a text file # UP and DOWN scrolling - (use cursor ) ###### import board import terminalio from adafruit_display_text import label from keyboard import Keyboard import busio import sdcardio import storage import os def save_file(): save_text = "save file" save_group = label.Label(terminalio.FONT, text=save_text) save_group.x = 10 save_group.y = 10 board.DISPLAY.root_group = save_group def open_file(): open_text = "open file" open_group = label.Label(terminalio.FONT, text=open_text) open_group.x = 10 open_group.y = 10 board.DISPLAY.root_group = open_group def editor(text): if page == "editor": ## WRAPPING ## calculate wrapping when entering a character lines = text.split("\n") current_line = lines[len(lines)-1] if len(current_line) > 35: text=text+"\n" # <- start a new line here ############################################## text = text+key text_area.text = text return text def esc(): if page == "editor": pass elif page == "save" or page == "open": board.DISPLAY.root_group = intro_text_area ## SD Card set up for saving text to SD card spi = busio.SPI(board.SD_SCK, MOSI=board.SD_MOSI, MISO=board.SD_MISO) cs = board.SD_CS try: sdcard = sdcardio.SDCard(spi, cs) vfs = storage.VfsFat(sdcard) storage.mount(vfs, "/sd") # access files on sd card here SD_status = "SD Card Mounted" except OSError: SD_status = "No SD card found" pass # SD card not inserted/found ######################################### keyb = Keyboard() page = "editor" intro_text = "Press CTRL+D to clear text\n"+SD_status+"\n\n" intro_text_area = label.Label(terminalio.FONT, text=intro_text, color="C3B") intro_text_area.x = 10 intro_text_area.y = 10 text = "" text_area = label.Label(terminalio.FONT, text=text) text_area.x = 0 text_area.y = 40 board.DISPLAY.root_group = intro_text_area intro_text_area.append(text_area) while True: key = keyb.scan() if key == "BACKSP": text = text[:-1] elif key == "CTRLD": text = "" elif key == "CTRLS": save_file() page = "save" elif key == "CTRLO": open_file() page="open" elif key == "ESC": esc() page = "editor" else: text = editor(text)