diff options
author | Kartik K. Agaram <vc@akkartik.com> | 2021-11-28 13:59:15 -0800 |
---|---|---|
committer | Kartik K. Agaram <vc@akkartik.com> | 2021-11-28 14:07:44 -0800 |
commit | cec57992b7b32cd75f411dcc998ddd7ce7f69b4a (patch) | |
tree | a9bfde1a63e92997841000eab48d58a5d7c086ad /src | |
parent | 570af7c2550c77489d455297b9a1d7ae4baa674a (diff) | |
download | teliva-cec57992b7b32cd75f411dcc998ddd7ce7f69b4a.tar.gz |
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
Diffstat (limited to 'src')
-rw-r--r-- | src/lcurses/window.c | 4 | ||||
-rw-r--r-- | src/lua.c | 3 |
2 files changed, 4 insertions, 3 deletions
diff --git a/src/lcurses/window.c b/src/lcurses/window.c index 8d3d5f1..87c5d08 100644 --- a/src/lcurses/window.c +++ b/src/lcurses/window.c @@ -1304,7 +1304,7 @@ Read a character from the window input. @see curses.echo @see keypad */ -extern void switch_to_editor (lua_State *L); +extern void developer_mode (lua_State *L); static int Wgetch(lua_State *L) { @@ -1318,7 +1318,7 @@ Wgetch(lua_State *L) exit(0); } if (c == CTRL_E) - switch_to_editor(L); + developer_mode(L); /* handle other standard menu hotkeys here */ return pushintresult(c); diff --git a/src/lua.c b/src/lua.c index 029b351..88e0868 100644 --- a/src/lua.c +++ b/src/lua.c @@ -952,6 +952,7 @@ int load_view_from_editor_state (lua_State *L) { int cx = lua_tointeger(L, -1); int back_to_big_picture = edit_from(L, "teliva_editor_buffer", /*error message*/ "", rowoff, coloff, cy, cx); lua_settop(L, editor_state_index); + // TODO: error handling like in edit_image return back_to_big_picture; } @@ -963,7 +964,7 @@ void select_view (lua_State *L) { extern void cleanup_curses (void); -void switch_to_editor (lua_State *L) { +void developer_mode (lua_State *L) { /* clobber the app's ncurses colors; we'll restart the app when we rerun it. */ for (int i = 0; i < 8; ++i) init_pair(i, i, -1); |