Commit Graph

527 Commits

Author SHA1 Message Date
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
Kartik K. Agaram 1bf2504a8b clean up a warning and a bit of duplication
Now we have 2 probably-valid warnings caused by my edits, and 1
false-positive.
2021-11-22 19:25:05 -08:00
Kartik K. Agaram 76329c0206 standardize warning flags everywhere
I'd like to enable -Wextra as well, but that creates some false
positives.

I've at least made my changes clean w.r.t. -Wextra.

Now we have 4 remaining warnings with gcc 9.3 that seem genuine. Need to
fix those.
2021-11-22 19:01:07 -08:00
Kartik K. Agaram e77f3eb9f9 . 2021-11-22 18:47:56 -08:00
Kartik K. Agaram 11d370493a drop a warning implied by -Wall 2021-11-22 18:37:11 -08:00
Kartik K. Agaram ef68041137 standardize CFLAGS in luasocket 2021-11-22 18:36:04 -08:00
Kartik K. Agaram 3b4d7131cb standardize CFLAGS
Adding -Wpedantic creates a new warning. Leaving it alone for now:
  https://stackoverflow.com/questions/31526876/casting-when-using-dlsym
2021-11-22 18:11:38 -08:00
Kartik K. Agaram 97a0254042 standardize CFLAGS in luasec
What in the world is up with the $MYCFLAGS convention in these Lua
makefiles? I don't know, but I'm going to leave it undisturbed as far as
possible.
2021-11-22 18:06:20 -08:00
Kartik K. Agaram c4ecb9a53d standardize on gcc
cc and gcc are identical on my system. But why rely on that.
2021-11-22 17:56:45 -08:00
Kartik K. Agaram c79527b784 delete final vestiges of embedded luasocket 2021-11-22 17:41:08 -08:00
Kartik K. Agaram 70a2e1db1d delete most of the embedded luasocket in luasec
Hilariously, I wasn't linking against it in the first place.
2021-11-22 17:37:41 -08:00
Kartik K. Agaram d40471e9dc luasec: fix 'make clean' 2021-11-22 00:12:37 -08:00
Kartik K. Agaram 5a484efe8c https now working!
Still extremely ugly:
- I've inlined all the namespaces under ssl, so you need to know that
  context and config are related to ssl.
- luasec comes with its own copy of luasocket. I haven't deduped that
  yet.
2021-11-21 15:55:52 -08:00
Kartik K. Agaram 3b44b9827d basic http requests starting to work
In the process we're starting to load almost all of luasocket by
default. And everything is working as expected, no unpleasant surprises.
2021-11-21 15:07:42 -08:00
Kartik K. Agaram fdd87c5eda now. we. have. JSON.
Completely unmodified from upstream.
2021-11-21 14:22:20 -08:00
Kartik K. Agaram 15b43d3092 drop some redundant `require`s 2021-11-20 23:35:22 -08:00
Kartik K. Agaram 548d59f918 luasocket now loading properly
I still haven't tried actually running it.
2021-11-20 23:34:29 -08:00
Kartik K. Agaram 02acfa7c9c rename 2021-11-20 21:03:38 -08:00
Kartik K. Agaram fa6faaa700 extract a helper 2021-11-20 20:35:37 -08:00
Kartik K. Agaram 6bdc3d17a7 inline luasocket
Just builds for now, isn't available yet to Lua code.
2021-11-20 20:26:17 -08:00
Kartik K. Agaram 38b21ef79b bugfix: support running from top-level
Unfortunately we can't currently run teliva from anywhere else :/
2021-11-20 19:59:32 -08:00
Kartik K. Agaram d6ff198e78 get rid of a distracting name
No distinction now between the C and Lua versions of the curses library.
We build them all together in one place.
2021-11-20 16:33:41 -08:00
Kartik K. Agaram b618bfc7cf port changes from minimal to maximal version
From lcurseslib.c to lcurses/ directory.
2021-11-20 16:33:41 -08:00
Kartik K. Agaram 8a3e81b4b0 report errors when calling non-existent functions 2021-11-20 10:13:58 -08:00
Kartik K. Agaram e693448b65 inline in C is not worth the trouble
https://merveilles.town/@akkartik/107310347838372198
2021-11-20 10:10:26 -08:00
Kartik K. Agaram b43747ecef inline lcurses maximally rather than minimally
Until now we had just the bare minimum bindings needed for the demos
built so far. Now we have all of lcurses building in place with minimal
changes.

