Commit Graph

527 Commits

Author SHA1 Message Date
Kartik K. Agaram e07fe0c87a make some space for callers of a function 2022-01-02 20:56:09 -08:00
Kartik K. Agaram 78516d140f start parameterizing viewport for editor 2022-01-02 20:14:24 -08:00
Kartik K. Agaram 1fd7f4ad18 drop os.getenv 2022-01-02 19:59:49 -08:00
Kartik K. Agaram d0111f1839 editable file permissions
Extremely cruddy implementation:
- I'm still unclear on how to represent the advice function:
  - How to handle errors when loading user configuration?
    Currently I refuse to start.
  - Whole function? More errors to handle in header and so on. What if
    the function is renamed?
  - Just body? Needs more structured editing support.
- Lots of duplication, particularly between the permissions in the menu
  and the permissions screen.

I don't know how to show the hostname at the time of connect() or
bind(), so networking is going to remain a boolean for now. It's also
unclear what effective constraints we can impose on what gets discussed
with a specific hostname. Everything outside the computer is out of
one's control.

One trick I learned is for consistently grabbing ASan logs on abort:
It's always safe to redirect stderr with ncurses!
2022-01-02 19:59:30 -08:00
Kartik K. Agaram a2081ee612 fork a new editor widget for non-code 2022-01-02 16:55:23 -08:00
Kartik K. Agaram f6aaf2fd1d better follow kilo's naming conventions 2022-01-02 16:52:36 -08:00
Kartik K. Agaram 30a1fb202e start peeling out an editor for non-code 2022-01-02 16:48:00 -08:00
Kartik K. Agaram 18a499c5c0 . 2022-01-02 16:35:01 -08:00
Kartik K. Agaram 2b1609f09b copy tweak 2022-01-02 15:52:02 -08:00
Kartik K. Agaram df5cd41637 rename 2022-01-02 15:46:46 -08:00
Kartik K. Agaram f7b4413494 . 2022-01-02 15:15:10 -08:00
Kartik K. Agaram 762b77f68b sandbox: tweaks to warning copy 2022-01-02 12:49:31 -08:00
Kartik K. Agaram 6859450182 sandbox: color tweaks 2022-01-02 12:47:24 -08:00
Kartik K. Agaram 40a0aca6e3 spacing 2021-12-26 00:04:28 -08:00
Kartik K. Agaram 3040ede3c8 undo accidental color scheme commit 2021-12-25 22:07:15 -08:00
Kartik K. Agaram 04a062e94d start persisting sandboxing settings
Zero guarantees of compatibility at this point.
2021-12-25 21:36:31 -08:00
Kartik K. Agaram e7dc519c40 reorg 2021-12-25 21:26:47 -08:00
Kartik K. Agaram 6ae7bf91b1 network calls are now sandboxed
I _think_ I don't need to gate other socket calls; you can't do anything
without bind() and connect(). And they should be good places to dump
more precise details later about the kind of server or client connection
being attempted.
2021-12-25 20:43:19 -08:00
Kartik K. Agaram 16d949e259 file open() is now sandboxed
In the process we now also have a mechanism for Teliva to overlay errors
while apps run. Might make sense to make that available to apps as well.
But I'm starting to realize that any app access to the Teliva areas of
the screen is fraught with risk.
2021-12-25 18:55:01 -08:00
Kartik K. Agaram f5ab71b4e1 flesh out very preliminary UI
Our sandboxing model is a blunt caricature, just two booleans. But let's
see how far this gets us.

Still doesn't persist, and definitely has no effect.
2021-12-25 18:51:05 -08:00
Kartik K. Agaram 8458ba0202 fix a couple of colors 2021-12-25 16:43:50 -08:00
Kartik K. Agaram 12cb565077 delete a couple more hacky function prototypes 2021-12-25 16:21:40 -08:00
Kartik K. Agaram dbbb396003 . 2021-12-25 16:16:48 -08:00
Kartik K. Agaram a36edb74f0 mock sandbox status and some initial colors
Current plan:
  - two booleans to gate file and network access, respectively
  - false shows as green, true shows as orange
  - if _both_ booleans are true, then both show as red to indicate that
    there are no protections.
2021-12-25 16:08:31 -08:00
Kartik K. Agaram 2b5559d8eb update all places when changing color scheme 2021-12-25 15:14:33 -08:00
Kartik K. Agaram 526d37e4ac fix menu colors in all color schemes
It looks like attron doesn't actually enable colors near 256, even
though https://linux.die.net/man/3/attron suggests it does.

  > COLOR_PAIR values can only be OR'd with attributes if the pair
  > number is less than 256.
2021-12-25 14:59:18 -08:00
Kartik K. Agaram 434d36f81f a little more reorg
Put stuff people messing with Teliva apps are likely to need above the C
interface.

