diff options
author | Kartik K. Agaram <vc@akkartik.com> | 2022-01-25 21:00:38 -0800 |
---|---|---|
committer | Kartik K. Agaram <vc@akkartik.com> | 2022-01-25 21:07:52 -0800 |
commit | 283d4dba59a08f8474d4e3556a7241f1767631a5 (patch) | |
tree | b73d561dfcb8c58194b25c135b480c6748f2b434 | |
parent | 2fc48626b5dcc83dcecb38eb1c0f230ef8f46710 (diff) | |
download | teliva-283d4dba59a08f8474d4e3556a7241f1767631a5.tar.gz |
new section in big picture: prose (non-code)
I've always found "Documentation" too pretentious.
-rw-r--r-- | src/teliva.c | 37 |
1 files changed, 33 insertions, 4 deletions
diff --git a/src/teliva.c b/src/teliva.c index a08c90b..45df601 100644 --- a/src/teliva.c +++ b/src/teliva.c @@ -351,6 +351,10 @@ static void clear_caller(lua_State* L) { assert(lua_gettop(L) == oldtop); } +static int starts_with(const char* s, const char* pre) { + return strncmp(pre, s, strlen(pre)) == 0; +} + /* return true if submitted */ static int edit_current_definition(lua_State* L); static void recent_changes_view(lua_State* L); @@ -391,6 +395,7 @@ restart: for (lua_pushnil(L); lua_next(L, t) != 0; lua_pop(L, 1)) { const char* definition_name = lua_tostring(L, -2); if (is_special_history_key(definition_name)) continue; + if (starts_with(definition_name, "doc:")) continue; lua_getglobal(L, definition_name); int is_userdata = lua_isuserdata(L, -1); int is_function = lua_isfunction(L, -1); @@ -421,6 +426,7 @@ restart: for (lua_pushnil(L); lua_next(L, t) != 0; lua_pop(L, 1)) { const char* definition_name = lua_tostring(L, -2); if (is_special_history_key(definition_name)) continue; + if (starts_with(definition_name, "doc:")) continue; lua_getglobal(L, definition_name); int is_userdata = lua_isuserdata(L, -1); lua_pop(L, 1); @@ -443,6 +449,33 @@ restart: level_size[level] = index_within_level; level++; + // documentation (non-code) buffers + y += 2; + mvprintw(y, 0, "prose: "); + index_within_level = 0; + for (int i = history_array_size; i > 0; --i) { + lua_rawgeti(L, history_array, i); + int t = lua_gettop(L); + for (lua_pushnil(L); lua_next(L, t) != 0; lua_pop(L, 1)) { + const char* definition_name = lua_tostring(L, -2); + if (is_special_history_key(definition_name)) continue; + if (starts_with(definition_name, "doc:")) { + if (is_current_definition(L, definition_name, i, history_array, history_array_size)) { + if (level == highlight_level && index_within_level == highlight_index_within_level) { + draw_highlighted_definition_name(definition_name); + strncpy(highlight, definition_name, CURRENT_DEFINITION_LEN); + } else { + draw_definition_name(definition_name); + } + ++index_within_level; + } + } + } + lua_pop(L, 1); // history element + } + level_size[level] = index_within_level; + level++; + // functions by level y += 2; mvprintw(y, 0, "functions: "); @@ -632,10 +665,6 @@ void draw_callers_of_current_definition(lua_State* L) { assert(oldtop == lua_gettop(L)); } -static int starts_with(const char* s, const char* pre) { - return strncmp(pre, s, strlen(pre)) == 0; -} - extern int resumeEdit(lua_State* L); extern int editFrom(lua_State* L, char* filename, int rowoff, int coloff, int cy, int cx); int restore_editor_view(lua_State* L) { |