about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2021-12-18 09:45:13 -0800
committerKartik K. Agaram <vc@akkartik.com>2021-12-18 09:45:13 -0800
commit59f223e7cb244867507a0c1f4471be1ce38bde60 (patch)
tree0debc065addf407966ca27d1315c32a3d642e80d
parentd818efb7c824ffcfe7e62384cd70ef1b7aa098a8 (diff)
downloadteliva-59f223e7cb244867507a0c1f4471be1ce38bde60.tar.gz
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
-rw-r--r--toot-toot.tlv5
1 files changed, 5 insertions, 0 deletions
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