The state of documentation for Teliva app creators is still quite poor.
All they really have to go on is the example apps.
2021-12-25 13:44:07 -08:00
Kartik K. Agaram bb6e79aa0d reorg: pull Teliva-specific stuff out of lua.c
It should now be easier to diff against the Lua 5.1 sources upstream.
2021-12-25 13:33:37 -08:00
Kartik K. Agaram 1e63a579d7 drop stdin/stdout/stderr and Lua default files
This isn't necessarily for sandboxing, but they don't really work right
now in the presence of ncurses, and it seems better to not include
broken stuff. Maybe we can get them to coexist with ncurses down the
road.
2021-12-25 11:35:50 -08:00
Kartik K. Agaram 917646fc9f sandbox: no popen
Again, too difficult to sandbox for now.
2021-12-25 11:04:23 -08:00
Kartik K. Agaram 6af91eb0d2 tlv format for transient editor state
Stop interpreting arbitrary Lua code when loading editor state. We don't
need that power or security risk.
2021-12-25 09:27:44 -08:00
Kartik K. Agaram 1b25d58a4f sandbox: no system()
Too hard to sandbox. Maybe we'll get back to it if there's some use case
only it can satisfy.
2021-12-25 08:22:15 -08:00
Kartik K. Agaram 916857dae0 cleaner test message
Was printing over passing tests for some reason.
2021-12-23 12:30:28 -08:00
Kartik K. Agaram 348945321d errors during tests are now handled
I should have documented that I'd never actually seen that code path
trigger before. Here's a minimal test that did it just now:

  function test_foo()
    return a+1
  end

  E2: [string "test_foo"]:2: attempt to perform arithmetic on global 'a' (a nil value)

A simple missing variable doesn't do it since it just evaluates to nil.

Without this commit, the above test was silently continuing to the main
app after failing tests.
2021-12-22 15:09:57 -08:00
Kartik K. Agaram 343316dcfa more precise control over menu order
I can't believe I didn't notice this until now.
2021-12-22 00:27:50 -08:00
Kartik K. Agaram 3dda99014c fix arrow keys in big picture view on Mac
Turns out arrow keys are considered `isprint()` on Mac.
2021-12-21 23:50:56 -08:00
Kartik K. Agaram 712d80e48a bugfix: ensure definition to edit has some name 2021-12-21 21:18:16 -08:00
Kartik K. Agaram 7cf65a3bea less confusing name 2021-12-21 19:59:15 -08:00
Kartik K. Agaram 577d47a6a7 arrow keys in big picture view 2021-12-21 19:53:32 -08:00
Kartik K. Agaram 3a20c0e227 gemini: echo urls while typing in
Let's see how much we need to tweak this solution.
2021-12-21 17:52:31 -08:00
Kartik K. Agaram 41bf615f43 nail down trusted Teliva channels a little more
In each session, Teliva has to bootstrap a trusted channel with the
computer owner while running arbitrarily untrusted code. So let's get
really, really precise about what the trusted channel consists of:
  - the bottom-most row of screen containing the menu
  - the keystrokes the owner types in
  - ncurses COLOR_PAIR slots 254 (menu) and 255 (error)

One reason the menu colors are important: we don't want people to get
used to apps that hide the menu colors by setting default
foreground/background to invisible and then drawing their own menu one
row up.

The error COLOR_PAIR I don't see any reason to carve out right now, but
it seems like a good idea for Teliva the framework to not get into the
habit of apps doing some things for it.

I'm not sure how realistic all this is (I feel quite ill-equipped to
think about security), but it seems worthwhile to err on the side of
paranoia. Teliva will be paranoid so people don't have to be.
2021-12-21 15:47:55 -08:00
Kartik K. Agaram 609730071e keep Teliva apps from pretending to be Teliva
Kind of a subtle idea. Teliva the framework is intended to be
trustworthy software that people install on their computers. The apps
people run using Teliva may be less trustworthy. The whole point of
Teliva is to provide a sandbox for running code before you trust it.

One way (of many) apps can be malicious is by subtly getting between
what people see and reality. Imagine, for example, an app that draws a
fake menu bar and offers a different hotkey to edit source code. When
someone presses that hotkey they think they're using the standard Teliva
editor but they're really using an editor within the app, which the app
uses to hide its most malicious bits from view.

Down the road Teliva will have more bits of UI, such as for asking for
permission to read sensitive data. It's important that people understand
what they're granting permission to, that apps can't tamper with the
communications channel between them and Teliva.

This is likely just one of many ways for an app to break out of its
sandbox. Teliva isn't sandboxed yet. I'm just taking my first steps on
this journey. In particular, there are other mechanisms for asking for
user input besides `getch()`. I don't yet have a big-picture view of the
Teliva sandbox.