The changes in this commit can run hanoi.lua when inlined into Lua 5.1,
but don't work with Teliva.
2021-11-19 19:11:03 -08:00
Kartik K. Agaram 720d728a8d tested on Mac OS 2021-11-14 12:33:25 -08:00
Kartik K. Agaram f40bc31cc3 import life.teliva into image format 2021-11-14 11:10:18 -08:00
Kartik K. Agaram 58d2d596ea cleaner error handling 2021-11-14 09:55:13 -08:00
Kartik K. Agaram a3ca7877da . 2021-11-14 09:48:41 -08:00
Kartik K. Agaram 7b91691b14 remain in editor on error 2021-11-14 09:48:41 -08:00
Kartik K. Agaram b3b844c5f7 . 2021-11-14 09:48:41 -08:00
Kartik K. Agaram 2cc6912e85 find _some_ way to show error on initial load 2021-11-14 09:48:41 -08:00
Kartik K. Agaram 4ab3ccebb5 more menu cleanup 2021-11-14 09:48:40 -08:00
Kartik K. Agaram af4fbe97bf . 2021-11-14 09:48:40 -08:00
Kartik K. Agaram 33331a7c50 drop support for non-image Lua scripts
We still have no story for error messages. We'll work on that next.
2021-11-14 07:59:15 -08:00
Kartik K. Agaram b50e393770 draw the browse dialog the same way 2021-11-14 07:53:20 -08:00
Kartik K. Agaram 12d738d5ce dialogs are not status messages 2021-11-14 07:34:23 -08:00
Kartik K. Agaram b4e3936170 smarter image browsing
- distinguish between unused functions and data
- don't hardcode a specific convention for the curses window object
2021-11-14 07:11:30 -08:00
Kartik K. Agaram 5be743324c slightly more robust on-disk format
Looks like Lua supports a little bit of programmability in its
multi-line string literals. Even though I can't find this documented
anywhere.
2021-11-14 00:52:25 -08:00
Kartik K. Agaram b64a21771e janky way to cancel browsing 2021-11-14 00:38:00 -08:00
Kartik K. Agaram d9aac11889 slightly more obvious browse dialog 2021-11-14 00:27:59 -08:00
Kartik K. Agaram 9db1cd174f cleaner dialogs 2021-11-14 00:23:20 -08:00
Kartik K. Agaram e451206e06 no, use Esc to cancel
It inserts an ugly pause for ghastly historical reasons having to do
with the origins of terminals. But hopefully this isn't a common case.
2021-11-14 00:07:28 -08:00
Kartik K. Agaram c5261224df use word at cursor when it's not at start of line 2021-11-14 00:02:04 -08:00
Kartik K. Agaram 8e9534ed4f editor: use ctrl-g to cancel dialogs 2021-11-13 23:59:05 -08:00
Kartik K. Agaram 711d764b37 jump to word at cursor by default 2021-11-13 23:55:08 -08:00
Kartik K. Agaram 812b930815 ctrl-u to clear response in go menu 2021-11-13 23:27:51 -08:00
Kartik K. Agaram d79e394a30 reset cursor position when switching definitions 2021-11-13 23:27:06 -08:00
Kartik K. Agaram 3c2a5e26ae . 2021-11-13 23:22:00 -08:00
Kartik K. Agaram 902ce6009d cleaner layout for a function's code and data 2021-11-13 23:14:52 -08:00
Kartik K. Agaram 0e74056cbb . 2021-11-13 22:48:59 -08:00
Kartik K. Agaram e990682fb2 . 2021-11-13 22:48:14 -08:00
Kartik K. Agaram 55302fd877 . 2021-11-13 22:45:44 -08:00
Kartik K. Agaram a0dbc38c34 generalize kilo's hard-coded multiline C syntax 2021-11-13 22:39:28 -08:00
Kartik K. Agaram 308cb7acbe . 2021-11-13 22:02:30 -08:00
Kartik K. Agaram 485cd25739 fix for editor highlighting
Bug introduced during the transition to ncurses.
2021-11-13 22:00:50 -08:00
Kartik K. Agaram a7139a6b14 clean up after the editor
Even though we don't need to leave ncurses mode, there's still a process
boundary to clean up before.
2021-11-13 21:33:12 -08:00
Kartik K. Agaram da76ec44f1 . 2021-11-13 21:25:52 -08:00
Kartik K. Agaram 88f4b1bb2b . 2021-11-13 21:23:14 -08:00
Kartik K. Agaram 90f86daf1c kill highlighting flags
Looks like they were never used in original Kilo.
2021-11-13 21:20:30 -08:00
Kartik K. Agaram a655059c8d replace Kilo's raw terminal handling with ncurses
This was on my todo list. What made it urgent was finding that calling
getch() even once while in ncurses caused Kilo to stop detecting arrow
keys. No need to debug that sort of nonsense.
2021-11-13 21:20:30 -08:00
Kartik K. Agaram 625a66e196 avoid side-effects on the Lua stack 2021-11-13 17:48:04 -08:00
Kartik K. Agaram 12b2a44cf6 stop leaking memory 2021-11-13 17:46:08 -08:00
Kartik K. Agaram 398112f756 memory corruption bug
I was saving an address on the stack to a global, and it was getting
clobbered later. This is the sort of thing I completely eliminated in
https://github.com/akkartik/mu :/

