From 59f223e7cb244867507a0c1f4471be1ce38bde60 Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Sat, 18 Dec 2021 09:45:13 -0800 Subject: [PATCH] toot-toot: save prose somewhere This is still quite klunky. Don't expect toot-toot to be a complete text editor. In particular, it'll happily lose toot data if you try to edit the app while editing a toot. Teliva is paranoid about avoiding data loss, but toot-toot.tlv is not. Mostly I just want toot-toot to interact with the clipboard. The only reason save exists is that copying directly from within the app inserts spurious line breaks. So now I'm saving to file, then `cat`ing file, then copying each toot out. I initially tried to use ctrl-s for the save hotkey, but that conflicts with terminal flow-control, and it's not obvious how ncurses manages IXON. And I don't want to go around ncurses and do something that's very likely to be unportable. Even ctrl-w, I worry that there are terminals out there that will close tab or something stupid like that. Feature wish list: - a hook to execute after exit. Just calling os.exit() doesn't work because the screen still clears any final prints when Teliva exits. Not sure how to handle this. Ncurses doesn't seem to have anything beyond endwin() for cleaning up after itself. - a hook to execute before exit, for things like asking for confirmation/save - a place for 'flash' notification messages, like that the file was saved --- toot-toot.tlv | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/toot-toot.tlv b/toot-toot.tlv index ce7b2bd..8b2f070 100644 --- a/toot-toot.tlv +++ b/toot-toot.tlv @@ -166,6 +166,7 @@ menu: >menu = {} >menu['^u'] = 'clear' + >menu['^w'] = "write prose to file 'toot' (edit does NOT save)" - __teliva_timestamp: original update: >function update(window) @@ -190,6 +191,10 @@ > elseif key == 21 then -- ctrl-u > prose = '' > cursor = 1 + > elseif key == 23 then -- ctrl-w + > local out = io.open('toot', 'w') + > out:write(prose, '\n') + > out:close() > elseif key == 10 or (key >= 32 and key < 127) then > prose = prose:insert(string.char(key), cursor-1) > cursor = cursor+1