It seems clear that I need to educate people on the difference between
different parts of screen. Depending on the app you install, most of the
screen may be a dark forest. It'll be important to know where the safe
path is, where you can speak to trusted advisors while in the forest.
2021-12-21 15:27:34 -08:00
Kartik K. Agaram d818efb7c8 pay more attention to where we display the cursor
It's still just in app control; I'm resisting the urge to introduce
"smarts".
2021-12-18 09:32:37 -08:00
Kartik K. Agaram 191538baf7 drop ASan from Makefile
Accidentally added at some point. It's a useful debugging aide, but I
don't want to require the additional dependencies on a first run.
2021-12-18 07:58:18 -08:00
Kartik K. Agaram 1d9a4fa1d5 ctrl-u: clear prose 2021-12-17 23:19:59 -08:00
Kartik K. Agaram caccafbc2c better copy on test failures 2021-12-17 22:38:00 -08:00
Kartik K. Agaram d6129cd571 correct count of test failures 2021-12-17 22:35:21 -08:00
Kartik K. Agaram 42b1bd842c keep tests from messing up big picture 2021-12-17 22:23:18 -08:00
Kartik K. Agaram c12ba48a63 one more protection against Lua stack leak 2021-12-17 22:23:18 -08:00
Kartik K. Agaram 92fe487349 experimental support for test errors 2021-12-17 22:23:17 -08:00
Kartik K. Agaram 580501b342 start of a test framework
Follows https://github.com/akkartik/wart, https://github.com/akkartik/mu0,
https://github.com/akkartik/mu1 and https://github.com/akkartik/mu.
2021-12-17 22:23:17 -08:00
Kartik K. Agaram 3921337b3f yet another stab at reorganizing stack assertions 2021-12-17 21:32:32 -08:00
Kartik K. Agaram a617b3e5ac . 2021-12-17 11:37:34 -08:00
Kartik K. Agaram 166c8e0ca0 . 2021-12-17 08:55:08 -08:00
Kartik K. Agaram 12b0a2a7b6 more protection against data loss 2021-12-17 08:46:11 -08:00
Kartik K. Agaram 59ef5da1d9 . 2021-12-17 08:39:31 -08:00
Kartik K. Agaram 18f9f4e4f4 protect against data loss in some rare situations
Examples:
  - you try to write file but disk is full
  - you have two Teliva files being edited at the same time

Both are situations where it's impossible to avoid some data loss.
However, we should now at least have some valid state of the .tlv file
saved to disk where we'd previously end up with a zero-size file or
garbage.
2021-12-16 21:27:45 -08:00
Kartik K. Agaram 2a6786fee5 fix another leak in the Lua stack
This fixes a segfault when scanning through a long history of recent
changes (say > 20 changes)
2021-12-16 20:53:50 -08:00
Kartik K. Agaram f979002939 more consistently show notes in recent changes
Teliva emits timestamps in multi-line format end in a newline. As a
result, notes get rendered on the next line and are then immediately
overwritten by the contents of the definition.

This bug was masked by my hacky 'original' timestamps which don't use
multi-line format.
2021-12-16 20:22:12 -08:00
Kartik K. Agaram 65b38f96ba stop leaking on the Lua stack, redux
An empty stack is too rigorous a line to hold. Instead we'll just ensure
we leave the stack the way we found it.
2021-12-16 20:07:59 -08:00
Kartik K. Agaram 76ed8d30f4 Revert "stop leaking on the Lua stack"
This reverts commit 7c1b9d0b91.

The 'big hammer' isn't good enough. The recent changes view seems to
need state on the stack across invocations of the editor.
2021-12-16 04:02:37 -08:00
Kartik K. Agaram 7c1b9d0b91 stop leaking on the Lua stack
..even if at the expense of leaking on the heap. Because the Lua stack
has very limited space (~20 slots). When it overflows, we segfault.
2021-12-16 02:50:32 -08:00
Kartik K. Agaram b425593af6 show all functions in big picture
We were missing functions in some larger programs.
2021-12-13 09:59:52 -08:00
Kartik K. Agaram f315e1d76a can again edit notes on changes 2021-12-11 15:30:33 -08:00
Kartik K. Agaram b9877fabdc . 2021-12-11 14:59:00 -08:00
Kartik K. Agaram 5c68906303 handle non-existent file 2021-12-11 14:01:34 -08:00
Kartik K. Agaram d25c37f86b bring back commandline args 2021-12-11 10:36:35 -08:00
Kartik K. Agaram c0c9d31688 snapshot: migrate all sample apps to new format 2021-12-11 10:22:53 -08:00
Kartik K. Agaram d5038fe514 snapshot: writing working?
This is a complete mess. I want to abstract reading multiline strings
behind a function, but the lookahead requirements for that are quite
stringent. What's a reasonable abstraction here?
2021-12-11 09:37:23 -08:00
Kartik K. Agaram 052c5501ac snapshot: key/value lines after multiline strings 2021-12-11 07:20:04 -08:00
Kartik K. Agaram 0b0a58da06 snapshot: start reading a new format
I really wanted to avoid getting into defining or parsing new file
formats. However, using the entire power of Lua is not ideal, as
described earlier in Konrad Hinsen's bug. In addition to everything
else, it's a vector for arbitrary code execution when someone loads an
untrusted image.

I could use JSON, but it requires ugly string escaping. Seems cleaner to
just use YAML. But YAML is complex and needs its own dependencies. If
I'm going to do my own, might as well make the multi-line string format
really clear.

I can't yet write the new format.
2021-12-11 00:43:26 -08:00
Kartik K. Agaram 47c8e9df22 comment 2021-12-08 22:37:54 -08:00
Kartik K. Agaram 653f9cc874 minor colorscheme tweak 2021-12-08 22:34:01 -08:00
Kartik K. Agaram 5a237bbcca display line numbers
Not my aesthetic choice, but essential at the moment for quickly
interpreting Lua errors.
2021-12-08 22:31:30 -08:00
Kartik K. Agaram 8a70fbd171 fix a use-after-free
Introduced Nov 28. Let's see if my intermittent segfaults stop now.
2021-12-08 16:47:59 -08:00
Kartik K. Agaram 74fd78c5b7 . 2021-12-07 23:45:04 -08:00
Kartik K. Agaram 20373578f4 cleaner 2021-12-07 17:28:46 -08:00
Kartik K. Agaram 46aa8c2cf8 slightly improve experience on Konrad Hinsen's bug
Steps to reproduce:
* Run teliva with some app.
* Press ctrl-e to edit the app.
* Select some function.
* Press ctrl-g and type in some Lua keyword like 'function' or 'while'
  (Since the first word in a function is often 'function', it becomes
  the default if you press ctrl-g immediately after entering the editor
  for a function.)
