Commit Graph

163 Commits

Author SHA1 Message Date
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 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 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 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 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 61accc5b8e . 2021-11-29 22:48:14 -08:00
Kartik K. Agaram b6bca6ac14 fix regression in showing error messages 2021-11-29 22:38:46 -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 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 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 3fee59527a select C99 standard 2021-11-27 07:18:24 -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