Now I'm taking a leaf out of the Mu playbook and leaking a little bit of
memory every time I switch definitions.
2021-11-13 17:42:39 -08:00
Kartik K. Agaram 51378afb2a . 2021-11-13 16:53:39 -08:00
Kartik K. Agaram c34db20756 very rudimentary definition browser
Never shows definitions that were never called. Including non-functions.
2021-11-13 16:36:12 -08:00
Kartik K. Agaram 7a24bed432 . 2021-11-13 16:28:13 -08:00
Kartik K. Agaram 998e666958 . 2021-11-13 16:13:05 -08:00
Kartik K. Agaram 5bf5e47077 . 2021-11-13 16:13:05 -08:00
Kartik K. Agaram 647a2520d6 shield kilo.c from teliva_editbuffer detail 2021-11-13 16:13:05 -08:00
Kartik K. Agaram ee0e7c36f5 . 2021-11-13 15:11:03 -08:00
Kartik K. Agaram 4e62aa95b0 . 2021-11-13 15:07:28 -08:00
Kartik K. Agaram cbd5e7d552 . 2021-11-13 15:07:14 -08:00
Kartik K. Agaram e06a7b1a7b . 2021-11-13 15:00:49 -08:00
Kartik K. Agaram 33b705282d . 2021-11-13 14:59:22 -08:00
Kartik K. Agaram 7623e7069a clean up experiment from previous commit 2021-11-13 10:10:16 -08:00
Kartik K. Agaram 5a44605143 instrumenting function calls with their depth 2021-11-13 08:16:41 -08:00
Kartik K. Agaram 0f4faf0e53 start using static linkage like the rest of Lua 2021-11-13 05:14:41 -08:00
Kartik K. Agaram d72eae5978 create empty file when navigating to empty definition 2021-11-11 17:41:37 -08:00
Kartik K. Agaram e7f33de81e fix incorrect hotkey in menu 2021-11-11 17:32:50 -08:00
Kartik K. Agaram f6c7bf6fd0 ctrl-g to edit a different definition 2021-11-11 17:29:40 -08:00
Kartik K. Agaram 4d20e71c80 gracefully handle missing definition 2021-11-11 17:04:29 -08:00
Kartik K. Agaram 8398f8e2d1 . 2021-11-11 17:00:18 -08:00
Kartik K. Agaram a76cd9067a global for current definition being edited 2021-11-11 16:47:09 -08:00
Kartik K. Agaram d303c6efb0 pass lua_State into editor 2021-11-11 16:42:02 -08:00
Kartik K. Agaram 0d6378aa51 delete a helper that hides stack side effects 2021-11-11 16:32:08 -08:00
Kartik K. Agaram 7b389ce41e extract a few helper functions 2021-11-11 16:16:55 -08:00
Kartik K. Agaram 2d05f5090f . 2021-11-11 16:15:06 -08:00
Kartik K. Agaram 15e0ac70f9 . 2021-11-11 16:09:46 -08:00
Kartik K. Agaram 3e7ff252af reorg 2021-11-11 15:50:52 -08:00
Kartik K. Agaram f43a1c7da0 edit a single hard-coded definition in the image
src/teliva counter.tlv
C-e  # switch to editor
C-e  # save and quit
C-x  # exit

counter.tlv now has the same logical contents, though the whitespace has
changed, and the order of keys is different.

The implementation is utterly ghastly. For one, I'm unnecessarily
interfacing with kilo through the file system.
2021-11-10 23:20:59 -08:00
Kartik K. Agaram 9a49b92703 . 2021-11-10 22:15:13 -08:00
Kartik K. Agaram efbb57d339 new .tlv image format
Plan is for this to be the default representation for Teliva programs.
Text-friendly but not meant to be edited directly as text. Will
eventually include both code and data definitions, both current snapshot
and past revision history.

Right now .tlv files seem to run. Error checking is non-existent,
because I don't understand Lua's idioms around 'status' yet. Opening the
editor expectedly segfaults.

This commit is the most mind-bending bit of code I've written in a long
time.
2021-11-10 22:09:12 -08:00
Kartik K. Agaram dc05a10e23 life: move starting pattern around on the screen
This assumes we're doing it early soon after opening a new pattern, when
it hasn't yet reached the margins. Quick and dirty, but seems good
enough.
2021-11-10 14:26:38 -08:00
Kartik K. Agaram b397edcfbd . 2021-11-09 20:52:53 -08:00
Kartik K. Agaram ef9c42084d switch menu bars to reverse video 2021-11-07 10:29:29 -08:00
Kartik K. Agaram 2b7ffea316 fix menu colors
I had it switching to a dark background on me.
2021-11-07 08:06:42 -08:00
Kartik K. Agaram 22f1624728 better support light backgrounds
Thanks nicolas decoster for reporting this issue.
2021-11-07 08:04:33 -08:00
Kartik K. Agaram 40fdaf2a2a more obvious phrasing
Early returns are only worthwhile if they're utterly obvious.
2021-11-07 06:30:15 -08:00
Kartik K. Agaram 51d6ae77d2 fix a regression in commit ee85ad384f 2021-11-07 06:28:24 -08:00