Commit Graph

739 Commits

Author SHA1 Message Date
Kartik K. Agaram
8584e15b68 use the new file API in most places
Really everywhere except zet.tlv. toot-toot is intended to emit
throwaway files anyway.
2022-03-06 02:49:26 -08:00
Kartik K. Agaram
a8d0c1a56a reconcile all apps with template.tlv
They may take more or less from it (sieve.tlv in particular takes
nothing since call depth doesn't help at all there), but what they take
is in the right order so that you can compare across apps.
2022-03-06 02:42:34 -08:00
Kartik K. Agaram
af9d7a16f3 starting to convert all file reads to the new API
For starters, this detail was puzzling when I returned to the Game of
Life app.
2022-03-06 02:12:06 -08:00
Kartik K. Agaram
f2d29c22f8 a simple hack to make caller apparent
Teliva isn't yet smart enough to know the caller of an indirect function
where the function being called goes through a local variable.

I'd expected fixing this to be a long death march. However, there's a
shockingly easy fix: just make every indirect call go through an
additional direct function call.

My policy for zet.tlv was that function 'main' could open any file. This
stopped working since I introduced spawn_main. But with this commit it's
working again.

I can also drop all my special-casing of 'main' since it's now a regular
Lua call.

We still can't rely on the caller of an indirect call. That affects
start_reading and start_writing, which really need to be part of the
framework.
2022-03-05 22:38:00 -08:00
Kartik K. Agaram
52ae23784b new API for file operations
File operations now always return a channel (or nil on error or
permission denied).

When start_reading() from a filename, you can repeatedly :recv() from
the channel it returns.
When :recv() returns nil, you're at the end of the file. Stop.

When you start_writing() to a filename, you can repeatedly :send() to
the channel it returns.
When you're done writing, :close() the channel. Writes to the file won't
be externally visible until you do.

To make this work I'm now always starting up the scheduler, so I need to
fix sieve.tlv.

Transparently running the scheduler is an abstraction, and whenever I
create an abstraction I always worry about how it might fail. There's
a hopefully-clear error when you read past end of a file.
2022-03-05 18:04:35 -08:00
Kartik K. Agaram
2d6b88204b anagrams.tlv: now fully responsive
If we press a key the computation now restarts instantly.

There's no fiction of multi-threading in Teliva. If the application
doesn't work right, it beach-balls. If it doesn't beach-ball under
normal circumstances you're more certain it'll never beach-ball. It's
more work up-front, but there's less variability in outcomes.
2022-03-05 16:15:32 -08:00
Kartik K. Agaram
43dd1f382e some dead code 2022-03-05 14:47:03 -08:00
Kartik K. Agaram
5530995188 reliably exit on confirmation
Until now you had to press ctrl-x twice in rapid succession to exit if
an app turned on non-blocking keyboard with nodelay(true). This became
particularly noticeable after the previous change to anagrams.tlv, which
could no longer exit.
2022-03-05 14:44:37 -08:00
Kartik K. Agaram
f72340cc37 fixup! no further confirmation once editing commences 2022-03-05 14:40:42 -08:00
Kartik K. Agaram
057f4a2870 anagrams.tlv: slightly more responsive
Now we cancel screen-painting if any key is pressed.

However it looks like just computing the list of anagrams can take a
long time.
2022-03-05 09:47:47 -08:00
Kartik K. Agaram
520cc09997 include caller in sandboxing messages 2022-03-04 21:25:38 -08:00
Kartik K. Agaram
2cfdad3381 simplify permissions model for file operations
We don't care to distinguish modes like "rw" or "a+". An app is
permitted to perform either just reads or both reads and writes.
2022-03-03 22:28:01 -08:00
Kartik K. Agaram
9722f44a94 clearer copy for confirmation dialog 2022-03-03 22:25:43 -08:00
Kartik K. Agaram
c53df5c4cc basic support for testing writes to screen 2022-03-03 22:10:58 -08:00
Kartik K. Agaram
983285c6b2 more unobtrusive skip message
In particular, the periods looked like passing tests.
2022-03-03 22:06:44 -08:00
Kartik K. Agaram
2b50b7289e no further confirmation once editing commences 2022-03-03 21:43:22 -08:00
Kartik K. Agaram
dd5bc9e3ac ask for confirmation on _any_ teliva shortcut
This feels more intrusive. Let's see how we like it. Will I start having
ctrl-x ctrl-x in my muscle memory?
2022-03-03 18:34:15 -08:00
Kartik K. Agaram
101c59d8cb experiment: drop -Wshadow
I'm totally fine with lexical scope in other languages. Why does it feel
like such a big deal in C?
2022-03-03 18:15:26 -08:00
Kartik K. Agaram
81849716fa fake keyboard constructor 2022-03-02 22:18:26 -08:00
Kartik K. Agaram
68d956e31a distinguish between window global and arg 2022-03-02 22:15:01 -08:00
Kartik K. Agaram
afb3f46db7 always ask for confirmation on exit
Let's see if we can live with this rather than some way to let apps
indicate if they want confirmation or not..
2022-03-01 23:10:46 -08:00
Kartik K. Agaram
46ef1adb08 zet.tlv: hotkeys are not alternatives
In any case, I want the convention to be '|' for alternation. '/' is
more likely to be a real hotkey.
2022-02-27 09:58:05 -08:00
Kartik K. Agaram
2546d91214 zet.tlv: streamline history 2022-02-27 09:47:09 -08:00
Kartik K. Agaram
ae51b06dab starting to make Teliva apps more testable
Tasteful apps should only perform side-effects through 'window'
arguments rather than the 'curses' module directly. It's ok however to
read constants like curses.A_NORMAL or curses.stdscr().

There are some limitations, unfortunately. Ncurses wasn't designed with
testability in mind. For example, there's no way to curs_set or
assume_default_colors without the 'curses' module. Oh well.
2022-02-27 08:41:30 -08:00
Kartik K. Agaram
891bced544 always run unit tests for channels and tasks 2022-02-26 22:57:48 -08:00
Kartik K. Agaram
42526cb15d import https://github.com/majek/lua-channels
Also a little test program to demo channels in action.
2022-02-26 22:48:48 -08:00
Kartik K. Agaram
061e6a21a5 duplicate keypress on failing test 2022-02-26 19:47:06 -08:00
Kartik K. Agaram
7852cdfebe readme tweak 2022-02-26 13:47:54 -08:00
Kartik K. Agaram
3e1fa8c5a7 a little program for kids: anagrams of names 2022-02-21 19:06:16 -08:00
Kartik K. Agaram
52372d1812 delete curses primitives to read whole lines
They make it seem like you can use them to create simple REPL apps, but
you can't, because standard Teliva shortcuts won't work.

I _could_ make them work by emulating them using getch(), but that feels
like an unnecessary abstraction for now.
2022-02-21 17:06:34 -08:00
Kartik K. Agaram
f8f1ec666a stop letting apps change directory
I introduced this ability when I packaged up the lfs directory, but it
can enable apps to circumvent sandboxing rules in some situations. If
you can socially engineer someone to allow reading a file called
'passwd' in the current directory, you can now change directory to /etc
and read something sensitive.

Protecting against stuff like this gets subtle. It's easy for people to
create policies that aren't robust to changing directories. Requiring
absolute paths is also pretty unfriendly. So the whole notion of current
directory is perhaps implicit state that is confusing to manage. Fix it
in the context of a single session.
2022-02-20 05:01:28 -08:00
Kartik K. Agaram
b36927e35c rewrite the section on Teliva's dependencies 2022-02-19 09:13:52 -08:00
Kartik K. Agaram
557774af42 Readme: move some sections around to flow better 2022-02-19 09:11:40 -08:00
Kartik K. Agaram
eb53603b06 starting a few Readme tweaks
For starters, drop some redundant prose here.
2022-02-19 09:10:29 -08:00
Kartik K. Agaram
b8cba84d20 bring back pcall and xpcall
They aren't evaluating strings after all.
2022-02-18 18:00:58 -08:00
Kartik K. Agaram
24db182620 show app blurb in screenshot 2022-02-17 20:47:19 -08:00
Kartik K. Agaram
9421ea7151 'doc:blurb': a place to briefly describe an app
This is for what the app does, as opposed to 'doc:main', which is also
intended to include commentary about the internal organization of the
app.
2022-02-17 20:16:36 -08:00
Kartik K. Agaram
0e19efeb2e fix a conflicting keyboard shortcut 2022-02-17 19:44:26 -08:00
Kartik K. Agaram
272d7532dc disable non-portable ASan flags 2022-02-16 20:53:53 -08:00
Kartik K. Agaram
27a99111ee fix chesstv.tlv after we introduced sandboxing 2022-02-12 18:58:24 -08:00
Kartik K. Agaram
3db03840e1 zet.tlv: new shortcuts, mostly for the editor 2022-02-12 17:59:30 -08:00
Kartik K. Agaram
5e200cf96a zet.tlv: some more editor shortcuts 2022-02-12 15:56:12 -08:00
Kartik K. Agaram
6a485ae4b4 stop aborting if audit log fills up
When I started logging getch() events (which are just to help the reader
orient on the log), this suddenly became more urgent.

Now the log is larger, and it's also a circular buffer that rolls back
to the start when it fills up.

The next failure mode will be if we see the buffer filled up with just
getch() calls, reducing visibility over real file and network
operations. In which case we'll need to start coalescing getch() events.
2022-02-12 15:45:04 -08:00
Kartik K. Agaram
bbd47aaa5b zet.tlv: yet another bugfix
Need for tests growing more acute..
2022-02-11 10:40:24 -08:00
Kartik K. Agaram
2d3cad5945 fix build on Mac OS 2022-02-10 23:42:09 -08:00
Kartik K. Agaram
d7436f047d zet.tlv: fix a couple more bugs
This snapshot was demoed at https://archive.org/details/akkartik-teliva-2022-02-10
2022-02-10 23:40:51 -08:00
Kartik K. Agaram
c55956bf96 zet.tlv: cross-links
We also made render dynamic, showing zettels in the first place it
encounters them in depth-first order.

Open question: how to show a collapsed outline view with the data model
I'm experimenting with. Not even clear 'outline' has meaning in the
presence of cross-links. Outliners privilege one view of the network.
Zettelkasten also does so; changing child/sibling relationships is a lot
of work. However, reading between the links it seems to try to provide
an escape hatch for rethinking connections using cross-links. I'm trying
to lean into that -- at the cost of providing outlines. We'll see if
this is a good trade-off.
2022-02-10 21:33:21 -08:00
Kartik K. Agaram
feb10708ae hacky support for caller main in file permissions 2022-02-10 16:40:40 -08:00
Kartik K. Agaram
c1e4b84222 fixup! clean up top-level Makefile targets 2022-02-10 16:40:22 -08:00
Kartik K. Agaram
76984aa90f allow Teliva to show its sandboxing message 2022-02-10 16:30:00 -08:00