* Type nothing. Run the app.

Desired behavior: app continues to run. The definition for the keyword
is silently ignored (in future we may want to provide an error message)

Behavior before this commit: app silently exited with non-zero status,
and refused to restart thereafter until the .tlv file was manually
edited to delete the definition for the Lua keyword.

Behavior after this commit: app throws an error message like these:

  * For `function`:
    ```
    src/teliva: x.tlv:99: '(' expected near '='
    sorry, you'll need to edit the image directly. press any key to exit.
    ```

  * For `while`:
    ```
    src/teliva: x.tlv:99: unexpected symbol near 'while'
    sorry, you'll need to edit the image directly. press any key to exit.
    ```

You still need to edit the .tlv file manually, but the steps for
recovery are a bit more discoverable.

To fix this properly I also need to fix a looming security hole I've
been thinking about for some time. The long-term goal of Teliva is to
put the human running apps in control of what they do, by sandboxing
accesses to the file system, network and so on. However, even after we
build gates on all of Lua's standard libraries, we're still parsing .tlv
files as Lua, with all of its power available.

Solution: load .tlv files as some sort of JSON-like subset of Lua. Maybe
I should just use JSON, and rely on code that's already in Teliva, even
if I'm introducing a new notation in the process.
2021-12-07 08:50:28 -08:00
Kartik K. Agaram 978f698bfd fix colors in startup errors 2021-12-06 22:10:10 -08:00
Kartik K. Agaram bba3559b06 slightly more obvious menu copy
Still sucks, though..
2021-12-06 20:35:39 -08:00
Kartik K. Agaram 8423192eee improve backspace copy 2021-12-06 20:15:04 -08:00
Kartik K. Agaram 6b307fba2b tweak solarized-esque scheme 2021-12-06 20:13:17 -08:00
Kartik K. Agaram a0c66dbe31 more configurable colors
Also start using 256 colors, under the assumption most people will have
them.
2021-12-06 16:53:11 -08:00
Kartik K. Agaram 8807168729 grey rather than harsh white background 2021-12-04 20:54:01 -08:00
Kartik K. Agaram 0429cfca74 clearer usage message 2021-12-04 20:38:49 -08:00
Kartik K. Agaram d9cf3433d9 start showing call stack on errors
It turns out Lua has been providing us this information all along! I'd
just not created the space on screen to show it. Make it persist better.

Kilo now no longer tracks its own status messages, which is a regression
in a rare condition.
2021-12-04 14:12:36 -08:00
Kartik K. Agaram 810e160136 another fix for colors
I'd assumed that assume_default_colors updates fg/bg -1, but it doesn't.
Looks like I can't ever use -1 colors.
2021-12-03 23:12:02 -08:00
Kartik K. Agaram 267489c19f support the comment/uncomment hotkey on Macs
^/ works on Linux but not on Mac
^- emits the same character code on Mac
^_ seems to be the underlying character code, and works on both
ctrl-7 also emits the same character code
2021-12-03 20:19:32 -08:00
Kartik K. Agaram 950957619c less ambiguous menus
Doesn't make sense to use '/' as a delimiter when we have hotkeys
involving '/'.
2021-12-03 20:13:52 -08:00
Kartik K. Agaram bbab1a7c10 get rid of `Esc` hotkey
For a variety of historical reasons, terminals pause every time you
press `Esc`. Let's get rid of that lag.
2021-12-03 19:45:51 -08:00
Kartik K. Agaram fe5f542991 typos 2021-12-03 19:11:52 -08:00
Kartik K. Agaram 138282549e experimenting with different keys
On a Thinkpad X13, the `delete` key emits `^[[3~` outside of Teliva.
Within Teliva, ncurses converts it to character code 330 (0x14a), which
it fails to recognize as KEY_BACKSPACE. Why?

My backspace is converted to character code 263, which ncurses does
recognize as KEY_BACKSPACE.

ctrl-h is character code 8.

Both 330 and 263 are valid Unicode code points, which feels really ugly
and ambiguous.
2021-12-03 18:38:17 -08:00
Kartik K. Agaram d3a12fb7f1 stop showing frequent save messages 2021-12-03 18:30:24 -08:00
Kartik K. Agaram a796070c9b show ^h in a couple more menus 2021-12-03 18:23:40 -08:00
Kartik K. Agaram 31af4bd1fd improve support for backspace
I still don't understand the entire state space here, so I'm trying to
err on the side of improving discoverability of the `ctrl-h` escape
hatch. Without requiring too wide a window to show all hotkeys on the
menu.
2021-12-03 18:05:25 -08:00
Kartik K. Agaram 4c196576aa error message when no app is provided
Also strip out a bunch of Lua's commandline parsing.
2021-12-03 17:34:21 -08:00
Kartik K. Agaram 8ea7a3bde5 . 2021-12-03 17:23:37 -08:00
Kartik K. Agaram 947abf2ba3 legible colors across all terminal configurations
So far I've been trying to make Teliva follow the default colorscheme of
the terminal, but that easily ends up with illegible color combinations.
New plan: always start with a light background within Teliva. People who
want a dark background will currently need to mess with C sources.

