about summary refs log tree commit diff stats
path: root/src
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2021-11-26 21:41:23 -0800
committerKartik K. Agaram <vc@akkartik.com>2021-11-26 21:43:31 -0800
commite2a53858a026af414c175d2ef78a169faca2509d (patch)
tree57ec2b6ea544e89129f624f58329d02bd010e434 /src
parent6b6fe7ce729989979d32e804a18225f02644c1ac (diff)
downloadteliva-e2a53858a026af414c175d2ef78a169faca2509d.tar.gz
support notes on edits
Unlike both conventional version control and wiki history, I'm planning
to always allow modifying commit messages.
Diffstat (limited to 'src')
-rw-r--r--src/lua.c40
1 files changed, 38 insertions, 2 deletions
diff --git a/src/lua.c b/src/lua.c
index f4e5265..904463f 100644
--- a/src/lua.c
+++ b/src/lua.c
@@ -540,6 +540,7 @@ static void recent_changes_menu (int cursor, int history_array_size) {
   menu_column += 3;  /* strlen isn't sufficient */
   attron(A_REVERSE);
   draw_string_on_menu("newer");
+  draw_menu_item("^e", "edit/add note");
   if (cursor < history_array_size)
     draw_menu_item("^u", "undo everything after this");
   attrset(A_NORMAL);
@@ -579,6 +580,13 @@ void render_recent_changes (lua_State *L, int history_array, int start_index, in
         attroff(FG(7));
       }
       lua_pop(L, 1);
+      lua_getfield(L, t, "__teliva_note");
+      if (!lua_isnil(L, -1)) {
+        attron(FG(6));
+        printw("  -- %s", lua_tostring(L, -1));
+        attroff(FG(6));
+      }
+      lua_pop(L, 1);
       y++;
       const char *definition_contents = lua_tostring(L, -1);
       int x = 1;
@@ -628,8 +636,30 @@ void add_undo_event(lua_State *L, int cursor) {
 }
 
 
-// TODO:
-//  add a note
+/* precondition: teliva_program is at top of stack */
+void save_note_to_editor_buffer (lua_State *L, int cursor) {
+  lua_rawgeti(L, -1, cursor);
+  lua_getfield(L, -1, "__teliva_note");
+  const char *contents = lua_tostring(L, -1);
+  FILE *out = fopen("teliva_editbuffer", "w");
+  if (contents != NULL)
+    fprintf(out, "%s", contents);
+  fclose(out);
+  lua_pop(L, 2);  /* contents, table at cursor */
+}
+
+
+/* precondition: teliva_program is at top of stack */
+void load_note_from_editor_buffer (lua_State *L, int cursor) {
+  char new_contents[8192] = {0};
+  read_editor_buffer(new_contents);
+  lua_rawgeti(L, -1, cursor);
+  lua_pushstring(L, new_contents);
+  lua_setfield(L, -2, "__teliva_note");
+  lua_pop(L, 1);  /* table at cursor */
+}
+
+
 void recent_changes (lua_State *L) {
   lua_getglobal(L, "teliva_program");
   int history_array = lua_gettop(L);
@@ -656,6 +686,12 @@ void recent_changes (lua_State *L) {
       case KEY_UP:
         if (cursor < history_array_size) ++cursor;
         break;
+      case CTRL_E:
+        save_note_to_editor_buffer(L, cursor);
+        edit_buffer(L, "");
+        load_note_from_editor_buffer(L, cursor);
+        save_image(L);
+        break;
       case CTRL_U:
         if (cursor < history_array_size) {
           add_undo_event(L, cursor);