Commit Graph

527 Commits

Author SHA1 Message Date
Kartik K. Agaram db7fd08e05 extract a helper
I'm starting to get quite indisciplined about where I introduce global
bindings. Seems reasonable since any modules in Teliva will come from
within the framework.
2022-03-06 08:41:45 -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 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 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 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 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 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 b8cba84d20 bring back pcall and xpcall
They aren't evaluating strings after all.
2022-02-18 18:00:58 -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 272d7532dc disable non-portable ASan flags 2022-02-16 20:53:53 -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 2d3cad5945 fix build on Mac OS 2022-02-10 23:42:09 -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 e552571b1e standardize key order in .tlv files
This will eliminate some spurious git diffs I keep having to clean up.
2022-02-09 09:18:05 -08:00
Kartik K. Agaram 3180e3e4fb typo 2022-02-08 18:30:02 -08:00
Kartik K. Agaram 504573a0de move most Teliva menus to the right
The problem I'm running into is that apps might want to perform their
own editing. So I can't take up prime estate like the ctrl-e hotkey or a
menu name of 'edit'.

I'm still prioritizing rendering Teliva's edit and permissions menu. If
the window is too narrow the app's settings will be overwritten and
Teliva's hotkeys will be preferentially displayed. Seems safer.
2022-02-07 22:54:17 -08:00
Kartik K. Agaram 21a3200c6a some more dead code 2022-02-06 13:48:46 -08:00
Kartik K. Agaram 3cfb8f7812 in fact, loadlib.c is all dead code now
Now we can be sure apps can't call `require`.
2022-02-06 13:34:16 -08:00
Kartik K. Agaram 63e3ba62c2 now all our supported platforms are POSIX 2022-02-06 13:30:32 -08:00
Kartik K. Agaram 6860a02396 drop all support for loading dynamic libraries 2022-02-06 13:29:38 -08:00
Kartik K. Agaram 8a9efc1b91 drop module 'package'
Just like with `require`, we don't we don't know how to sandbox it.