This should somewhat fix https://github.com/akkartik/teliva/issues/1.
It's still not clear whether the default should be a dark or light
background. While dark background is more common in terminals, I believe
newcomers to terminals will prefer a light background. Then again, I'm
biased since I use a light background in my terminals.
2021-12-03 16:59:25 -08:00
Kartik K. Agaram 6f6595b39a show state of screen on runtime error
This is essential when debugging.
2021-12-03 16:12:51 -08:00
Kartik K. Agaram c7dea9f5a3 . 2021-12-03 16:00:59 -08:00
Kartik K. Agaram 87443b9815 extract a helper 2021-12-03 15:54:35 -08:00
Kartik K. Agaram 3f930ed73e fix a slight portability issue, maybe
When installing using NixOS[1], the screen looks wrong. It looks like
attrset(A_NORMAL) does not undo color changes with some versions of
dependencies.

[1] https://github.com/marianoguerra/marianoguerra.github.io/blob/master/advent-of-future-of-code/days/day-02.md
2021-12-02 01:49:57 -08:00
Kartik K. Agaram e001212e99 stop inserting ctrl- keys into programs 2021-11-30 17:44:01 -08:00
Kartik K. Agaram f5a6f434c5 better cross-platform backspace support
I wish I could just hide KEY_BACKSPACE and prevent myself from using it
by accident.

Then again, I'm not making this smarts available in Teliva programs
themselves. Just for the Teliva environment.
2021-11-30 09:56:06 -08:00
Kartik K. Agaram ce3ad17a05 kilo bugfix: syntax highlight final word in line
Kilo likely never ran into this because it's only been tested on C,
which uses semi-colons at the end of each statement.
2021-11-29 22:49:47 -08:00
Kartik K. Agaram 85e06b7b0f gotcha: silent string concatenation 2021-11-29 22:49:45 -08:00
Kartik K. Agaram 61accc5b8e . 2021-11-29 22:48:14 -08:00
Kartik K. Agaram d7a1792768 a couple more global curses bindings 2021-11-29 22:40:42 -08:00
Kartik K. Agaram b6bca6ac14 fix regression in showing error messages 2021-11-29 22:38:46 -08:00
Kartik K. Agaram fa52f129fb . 2021-11-29 22:06:54 -08:00
Kartik K. Agaram 36d3d10b1a let people fix bad images from within Teliva
Short of syntax errors that keep us from parsing the teliva_program
table, we should now be able to recover gracefully from everything.

Yesterday I started to try to add this to load_definitions before
realizing most errors are only noticed while running `main`. But I
didn't think of recovering from the docall of `main` until this morning.
2021-11-29 08:16:47 -08:00
Kartik K. Agaram c9de6ae5d6 redo uncomment
It was printing a phantom null at end of line on screen.
2021-11-28 21:48:38 -08:00
Kartik K. Agaram 418fce4464 auto-indent 2021-11-28 21:21:17 -08:00
Kartik K. Agaram 3203bf7aff tab key: always insert two spaces 2021-11-28 21:16:50 -08:00
Kartik K. Agaram f6c2974cb4 hide some 'advanced' hotkeys to support narrow windows 2021-11-28 21:09:29 -08:00
Kartik K. Agaram e80af9206c ctrl-/ to comment/uncomment line 2021-11-28 21:08:12 -08:00
Kartik K. Agaram eec4845c31 ctrl-u/ctrl-k to make editing a bit more ergonomic 2021-11-28 20:48:54 -08:00
Kartik K. Agaram 68211363ca special indent settings for kilo 2021-11-28 20:41:55 -08:00
Kartik K. Agaram 316e309928 indent 2021-11-28 20:41:55 -08:00
Kartik K. Agaram b24a47dd0d mac backspace attempt 3 2021-11-28 16:27:02 -08:00
Kartik K. Agaram af4e2e0751 fix half-assed mac os backspace commit 2021-11-28 16:19:01 -08:00
Kartik K. Agaram 383832b58b sacrificing another LoC to ward off crashes
It makes me very nervous now that there's save_editor_state within
editor event loop, when the editor could be editing notes. Things are
slightly better than this morning, but this prototype still suxxors.
2021-11-28 15:55:01 -08:00
Kartik K. Agaram 2ea9462ed1 editing notes sucks a little less
I think I've gotten rid of all the segfaults, but it's still pretty
messed up: if you hit ctrl-g and go edit some definition, it doesn't get
saved. You're just storing the edit in the note.
2021-11-28 15:45:28 -08:00
Kartik K. Agaram 2f42187663 fix the bug described in commit cec57992b7 2021-11-28 15:19:26 -08:00
Kartik K. Agaram 37068ef8d2 rename a fn and reorganize its responsibilities 2021-11-28 15:14:00 -08:00
Kartik K. Agaram 908b2634c6 split a lumpy abstraction into two cleaner ones
I'm mindful of the way abstractions can create duplicate effort:
  https://flak.tedunangst.com/post/browser-ktrace-browsing

== Kartik's SAD theorem
As programs grow complex, you will be repeatedly forced to either:
  - maintain some State,
  - perform some computations Again,
  - or Duplicate some code.

