From edbad154a65f47dc77dbb901801651e28c4f5e55 Mon Sep 17 00:00:00 2001 From: Leo Tenenbaum Date: Fri, 5 Mar 2021 16:49:17 -0500 Subject: fix :shell with no files open, write cwd to session --- README.md | 5 +++-- main.c | 21 ++++++++++++--------- session.c | 6 +++++- 3 files changed, 20 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 6531884..a638c43 100644 --- a/README.md +++ b/README.md @@ -11,8 +11,9 @@ I'll release installers after testing it a bit more to try to find any bugs ther ## Why? There are a lot of text editors out there. ted doesn't do anything new. -But in the modern world of text editors running browsers internally, it can be nice to have -a simple editor that starts up practically instantaneously, and performs well on reasonably-sized files. +I made ted because I wanted a simple editor that starts up practically instantaneously, +and performs well on reasonably-sized files. I've also added features I find to be particularly useful, +while still keeping it relatively simple. ## Supported features (more coming soon) diff --git a/main.c b/main.c index de8f3ce..1fe6266 100644 --- a/main.c +++ b/main.c @@ -779,7 +779,7 @@ int main(int argc, char **argv) { strcpy(ted->window_title, "ted"); - if (ted->nodes_used[0]) { + { float const padding = settings->padding; float x1 = padding, y = window_height-padding, x2 = window_width-padding; Node *node = &ted->nodes[0]; @@ -796,15 +796,18 @@ int main(int argc, char **argv) { y -= padding; } - float y1 = padding; - node_frame(ted, node, rect4(x1, y1, x2, y)); - if (ted->autocomplete) { - autocomplete_frame(ted); + if (ted->nodes_used[0]) { + float y1 = padding; + node_frame(ted, node, rect4(x1, y1, x2, y)); + if (ted->autocomplete) { + autocomplete_frame(ted); + } + } else { + ted->autocomplete = false; + text_utf8_anchored(font, "Press Ctrl+O to open a file or Ctrl+N to create a new one.", + window_width * 0.5f, window_height * 0.5f, colors[COLOR_TEXT_SECONDARY], ANCHOR_MIDDLE); + text_render(font); } - } else { - text_utf8_anchored(font, "Press Ctrl+O to open a file or Ctrl+N to create a new one.", - window_width * 0.5f, window_height * 0.5f, colors[COLOR_TEXT_SECONDARY], ANCHOR_MIDDLE); - text_render(font); } // stop dragging tab if mouse was released diff --git a/session.c b/session.c index 5a07afb..8e2061d 100644 --- a/session.c +++ b/session.c @@ -1,5 +1,5 @@ #define SESSION_FILENAME "session.txt" -#define SESSION_VERSION "\x7fTED0001" +#define SESSION_VERSION "\x7fTED0002" static void session_write_node(Ted *ted, FILE *fp, u16 node_idx) { Node *node = &ted->nodes[node_idx]; @@ -95,6 +95,8 @@ static void session_read_buffer(Ted *ted, FILE *fp) { static void session_write_file(Ted *ted, FILE *fp) { fwrite(SESSION_VERSION, 1, sizeof SESSION_VERSION, fp); + write_cstr(fp, ted->cwd); + write_u16(fp, ted->active_node ? (u16)(ted->active_node - ted->nodes) : U16_MAX); // active node idx write_u16(fp, ted->active_buffer ? (u16)(ted->active_buffer - ted->buffers) : U16_MAX); // active buffer idx @@ -123,6 +125,8 @@ static void session_read_file(Ted *ted, FILE *fp) { return; // wrong version } + read_cstr(fp, ted->cwd, sizeof ted->cwd); + u16 active_node_idx = read_u16(fp); u16 active_buffer_idx = read_u16(fp); -- cgit v1.2.3