diff --git a/zet.tlv b/zet.tlv index 6db79ad..78ee02b 100644 --- a/zet.tlv +++ b/zet.tlv @@ -2509,120 +2509,6 @@ > view_settings.first_zettel = current_zettel_id > end >end -- __teliva_timestamp: - >Sat Feb 12 15:04:22 2022 - editz: - >function editz() - > local old_menu = menu - > menu = { - > {'^e', 'finish edit'}, - > {'^g', 'cancel edit'}, - > } - > local old_data = string.sub(zettels[current_zettel_id].data, 1) - > local top = (render_state.curr_h - 1) * (view_settings.height + view_settings.vmargin) - > local bottom = top + view_settings.height - > local left = (render_state.curr_w - 1) * (view_settings.width + view_settings.hmargin) - > local right = left + view_settings.width - > local cursor = string.len(zettels[current_zettel_id].data)+1 - > local quit = false - > curses.curs_set(1) - > while not quit do - > editz_render(window, zettels[current_zettel_id].data, cursor, top, bottom, left, right) - > quit, zettels[current_zettel_id].data, cursor = editz_update(window, zettels[current_zettel_id].data, cursor, old_data) - > end - > curses.curs_set(0) - > menu = old_menu - >end -- __teliva_timestamp: - >Sat Feb 12 15:05:20 2022 - editz_update: - >function editz_update(window, prose, cursor, original_prose) - > local key = window:getch() - > local h, w = window:getmaxyx() - > if key == curses.KEY_LEFT then - > if cursor > 1 then - > cursor = cursor-1 - > end - > elseif key == curses.KEY_RIGHT then - > if cursor <= #prose then - > cursor = cursor+1 - > end - > elseif key == curses.KEY_DOWN then - > cursor = cursor_down(prose, cursor, w) - > elseif key == curses.KEY_UP then - > cursor = cursor_up(prose, cursor, w) - > elseif key == curses.KEY_BACKSPACE or key == 8 or key == 127 then -- ctrl-h, ctrl-?, delete - > if cursor > 1 then - > cursor = cursor-1 - > prose = prose:remove(cursor) - > end - > elseif key == 5 then -- ctrl-e - > return true, prose, cursor - > elseif key == 7 then -- ctrl-g - > return true, original_prose, cursor - > elseif key == 10 or (key >= 32 and key < 127) then - > prose = prose:insert(string.char(key), cursor-1) - > cursor = cursor+1 - > end - > return false, prose, cursor - >end -- __teliva_timestamp: - >Sat Feb 12 15:08:04 2022 - editz: - >function editz() - > local old_menu = menu - > menu = { - > {'^e', 'finish edit'}, - > {'^g', 'cancel edit'}, - > {'^a', '< {'^b', ' {'^f', 'word>'}, - > {'^l', 'line>>'}, - > } - > local old_data = string.sub(zettels[current_zettel_id].data, 1) - > local top = (render_state.curr_h - 1) * (view_settings.height + view_settings.vmargin) - > local bottom = top + view_settings.height - > local left = (render_state.curr_w - 1) * (view_settings.width + view_settings.hmargin) - > local right = left + view_settings.width - > local cursor = string.len(zettels[current_zettel_id].data)+1 - > local quit = false - > curses.curs_set(1) - > while not quit do - > editz_render(window, zettels[current_zettel_id].data, cursor, top, bottom, left, right) - > quit, zettels[current_zettel_id].data, cursor = editz_update(window, zettels[current_zettel_id].data, cursor, old_data) - > end - > curses.curs_set(0) - > menu = old_menu - >end -- __teliva_timestamp: - >Sat Feb 12 15:08:58 2022 - editz: - >function editz() - > local old_menu = menu - > menu = { - > {'^e', 'finish edit'}, - > {'^g', 'cancel edit'}, - > {'^a', '< {'^b', ' {'^f', 'word>'}, - > {'^l', 'line>>'}, - > {'^k/^u', 'del <>'}, - > } - > local old_data = string.sub(zettels[current_zettel_id].data, 1) - > local top = (render_state.curr_h - 1) * (view_settings.height + view_settings.vmargin) - > local bottom = top + view_settings.height - > local left = (render_state.curr_w - 1) * (view_settings.width + view_settings.hmargin) - > local right = left + view_settings.width - > local cursor = string.len(zettels[current_zettel_id].data)+1 - > local quit = false - > curses.curs_set(1) - > while not quit do - > editz_render(window, zettels[current_zettel_id].data, cursor, top, bottom, left, right) - > quit, zettels[current_zettel_id].data, cursor = editz_update(window, zettels[current_zettel_id].data, cursor, old_data) - > end - > curses.curs_set(0) - > menu = old_menu - >end - __teliva_timestamp: >Sat Feb 12 15:11:15 2022 editz_update: @@ -2694,202 +2580,6 @@ > curses.curs_set(0) > menu = old_menu >end -- __teliva_timestamp: - >Sat Feb 12 15:31:27 2022 - editz_update: - >function editz_update(window, prose, cursor, original_prose) - > local key = window:getch() - > local h, w = window:getmaxyx() - > -- cursor movement - > if key == curses.KEY_LEFT then - > if cursor > 1 then - > cursor = cursor-1 - > end - > elseif key == curses.KEY_RIGHT then - > if cursor <= #prose then - > cursor = cursor+1 - > end - > elseif key == curses.KEY_DOWN then - > cursor = cursor_down(prose, cursor, w) - > elseif key == curses.KEY_UP then - > cursor = cursor_up(prose, cursor, w) - > elseif key == curses.KEY_BACKSPACE or key == 8 or key == 127 then -- ctrl-h, ctrl-?, delete - > if cursor > 1 then - > cursor = cursor-1 - > prose = prose:remove(cursor) - > end - > elseif key == 1 then -- ctrl-a - > while cursor > 1 and prose[cursor] ~= '\n' do - > cursor = cursor-1 - > end - > elseif key == 12 then -- ctrl-l - > elseif key == 6 then -- ctrl-f - > elseif key == 2 then -- ctrl-b - > -- delete - > elseif key == 11 then -- ctrl-k - > -- exit - > elseif key == 5 then -- ctrl-e - > return true, prose, cursor - > elseif key == 7 then -- ctrl-g - > return true, original_prose, cursor - > -- insert - > elseif key == 10 or (key >= 32 and key < 127) then - > prose = prose:insert(string.char(key), cursor-1) - > cursor = cursor+1 - > end - > return false, prose, cursor - >end -- __teliva_timestamp: - >Sat Feb 12 15:48:35 2022 - editz_update: - >function editz_update(window, prose, cursor, original_prose) - > local key = window:getch() - > local h, w = window:getmaxyx() - > -- cursor movement - > if key == curses.KEY_LEFT then - > if cursor > 1 then - > cursor = cursor-1 - > end - > elseif key == curses.KEY_RIGHT then - > if cursor <= #prose then - > cursor = cursor+1 - > end - > elseif key == curses.KEY_DOWN then - > cursor = cursor_down(prose, cursor, w) - > elseif key == curses.KEY_UP then - > cursor = cursor_up(prose, cursor, w) - > elseif key == curses.KEY_BACKSPACE or key == 8 or key == 127 then -- ctrl-h, ctrl-?, delete - > if cursor > 1 then - > cursor = cursor-1 - > prose = prose:remove(cursor) - > end - > elseif key == 1 then -- ctrl-a - > while cursor > 1 do - > if prose[cursor-1] == '\n' then break end - > cursor = cursor-1 - > end - > elseif key == 12 then -- ctrl-l - > elseif key == 6 then -- ctrl-f - > elseif key == 2 then -- ctrl-b - > -- delete - > elseif key == 11 then -- ctrl-k - > -- exit - > elseif key == 5 then -- ctrl-e - > return true, prose, cursor - > elseif key == 7 then -- ctrl-g - > return true, original_prose, cursor - > -- insert - > elseif key == 10 or (key >= 32 and key < 127) then - > prose = prose:insert(string.char(key), cursor-1) - > cursor = cursor+1 - > end - > return false, prose, cursor - >end -- __teliva_timestamp: - >Sat Feb 12 15:49:49 2022 - editz_update: - >function editz_update(window, prose, cursor, original_prose) - > local key = window:getch() - > local h, w = window:getmaxyx() - > -- cursor movement - > if key == curses.KEY_LEFT then - > if cursor > 1 then - > cursor = cursor-1 - > end - > elseif key == curses.KEY_RIGHT then - > if cursor <= #prose then - > cursor = cursor+1 - > end - > elseif key == curses.KEY_DOWN then - > cursor = cursor_down(prose, cursor, w) - > elseif key == curses.KEY_UP then - > cursor = cursor_up(prose, cursor, w) - > elseif key == curses.KEY_BACKSPACE or key == 8 or key == 127 then -- ctrl-h, ctrl-?, delete - > if cursor > 1 then - > cursor = cursor-1 - > prose = prose:remove(cursor) - > end - > elseif key == 1 then -- ctrl-a - > while cursor > 1 do - > if prose[cursor-1] == '\n' then break end - > cursor = cursor-1 - > end - > elseif key == 12 then -- ctrl-l - > local max = string.len(prose) - > while cursor <= max and prose[cursor] ~= '\n' do - > cursor = cursor+1 - > end - > elseif key == 6 then -- ctrl-f - > elseif key == 2 then -- ctrl-b - > -- delete - > elseif key == 11 then -- ctrl-k - > -- exit - > elseif key == 5 then -- ctrl-e - > return true, prose, cursor - > elseif key == 7 then -- ctrl-g - > return true, original_prose, cursor - > -- insert - > elseif key == 10 or (key >= 32 and key < 127) then - > prose = prose:insert(string.char(key), cursor-1) - > cursor = cursor+1 - > end - > return false, prose, cursor - >end -- __teliva_timestamp: - >Sat Feb 12 15:53:52 2022 - editz_update: - >function editz_update(window, prose, cursor, original_prose) - > local key = window:getch() - > local h, w = window:getmaxyx() - > -- cursor movement - > if key == curses.KEY_LEFT then - > if cursor > 1 then - > cursor = cursor-1 - > end - > elseif key == curses.KEY_RIGHT then - > if cursor <= #prose then - > cursor = cursor+1 - > end - > elseif key == curses.KEY_DOWN then - > cursor = cursor_down(prose, cursor, w) - > elseif key == curses.KEY_UP then - > cursor = cursor_up(prose, cursor, w) - > elseif key == curses.KEY_BACKSPACE or key == 8 or key == 127 then -- ctrl-h, ctrl-?, delete - > if cursor > 1 then - > cursor = cursor-1 - > prose = prose:remove(cursor) - > end - > elseif key == 1 then -- ctrl-a - > while cursor > 1 do - > if prose[cursor-1] == '\n' then break end - > cursor = cursor-1 - > end - > elseif key == 12 then -- ctrl-l - > local max = string.len(prose) - > while cursor <= max and prose[cursor] ~= '\n' do - > cursor = cursor+1 - > end - > elseif key == 6 then -- ctrl-f - > elseif key == 2 then -- ctrl-b - > -- delete - > elseif key == 11 then -- ctrl-k - > while cursor > 1 do - > if prose[cursor-1] == '\n' then break end - > cursor = cursor-1 - > prose = prose:remove(cursor) - > end - > -- exit - > elseif key == 5 then -- ctrl-e - > return true, prose, cursor - > elseif key == 7 then -- ctrl-g - > return true, original_prose, cursor - > -- insert - > elseif key == 10 or (key >= 32 and key < 127) then - > prose = prose:insert(string.char(key), cursor-1) - > cursor = cursor+1 - > end - > return false, prose, cursor - >end - __teliva_timestamp: >Sat Feb 12 15:55:10 2022 __teliva_note: @@ -2945,283 +2635,6 @@ > end > return false, prose, cursor >end -- __teliva_timestamp: - >Sat Feb 12 16:50:36 2022 - editz_update: - >function editz_update(window, prose, cursor, original_prose) - > local key = window:getch() - > local h, w = window:getmaxyx() - > -- cursor movement - > if key == curses.KEY_LEFT then - > if cursor > 1 then - > cursor = cursor-1 - > end - > elseif key == curses.KEY_RIGHT then - > if cursor <= #prose then - > cursor = cursor+1 - > end - > elseif key == curses.KEY_DOWN then - > cursor = cursor_down(prose, cursor, w) - > elseif key == curses.KEY_UP then - > cursor = cursor_up(prose, cursor, w) - > elseif key == curses.KEY_BACKSPACE or key == 8 or key == 127 then -- ctrl-h, ctrl-?, delete - > if cursor > 1 then - > cursor = cursor-1 - > prose = prose:remove(cursor) - > end - > elseif key == 1 then -- ctrl-a - > while cursor > 1 do - > if prose[cursor-1] == '\n' then break end - > cursor = cursor-1 - > end - > elseif key == 12 then -- ctrl-l - > local max = string.len(prose) - > while cursor <= max and prose[cursor] ~= '\n' do - > cursor = cursor+1 - > end - > elseif key == 6 then -- ctrl-f - > elseif key == 2 then -- ctrl-b - > while cursor > 1 do - > -- first skip all alphanumeric letters - > if string.match(prose[cursor], '%w') then - > cursor = cursor-1 - > -- then stop at the last non-alphanumeric letter - > elseif string.match(prose[cursor-1], '%w') then - > break - > else - > cursor = cursor-1 - > end - > end - > -- delete - > elseif key == 11 then -- ctrl-k - > while cursor <= string.len(prose) and prose[cursor] ~= '\n' do - > prose = prose:remove(cursor) - > end - > -- exit - > elseif key == 5 then -- ctrl-e - > return true, prose, cursor - > elseif key == 7 then -- ctrl-g - > return true, original_prose, cursor - > -- insert - > elseif key == 10 or (key >= 32 and key < 127) then - > prose = prose:insert(string.char(key), cursor-1) - > cursor = cursor+1 - > end - > return false, prose, cursor - >end -- __teliva_timestamp: - >Sat Feb 12 16:58:41 2022 - editz_update: - >function editz_update(window, prose, cursor, original_prose) - > local key = window:getch() - > local h, w = window:getmaxyx() - > -- cursor movement - > if key == curses.KEY_LEFT then - > if cursor > 1 then - > cursor = cursor-1 - > end - > elseif key == curses.KEY_RIGHT then - > if cursor <= #prose then - > cursor = cursor+1 - > end - > elseif key == curses.KEY_DOWN then - > cursor = cursor_down(prose, cursor, w) - > elseif key == curses.KEY_UP then - > cursor = cursor_up(prose, cursor, w) - > elseif key == curses.KEY_BACKSPACE or key == 8 or key == 127 then -- ctrl-h, ctrl-?, delete - > if cursor > 1 then - > cursor = cursor-1 - > prose = prose:remove(cursor) - > end - > elseif key == 1 then -- ctrl-a - > -- to start of line - > while cursor > 1 do - > if prose[cursor-1] == '\n' then break end - > cursor = cursor-1 - > end - > elseif key == 12 then -- ctrl-l - > -- to end of line - > local max = string.len(prose) - > while cursor <= max and prose[cursor] ~= '\n' do - > cursor = cursor+1 - > end - > elseif key == 6 then -- ctrl-f - > -- to next word - > local max = string.len(prose) - > while cursor <= max and string.match(prose[cursor], '%w') do - > cursor = cursor+1 - > end - > while cursor <= max and string.match(prose[cursor], '%W') do - > cursor = cursor+1 - > end - > elseif key == 2 then -- ctrl-b - > -- to previous word - > while cursor > 1 and string.match(prose[cursor], '%W') do - > cursor = cursor-1 - > end - > while cursor > 1 and string.match(prose[cursor], '%w') do - > cursor = cursor-1 - > end - > while cursor > 1 and string.match(prose[cursor-1], '%w') do - > cursor = cursor-1 - > end - > -- delete - > elseif key == 11 then -- ctrl-k - > while cursor <= string.len(prose) and prose[cursor] ~= '\n' do - > prose = prose:remove(cursor) - > end - > -- exit - > elseif key == 5 then -- ctrl-e - > return true, prose, cursor - > elseif key == 7 then -- ctrl-g - > return true, original_prose, cursor - > -- insert - > elseif key == 10 or (key >= 32 and key < 127) then - > prose = prose:insert(string.char(key), cursor-1) - > cursor = cursor+1 - > end - > return false, prose, cursor - >end -- __teliva_timestamp: - >Sat Feb 12 16:59:37 2022 - editz_update: - >function editz_update(window, prose, cursor, original_prose) - > local key = window:getch() - > local h, w = window:getmaxyx() - > -- cursor movement - > if key == curses.KEY_LEFT then - > if cursor > 1 then - > cursor = cursor-1 - > end - > elseif key == curses.KEY_RIGHT then - > if cursor <= #prose then - > cursor = cursor+1 - > end - > elseif key == curses.KEY_DOWN then - > cursor = cursor_down(prose, cursor, w) - > elseif key == curses.KEY_UP then - > cursor = cursor_up(prose, cursor, w) - > elseif key == curses.KEY_BACKSPACE or key == 8 or key == 127 then -- ctrl-h, ctrl-?, delete - > if cursor > 1 then - > cursor = cursor-1 - > prose = prose:remove(cursor) - > end - > elseif key == 1 then -- ctrl-a - > -- to start of line - > while cursor > 1 do - > if prose[cursor-1] == '\n' then break end - > cursor = cursor-1 - > end - > elseif key == 12 then -- ctrl-l - > -- to end of line - > local max = string.len(prose) - > while cursor <= max and prose[cursor] ~= '\n' do - > cursor = cursor+1 - > end - > elseif key == 6 then -- ctrl-f - > -- to next word - > local max = string.len(prose) - > while cursor <= max and string.match(prose[cursor], '%w') do - > cursor = cursor+1 - > end - > while cursor <= max and string.match(prose[cursor], '%W') do - > cursor = cursor+1 - > end - > elseif key == 2 then -- ctrl-b - > -- to previous word - > while cursor > 1 and string.match(prose[cursor], '%W') do - > cursor = cursor-1 - > end - > while cursor > 1 and string.match(prose[cursor-1], '%w') do - > cursor = cursor-1 - > end - > -- delete - > elseif key == 11 then -- ctrl-k - > while cursor <= string.len(prose) and prose[cursor] ~= '\n' do - > prose = prose:remove(cursor) - > end - > -- exit - > elseif key == 5 then -- ctrl-e - > return true, prose, cursor - > elseif key == 7 then -- ctrl-g - > return true, original_prose, cursor - > -- insert - > elseif key == 10 or (key >= 32 and key < 127) then - > prose = prose:insert(string.char(key), cursor-1) - > cursor = cursor+1 - > end - > return false, prose, cursor - >end -- __teliva_timestamp: - >Sat Feb 12 17:00:00 2022 - editz_update: - >function editz_update(window, prose, cursor, original_prose) - > local key = window:getch() - > local h, w = window:getmaxyx() - > -- cursor movement - > if key == curses.KEY_LEFT then - > if cursor > 1 then - > cursor = cursor-1 - > end - > elseif key == curses.KEY_RIGHT then - > if cursor <= #prose then - > cursor = cursor+1 - > end - > elseif key == curses.KEY_DOWN then - > cursor = cursor_down(prose, cursor, w) - > elseif key == curses.KEY_UP then - > cursor = cursor_up(prose, cursor, w) - > elseif key == curses.KEY_BACKSPACE or key == 8 or key == 127 then -- ctrl-h, ctrl-?, delete - > if cursor > 1 then - > cursor = cursor-1 - > prose = prose:remove(cursor) - > end - > elseif key == 1 then -- ctrl-a - > -- to start of line - > while cursor > 1 do - > if prose[cursor-1] == '\n' then break end - > cursor = cursor-1 - > end - > elseif key == 12 then -- ctrl-l - > -- to end of line - > local max = string.len(prose) - > while cursor <= max and prose[cursor] ~= '\n' do - > cursor = cursor+1 - > end - > elseif key == 6 then -- ctrl-f - > -- to next word - > local max = string.len(prose) - > while cursor <= max and string.match(prose[cursor], '%w') do - > cursor = cursor+1 - > end - > while cursor <= max and string.match(prose[cursor], '%W') do - > cursor = cursor+1 - > end - > elseif key == 2 then -- ctrl-b - > -- to previous word - > while cursor > 1 and string.match(prose[cursor], '%W') do - > cursor = cursor-1 - > end - > while cursor > 1 and string.match(prose[cursor], '%w') do - > cursor = cursor-1 - > end - > -- delete - > elseif key == 11 then -- ctrl-k - > while cursor <= string.len(prose) and prose[cursor] ~= '\n' do - > prose = prose:remove(cursor) - > end - > -- exit - > elseif key == 5 then -- ctrl-e - > return true, prose, cursor - > elseif key == 7 then -- ctrl-g - > return true, original_prose, cursor - > -- insert - > elseif key == 10 or (key >= 32 and key < 127) then - > prose = prose:insert(string.char(key), cursor-1) - > cursor = cursor+1 - > end - > return false, prose, cursor - >end - __teliva_timestamp: >Sat Feb 12 17:01:45 2022 __teliva_note: @@ -3419,147 +2832,6 @@ > end > window:refresh() >end -- __teliva_timestamp: - >Sat Feb 12 17:17:45 2022 - update: - >function update(window) - > local key = window:getch() - > local h, w = window:getmaxyx() - > local curr = zettels[current_zettel_id] - > assert(curr, string.format('cursor fell off the edge of the world: %s', type(current_zettel_id))) - > -- move along the graph - > if key == string.byte('j') then - > if curr.child then - > current_zettel_id = curr.child - > elseif curr.next then - > current_zettel_id = curr.next - > elseif curr.parent and zettels[curr.parent].next then - > current_zettel_id = zettels[curr.parent].next - > end - > elseif key == string.byte('k') then - > if curr.parent then - > current_zettel_id = curr.parent - > end - > elseif key == string.byte('h') then - > if curr.prev then - > current_zettel_id = curr.prev - > elseif curr.parent then - > current_zettel_id = curr.parent - > end - > elseif key == string.byte('l') then - > if curr.next then - > current_zettel_id = curr.next - > elseif curr.parent and zettels[curr.parent].next then - > current_zettel_id = zettels[curr.parent].next - > end - > if not render_state.displayed[current_zettel_id] then - > rend - > -- move along the screen - > elseif key == curses.KEY_UP then - > if render_state.curr_h > 1 then - > current_zettel_id = render_state.wh2id[render_state.curr_w][render_state.curr_h - 1] - > end - > elseif key == curses.KEY_DOWN then - > if render_state.wh2id[render_state.curr_w][render_state.curr_h + 1] then - > current_zettel_id = render_state.wh2id[render_state.curr_w][render_state.curr_h + 1] - > end - > elseif key == curses.KEY_LEFT then - > if render_state.curr_w > 1 then - > current_zettel_id = render_state.wh2id[render_state.curr_w - 1][render_state.curr_h] - > end - > elseif key == curses.KEY_RIGHT then - > if render_state.wh2id[render_state.curr_w + 1] and render_state.wh2id[render_state.curr_w + 1][render_state.curr_h] then - > current_zettel_id = render_state.wh2id[render_state.curr_w + 1][render_state.curr_h] - > end - > -- mutations - > elseif key == string.byte('e') then - > editz(window) - > elseif key == string.byte('a') then - > -- insert sibling after - > local old = curr.next - > curr.next = new_id() - > local new = zettels[curr.next] - > new.data = '' - > new.next = old - > new.prev = current_zettel_id - > if old then - > zettels[old].prev = curr.next - > assert(curr.parent == zettels[old].parent, 'siblings should have same parent') - > end - > new.parent = curr.parent - > current_zettel_id = curr.next - > render(window) -- recompute render_state - > editz(window) - > elseif key == string.byte('b') then - > -- insert sibling before - > local old = curr.prev - > curr.prev = new_id() - > local new = zettels[curr.prev] - > new.data = '' - > new.prev = old - > new.next = current_zettel_id - > if old then - > zettels[old].next = curr.prev - > assert(curr.parent == zettels[old].parent, 'siblings should have same parent') - > end - > new.parent = curr.parent - > current_zettel_id = curr.prev - > render(window) -- recompute render_state - > editz(window) - > elseif key == string.byte('c') then - > -- insert child - > local old = curr.child - > curr.child = new_id() - > local new = zettels[curr.child] - > new.data = '' - > new.next = old - > if old then - > assert(zettels[old].prev == nil, "first child shouldn't have a previous sibling") - > zettels[old].prev = curr.child - > end - > new.parent = current_zettel_id - > current_zettel_id = curr.child - > render(window) -- recompute render_state - > editz(window) - > -- cross-links - > elseif key == string.byte('s') then - > -- save zettel to a stash - > stash = current_zettel_id - > elseif key == string.byte('t') then - > -- cross-link a zettel bidirectionally with what's on the stash - > local insert_crosslink = - > function(a, rel, b_id) - > if a.crosslinks == nil then - > a.crosslinks = {} - > end - > a.crosslinks[rel] = b_id - > end - > insert_crosslink(curr, 'a', stash) - > insert_crosslink(zettels[stash], 'a', current_zettel_id) - > stash = nil - > -- view settings - > elseif key == string.byte('x') then - > if view_settings.width > 5 then - > view_settings.width = view_settings.width - 5 - > end - > elseif key == string.byte('X') then - > if view_settings.width < w-5 then - > view_settings.width = view_settings.width + 5 - > end - > elseif key == string.byte('y') then - > if view_settings.height > 0 then - > view_settings.height = view_settings.height - 1 - > end - > elseif key == string.byte('Y') then - > if view_settings.height < h-2 then - > view_settings.height = view_settings.height + 1 - > end - > elseif key == string.byte('z') then - > -- scroll to show the current zettel at top of screen - > -- often has the effect of zooming in on its hierarchy - > view_settings.first_zettel = current_zettel_id - > end - >end - __teliva_timestamp: >Sat Feb 12 17:18:34 2022 __teliva_note: @@ -3717,163 +2989,6 @@ > view_settings.first_zettel = current_zettel_id > end >end -- __teliva_timestamp: - >Sat Feb 12 17:21:48 2022 - update: - >function update(window) - > local key = window:getch() - > local h, w = window:getmaxyx() - > local curr = zettels[current_zettel_id] - > assert(curr, string.format('cursor fell off the edge of the world: %s', type(current_zettel_id))) - > -- move along the graph - > if key == string.byte('j') then - > if curr.child then - > current_zettel_id = curr.child - > elseif curr.next then - > current_zettel_id = curr.next - > elseif curr.parent and zettels[curr.parent].next then - > current_zettel_id = zettels[curr.parent].next - > end - > -- scroll if necessary - > if not render_state.displayed[current_zettel_id] then - > view_settings.first_zettel = current_zettel_id - > end - > elseif key == string.byte('k') then - > if curr.parent then - > current_zettel_id = curr.parent - > elseif curr.prev then - > current_zettel_id = curr.prev - > end - > -- scroll if necessary - > if not render_state.displayed[current_zettel_id] then - > view_settings.first_zettel = current_zettel_id - > end - > elseif key == string.byte('h') then - > if curr.prev then - > current_zettel_id = curr.prev - > elseif curr.parent then - > current_zettel_id = curr.parent - > end - > -- scroll if necessary - > if not render_state.displayed[current_zettel_id] then - > view_settings.first_zettel = current_zettel_id - > end - > elseif key == string.byte('l') then - > if curr.next then - > current_zettel_id = curr.next - > elseif curr.parent and zettels[curr.parent].next then - > current_zettel_id = zettels[curr.parent].next - > end - > -- scroll if necessary - > if not render_state.displayed[current_zettel_id] then - > view_settings.first_zettel = current_zettel_id - > end - > -- move along the screen - > elseif key == curses.KEY_UP then - > if render_state.curr_h > 1 then - > current_zettel_id = render_state.wh2id[render_state.curr_w][render_state.curr_h - 1] - > end - > elseif key == curses.KEY_DOWN then - > if render_state.wh2id[render_state.curr_w][render_state.curr_h + 1] then - > current_zettel_id = render_state.wh2id[render_state.curr_w][render_state.curr_h + 1] - > end - > elseif key == curses.KEY_LEFT then - > if render_state.curr_w > 1 then - > current_zettel_id = render_state.wh2id[render_state.curr_w - 1][render_state.curr_h] - > end - > elseif key == curses.KEY_RIGHT then - > if render_state.wh2id[render_state.curr_w + 1] and render_state.wh2id[render_state.curr_w + 1][render_state.curr_h] then - > current_zettel_id = render_state.wh2id[render_state.curr_w + 1][render_state.curr_h] - > end - > -- mutations - > elseif key == string.byte('e') then - > editz(window) - > elseif key == string.byte('a') then - > -- insert sibling after - > local old = curr.next - > curr.next = new_id() - > local new = zettels[curr.next] - > new.data = '' - > new.next = old - > new.prev = current_zettel_id - > if old then - > zettels[old].prev = curr.next - > assert(curr.parent == zettels[old].parent, 'siblings should have same parent') - > end - > new.parent = curr.parent - > current_zettel_id = curr.next - > render(window) -- recompute render_state - > editz(window) - > elseif key == string.byte('b') then - > -- insert sibling before - > local old = curr.prev - > curr.prev = new_id() - > local new = zettels[curr.prev] - > new.data = '' - > new.prev = old - > new.next = current_zettel_id - > if old then - > zettels[old].next = curr.prev - > assert(curr.parent == zettels[old].parent, 'siblings should have same parent') - > end - > new.parent = curr.parent - > current_zettel_id = curr.prev - > render(window) -- recompute render_state - > editz(window) - > elseif key == string.byte('c') then - > -- insert child - > local old = curr.child - > curr.child = new_id() - > local new = zettels[curr.child] - > new.data = '' - > new.next = old - > if old then - > assert(zettels[old].prev == nil, "first child shouldn't have a previous sibling") - > zettels[old].prev = curr.child - > end - > new.parent = current_zettel_id - > current_zettel_id = curr.child - > render(window) -- recompute render_state - > editz(window) - > -- cross-links - > elseif key == string.byte('s') then - > -- save zettel to a stash - > stash = current_zettel_id - > elseif key == string.byte('t') then - > -- cross-link a zettel bidirectionally with what's on the stash - > local insert_crosslink = - > function(a, rel, b_id) - > if a.crosslinks == nil then - > a.crosslinks = {} - > end - > a.crosslinks[rel] = b_id - > end - > insert_crosslink(curr, 'a', stash) - > insert_crosslink(zettels[stash], 'a', current_zettel_id) - > stash = nil - > -- view settings - > elseif key == string.byte('x') then - > if view_settings.width > 5 then - > view_settings.width = view_settings.width - 5 - > end - > elseif key == string.byte('X') then - > if view_settings.width < w-5 then - > view_settings.width = view_settings.width + 5 - > end - > elseif key == string.byte('y') then - > if view_settings.height > 0 then - > view_settings.height = view_settings.height - 1 - > end - > elseif key == string.byte('Y') then - > if view_settings.height < h-2 then - > view_settings.height = view_settings.height + 1 - > end - > elseif key == string.byte('z') then - > -- scroll to show the current zettel at top of screen - > -- often has the effect of zooming in on its hierarchy - > view_settings.first_zettel = current_zettel_id - > end - >end - __teliva_timestamp: >Sat Feb 12 17:23:33 2022 __teliva_note: @@ -4054,2150 +3169,6 @@ > {'t', 'link with stash'}, > {'z', 'scroll'}, >} -- __teliva_timestamp: - >Sat Feb 12 17:30:55 2022 - render_state: - >-- some information about what's been drawn on screen - >-- not saved between app restarts - >render_state = { - > -- where the current zettel is, in units of zettels - > curr_h = 1, - > curr_w = 1, - > -- what zettel is at each position on screen, in units of zettels - > hw2id = {}, - > -- list of zettels currently displayed - > displayed = {}, - > -- history of screen render state - > history = {}, -- we just need view_settings.first_zettel and current_zettel_id - >} -- __teliva_timestamp: - >Sat Feb 12 17:46:09 2022 - update: - >function update(window) - > local key = window:getch() - > local h, w = window:getmaxyx() - > local curr = zettels[current_zettel_id] - > assert(curr, string.format('cursor fell off the edge of the world: %s', type(current_zettel_id))) - > -- read from or write to render_state.history - > if key == string.byte('<') then - > -- previous zettel moved to - > -- does NOT undo mutations - > if #render_state.history > 0 then - > view_settings.first_zettel = render_state.history[-1].first_zettel - > current_zettel_id = render_state.history[-1].current_zettel_id - > render_state.history:remove() - > end - > return - > end - > if key ~= string.byte('e') then - > render_state.history:insert(view_settings.first_zettel, current_zettel_id) - > end - > -- move along the graph - > if key == string.byte('j') then - > -- child or next sibling - > if curr.child then - > current_zettel_id = curr.child - > elseif curr.next then - > current_zettel_id = curr.next - > elseif curr.parent and zettels[curr.parent].next then - > current_zettel_id = zettels[curr.parent].next - > end - > -- scroll if necessary - > if not render_state.displayed[current_zettel_id] then - > view_settings.first_zettel = current_zettel_id - > end - > elseif key == string.byte('k') then - > -- parent or previous sibling - > if curr.parent then - > current_zettel_id = curr.parent - > elseif curr.prev then - > current_zettel_id = curr.prev - > end - > -- scroll if necessary - > if not render_state.displayed[current_zettel_id] then - > view_settings.first_zettel = current_zettel_id - > end - > elseif key == string.byte('h') then - > -- previous sibling or parent - > if curr.prev then - > current_zettel_id = curr.prev - > elseif curr.parent then - > current_zettel_id = curr.parent - > end - > -- scroll if necessary - > if not render_state.displayed[current_zettel_id] then - > view_settings.first_zettel = current_zettel_id - > end - > elseif key == string.byte('l') then - > -- next sibling or next sibling of parent - > if curr.next then - > current_zettel_id = curr.next - > elseif curr.parent and zettels[curr.parent].next then - > current_zettel_id = zettels[curr.parent].next - > end - > -- scroll if necessary - > if not render_state.displayed[current_zettel_id] then - > view_settings.first_zettel = current_zettel_id - > end - > -- move along the screen - > elseif key == curses.KEY_UP then - > if render_state.curr_h > 1 then - > current_zettel_id = render_state.wh2id[render_state.curr_w][render_state.curr_h - 1] - > end - > elseif key == curses.KEY_DOWN then - > if render_state.wh2id[render_state.curr_w][render_state.curr_h + 1] then - > current_zettel_id = render_state.wh2id[render_state.curr_w][render_state.curr_h + 1] - > end - > elseif key == curses.KEY_LEFT then - > if render_state.curr_w > 1 then - > current_zettel_id = render_state.wh2id[render_state.curr_w - 1][render_state.curr_h] - > end - > elseif key == curses.KEY_RIGHT then - > if render_state.wh2id[render_state.curr_w + 1] and render_state.wh2id[render_state.curr_w + 1][render_state.curr_h] then - > current_zettel_id = render_state.wh2id[render_state.curr_w + 1][render_state.curr_h] - > end - > -- mutations - > elseif key == string.byte('e') then - > editz(window) - > elseif key == string.byte('a') then - > -- insert sibling after - > local old = curr.next - > curr.next = new_id() - > local new = zettels[curr.next] - > new.data = '' - > new.next = old - > new.prev = current_zettel_id - > if old then - > zettels[old].prev = curr.next - > assert(curr.parent == zettels[old].parent, 'siblings should have same parent') - > end - > new.parent = curr.parent - > current_zettel_id = curr.next - > render(window) -- recompute render_state - > editz(window) - > elseif key == string.byte('b') then - > -- insert sibling before - > local old = curr.prev - > curr.prev = new_id() - > local new = zettels[curr.prev] - > new.data = '' - > new.prev = old - > new.next = current_zettel_id - > if old then - > zettels[old].next = curr.prev - > assert(curr.parent == zettels[old].parent, 'siblings should have same parent') - > end - > new.parent = curr.parent - > current_zettel_id = curr.prev - > render(window) -- recompute render_state - > editz(window) - > elseif key == string.byte('c') then - > -- insert child - > local old = curr.child - > curr.child = new_id() - > local new = zettels[curr.child] - > new.data = '' - > new.next = old - > if old then - > assert(zettels[old].prev == nil, "first child shouldn't have a previous sibling") - > zettels[old].prev = curr.child - > end - > new.parent = current_zettel_id - > current_zettel_id = curr.child - > render(window) -- recompute render_state - > editz(window) - > -- cross-links - > elseif key == string.byte('s') then - > -- save zettel to a stash - > stash = current_zettel_id - > elseif key == string.byte('t') then - > -- cross-link a zettel bidirectionally with what's on the stash - > local insert_crosslink = - > function(a, rel, b_id) - > if a.crosslinks == nil then - > a.crosslinks = {} - > end - > a.crosslinks[rel] = b_id - > end - > insert_crosslink(curr, 'a', stash) - > insert_crosslink(zettels[stash], 'a', current_zettel_id) - > stash = nil - > -- view settings - > elseif key == string.byte('x') then - > if view_settings.width > 5 then - > view_settings.width = view_settings.width - 5 - > end - > elseif key == string.byte('X') then - > if view_settings.width < w-5 then - > view_settings.width = view_settings.width + 5 - > end - > elseif key == string.byte('y') then - > if view_settings.height > 0 then - > view_settings.height = view_settings.height - 1 - > end - > elseif key == string.byte('Y') then - > if view_settings.height < h-2 then - > view_settings.height = view_settings.height + 1 - > end - > elseif key == string.byte('z') then - > -- scroll to show the current zettel at top of screen - > -- often has the effect of zooming in on its hierarchy - > view_settings.first_zettel = current_zettel_id - > end - >end -- __teliva_timestamp: - >Sat Feb 12 17:47:08 2022 - update: - >function update(window) - > local key = window:getch() - > local h, w = window:getmaxyx() - > local curr = zettels[current_zettel_id] - > assert(curr, string.format('cursor fell off the edge of the world: %s', type(current_zettel_id))) - > -- read from or write to render_state.history - > if key == string.byte('<') then - > -- previous zettel moved to - > -- does NOT undo mutations - > if #render_state.history > 0 then - > view_settings.first_zettel = render_state.history[-1].first_zettel - > current_zettel_id = render_state.history[-1].current_zettel_id - > render_state.history:remove() - > end - > return - > end - > if key ~= string.byte('e') then - > render_state.history:insert({first_zettel=view_settings.first_zettel, current_zettel_id=current_zettel_id}) - > end - > -- move along the graph - > if key == string.byte('j') then - > -- child or next sibling - > if curr.child then - > current_zettel_id = curr.child - > elseif curr.next then - > current_zettel_id = curr.next - > elseif curr.parent and zettels[curr.parent].next then - > current_zettel_id = zettels[curr.parent].next - > end - > -- scroll if necessary - > if not render_state.displayed[current_zettel_id] then - > view_settings.first_zettel = current_zettel_id - > end - > elseif key == string.byte('k') then - > -- parent or previous sibling - > if curr.parent then - > current_zettel_id = curr.parent - > elseif curr.prev then - > current_zettel_id = curr.prev - > end - > -- scroll if necessary - > if not render_state.displayed[current_zettel_id] then - > view_settings.first_zettel = current_zettel_id - > end - > elseif key == string.byte('h') then - > -- previous sibling or parent - > if curr.prev then - > current_zettel_id = curr.prev - > elseif curr.parent then - > current_zettel_id = curr.parent - > end - > -- scroll if necessary - > if not render_state.displayed[current_zettel_id] then - > view_settings.first_zettel = current_zettel_id - > end - > elseif key == string.byte('l') then - > -- next sibling or next sibling of parent - > if curr.next then - > current_zettel_id = curr.next - > elseif curr.parent and zettels[curr.parent].next then - > current_zettel_id = zettels[curr.parent].next - > end - > -- scroll if necessary - > if not render_state.displayed[current_zettel_id] then - > view_settings.first_zettel = current_zettel_id - > end - > -- move along the screen - > elseif key == curses.KEY_UP then - > if render_state.curr_h > 1 then - > current_zettel_id = render_state.wh2id[render_state.curr_w][render_state.curr_h - 1] - > end - > elseif key == curses.KEY_DOWN then - > if render_state.wh2id[render_state.curr_w][render_state.curr_h + 1] then - > current_zettel_id = render_state.wh2id[render_state.curr_w][render_state.curr_h + 1] - > end - > elseif key == curses.KEY_LEFT then - > if render_state.curr_w > 1 then - > current_zettel_id = render_state.wh2id[render_state.curr_w - 1][render_state.curr_h] - > end - > elseif key == curses.KEY_RIGHT then - > if render_state.wh2id[render_state.curr_w + 1] and render_state.wh2id[render_state.curr_w + 1][render_state.curr_h] then - > current_zettel_id = render_state.wh2id[render_state.curr_w + 1][render_state.curr_h] - > end - > -- mutations - > elseif key == string.byte('e') then - > editz(window) - > elseif key == string.byte('a') then - > -- insert sibling after - > local old = curr.next - > curr.next = new_id() - > local new = zettels[curr.next] - > new.data = '' - > new.next = old - > new.prev = current_zettel_id - > if old then - > zettels[old].prev = curr.next - > assert(curr.parent == zettels[old].parent, 'siblings should have same parent') - > end - > new.parent = curr.parent - > current_zettel_id = curr.next - > render(window) -- recompute render_state - > editz(window) - > elseif key == string.byte('b') then - > -- insert sibling before - > local old = curr.prev - > curr.prev = new_id() - > local new = zettels[curr.prev] - > new.data = '' - > new.prev = old - > new.next = current_zettel_id - > if old then - > zettels[old].next = curr.prev - > assert(curr.parent == zettels[old].parent, 'siblings should have same parent') - > end - > new.parent = curr.parent - > current_zettel_id = curr.prev - > render(window) -- recompute render_state - > editz(window) - > elseif key == string.byte('c') then - > -- insert child - > local old = curr.child - > curr.child = new_id() - > local new = zettels[curr.child] - > new.data = '' - > new.next = old - > if old then - > assert(zettels[old].prev == nil, "first child shouldn't have a previous sibling") - > zettels[old].prev = curr.child - > end - > new.parent = current_zettel_id - > current_zettel_id = curr.child - > render(window) -- recompute render_state - > editz(window) - > -- cross-links - > elseif key == string.byte('s') then - > -- save zettel to a stash - > stash = current_zettel_id - > elseif key == string.byte('t') then - > -- cross-link a zettel bidirectionally with what's on the stash - > local insert_crosslink = - > function(a, rel, b_id) - > if a.crosslinks == nil then - > a.crosslinks = {} - > end - > a.crosslinks[rel] = b_id - > end - > insert_crosslink(curr, 'a', stash) - > insert_crosslink(zettels[stash], 'a', current_zettel_id) - > stash = nil - > -- view settings - > elseif key == string.byte('x') then - > if view_settings.width > 5 then - > view_settings.width = view_settings.width - 5 - > end - > elseif key == string.byte('X') then - > if view_settings.width < w-5 then - > view_settings.width = view_settings.width + 5 - > end - > elseif key == string.byte('y') then - > if view_settings.height > 0 then - > view_settings.height = view_settings.height - 1 - > end - > elseif key == string.byte('Y') then - > if view_settings.height < h-2 then - > view_settings.height = view_settings.height + 1 - > end - > elseif key == string.byte('z') then - > -- scroll to show the current zettel at top of screen - > -- often has the effect of zooming in on its hierarchy - > view_settings.first_zettel = current_zettel_id - > end - >end -- __teliva_timestamp: - >Sat Feb 12 17:48:38 2022 - update: - >function update(window) - > local key = window:getch() - > local h, w = window:getmaxyx() - > local curr = zettels[current_zettel_id] - > assert(curr, string.format('cursor fell off the edge of the world: %s', type(current_zettel_id))) - > -- read from or write to render_state.history - > if key == string.byte('<') then - > -- previous zettel moved to - > -- does NOT undo mutations - > if #render_state.history > 0 then - > view_settings.first_zettel = render_state.history[-1].first_zettel - > current_zettel_id = render_state.history[-1].current_zettel_id - > render_state.history:remove() - > end - > return - > end - > if key ~= string.byte('e') then - > window:mvaddstr(30, 60, renderstate.history) - > window:getch() - > render_state.history:insert({first_zettel=view_settings.first_zettel, current_zettel_id=current_zettel_id}) - > end - > -- move along the graph - > if key == string.byte('j') then - > -- child or next sibling - > if curr.child then - > current_zettel_id = curr.child - > elseif curr.next then - > current_zettel_id = curr.next - > elseif curr.parent and zettels[curr.parent].next then - > current_zettel_id = zettels[curr.parent].next - > end - > -- scroll if necessary - > if not render_state.displayed[current_zettel_id] then - > view_settings.first_zettel = current_zettel_id - > end - > elseif key == string.byte('k') then - > -- parent or previous sibling - > if curr.parent then - > current_zettel_id = curr.parent - > elseif curr.prev then - > current_zettel_id = curr.prev - > end - > -- scroll if necessary - > if not render_state.displayed[current_zettel_id] then - > view_settings.first_zettel = current_zettel_id - > end - > elseif key == string.byte('h') then - > -- previous sibling or parent - > if curr.prev then - > current_zettel_id = curr.prev - > elseif curr.parent then - > current_zettel_id = curr.parent - > end - > -- scroll if necessary - > if not render_state.displayed[current_zettel_id] then - > view_settings.first_zettel = current_zettel_id - > end - > elseif key == string.byte('l') then - > -- next sibling or next sibling of parent - > if curr.next then - > current_zettel_id = curr.next - > elseif curr.parent and zettels[curr.parent].next then - > current_zettel_id = zettels[curr.parent].next - > end - > -- scroll if necessary - > if not render_state.displayed[current_zettel_id] then - > view_settings.first_zettel = current_zettel_id - > end - > -- move along the screen - > elseif key == curses.KEY_UP then - > if render_state.curr_h > 1 then - > current_zettel_id = render_state.wh2id[render_state.curr_w][render_state.curr_h - 1] - > end - > elseif key == curses.KEY_DOWN then - > if render_state.wh2id[render_state.curr_w][render_state.curr_h + 1] then - > current_zettel_id = render_state.wh2id[render_state.curr_w][render_state.curr_h + 1] - > end - > elseif key == curses.KEY_LEFT then - > if render_state.curr_w > 1 then - > current_zettel_id = render_state.wh2id[render_state.curr_w - 1][render_state.curr_h] - > end - > elseif key == curses.KEY_RIGHT then - > if render_state.wh2id[render_state.curr_w + 1] and render_state.wh2id[render_state.curr_w + 1][render_state.curr_h] then - > current_zettel_id = render_state.wh2id[render_state.curr_w + 1][render_state.curr_h] - > end - > -- mutations - > elseif key == string.byte('e') then - > editz(window) - > elseif key == string.byte('a') then - > -- insert sibling after - > local old = curr.next - > curr.next = new_id() - > local new = zettels[curr.next] - > new.data = '' - > new.next = old - > new.prev = current_zettel_id - > if old then - > zettels[old].prev = curr.next - > assert(curr.parent == zettels[old].parent, 'siblings should have same parent') - > end - > new.parent = curr.parent - > current_zettel_id = curr.next - > render(window) -- recompute render_state - > editz(window) - > elseif key == string.byte('b') then - > -- insert sibling before - > local old = curr.prev - > curr.prev = new_id() - > local new = zettels[curr.prev] - > new.data = '' - > new.prev = old - > new.next = current_zettel_id - > if old then - > zettels[old].next = curr.prev - > assert(curr.parent == zettels[old].parent, 'siblings should have same parent') - > end - > new.parent = curr.parent - > current_zettel_id = curr.prev - > render(window) -- recompute render_state - > editz(window) - > elseif key == string.byte('c') then - > -- insert child - > local old = curr.child - > curr.child = new_id() - > local new = zettels[curr.child] - > new.data = '' - > new.next = old - > if old then - > assert(zettels[old].prev == nil, "first child shouldn't have a previous sibling") - > zettels[old].prev = curr.child - > end - > new.parent = current_zettel_id - > current_zettel_id = curr.child - > render(window) -- recompute render_state - > editz(window) - > -- cross-links - > elseif key == string.byte('s') then - > -- save zettel to a stash - > stash = current_zettel_id - > elseif key == string.byte('t') then - > -- cross-link a zettel bidirectionally with what's on the stash - > local insert_crosslink = - > function(a, rel, b_id) - > if a.crosslinks == nil then - > a.crosslinks = {} - > end - > a.crosslinks[rel] = b_id - > end - > insert_crosslink(curr, 'a', stash) - > insert_crosslink(zettels[stash], 'a', current_zettel_id) - > stash = nil - > -- view settings - > elseif key == string.byte('x') then - > if view_settings.width > 5 then - > view_settings.width = view_settings.width - 5 - > end - > elseif key == string.byte('X') then - > if view_settings.width < w-5 then - > view_settings.width = view_settings.width + 5 - > end - > elseif key == string.byte('y') then - > if view_settings.height > 0 then - > view_settings.height = view_settings.height - 1 - > end - > elseif key == string.byte('Y') then - > if view_settings.height < h-2 then - > view_settings.height = view_settings.height + 1 - > end - > elseif key == string.byte('z') then - > -- scroll to show the current zettel at top of screen - > -- often has the effect of zooming in on its hierarchy - > view_settings.first_zettel = current_zettel_id - > end - >end -- __teliva_timestamp: - >Sat Feb 12 17:48:50 2022 - update: - >function update(window) - > local key = window:getch() - > local h, w = window:getmaxyx() - > local curr = zettels[current_zettel_id] - > assert(curr, string.format('cursor fell off the edge of the world: %s', type(current_zettel_id))) - > -- read from or write to render_state.history - > if key == string.byte('<') then - > -- previous zettel moved to - > -- does NOT undo mutations - > if #render_state.history > 0 then - > view_settings.first_zettel = render_state.history[-1].first_zettel - > current_zettel_id = render_state.history[-1].current_zettel_id - > render_state.history:remove() - > end - > return - > end - > if key ~= string.byte('e') then - > window:mvaddstr(30, 60, render_state.history) - > window:getch() - > render_state.history:insert({first_zettel=view_settings.first_zettel, current_zettel_id=current_zettel_id}) - > end - > -- move along the graph - > if key == string.byte('j') then - > -- child or next sibling - > if curr.child then - > current_zettel_id = curr.child - > elseif curr.next then - > current_zettel_id = curr.next - > elseif curr.parent and zettels[curr.parent].next then - > current_zettel_id = zettels[curr.parent].next - > end - > -- scroll if necessary - > if not render_state.displayed[current_zettel_id] then - > view_settings.first_zettel = current_zettel_id - > end - > elseif key == string.byte('k') then - > -- parent or previous sibling - > if curr.parent then - > current_zettel_id = curr.parent - > elseif curr.prev then - > current_zettel_id = curr.prev - > end - > -- scroll if necessary - > if not render_state.displayed[current_zettel_id] then - > view_settings.first_zettel = current_zettel_id - > end - > elseif key == string.byte('h') then - > -- previous sibling or parent - > if curr.prev then - > current_zettel_id = curr.prev - > elseif curr.parent then - > current_zettel_id = curr.parent - > end - > -- scroll if necessary - > if not render_state.displayed[current_zettel_id] then - > view_settings.first_zettel = current_zettel_id - > end - > elseif key == string.byte('l') then - > -- next sibling or next sibling of parent - > if curr.next then - > current_zettel_id = curr.next - > elseif curr.parent and zettels[curr.parent].next then - > current_zettel_id = zettels[curr.parent].next - > end - > -- scroll if necessary - > if not render_state.displayed[current_zettel_id] then - > view_settings.first_zettel = current_zettel_id - > end - > -- move along the screen - > elseif key == curses.KEY_UP then - > if render_state.curr_h > 1 then - > current_zettel_id = render_state.wh2id[render_state.curr_w][render_state.curr_h - 1] - > end - > elseif key == curses.KEY_DOWN then - > if render_state.wh2id[render_state.curr_w][render_state.curr_h + 1] then - > current_zettel_id = render_state.wh2id[render_state.curr_w][render_state.curr_h + 1] - > end - > elseif key == curses.KEY_LEFT then - > if render_state.curr_w > 1 then - > current_zettel_id = render_state.wh2id[render_state.curr_w - 1][render_state.curr_h] - > end - > elseif key == curses.KEY_RIGHT then - > if render_state.wh2id[render_state.curr_w + 1] and render_state.wh2id[render_state.curr_w + 1][render_state.curr_h] then - > current_zettel_id = render_state.wh2id[render_state.curr_w + 1][render_state.curr_h] - > end - > -- mutations - > elseif key == string.byte('e') then - > editz(window) - > elseif key == string.byte('a') then - > -- insert sibling after - > local old = curr.next - > curr.next = new_id() - > local new = zettels[curr.next] - > new.data = '' - > new.next = old - > new.prev = current_zettel_id - > if old then - > zettels[old].prev = curr.next - > assert(curr.parent == zettels[old].parent, 'siblings should have same parent') - > end - > new.parent = curr.parent - > current_zettel_id = curr.next - > render(window) -- recompute render_state - > editz(window) - > elseif key == string.byte('b') then - > -- insert sibling before - > local old = curr.prev - > curr.prev = new_id() - > local new = zettels[curr.prev] - > new.data = '' - > new.prev = old - > new.next = current_zettel_id - > if old then - > zettels[old].next = curr.prev - > assert(curr.parent == zettels[old].parent, 'siblings should have same parent') - > end - > new.parent = curr.parent - > current_zettel_id = curr.prev - > render(window) -- recompute render_state - > editz(window) - > elseif key == string.byte('c') then - > -- insert child - > local old = curr.child - > curr.child = new_id() - > local new = zettels[curr.child] - > new.data = '' - > new.next = old - > if old then - > assert(zettels[old].prev == nil, "first child shouldn't have a previous sibling") - > zettels[old].prev = curr.child - > end - > new.parent = current_zettel_id - > current_zettel_id = curr.child - > render(window) -- recompute render_state - > editz(window) - > -- cross-links - > elseif key == string.byte('s') then - > -- save zettel to a stash - > stash = current_zettel_id - > elseif key == string.byte('t') then - > -- cross-link a zettel bidirectionally with what's on the stash - > local insert_crosslink = - > function(a, rel, b_id) - > if a.crosslinks == nil then - > a.crosslinks = {} - > end - > a.crosslinks[rel] = b_id - > end - > insert_crosslink(curr, 'a', stash) - > insert_crosslink(zettels[stash], 'a', current_zettel_id) - > stash = nil - > -- view settings - > elseif key == string.byte('x') then - > if view_settings.width > 5 then - > view_settings.width = view_settings.width - 5 - > end - > elseif key == string.byte('X') then - > if view_settings.width < w-5 then - > view_settings.width = view_settings.width + 5 - > end - > elseif key == string.byte('y') then - > if view_settings.height > 0 then - > view_settings.height = view_settings.height - 1 - > end - > elseif key == string.byte('Y') then - > if view_settings.height < h-2 then - > view_settings.height = view_settings.height + 1 - > end - > elseif key == string.byte('z') then - > -- scroll to show the current zettel at top of screen - > -- often has the effect of zooming in on its hierarchy - > view_settings.first_zettel = current_zettel_id - > end - >end -- __teliva_timestamp: - >Sat Feb 12 17:49:04 2022 - update: - >function update(window) - > local key = window:getch() - > local h, w = window:getmaxyx() - > local curr = zettels[current_zettel_id] - > assert(curr, string.format('cursor fell off the edge of the world: %s', type(current_zettel_id))) - > -- read from or write to render_state.history - > if key == string.byte('<') then - > -- previous zettel moved to - > -- does NOT undo mutations - > if #render_state.history > 0 then - > view_settings.first_zettel = render_state.history[-1].first_zettel - > current_zettel_id = render_state.history[-1].current_zettel_id - > render_state.history:remove() - > end - > return - > end - > if key ~= string.byte('e') then - > window:mvaddstr(30, 60, '') - > print(render_state.history) - > window:getch() - > render_state.history:insert({first_zettel=view_settings.first_zettel, current_zettel_id=current_zettel_id}) - > end - > -- move along the graph - > if key == string.byte('j') then - > -- child or next sibling - > if curr.child then - > current_zettel_id = curr.child - > elseif curr.next then - > current_zettel_id = curr.next - > elseif curr.parent and zettels[curr.parent].next then - > current_zettel_id = zettels[curr.parent].next - > end - > -- scroll if necessary - > if not render_state.displayed[current_zettel_id] then - > view_settings.first_zettel = current_zettel_id - > end - > elseif key == string.byte('k') then - > -- parent or previous sibling - > if curr.parent then - > current_zettel_id = curr.parent - > elseif curr.prev then - > current_zettel_id = curr.prev - > end - > -- scroll if necessary - > if not render_state.displayed[current_zettel_id] then - > view_settings.first_zettel = current_zettel_id - > end - > elseif key == string.byte('h') then - > -- previous sibling or parent - > if curr.prev then - > current_zettel_id = curr.prev - > elseif curr.parent then - > current_zettel_id = curr.parent - > end - > -- scroll if necessary - > if not render_state.displayed[current_zettel_id] then - > view_settings.first_zettel = current_zettel_id - > end - > elseif key == string.byte('l') then - > -- next sibling or next sibling of parent - > if curr.next then - > current_zettel_id = curr.next - > elseif curr.parent and zettels[curr.parent].next then - > current_zettel_id = zettels[curr.parent].next - > end - > -- scroll if necessary - > if not render_state.displayed[current_zettel_id] then - > view_settings.first_zettel = current_zettel_id - > end - > -- move along the screen - > elseif key == curses.KEY_UP then - > if render_state.curr_h > 1 then - > current_zettel_id = render_state.wh2id[render_state.curr_w][render_state.curr_h - 1] - > end - > elseif key == curses.KEY_DOWN then - > if render_state.wh2id[render_state.curr_w][render_state.curr_h + 1] then - > current_zettel_id = render_state.wh2id[render_state.curr_w][render_state.curr_h + 1] - > end - > elseif key == curses.KEY_LEFT then - > if render_state.curr_w > 1 then - > current_zettel_id = render_state.wh2id[render_state.curr_w - 1][render_state.curr_h] - > end - > elseif key == curses.KEY_RIGHT then - > if render_state.wh2id[render_state.curr_w + 1] and render_state.wh2id[render_state.curr_w + 1][render_state.curr_h] then - > current_zettel_id = render_state.wh2id[render_state.curr_w + 1][render_state.curr_h] - > end - > -- mutations - > elseif key == string.byte('e') then - > editz(window) - > elseif key == string.byte('a') then - > -- insert sibling after - > local old = curr.next - > curr.next = new_id() - > local new = zettels[curr.next] - > new.data = '' - > new.next = old - > new.prev = current_zettel_id - > if old then - > zettels[old].prev = curr.next - > assert(curr.parent == zettels[old].parent, 'siblings should have same parent') - > end - > new.parent = curr.parent - > current_zettel_id = curr.next - > render(window) -- recompute render_state - > editz(window) - > elseif key == string.byte('b') then - > -- insert sibling before - > local old = curr.prev - > curr.prev = new_id() - > local new = zettels[curr.prev] - > new.data = '' - > new.prev = old - > new.next = current_zettel_id - > if old then - > zettels[old].next = curr.prev - > assert(curr.parent == zettels[old].parent, 'siblings should have same parent') - > end - > new.parent = curr.parent - > current_zettel_id = curr.prev - > render(window) -- recompute render_state - > editz(window) - > elseif key == string.byte('c') then - > -- insert child - > local old = curr.child - > curr.child = new_id() - > local new = zettels[curr.child] - > new.data = '' - > new.next = old - > if old then - > assert(zettels[old].prev == nil, "first child shouldn't have a previous sibling") - > zettels[old].prev = curr.child - > end - > new.parent = current_zettel_id - > current_zettel_id = curr.child - > render(window) -- recompute render_state - > editz(window) - > -- cross-links - > elseif key == string.byte('s') then - > -- save zettel to a stash - > stash = current_zettel_id - > elseif key == string.byte('t') then - > -- cross-link a zettel bidirectionally with what's on the stash - > local insert_crosslink = - > function(a, rel, b_id) - > if a.crosslinks == nil then - > a.crosslinks = {} - > end - > a.crosslinks[rel] = b_id - > end - > insert_crosslink(curr, 'a', stash) - > insert_crosslink(zettels[stash], 'a', current_zettel_id) - > stash = nil - > -- view settings - > elseif key == string.byte('x') then - > if view_settings.width > 5 then - > view_settings.width = view_settings.width - 5 - > end - > elseif key == string.byte('X') then - > if view_settings.width < w-5 then - > view_settings.width = view_settings.width + 5 - > end - > elseif key == string.byte('y') then - > if view_settings.height > 0 then - > view_settings.height = view_settings.height - 1 - > end - > elseif key == string.byte('Y') then - > if view_settings.height < h-2 then - > view_settings.height = view_settings.height + 1 - > end - > elseif key == string.byte('z') then - > -- scroll to show the current zettel at top of screen - > -- often has the effect of zooming in on its hierarchy - > view_settings.first_zettel = current_zettel_id - > end - >end -- __teliva_timestamp: - >Sat Feb 12 17:49:34 2022 - update: - >function update(window) - > local key = window:getch() - > local h, w = window:getmaxyx() - > local curr = zettels[current_zettel_id] - > assert(curr, string.format('cursor fell off the edge of the world: %s', type(current_zettel_id))) - > -- read from or write to render_state.history - > if key == string.byte('<') then - > -- previous zettel moved to - > -- does NOT undo mutations - > if #render_state.history > 0 then - > view_settings.first_zettel = render_state.history[-1].first_zettel - > current_zettel_id = render_state.history[-1].current_zettel_id - > render_state.history:remove() - > end - > return - > end - > if key ~= string.byte('e') then - > window:mvaddstr(30, 60, '') - > print(render_state.history) - > window:getch() - > local history = render_state.history - > history:insert({first_zettel=view_settings.first_zettel, current_zettel_id=current_zettel_id}) - > end - > -- move along the graph - > if key == string.byte('j') then - > -- child or next sibling - > if curr.child then - > current_zettel_id = curr.child - > elseif curr.next then - > current_zettel_id = curr.next - > elseif curr.parent and zettels[curr.parent].next then - > current_zettel_id = zettels[curr.parent].next - > end - > -- scroll if necessary - > if not render_state.displayed[current_zettel_id] then - > view_settings.first_zettel = current_zettel_id - > end - > elseif key == string.byte('k') then - > -- parent or previous sibling - > if curr.parent then - > current_zettel_id = curr.parent - > elseif curr.prev then - > current_zettel_id = curr.prev - > end - > -- scroll if necessary - > if not render_state.displayed[current_zettel_id] then - > view_settings.first_zettel = current_zettel_id - > end - > elseif key == string.byte('h') then - > -- previous sibling or parent - > if curr.prev then - > current_zettel_id = curr.prev - > elseif curr.parent then - > current_zettel_id = curr.parent - > end - > -- scroll if necessary - > if not render_state.displayed[current_zettel_id] then - > view_settings.first_zettel = current_zettel_id - > end - > elseif key == string.byte('l') then - > -- next sibling or next sibling of parent - > if curr.next then - > current_zettel_id = curr.next - > elseif curr.parent and zettels[curr.parent].next then - > current_zettel_id = zettels[curr.parent].next - > end - > -- scroll if necessary - > if not render_state.displayed[current_zettel_id] then - > view_settings.first_zettel = current_zettel_id - > end - > -- move along the screen - > elseif key == curses.KEY_UP then - > if render_state.curr_h > 1 then - > current_zettel_id = render_state.wh2id[render_state.curr_w][render_state.curr_h - 1] - > end - > elseif key == curses.KEY_DOWN then - > if render_state.wh2id[render_state.curr_w][render_state.curr_h + 1] then - > current_zettel_id = render_state.wh2id[render_state.curr_w][render_state.curr_h + 1] - > end - > elseif key == curses.KEY_LEFT then - > if render_state.curr_w > 1 then - > current_zettel_id = render_state.wh2id[render_state.curr_w - 1][render_state.curr_h] - > end - > elseif key == curses.KEY_RIGHT then - > if render_state.wh2id[render_state.curr_w + 1] and render_state.wh2id[render_state.curr_w + 1][render_state.curr_h] then - > current_zettel_id = render_state.wh2id[render_state.curr_w + 1][render_state.curr_h] - > end - > -- mutations - > elseif key == string.byte('e') then - > editz(window) - > elseif key == string.byte('a') then - > -- insert sibling after - > local old = curr.next - > curr.next = new_id() - > local new = zettels[curr.next] - > new.data = '' - > new.next = old - > new.prev = current_zettel_id - > if old then - > zettels[old].prev = curr.next - > assert(curr.parent == zettels[old].parent, 'siblings should have same parent') - > end - > new.parent = curr.parent - > current_zettel_id = curr.next - > render(window) -- recompute render_state - > editz(window) - > elseif key == string.byte('b') then - > -- insert sibling before - > local old = curr.prev - > curr.prev = new_id() - > local new = zettels[curr.prev] - > new.data = '' - > new.prev = old - > new.next = current_zettel_id - > if old then - > zettels[old].next = curr.prev - > assert(curr.parent == zettels[old].parent, 'siblings should have same parent') - > end - > new.parent = curr.parent - > current_zettel_id = curr.prev - > render(window) -- recompute render_state - > editz(window) - > elseif key == string.byte('c') then - > -- insert child - > local old = curr.child - > curr.child = new_id() - > local new = zettels[curr.child] - > new.data = '' - > new.next = old - > if old then - > assert(zettels[old].prev == nil, "first child shouldn't have a previous sibling") - > zettels[old].prev = curr.child - > end - > new.parent = current_zettel_id - > current_zettel_id = curr.child - > render(window) -- recompute render_state - > editz(window) - > -- cross-links - > elseif key == string.byte('s') then - > -- save zettel to a stash - > stash = current_zettel_id - > elseif key == string.byte('t') then - > -- cross-link a zettel bidirectionally with what's on the stash - > local insert_crosslink = - > function(a, rel, b_id) - > if a.crosslinks == nil then - > a.crosslinks = {} - > end - > a.crosslinks[rel] = b_id - > end - > insert_crosslink(curr, 'a', stash) - > insert_crosslink(zettels[stash], 'a', current_zettel_id) - > stash = nil - > -- view settings - > elseif key == string.byte('x') then - > if view_settings.width > 5 then - > view_settings.width = view_settings.width - 5 - > end - > elseif key == string.byte('X') then - > if view_settings.width < w-5 then - > view_settings.width = view_settings.width + 5 - > end - > elseif key == string.byte('y') then - > if view_settings.height > 0 then - > view_settings.height = view_settings.height - 1 - > end - > elseif key == string.byte('Y') then - > if view_settings.height < h-2 then - > view_settings.height = view_settings.height + 1 - > end - > elseif key == string.byte('z') then - > -- scroll to show the current zettel at top of screen - > -- often has the effect of zooming in on its hierarchy - > view_settings.first_zettel = current_zettel_id - > end - >end -- __teliva_timestamp: - >Sat Feb 12 17:50:49 2022 - update: - >function update(window) - > local key = window:getch() - > local h, w = window:getmaxyx() - > local curr = zettels[current_zettel_id] - > assert(curr, string.format('cursor fell off the edge of the world: %s', type(current_zettel_id))) - > -- read from or write to render_state.history - > if key == string.byte('<') then - > -- previous zettel moved to - > -- does NOT undo mutations - > if #render_state.history > 0 then - > view_settings.first_zettel = render_state.history[-1].first_zettel - > current_zettel_id = render_state.history[-1].current_zettel_id - > table.remove(render_state.history) - > end - > return - > end - > if key ~= string.byte('e') then - > table.insert(render_state.history, {first_zettel=view_settings.first_zettel, current_zettel_id=current_zettel_id}) - > end - > -- move along the graph - > if key == string.byte('j') then - > -- child or next sibling - > if curr.child then - > current_zettel_id = curr.child - > elseif curr.next then - > current_zettel_id = curr.next - > elseif curr.parent and zettels[curr.parent].next then - > current_zettel_id = zettels[curr.parent].next - > end - > -- scroll if necessary - > if not render_state.displayed[current_zettel_id] then - > view_settings.first_zettel = current_zettel_id - > end - > elseif key == string.byte('k') then - > -- parent or previous sibling - > if curr.parent then - > current_zettel_id = curr.parent - > elseif curr.prev then - > current_zettel_id = curr.prev - > end - > -- scroll if necessary - > if not render_state.displayed[current_zettel_id] then - > view_settings.first_zettel = current_zettel_id - > end - > elseif key == string.byte('h') then - > -- previous sibling or parent - > if curr.prev then - > current_zettel_id = curr.prev - > elseif curr.parent then - > current_zettel_id = curr.parent - > end - > -- scroll if necessary - > if not render_state.displayed[current_zettel_id] then - > view_settings.first_zettel = current_zettel_id - > end - > elseif key == string.byte('l') then - > -- next sibling or next sibling of parent - > if curr.next then - > current_zettel_id = curr.next - > elseif curr.parent and zettels[curr.parent].next then - > current_zettel_id = zettels[curr.parent].next - > end - > -- scroll if necessary - > if not render_state.displayed[current_zettel_id] then - > view_settings.first_zettel = current_zettel_id - > end - > -- move along the screen - > elseif key == curses.KEY_UP then - > if render_state.curr_h > 1 then - > current_zettel_id = render_state.wh2id[render_state.curr_w][render_state.curr_h - 1] - > end - > elseif key == curses.KEY_DOWN then - > if render_state.wh2id[render_state.curr_w][render_state.curr_h + 1] then - > current_zettel_id = render_state.wh2id[render_state.curr_w][render_state.curr_h + 1] - > end - > elseif key == curses.KEY_LEFT then - > if render_state.curr_w > 1 then - > current_zettel_id = render_state.wh2id[render_state.curr_w - 1][render_state.curr_h] - > end - > elseif key == curses.KEY_RIGHT then - > if render_state.wh2id[render_state.curr_w + 1] and render_state.wh2id[render_state.curr_w + 1][render_state.curr_h] then - > current_zettel_id = render_state.wh2id[render_state.curr_w + 1][render_state.curr_h] - > end - > -- mutations - > elseif key == string.byte('e') then - > editz(window) - > elseif key == string.byte('a') then - > -- insert sibling after - > local old = curr.next - > curr.next = new_id() - > local new = zettels[curr.next] - > new.data = '' - > new.next = old - > new.prev = current_zettel_id - > if old then - > zettels[old].prev = curr.next - > assert(curr.parent == zettels[old].parent, 'siblings should have same parent') - > end - > new.parent = curr.parent - > current_zettel_id = curr.next - > render(window) -- recompute render_state - > editz(window) - > elseif key == string.byte('b') then - > -- insert sibling before - > local old = curr.prev - > curr.prev = new_id() - > local new = zettels[curr.prev] - > new.data = '' - > new.prev = old - > new.next = current_zettel_id - > if old then - > zettels[old].next = curr.prev - > assert(curr.parent == zettels[old].parent, 'siblings should have same parent') - > end - > new.parent = curr.parent - > current_zettel_id = curr.prev - > render(window) -- recompute render_state - > editz(window) - > elseif key == string.byte('c') then - > -- insert child - > local old = curr.child - > curr.child = new_id() - > local new = zettels[curr.child] - > new.data = '' - > new.next = old - > if old then - > assert(zettels[old].prev == nil, "first child shouldn't have a previous sibling") - > zettels[old].prev = curr.child - > end - > new.parent = current_zettel_id - > current_zettel_id = curr.child - > render(window) -- recompute render_state - > editz(window) - > -- cross-links - > elseif key == string.byte('s') then - > -- save zettel to a stash - > stash = current_zettel_id - > elseif key == string.byte('t') then - > -- cross-link a zettel bidirectionally with what's on the stash - > local insert_crosslink = - > function(a, rel, b_id) - > if a.crosslinks == nil then - > a.crosslinks = {} - > end - > a.crosslinks[rel] = b_id - > end - > insert_crosslink(curr, 'a', stash) - > insert_crosslink(zettels[stash], 'a', current_zettel_id) - > stash = nil - > -- view settings - > elseif key == string.byte('x') then - > if view_settings.width > 5 then - > view_settings.width = view_settings.width - 5 - > end - > elseif key == string.byte('X') then - > if view_settings.width < w-5 then - > view_settings.width = view_settings.width + 5 - > end - > elseif key == string.byte('y') then - > if view_settings.height > 0 then - > view_settings.height = view_settings.height - 1 - > end - > elseif key == string.byte('Y') then - > if view_settings.height < h-2 then - > view_settings.height = view_settings.height + 1 - > end - > elseif key == string.byte('z') then - > -- scroll to show the current zettel at top of screen - > -- often has the effect of zooming in on its hierarchy - > view_settings.first_zettel = current_zettel_id - > end - >end -- __teliva_timestamp: - >Sat Feb 12 17:52:42 2022 - update: - >function update(window) - > local key = window:getch() - > local h, w = window:getmaxyx() - > local curr = zettels[current_zettel_id] - > assert(curr, string.format('cursor fell off the edge of the world: %s', type(current_zettel_id))) - > -- read from or write to render_state.history - > if key == string.byte('<') then - > -- previous zettel moved to - > -- does NOT undo mutations - > if #render_state.history > 0 then - > local previous_state = render_state.history[-1] - > window:mvaddstr(30, 60, '') - > print(previous_state) - > window:getch() - > view_settings.first_zettel = previous_state.first_zettel - > current_zettel_id = render_state.history[-1].current_zettel_id - > table.remove(render_state.history) - > end - > return - > end - > if key ~= string.byte('e') then - > table.insert(render_state.history, {first_zettel=view_settings.first_zettel, current_zettel_id=current_zettel_id}) - > end - > -- move along the graph - > if key == string.byte('j') then - > -- child or next sibling - > if curr.child then - > current_zettel_id = curr.child - > elseif curr.next then - > current_zettel_id = curr.next - > elseif curr.parent and zettels[curr.parent].next then - > current_zettel_id = zettels[curr.parent].next - > end - > -- scroll if necessary - > if not render_state.displayed[current_zettel_id] then - > view_settings.first_zettel = current_zettel_id - > end - > elseif key == string.byte('k') then - > -- parent or previous sibling - > if curr.parent then - > current_zettel_id = curr.parent - > elseif curr.prev then - > current_zettel_id = curr.prev - > end - > -- scroll if necessary - > if not render_state.displayed[current_zettel_id] then - > view_settings.first_zettel = current_zettel_id - > end - > elseif key == string.byte('h') then - > -- previous sibling or parent - > if curr.prev then - > current_zettel_id = curr.prev - > elseif curr.parent then - > current_zettel_id = curr.parent - > end - > -- scroll if necessary - > if not render_state.displayed[current_zettel_id] then - > view_settings.first_zettel = current_zettel_id - > end - > elseif key == string.byte('l') then - > -- next sibling or next sibling of parent - > if curr.next then - > current_zettel_id = curr.next - > elseif curr.parent and zettels[curr.parent].next then - > current_zettel_id = zettels[curr.parent].next - > end - > -- scroll if necessary - > if not render_state.displayed[current_zettel_id] then - > view_settings.first_zettel = current_zettel_id - > end - > -- move along the screen - > elseif key == curses.KEY_UP then - > if render_state.curr_h > 1 then - > current_zettel_id = render_state.wh2id[render_state.curr_w][render_state.curr_h - 1] - > end - > elseif key == curses.KEY_DOWN then - > if render_state.wh2id[render_state.curr_w][render_state.curr_h + 1] then - > current_zettel_id = render_state.wh2id[render_state.curr_w][render_state.curr_h + 1] - > end - > elseif key == curses.KEY_LEFT then - > if render_state.curr_w > 1 then - > current_zettel_id = render_state.wh2id[render_state.curr_w - 1][render_state.curr_h] - > end - > elseif key == curses.KEY_RIGHT then - > if render_state.wh2id[render_state.curr_w + 1] and render_state.wh2id[render_state.curr_w + 1][render_state.curr_h] then - > current_zettel_id = render_state.wh2id[render_state.curr_w + 1][render_state.curr_h] - > end - > -- mutations - > elseif key == string.byte('e') then - > editz(window) - > elseif key == string.byte('a') then - > -- insert sibling after - > local old = curr.next - > curr.next = new_id() - > local new = zettels[curr.next] - > new.data = '' - > new.next = old - > new.prev = current_zettel_id - > if old then - > zettels[old].prev = curr.next - > assert(curr.parent == zettels[old].parent, 'siblings should have same parent') - > end - > new.parent = curr.parent - > current_zettel_id = curr.next - > render(window) -- recompute render_state - > editz(window) - > elseif key == string.byte('b') then - > -- insert sibling before - > local old = curr.prev - > curr.prev = new_id() - > local new = zettels[curr.prev] - > new.data = '' - > new.prev = old - > new.next = current_zettel_id - > if old then - > zettels[old].next = curr.prev - > assert(curr.parent == zettels[old].parent, 'siblings should have same parent') - > end - > new.parent = curr.parent - > current_zettel_id = curr.prev - > render(window) -- recompute render_state - > editz(window) - > elseif key == string.byte('c') then - > -- insert child - > local old = curr.child - > curr.child = new_id() - > local new = zettels[curr.child] - > new.data = '' - > new.next = old - > if old then - > assert(zettels[old].prev == nil, "first child shouldn't have a previous sibling") - > zettels[old].prev = curr.child - > end - > new.parent = current_zettel_id - > current_zettel_id = curr.child - > render(window) -- recompute render_state - > editz(window) - > -- cross-links - > elseif key == string.byte('s') then - > -- save zettel to a stash - > stash = current_zettel_id - > elseif key == string.byte('t') then - > -- cross-link a zettel bidirectionally with what's on the stash - > local insert_crosslink = - > function(a, rel, b_id) - > if a.crosslinks == nil then - > a.crosslinks = {} - > end - > a.crosslinks[rel] = b_id - > end - > insert_crosslink(curr, 'a', stash) - > insert_crosslink(zettels[stash], 'a', current_zettel_id) - > stash = nil - > -- view settings - > elseif key == string.byte('x') then - > if view_settings.width > 5 then - > view_settings.width = view_settings.width - 5 - > end - > elseif key == string.byte('X') then - > if view_settings.width < w-5 then - > view_settings.width = view_settings.width + 5 - > end - > elseif key == string.byte('y') then - > if view_settings.height > 0 then - > view_settings.height = view_settings.height - 1 - > end - > elseif key == string.byte('Y') then - > if view_settings.height < h-2 then - > view_settings.height = view_settings.height + 1 - > end - > elseif key == string.byte('z') then - > -- scroll to show the current zettel at top of screen - > -- often has the effect of zooming in on its hierarchy - > view_settings.first_zettel = current_zettel_id - > end - >end -- __teliva_timestamp: - >Sat Feb 12 17:54:43 2022 - update: - >function update(window) - > local key = window:getch() - > local h, w = window:getmaxyx() - > local curr = zettels[current_zettel_id] - > assert(curr, string.format('cursor fell off the edge of the world: %s', type(current_zettel_id))) - > -- read from or write to render_state.history - > if key == string.byte('<') then - > -- previous zettel moved to - > -- does NOT undo mutations - > if #render_state.history > 0 then - > window:mvaddstr(30, 60, '') - > print(#render_state.history) - > local previous_state = render_state.history[-1] - > print(previous_state) - > window:getch() - > view_settings.first_zettel = previous_state.first_zettel - > current_zettel_id = render_state.history[-1].current_zettel_id - > table.remove(render_state.history) - > end - > return - > end - > if key ~= string.byte('e') then - > table.insert(render_state.history, {first_zettel=view_settings.first_zettel, current_zettel_id=current_zettel_id}) - > end - > -- move along the graph - > if key == string.byte('j') then - > -- child or next sibling - > if curr.child then - > current_zettel_id = curr.child - > elseif curr.next then - > current_zettel_id = curr.next - > elseif curr.parent and zettels[curr.parent].next then - > current_zettel_id = zettels[curr.parent].next - > end - > -- scroll if necessary - > if not render_state.displayed[current_zettel_id] then - > view_settings.first_zettel = current_zettel_id - > end - > elseif key == string.byte('k') then - > -- parent or previous sibling - > if curr.parent then - > current_zettel_id = curr.parent - > elseif curr.prev then - > current_zettel_id = curr.prev - > end - > -- scroll if necessary - > if not render_state.displayed[current_zettel_id] then - > view_settings.first_zettel = current_zettel_id - > end - > elseif key == string.byte('h') then - > -- previous sibling or parent - > if curr.prev then - > current_zettel_id = curr.prev - > elseif curr.parent then - > current_zettel_id = curr.parent - > end - > -- scroll if necessary - > if not render_state.displayed[current_zettel_id] then - > view_settings.first_zettel = current_zettel_id - > end - > elseif key == string.byte('l') then - > -- next sibling or next sibling of parent - > if curr.next then - > current_zettel_id = curr.next - > elseif curr.parent and zettels[curr.parent].next then - > current_zettel_id = zettels[curr.parent].next - > end - > -- scroll if necessary - > if not render_state.displayed[current_zettel_id] then - > view_settings.first_zettel = current_zettel_id - > end - > -- move along the screen - > elseif key == curses.KEY_UP then - > if render_state.curr_h > 1 then - > current_zettel_id = render_state.wh2id[render_state.curr_w][render_state.curr_h - 1] - > end - > elseif key == curses.KEY_DOWN then - > if render_state.wh2id[render_state.curr_w][render_state.curr_h + 1] then - > current_zettel_id = render_state.wh2id[render_state.curr_w][render_state.curr_h + 1] - > end - > elseif key == curses.KEY_LEFT then - > if render_state.curr_w > 1 then - > current_zettel_id = render_state.wh2id[render_state.curr_w - 1][render_state.curr_h] - > end - > elseif key == curses.KEY_RIGHT then - > if render_state.wh2id[render_state.curr_w + 1] and render_state.wh2id[render_state.curr_w + 1][render_state.curr_h] then - > current_zettel_id = render_state.wh2id[render_state.curr_w + 1][render_state.curr_h] - > end - > -- mutations - > elseif key == string.byte('e') then - > editz(window) - > elseif key == string.byte('a') then - > -- insert sibling after - > local old = curr.next - > curr.next = new_id() - > local new = zettels[curr.next] - > new.data = '' - > new.next = old - > new.prev = current_zettel_id - > if old then - > zettels[old].prev = curr.next - > assert(curr.parent == zettels[old].parent, 'siblings should have same parent') - > end - > new.parent = curr.parent - > current_zettel_id = curr.next - > render(window) -- recompute render_state - > editz(window) - > elseif key == string.byte('b') then - > -- insert sibling before - > local old = curr.prev - > curr.prev = new_id() - > local new = zettels[curr.prev] - > new.data = '' - > new.prev = old - > new.next = current_zettel_id - > if old then - > zettels[old].next = curr.prev - > assert(curr.parent == zettels[old].parent, 'siblings should have same parent') - > end - > new.parent = curr.parent - > current_zettel_id = curr.prev - > render(window) -- recompute render_state - > editz(window) - > elseif key == string.byte('c') then - > -- insert child - > local old = curr.child - > curr.child = new_id() - > local new = zettels[curr.child] - > new.data = '' - > new.next = old - > if old then - > assert(zettels[old].prev == nil, "first child shouldn't have a previous sibling") - > zettels[old].prev = curr.child - > end - > new.parent = current_zettel_id - > current_zettel_id = curr.child - > render(window) -- recompute render_state - > editz(window) - > -- cross-links - > elseif key == string.byte('s') then - > -- save zettel to a stash - > stash = current_zettel_id - > elseif key == string.byte('t') then - > -- cross-link a zettel bidirectionally with what's on the stash - > local insert_crosslink = - > function(a, rel, b_id) - > if a.crosslinks == nil then - > a.crosslinks = {} - > end - > a.crosslinks[rel] = b_id - > end - > insert_crosslink(curr, 'a', stash) - > insert_crosslink(zettels[stash], 'a', current_zettel_id) - > stash = nil - > -- view settings - > elseif key == string.byte('x') then - > if view_settings.width > 5 then - > view_settings.width = view_settings.width - 5 - > end - > elseif key == string.byte('X') then - > if view_settings.width < w-5 then - > view_settings.width = view_settings.width + 5 - > end - > elseif key == string.byte('y') then - > if view_settings.height > 0 then - > view_settings.height = view_settings.height - 1 - > end - > elseif key == string.byte('Y') then - > if view_settings.height < h-2 then - > view_settings.height = view_settings.height + 1 - > end - > elseif key == string.byte('z') then - > -- scroll to show the current zettel at top of screen - > -- often has the effect of zooming in on its hierarchy - > view_settings.first_zettel = current_zettel_id - > end - >end -- __teliva_timestamp: - >Sat Feb 12 17:55:42 2022 - update: - >function update(window) - > local key = window:getch() - > local h, w = window:getmaxyx() - > local curr = zettels[current_zettel_id] - > assert(curr, string.format('cursor fell off the edge of the world: %s', type(current_zettel_id))) - > -- read from or write to render_state.history - > if key == string.byte('<') then - > -- previous zettel moved to - > -- does NOT undo mutations - > if #render_state.history > 0 then - > local previous_state = render_state.history[#render_state.history] - > view_settings.first_zettel = previous_state.first_zettel - > current_zettel_id = render_state.history[-1].current_zettel_id - > table.remove(render_state.history) - > end - > return - > end - > if key ~= string.byte('e') then - > table.insert(render_state.history, {first_zettel=view_settings.first_zettel, current_zettel_id=current_zettel_id}) - > end - > -- move along the graph - > if key == string.byte('j') then - > -- child or next sibling - > if curr.child then - > current_zettel_id = curr.child - > elseif curr.next then - > current_zettel_id = curr.next - > elseif curr.parent and zettels[curr.parent].next then - > current_zettel_id = zettels[curr.parent].next - > end - > -- scroll if necessary - > if not render_state.displayed[current_zettel_id] then - > view_settings.first_zettel = current_zettel_id - > end - > elseif key == string.byte('k') then - > -- parent or previous sibling - > if curr.parent then - > current_zettel_id = curr.parent - > elseif curr.prev then - > current_zettel_id = curr.prev - > end - > -- scroll if necessary - > if not render_state.displayed[current_zettel_id] then - > view_settings.first_zettel = current_zettel_id - > end - > elseif key == string.byte('h') then - > -- previous sibling or parent - > if curr.prev then - > current_zettel_id = curr.prev - > elseif curr.parent then - > current_zettel_id = curr.parent - > end - > -- scroll if necessary - > if not render_state.displayed[current_zettel_id] then - > view_settings.first_zettel = current_zettel_id - > end - > elseif key == string.byte('l') then - > -- next sibling or next sibling of parent - > if curr.next then - > current_zettel_id = curr.next - > elseif curr.parent and zettels[curr.parent].next then - > current_zettel_id = zettels[curr.parent].next - > end - > -- scroll if necessary - > if not render_state.displayed[current_zettel_id] then - > view_settings.first_zettel = current_zettel_id - > end - > -- move along the screen - > elseif key == curses.KEY_UP then - > if render_state.curr_h > 1 then - > current_zettel_id = render_state.wh2id[render_state.curr_w][render_state.curr_h - 1] - > end - > elseif key == curses.KEY_DOWN then - > if render_state.wh2id[render_state.curr_w][render_state.curr_h + 1] then - > current_zettel_id = render_state.wh2id[render_state.curr_w][render_state.curr_h + 1] - > end - > elseif key == curses.KEY_LEFT then - > if render_state.curr_w > 1 then - > current_zettel_id = render_state.wh2id[render_state.curr_w - 1][render_state.curr_h] - > end - > elseif key == curses.KEY_RIGHT then - > if render_state.wh2id[render_state.curr_w + 1] and render_state.wh2id[render_state.curr_w + 1][render_state.curr_h] then - > current_zettel_id = render_state.wh2id[render_state.curr_w + 1][render_state.curr_h] - > end - > -- mutations - > elseif key == string.byte('e') then - > editz(window) - > elseif key == string.byte('a') then - > -- insert sibling after - > local old = curr.next - > curr.next = new_id() - > local new = zettels[curr.next] - > new.data = '' - > new.next = old - > new.prev = current_zettel_id - > if old then - > zettels[old].prev = curr.next - > assert(curr.parent == zettels[old].parent, 'siblings should have same parent') - > end - > new.parent = curr.parent - > current_zettel_id = curr.next - > render(window) -- recompute render_state - > editz(window) - > elseif key == string.byte('b') then - > -- insert sibling before - > local old = curr.prev - > curr.prev = new_id() - > local new = zettels[curr.prev] - > new.data = '' - > new.prev = old - > new.next = current_zettel_id - > if old then - > zettels[old].next = curr.prev - > assert(curr.parent == zettels[old].parent, 'siblings should have same parent') - > end - > new.parent = curr.parent - > current_zettel_id = curr.prev - > render(window) -- recompute render_state - > editz(window) - > elseif key == string.byte('c') then - > -- insert child - > local old = curr.child - > curr.child = new_id() - > local new = zettels[curr.child] - > new.data = '' - > new.next = old - > if old then - > assert(zettels[old].prev == nil, "first child shouldn't have a previous sibling") - > zettels[old].prev = curr.child - > end - > new.parent = current_zettel_id - > current_zettel_id = curr.child - > render(window) -- recompute render_state - > editz(window) - > -- cross-links - > elseif key == string.byte('s') then - > -- save zettel to a stash - > stash = current_zettel_id - > elseif key == string.byte('t') then - > -- cross-link a zettel bidirectionally with what's on the stash - > local insert_crosslink = - > function(a, rel, b_id) - > if a.crosslinks == nil then - > a.crosslinks = {} - > end - > a.crosslinks[rel] = b_id - > end - > insert_crosslink(curr, 'a', stash) - > insert_crosslink(zettels[stash], 'a', current_zettel_id) - > stash = nil - > -- view settings - > elseif key == string.byte('x') then - > if view_settings.width > 5 then - > view_settings.width = view_settings.width - 5 - > end - > elseif key == string.byte('X') then - > if view_settings.width < w-5 then - > view_settings.width = view_settings.width + 5 - > end - > elseif key == string.byte('y') then - > if view_settings.height > 0 then - > view_settings.height = view_settings.height - 1 - > end - > elseif key == string.byte('Y') then - > if view_settings.height < h-2 then - > view_settings.height = view_settings.height + 1 - > end - > elseif key == string.byte('z') then - > -- scroll to show the current zettel at top of screen - > -- often has the effect of zooming in on its hierarchy - > view_settings.first_zettel = current_zettel_id - > end - >end -- __teliva_timestamp: - >Sat Feb 12 17:56:13 2022 - update: - >function update(window) - > local key = window:getch() - > local h, w = window:getmaxyx() - > local curr = zettels[current_zettel_id] - > assert(curr, string.format('cursor fell off the edge of the world: %s', type(current_zettel_id))) - > -- read from or write to render_state.history - > if key == string.byte('<') then - > -- previous zettel moved to - > -- does NOT undo mutations - > if #render_state.history > 0 then - > print(render_state.history[1]) - > window:getch() - > local previous_state = render_state.history[#render_state.history] - > view_settings.first_zettel = previous_state.first_zettel - > current_zettel_id = render_state.history[-1].current_zettel_id - > table.remove(render_state.history) - > end - > return - > end - > if key ~= string.byte('e') then - > table.insert(render_state.history, {first_zettel=view_settings.first_zettel, current_zettel_id=current_zettel_id}) - > end - > -- move along the graph - > if key == string.byte('j') then - > -- child or next sibling - > if curr.child then - > current_zettel_id = curr.child - > elseif curr.next then - > current_zettel_id = curr.next - > elseif curr.parent and zettels[curr.parent].next then - > current_zettel_id = zettels[curr.parent].next - > end - > -- scroll if necessary - > if not render_state.displayed[current_zettel_id] then - > view_settings.first_zettel = current_zettel_id - > end - > elseif key == string.byte('k') then - > -- parent or previous sibling - > if curr.parent then - > current_zettel_id = curr.parent - > elseif curr.prev then - > current_zettel_id = curr.prev - > end - > -- scroll if necessary - > if not render_state.displayed[current_zettel_id] then - > view_settings.first_zettel = current_zettel_id - > end - > elseif key == string.byte('h') then - > -- previous sibling or parent - > if curr.prev then - > current_zettel_id = curr.prev - > elseif curr.parent then - > current_zettel_id = curr.parent - > end - > -- scroll if necessary - > if not render_state.displayed[current_zettel_id] then - > view_settings.first_zettel = current_zettel_id - > end - > elseif key == string.byte('l') then - > -- next sibling or next sibling of parent - > if curr.next then - > current_zettel_id = curr.next - > elseif curr.parent and zettels[curr.parent].next then - > current_zettel_id = zettels[curr.parent].next - > end - > -- scroll if necessary - > if not render_state.displayed[current_zettel_id] then - > view_settings.first_zettel = current_zettel_id - > end - > -- move along the screen - > elseif key == curses.KEY_UP then - > if render_state.curr_h > 1 then - > current_zettel_id = render_state.wh2id[render_state.curr_w][render_state.curr_h - 1] - > end - > elseif key == curses.KEY_DOWN then - > if render_state.wh2id[render_state.curr_w][render_state.curr_h + 1] then - > current_zettel_id = render_state.wh2id[render_state.curr_w][render_state.curr_h + 1] - > end - > elseif key == curses.KEY_LEFT then - > if render_state.curr_w > 1 then - > current_zettel_id = render_state.wh2id[render_state.curr_w - 1][render_state.curr_h] - > end - > elseif key == curses.KEY_RIGHT then - > if render_state.wh2id[render_state.curr_w + 1] and render_state.wh2id[render_state.curr_w + 1][render_state.curr_h] then - > current_zettel_id = render_state.wh2id[render_state.curr_w + 1][render_state.curr_h] - > end - > -- mutations - > elseif key == string.byte('e') then - > editz(window) - > elseif key == string.byte('a') then - > -- insert sibling after - > local old = curr.next - > curr.next = new_id() - > local new = zettels[curr.next] - > new.data = '' - > new.next = old - > new.prev = current_zettel_id - > if old then - > zettels[old].prev = curr.next - > assert(curr.parent == zettels[old].parent, 'siblings should have same parent') - > end - > new.parent = curr.parent - > current_zettel_id = curr.next - > render(window) -- recompute render_state - > editz(window) - > elseif key == string.byte('b') then - > -- insert sibling before - > local old = curr.prev - > curr.prev = new_id() - > local new = zettels[curr.prev] - > new.data = '' - > new.prev = old - > new.next = current_zettel_id - > if old then - > zettels[old].next = curr.prev - > assert(curr.parent == zettels[old].parent, 'siblings should have same parent') - > end - > new.parent = curr.parent - > current_zettel_id = curr.prev - > render(window) -- recompute render_state - > editz(window) - > elseif key == string.byte('c') then - > -- insert child - > local old = curr.child - > curr.child = new_id() - > local new = zettels[curr.child] - > new.data = '' - > new.next = old - > if old then - > assert(zettels[old].prev == nil, "first child shouldn't have a previous sibling") - > zettels[old].prev = curr.child - > end - > new.parent = current_zettel_id - > current_zettel_id = curr.child - > render(window) -- recompute render_state - > editz(window) - > -- cross-links - > elseif key == string.byte('s') then - > -- save zettel to a stash - > stash = current_zettel_id - > elseif key == string.byte('t') then - > -- cross-link a zettel bidirectionally with what's on the stash - > local insert_crosslink = - > function(a, rel, b_id) - > if a.crosslinks == nil then - > a.crosslinks = {} - > end - > a.crosslinks[rel] = b_id - > end - > insert_crosslink(curr, 'a', stash) - > insert_crosslink(zettels[stash], 'a', current_zettel_id) - > stash = nil - > -- view settings - > elseif key == string.byte('x') then - > if view_settings.width > 5 then - > view_settings.width = view_settings.width - 5 - > end - > elseif key == string.byte('X') then - > if view_settings.width < w-5 then - > view_settings.width = view_settings.width + 5 - > end - > elseif key == string.byte('y') then - > if view_settings.height > 0 then - > view_settings.height = view_settings.height - 1 - > end - > elseif key == string.byte('Y') then - > if view_settings.height < h-2 then - > view_settings.height = view_settings.height + 1 - > end - > elseif key == string.byte('z') then - > -- scroll to show the current zettel at top of screen - > -- often has the effect of zooming in on its hierarchy - > view_settings.first_zettel = current_zettel_id - > end - >end -- __teliva_timestamp: - >Sat Feb 12 17:56:25 2022 - update: - >function update(window) - > local key = window:getch() - > local h, w = window:getmaxyx() - > local curr = zettels[current_zettel_id] - > assert(curr, string.format('cursor fell off the edge of the world: %s', type(current_zettel_id))) - > -- read from or write to render_state.history - > if key == string.byte('<') then - > -- previous zettel moved to - > -- does NOT undo mutations - > if #render_state.history > 0 then - > window:mvaddstr(30, 60, '') - > print(render_state.history[1]) - > window:getch() - > local previous_state = render_state.history[#render_state.history] - > view_settings.first_zettel = previous_state.first_zettel - > current_zettel_id = render_state.history[-1].current_zettel_id - > table.remove(render_state.history) - > end - > return - > end - > if key ~= string.byte('e') then - > table.insert(render_state.history, {first_zettel=view_settings.first_zettel, current_zettel_id=current_zettel_id}) - > end - > -- move along the graph - > if key == string.byte('j') then - > -- child or next sibling - > if curr.child then - > current_zettel_id = curr.child - > elseif curr.next then - > current_zettel_id = curr.next - > elseif curr.parent and zettels[curr.parent].next then - > current_zettel_id = zettels[curr.parent].next - > end - > -- scroll if necessary - > if not render_state.displayed[current_zettel_id] then - > view_settings.first_zettel = current_zettel_id - > end - > elseif key == string.byte('k') then - > -- parent or previous sibling - > if curr.parent then - > current_zettel_id = curr.parent - > elseif curr.prev then - > current_zettel_id = curr.prev - > end - > -- scroll if necessary - > if not render_state.displayed[current_zettel_id] then - > view_settings.first_zettel = current_zettel_id - > end - > elseif key == string.byte('h') then - > -- previous sibling or parent - > if curr.prev then - > current_zettel_id = curr.prev - > elseif curr.parent then - > current_zettel_id = curr.parent - > end - > -- scroll if necessary - > if not render_state.displayed[current_zettel_id] then - > view_settings.first_zettel = current_zettel_id - > end - > elseif key == string.byte('l') then - > -- next sibling or next sibling of parent - > if curr.next then - > current_zettel_id = curr.next - > elseif curr.parent and zettels[curr.parent].next then - > current_zettel_id = zettels[curr.parent].next - > end - > -- scroll if necessary - > if not render_state.displayed[current_zettel_id] then - > view_settings.first_zettel = current_zettel_id - > end - > -- move along the screen - > elseif key == curses.KEY_UP then - > if render_state.curr_h > 1 then - > current_zettel_id = render_state.wh2id[render_state.curr_w][render_state.curr_h - 1] - > end - > elseif key == curses.KEY_DOWN then - > if render_state.wh2id[render_state.curr_w][render_state.curr_h + 1] then - > current_zettel_id = render_state.wh2id[render_state.curr_w][render_state.curr_h + 1] - > end - > elseif key == curses.KEY_LEFT then - > if render_state.curr_w > 1 then - > current_zettel_id = render_state.wh2id[render_state.curr_w - 1][render_state.curr_h] - > end - > elseif key == curses.KEY_RIGHT then - > if render_state.wh2id[render_state.curr_w + 1] and render_state.wh2id[render_state.curr_w + 1][render_state.curr_h] then - > current_zettel_id = render_state.wh2id[render_state.curr_w + 1][render_state.curr_h] - > end - > -- mutations - > elseif key == string.byte('e') then - > editz(window) - > elseif key == string.byte('a') then - > -- insert sibling after - > local old = curr.next - > curr.next = new_id() - > local new = zettels[curr.next] - > new.data = '' - > new.next = old - > new.prev = current_zettel_id - > if old then - > zettels[old].prev = curr.next - > assert(curr.parent == zettels[old].parent, 'siblings should have same parent') - > end - > new.parent = curr.parent - > current_zettel_id = curr.next - > render(window) -- recompute render_state - > editz(window) - > elseif key == string.byte('b') then - > -- insert sibling before - > local old = curr.prev - > curr.prev = new_id() - > local new = zettels[curr.prev] - > new.data = '' - > new.prev = old - > new.next = current_zettel_id - > if old then - > zettels[old].next = curr.prev - > assert(curr.parent == zettels[old].parent, 'siblings should have same parent') - > end - > new.parent = curr.parent - > current_zettel_id = curr.prev - > render(window) -- recompute render_state - > editz(window) - > elseif key == string.byte('c') then - > -- insert child - > local old = curr.child - > curr.child = new_id() - > local new = zettels[curr.child] - > new.data = '' - > new.next = old - > if old then - > assert(zettels[old].prev == nil, "first child shouldn't have a previous sibling") - > zettels[old].prev = curr.child - > end - > new.parent = current_zettel_id - > current_zettel_id = curr.child - > render(window) -- recompute render_state - > editz(window) - > -- cross-links - > elseif key == string.byte('s') then - > -- save zettel to a stash - > stash = current_zettel_id - > elseif key == string.byte('t') then - > -- cross-link a zettel bidirectionally with what's on the stash - > local insert_crosslink = - > function(a, rel, b_id) - > if a.crosslinks == nil then - > a.crosslinks = {} - > end - > a.crosslinks[rel] = b_id - > end - > insert_crosslink(curr, 'a', stash) - > insert_crosslink(zettels[stash], 'a', current_zettel_id) - > stash = nil - > -- view settings - > elseif key == string.byte('x') then - > if view_settings.width > 5 then - > view_settings.width = view_settings.width - 5 - > end - > elseif key == string.byte('X') then - > if view_settings.width < w-5 then - > view_settings.width = view_settings.width + 5 - > end - > elseif key == string.byte('y') then - > if view_settings.height > 0 then - > view_settings.height = view_settings.height - 1 - > end - > elseif key == string.byte('Y') then - > if view_settings.height < h-2 then - > view_settings.height = view_settings.height + 1 - > end - > elseif key == string.byte('z') then - > -- scroll to show the current zettel at top of screen - > -- often has the effect of zooming in on its hierarchy - > view_settings.first_zettel = current_zettel_id - > end - >end - __teliva_timestamp: >Sat Feb 12 17:57:15 2022 update: