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
This commit is contained in:
Kartik K. Agaram 2021-12-18 09:45:13 -08:00
parent d818efb7c8
commit 59f223e7cb
1 changed files with 5 additions and 0 deletions

View File

@ -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