Here a small amount of duplication seems like the best alternative.
Particularly since no syscalls are involved.
2021-11-28 15:03:10 -08:00
Kartik K. Agaram aed8da7750 purge abstraction hiding teliva_editor_buffer 2021-11-28 14:51:35 -08:00
Kartik K. Agaram 38def8500e inline another function
I'm going to give up on hiding teliva_editor_buffer from kilo. It was
taking too much knowledge of extern function prototypes on both sides.
2021-11-28 14:40:39 -08:00
Kartik K. Agaram f8176bfe67 take one responsibility away from edit_image
Also rename it appropriately.
2021-11-28 14:36:42 -08:00
Kartik K. Agaram cfb366af80 . 2021-11-28 14:25:26 -08:00
Kartik K. Agaram 499286566d inline an unnecessary function 2021-11-28 14:25:01 -08:00
Kartik K. Agaram cec57992b7 start streamlining architecture
All the spaghetti is hiding another issue: when we load editor state,
that code path currently never leads to importing the edited buffer back
into the image.

Yet another attempt at drawing the state diagram:
  Wgetch -> switch_to_editor -> select_view
  select_view -> load_editor_state | big_picture_view
  load_editor_state -> edit_from -> editorProcessKeypress
  big_picture_view -> edit_image -> edit_buffer -> resumeEdit* -> load_editor_buffer -> editorProcessKeypress
  big_picture_view -> recent_changes
  recent_changes -> big_picture_view | edit_buffer

The problem is that load_editor_state doesn't eventually call
load_editor_buffer the way its sibling big_picture_view does.

For starters, it's confusing that switch_to_editor calls
big_picture_view which calls other editor functions. What is 'editor'
here, anyway?

Let's rename switch_to_editor to developer_mode. So the app starts out
in user mode, and might eventually transition to developer mode.
Developer mode is a black hole; to leave it and return to user mode we
restart the entire app.

The architecture in my mind is now:
  - Teliva consists of user mode and developer mode
  - Developer mode consists of multiple views
  - Each view, when it needs to edit something:
      - initializes kilo
      - loads a buffer into it
      - resumes editing the buffer as necessary
2021-11-28 14:07:44 -08:00
Kartik K. Agaram 570af7c255 fix going to big picture after saving editor state
My code is already at spaghetti levels. Some coping mechanisms.

===
The big problem with the Teliva approach compared to my previous Mu
project: no tests. At this point I should document the growing list of
manual tests I've been maintaining:

  run a program
  run a program, edit
  run a program, edit, make an edit, run | edit takes effect
  run a program with error
  run a program, edit, make an error, run
  run a program, edit, ^g to a different definition, make an edit, ^e to run again
  run a program, edit, ^g to a non-existent definition
  run a program, edit, ^g to a different definition, ^g to a different definition, ^e to run again
  start -> big picture -> edit -> move cursor -> run -> edit | cursor preserved
  start -> big picture -> edit A -> move cursor -> big picture -> edit B | cursor initialized
  start -> big picture -> edit A -> move cursor -> run -> exit -> start -> big picture -> edit B | cursor initialized
  start -> big picture -> edit A -> move cursor -> run -> exit -> start -> big picture -> edit B -> big picture (*)

  syntax highlighting for line comments
  syntax highlighting for multiline comments

(*) - fixed in this commit

===
Coarse-grained state diagram (ignoring recent_changes_view):
  app -> big picture on ^e
  big picture -> editor when selecting a definition
  editor -> app on e
  editor -> big picture on ^b

Fine-grained sequence diagram:
  main -> pmain -> ... -> Wgetch -> switch_to_editor -> select_view
  select_view -> load_editor_state, falling through to big_picture_view if needed
  load_editor_state -> edit_from -> editorProcessKeypress

The consequence I hadn't fully internalized was the return path:
  editorProcessKeypress -> edit_from -> big_picture_view

Which implies that load_editor_state fails in two ways:
  - when the state doesn't exist or is not applicable or is corrupted
  - when editing from the state explicitly requested the big picture view

Switching the return value semantics for load_editor_state now supports
both ways.
2021-11-28 12:04:16 -08:00
Kartik K. Agaram 462a45a39f yet another fucking makefile bug
Making changes to lcurses directory was causing it to be compiled, but
not causing teliva to be relinked.

Now I'm:
  - unconditionally running `make` on subdirectories
  - conditionally linking their outputs

Seems reasonable when I put it like that. Hopefully this is working now.

I used to know `make` down cold a decade ago, but it's evaporated from
my brain.
2021-11-28 11:41:09 -08:00
Kartik K. Agaram 8fd568647a clear editor state across user-visible restarts
Teliva's constantly restarting without the user being aware of it. So
far I figured saving history across the user actually exiting and
restarting Teliva was just a happy "feature". However, it looks like
that's actually more complex to implement. Keeping editor state across
user-visible restarts results in these problems:

- opening the editor after restart has the cursor position messed up, no
  matter what definition you open.
- more seriously, opening the editor after restart can't seem to get to
  the big-picture view anymore.