(Though we still have `require` because standard libraries outside apps
need it. I need to make sure apps can't invoke `require`..)
2022-02-06 13:12:46 -08:00
Kartik K. Agaram b79d6be383 drop some more untested platforms 2022-02-06 13:08:46 -08:00
Kartik K. Agaram 467ce31371 drop USE_LINUX and similar defines
How many levels of macros do we need. Also stop lying that we're using
Linux in BSD.
2022-02-06 13:06:27 -08:00
Kartik K. Agaram c101d1a3c5 drop MinGW
I've never tested with it, and it is likely broken after all my changes
to base Lua 5.1. Might as well be transparent about that.

If you care about this platform, please let me know:
  http://akkartik.name/contact
2022-02-06 12:44:51 -08:00
Kartik K. Agaram a6addb8e42 unused #define 2022-02-06 12:42:46 -08:00
Kartik K. Agaram 5e4ca1d470 don't perturb cursor when drawing menu 2022-02-04 23:55:28 -08:00
Kartik K. Agaram 5c1a7b6b12 fix a couple of warnings
It's not clear to me where my Linux gets strlcpy and strlcat from
¯\_(ツ)_/¯
2022-02-03 20:59:08 -08:00
Kartik K. Agaram f5be8e1955 prose typos and edits 2022-02-03 17:51:08 -08:00
Kartik K. Agaram 02104952d2 fix a bug in kilo
Submitted upstream at https://github.com/antirez/kilo/pull/81.
2022-02-03 17:48:01 -08:00
Kartik K. Agaram a8dfea1d3c drop io.lines()
I'd already dropped the variant without a filename. But even the variant
with a filename is very easy to use in a way that is confusing to use in
the presence of sandboxing:

* call io.lines()
* Sandboxing saves an error, io.lines() returns nil
* Caller (usually a loop) raises an error.
* We show the error and not the sandboxing failure.
* Worse, there's no way to adjust permissions from within Teliva,
  because we can't ever get to that menu while there's an error.

Best solution I can come up with: encourage a separate step for
translating filename to file handle. That way it's more obvious that we
need to check for errors.
2022-02-02 23:44:25 -08:00
Kartik K. Agaram 8f8a0e5a18 tweak an entry in the audit log 2022-02-02 23:38:45 -08:00
Kartik K. Agaram f5a1c22dc5 sandbox: no way to run arbitrary Lua code strings 2022-02-02 22:21:38 -08:00
Kartik K. Agaram 664b94f414 include keys typed into audit log
This will help people cross-correlate when the app performs specific
calls.
2022-02-01 21:19:51 -08:00
Kartik K. Agaram 90904f344a file permissions: decide based on calling function 2022-02-01 20:59:53 -08:00
Kartik K. Agaram 88404d41ea copy realpath() from FreeBSD repo
To sandbox apps robustly, we're going to need to always work with
canonical absolute paths.
2022-01-30 12:22:42 -08:00
Kartik K. Agaram 7a13adb52c try to get by with one feature macro
I fucking hate feature macros. Egregious discharge of our
division-of-labor-obsessed society. People should be able to introduce
names. People should be able to give up names to lower levels of
abstraction when they encounter conflicts.

Feature macros seem to exist[1] to support more than two levels of
abstraction. You try to build, one of your libraries fails to build
because of a conflict between it and one level down. You don't want to
modify this library. Just fucking https://catern.com/change_code.html
already. But no, I have to litter my code with feature macros even
though I just want the abstraction the original library provides.

[1] https://man7.org/linux/man-pages/man7/feature_test_macros.7.html
    https://lwn.net/Articles/590381
2022-01-29 12:41:20 -08:00
Kartik K. Agaram 24f0781d2b new library: luafilesystem (lfs)
https://github.com/keplerproject/luafilesystem

The new commander.tlv app demonstrates it working.
2022-01-29 12:39:53 -08:00
Kartik K. Agaram 90fc24ed04 fixup! redo lua vs prose
Forgot to include some hunks.
2022-01-29 12:22:32 -08:00
Kartik K. Agaram 1f620a28d7 more precise dependencies 2022-01-29 11:36:00 -08:00
Kartik K. Agaram e782cb1ead bugfix: editor was no longer saving anything
I made the changes reverted here out of a mistaken sense that
big-picture edits would interfere with Teliva's memory of what is
currently being edited (teliva_editor_state).
2022-01-27 00:40:33 -08:00
Kartik K. Agaram ce186e85f4 redo lua vs prose
Previously we weren't dynamically selecting how to highlight a buffer
after navigating with ctrl-g. That should work now.
2022-01-26 15:22:55 -08:00
Kartik K. Agaram 18183f3e4b indent 2022-01-26 15:20:55 -08:00
Kartik K. Agaram b493ed32b8 get Teliva working on FreeBSD 2022-01-26 09:36:06 -08:00
Kartik K. Agaram cbe85a18c7 rename the custom big picture view to doc:main 2022-01-25 23:25:05 -08:00
Kartik K. Agaram 32d86bfc7f override big picture view with doc:bp if it exists
Going to big picture from doc:bp still goes to the default
auto-generated big picture view.

While doc:bp provides some programmability, it's also far klunkier than
the default view. Rendering is worse, and it's always in edit mode
because I'm trying to avoid complicating the UX with a notion of
rendered markup. That means cursor movement is less convenient. It's
also easy to accidentally edit the big-picture view.
2022-01-25 23:07:43 -08:00
Kartik K. Agaram 7fd434a692 better default word at cursor for prose 2022-01-25 22:34:38 -08:00
Kartik K. Agaram e205057ff2 highlight [[wikiwords]] in prose
These are just hints that there's something worth jumping to. The
jumping still happens using ctrl-g.
2022-01-25 22:31:53 -08:00
Kartik K. Agaram 91d47faf23 disable Lua colors in prose 2022-01-25 21:44:01 -08:00
Kartik K. Agaram 84d76b11fa rename 2022-01-25 21:23:20 -08:00
Kartik K. Agaram 283d4dba59 new section in big picture: prose (non-code)
I've always found "Documentation" too pretentious.
2022-01-25 21:07:52 -08:00
Kartik K. Agaram 2fc48626b5 optimization: stop saving identical definitions
This is long overdue.
2022-01-25 20:53:46 -08:00
Kartik K. Agaram 2e38583da2 save doc: buffers to .tlv images 2022-01-25 20:45:00 -08:00
Kartik K. Agaram 39781351ee delete a redundant function prototype 2022-01-25 20:39:49 -08:00
Kartik K. Agaram d20e6a415f rename a function 2022-01-25 20:36:26 -08:00
Kartik K. Agaram c5f6e30042 start supporting non-code "buffers"
First step: when a "definition" starts with "doc:" it's not a
definition, just a buffer. Stop trying to interpret it as Lua.
2022-01-25 20:29:35 -08:00
Kartik K. Agaram 6d53235dfc work around a bug in NetBSD libcurses
http://gnats.netbsd.org/56664 reported.
2022-01-24 20:43:30 -08:00
Kartik K. Agaram 6a33284b07 get Teliva running on NetBSD
NetBSD still uses curses by default. One _could_ install ncurses, but I
don't have access to a NetBSD box with permissions to install ncurses,
so I'm experimenting to see how far we can get with just curses. So far
most of the apps seem to work, with the exception of one bug that I'll
commit next.
2022-01-24 20:15:43 -08:00
Kartik K. Agaram e4f934db6b delete some dead code
I'm kinda sorta able to get lcurses running on NetBSD 9.2 without this
particular hack.
2022-01-24 20:06:33 -08:00
Kartik K. Agaram a3a207d2e3 more generic build target in luasocket 2022-01-24 17:32:42 -08:00
Kartik K. Agaram 058145ee23 clarify generic 'bsd' build target
We still only have OpenBSD working.
2022-01-24 17:25:50 -08:00
Kartik K. Agaram 5258fbec7c file permissions: clear stale errors 2022-01-16 22:34:21 -08:00
Kartik K. Agaram 06edd8bda7 editing apps: clean up some stale prints 2022-01-16 22:33:41 -08:00
Kartik K. Agaram abc2ea4675 file access policy: support editing with >10 lines 2022-01-16 15:53:27 -08:00
Kartik K. Agaram 863f14041d kilo: cleaner go menu 2022-01-11 20:25:11 -08:00
Kartik K. Agaram 4eb4bc4f58 some heuristic guidance on permissions screen 2022-01-04 23:42:01 -08:00
Kartik K. Agaram ffd600b111 try running permissions advice after editing
This implies it must be side-effect free. We still need to figure out
how to convey that to the computer owner.
2022-01-04 22:33:07 -08:00
Kartik K. Agaram 855eafd1d9 slightly better error message 2022-01-04 22:09:42 -08:00
Kartik K. Agaram 64f8a1e15d reorg 2022-01-04 22:09:23 -08:00
Kartik K. Agaram 4798d97a15 feels more consistent to exit editor with ctrl-x 2022-01-04 21:52:23 -08:00
Kartik K. Agaram 08c1ea8fc4 extract function 2022-01-04 21:48:55 -08:00
Kartik K. Agaram 3d6b9b0adc load permissions properly in a third place 2022-01-04 21:41:41 -08:00
Kartik K. Agaram 4018c2e8e2 when editing a function, show its callers
No way to select between them. That complicates the UI too much when we
do so much with the cursor. But it's still useful to suggest things to
type in after ctrl-g.
2022-01-03 23:36:44 -08:00
Kartik K. Agaram 7812ebc5f1 start saving callers of functions
I think this is significantly slowing things down. Perhaps we should
sample or something.
2022-01-03 13:26:38 -08:00
Kartik K. Agaram 1c78ab3d2e comment 2022-01-03 13:24:21 -08:00
Kartik K. Agaram f6cf8f801c rename 2022-01-03 13:24:01 -08:00
Kartik K. Agaram 14ab0729c9 extract a function 2022-01-03 10:23:25 -08:00
Kartik K. Agaram 1261f3f3c9 events view: jump to a function 2022-01-03 09:58:34 -08:00
Kartik K. Agaram 0abd09dc05 rendering improvement 2022-01-02 22:52:57 -08:00
Kartik K. Agaram be0c936276 error handling when editing file permissions
Still highly non-ideal. Lua is a dynamic language, and has low ability
to detect syntax errors within functions.

Perhaps I should run a test call after every edit.
2022-01-02 22:51:27 -08:00
Kartik K. Agaram e3cef7ee56 bugfix: policies must end in newline
I believe kilo kinda naturally enforces that. We'll see.
2022-01-02 22:38:28 -08:00
Kartik K. Agaram b97291602b instrument some obvious syscalls 2022-01-02 22:36:33 -08:00
Kartik K. Agaram 49a03587ef indent 2022-01-02 22:20:48 -08:00
Kartik K. Agaram a901203227 start on a view of audit events 2022-01-02 22:13:47 -08:00
Kartik K. Agaram 74360f20be . 2022-01-02 21:39:53 -08:00
Kartik K. Agaram 2d0bb4438c editing file permissions 2022-01-02 21:33:49 -08:00