Rather than try to debug what's going on, I'm going to just cordon off
that part of the state space for now.
2021-11-28 11:38:06 -08:00
Kartik K. Agaram 41803e4afc use header everywhere 2021-11-28 11:11:30 -08:00
Kartik K. Agaram c015ffe40a unused variable 2021-11-28 11:10:34 -08:00
Kartik K. Agaram 2f3c800a49 standardize filenames that teliva strews on disk
We still need a proper story for file system side effects. But it's not
time yet for sandboxing considerations. Soon, but not yet.
2021-11-28 10:54:25 -08:00
Kartik K. Agaram 2b8b811175 restore editor state from snapshot 2021-11-28 10:50:13 -08:00
Kartik K. Agaram d3d8c13828 make look_up_definition more composable 2021-11-28 10:44:40 -08:00
Kartik K. Agaram 6388bc08c4 save a snapshot of editor state across restarts
We're not using this yet.

I agonized over this decision for several weeks. Is Teliva's need to
restart with execve an utter hack or a good thing? I'm leaning towards
the latter. Constantly exercising the initial flow makes Teliva more
crash-only. We can build Steve Yegge's idea of immortality (http://steve-yegge.blogspot.com/2007/01/pinocchio-problem.html)
out of crash-only primitives, just by making reboots instantaneous. But
focusing directly on immortality tends to compromise crash-only by
exercising it more rarely.

One other issue this brings up: loading these Lua tables from disk is a
vector for arbitrary code execution. I need to fix these when I get to
sandboxing.
2021-11-28 10:44:40 -08:00
Kartik K. Agaram 13bfb7308a more salient concept of 'views' 2021-11-28 09:48:04 -08:00
Kartik K. Agaram 1ac98e28e6 fix backspace on Mac
I'm deliberately restricting this incompatibility to the editor
environment for now.
2021-11-28 08:50:47 -08:00
Kartik K. Agaram 75ded7a918 editor hotkeys: sol/eol
I'm growing attached to ^e, so mildly breaking with convention there.
Perhaps this is a bad idea.
2021-11-28 08:44:37 -08:00
Kartik K. Agaram 107af65f3c pass some CFLAGS at least to libcurses
My Makefiles are an utter mess. Unclear how to reconcile staying close
to upstream with being clean in isolation.
2021-11-27 09:24:00 -08:00
Kartik K. Agaram 295c99c2d9 . 2021-11-27 09:00:38 -08:00
Kartik K. Agaram 7d71663f1a one final issue building on Mac OS X 2021-11-27 08:10:18 -08:00
Kartik K. Agaram 7814c1c98a now building on OpenBSD
Still emitting a bunch of warnings on OpenBSD, though.
2021-11-27 07:58:58 -08:00
Kartik K. Agaram 8a36b2583c select C99 in luasec
I can't select C99 in luasocket, because I don't know how to include
the definition of struct timespec. All this fucking complexity. But
hopefully things will build on OpenBSD now.
2021-11-27 07:28:12 -08:00
Kartik K. Agaram 3fee59527a select C99 standard 2021-11-27 07:18:24 -08:00
Kartik K. Agaram fd4ca45ae5 clean up luasocket build file
Teliva is never intended to be "installed" somewhere. Just work inside
its directory and separately share the .tlv files you create. (Though I
don't yet have a good flow for starting a new .tlv file.)
2021-11-27 06:57:38 -08:00
Kartik K. Agaram c558d2c565 . 2021-11-27 00:42:15 -08:00
Kartik K. Agaram ff43b5bae1 fix build on Mac 2021-11-27 00:41:17 -08:00
Kartik K. Agaram 83050ec38e starting to test compilation on Mac and BSD.
For starters, put Linux-specific stuff in a Linux-specific target.

By not resetting MYCFLAGS and MYLDFLAGS, I'm unnecessarily passing in
-DLUA_USE_LINUX. But that'll make it easier to get things running on Mac
and BSD.
2021-11-27 00:34:49 -08:00
Kartik K. Agaram 1e911f95ef bugfix: emit legal Lua representation 2021-11-26 22:03:47 -08:00
Kartik K. Agaram 662d1cf202 support space/backspace in recent changes view 2021-11-26 21:54:45 -08:00
Kartik K. Agaram 2426fe7a79 standardize indent 2021-11-26 21:50:53 -08:00
Kartik K. Agaram 7e86f6d123 colorize comments in recent changes 2021-11-26 21:48:31 -08:00
Kartik K. Agaram e2a53858a0 support notes on edits
Unlike both conventional version control and wiki history, I'm planning
to always allow modifying commit messages.
2021-11-26 21:43:31 -08:00
Kartik K. Agaram 6b6fe7ce72 periodic cleanup of warnings 2021-11-26 21:22:20 -08:00
Kartik K. Agaram db7202ccfd . 2021-11-26 21:20:23 -08:00
Kartik K. Agaram 35fe28a36f . 2021-11-26 21:19:41 -08:00
Kartik K. Agaram 0c211dec77 don't mislead immediately after undo 2021-11-26 20:00:32 -08:00
Kartik K. Agaram b954ab869e . 2021-11-26 19:52:31 -08:00
Kartik K. Agaram 0726692546 more obvious serialization of undo events 2021-11-26 19:45:19 -08:00
Kartik K. Agaram 3cb37a0f39 render undo events 2021-11-26 19:38:51 -08:00
Kartik K. Agaram a0171352a1 start processing undo events 2021-11-26 19:33:35 -08:00
Kartik K. Agaram 576ab1df8d start recording undo events in timeline
We're not using or rendering them yet.
2021-11-26 18:59:31 -08:00
Kartik K. Agaram 07bf55b460 save timestamp on change; show in recent changes 2021-11-26 18:47:50 -08:00
Kartik K. Agaram f3dd541561 . 2021-11-26 18:21:04 -08:00
Kartik K. Agaram 555159fb9a clean up traces of an old experiment 2021-11-26 18:18:58 -08:00
Kartik K. Agaram 720ff19351 add support for metadata in Teliva programs
They don't have any semantics yet. We just ignore them for now.
2021-11-26 18:17:35 -08:00
Kartik K. Agaram 7295ce050d undo to a specific point
Still highly experimental. I'm not persisting state yet.
2021-11-26 18:05:41 -08:00
Kartik K. Agaram 080ea49d23 standardize screen headings 2021-11-26 18:04:58 -08:00
Kartik K. Agaram 0800f65eff start of 'recent changes' screen
I'm still unclear on precisely what the experience should be here. We
probably don't need all of a version control system. The goal is just to
be able to answer the question, "what did I change recently that caused
things to break?"

For now let's just start with letting people see past versions.
2021-11-26 18:03:20 -08:00
Kartik K. Agaram 283cc7ea52 eliminate tail call using goto 2021-11-26 16:54:45 -08:00
Kartik K. Agaram 0b365d3e4d clean up terminal in a specific situation
The problem: if ever I hit ctrl-e to go to the big picture view and then
hit Esc to go back to running the app, my terminal was messed up after
exiting the app.

Why did I even have this gunk? Perhaps it dates from the time when kilo
was emitting raw escape sequences rather than using ncurses.
2021-11-26 16:39:20 -08:00
Kartik K. Agaram e699b5a052 dedup an enum 2021-11-26 16:26:13 -08:00
Kartik K. Agaram 5bc52a5cba . 2021-11-26 16:10:02 -08:00
Kartik K. Agaram 2c80411224 . 2021-11-26 16:09:15 -08:00
Kartik K. Agaram f930b9e7c7 extract a function 2021-11-25 21:04:08 -08:00
Kartik K. Agaram 61ea63adca more stack hygiene 2021-11-25 21:02:27 -08:00
Kartik K. Agaram f5221ba651 one more curses binding 2021-11-25 20:51:38 -08:00
Kartik K. Agaram 73a22a397e libraries don't need Lua's `#define`s and whatnot 2021-11-25 20:21:05 -08:00
Kartik K. Agaram 16a98ea1b3 . 2021-11-25 20:16:41 -08:00
Kartik K. Agaram 4d7e99c343 . 2021-11-25 20:13:49 -08:00
Kartik K. Agaram d6810aba30 dedup definitions in big-picture view
We only want to show most recent version of each binding.
2021-11-25 20:02:10 -08:00
Kartik K. Agaram 4a8691c3dc new shortcut: return to big-picture view 2021-11-25 20:01:40 -08:00
Kartik K. Agaram f58d5b8354 teliva is now ASan-clean again
At least in short runs.

Encouraging that the problem was in a recent commit (5a63a5ca40 from
yesterday when I introduced version control).

Disabling Address Sanitizer again.
2021-11-25 19:27:30 -08:00
Kartik K. Agaram 05f4482139 make upstream kilo ASan-clean
Many thanks to dirkf for https://github.com/antirez/kilo/pull/73!

However, teliva is still not ASan-clean.
2021-11-25 11:28:05 -08:00
Kartik K. Agaram 6727045165 temporarily start using the address sanitizer 2021-11-25 11:25:28 -08:00
Kartik K. Agaram 103b8e17bb jettison luac
I'm starting to see some heap buffer overruns, which means we have too
much C code.

I noticed this because editing life.tlv no longer works after commit
5a63a5ca4. However, the offending heap overrun has been around long
before that. It's just been a silent bug until now.
2021-11-25 11:22:26 -08:00
Kartik K. Agaram d606e93839 rename 2021-11-24 12:50:05 -08:00
Kartik K. Agaram 5a63a5ca40 monotonically accumulate versions of definitions
One old drawback now has a new look. Before, we loaded definitions in
order, so global definitions had to exist before other global
definitions that used them. See window and grid in life.tlv. Now we load
definitions in reverse order, so initialization needs to change. Worse,
if we update window, we need to edit grid just to fix the order.

This implies that we can't yet optimize away bindings where there are no
new changes.
2021-11-24 10:10:38 -08:00
Kartik K. Agaram b40ad26544 more Makefile streamlining
Since everything is in my control there's no need to parameterize
include paths.

It's a struggle to get make to run when it should. Lying that something
is phony stops working when it's a dependency. Commands get
unnecessarily run. Just fucking run recursive makes directly in the
target that depends on them.
2021-11-24 09:28:01 -08:00
Kartik K. Agaram a788f80a92 . 2021-11-24 07:55:39 -08:00
Kartik K. Agaram b670747d9e consistent file ops
Now we're down to 1 real warning and 1 false positive.
2021-11-24 07:54:48 -08:00
Kartik K. Agaram aff8afa12d style 2021-11-24 07:48:49 -08:00
Kartik K. Agaram 64b609f743 rename 2021-11-24 07:04:04 -08:00
Kartik K. Agaram bd9020c5b3 indent 2021-11-24 06:43:32 -08:00