summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Untitled3
-rw-r--r--buffer.c2
-rw-r--r--colors.h2
-rw-r--r--command.c2
-rw-r--r--main.c28
-rw-r--r--menu.c26
-rw-r--r--ted.c14
-rw-r--r--ted.cfg2
8 files changed, 39 insertions, 40 deletions
diff --git a/Untitled b/Untitled
deleted file mode 100644
index 6609522..0000000
--- a/Untitled
+++ /dev/null
@@ -1,3 +0,0 @@
-aaaa 1 2 3 4
-56 78 910 1112
-testing
diff --git a/buffer.c b/buffer.c
index d7699db..3649a68 100644
--- a/buffer.c
+++ b/buffer.c
@@ -625,7 +625,7 @@ Status buffer_load_file(TextBuffer *buffer, char const *filename) {
success = false;
}
} else {
- buffer_seterr(buffer, "File %s does not exist.", filename);
+ buffer_seterr(buffer, "Couldn't open file %s: %s.", filename, strerror(errno));
success = false;
}
return success;
diff --git a/colors.h b/colors.h
index 60aeaf3..7945beb 100644
--- a/colors.h
+++ b/colors.h
@@ -2,6 +2,7 @@ ENUM_U16 {
COLOR_UNKNOWN,
COLOR_TEXT,
+ COLOR_TEXT_SECONDARY,
COLOR_BG,
COLOR_HL,
COLOR_CURSOR,
@@ -33,6 +34,7 @@ typedef struct {
static ColorName const color_names[COLOR_COUNT] = {
{COLOR_UNKNOWN, "unknown"},
{COLOR_TEXT, "text"},
+ {COLOR_TEXT_SECONDARY, "text-secondary"},
{COLOR_BG, "bg"},
{COLOR_HL, "hl"},
{COLOR_CURSOR, "cursor"},
diff --git a/command.c b/command.c
index 3a52746..5ff7444 100644
--- a/command.c
+++ b/command.c
@@ -220,7 +220,7 @@ void command_execute(Ted *ted, Command c, i64 argument) {
case CMD_TAB_CLOSE: {
if (ted->menu) {
- menu_close(ted, true);
+ menu_close(ted);
} else {
Node *node = ted->active_node;
if (node) {
diff --git a/main.c b/main.c
index cfabb85..1709a97 100644
--- a/main.c
+++ b/main.c
@@ -1,7 +1,4 @@
// @TODO:
-// - try opening a file you don't have read permission for -- check for memory leaks!
-
-// - show something informative when there's no nodes open (i.e. ted->active_node == NULL).
// - split
// - Windows installation
#include "base.h"
@@ -101,7 +98,7 @@ int main(int argc, char **argv) {
setlocale(LC_ALL, ""); // allow unicode
// read command-line arguments
- char const *starting_filename = TED_UNTITLED;
+ char const *starting_filename = NULL;
switch (argc) {
case 0: case 1: break;
case 2:
@@ -257,11 +254,20 @@ int main(int argc, char **argv) {
arr_add(node->tabs, 0);
- if (fs_file_exists(starting_filename)) {
- if (!buffer_load_file(buffer, starting_filename))
+ char path[TED_PATH_MAX];
+ if (starting_filename) {
+ // get full path to file
+ strbuf_printf(path, "%s%s%s", ted->cwd, ted->cwd[strlen(ted->cwd) - 1] == PATH_SEPARATOR ? "" : PATH_SEPARATOR_STR,
+ starting_filename);
+ } else {
+ strbuf_printf(path, "Untitled");
+ }
+
+ if (starting_filename && fs_file_exists(path)) {
+ if (!buffer_load_file(buffer, path))
ted_seterr(ted, "Couldn't load file: %s", buffer_geterr(buffer));
} else {
- buffer_new_file(buffer, starting_filename);
+ buffer_new_file(buffer, path);
if (buffer_haserr(buffer))
ted_seterr(ted, "Couldn't create file: %s", buffer_geterr(buffer));
}
@@ -475,10 +481,14 @@ int main(int argc, char **argv) {
Font *font = ted->font;
- {
+ if (ted->active_node) {
float x1 = 25, y1 = 25, x2 = window_width-25, y2 = window_height-25;
Node *node = ted->root;
node_frame(ted, node, rect4(x1, y1, x2, y2));
+ } else {
+ gl_color_rgba(colors[COLOR_TEXT_SECONDARY]);
+ text_render_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, ANCHOR_MIDDLE);
}
Menu menu = ted->menu;
@@ -561,7 +571,7 @@ int main(int argc, char **argv) {
if (ted->menu)
- menu_close(ted, false); // free any memory used by the current menu
+ menu_close(ted); // free any memory used by the current menu
if (log) fclose(log);
diff --git a/menu.c b/menu.c
index 8fd0a3b..f979b72 100644
--- a/menu.c
+++ b/menu.c
@@ -20,8 +20,8 @@ static void menu_open(Ted *ted, Menu menu) {
}
}
-static void menu_close(Ted *ted, bool restore_prev_active_buffer) {
- if (restore_prev_active_buffer) ted->active_buffer = ted->prev_active_buffer;
+static void menu_close(Ted *ted) {
+ ted->active_buffer = ted->prev_active_buffer;
ted->prev_active_buffer = NULL;
switch (ted->menu) {
case MENU_NONE: assert(0); break;
@@ -44,7 +44,7 @@ static void menu_escape(Ted *ted) {
*ted->warn_overwrite = 0;
ted->active_buffer = &ted->line_buffer;
} else {
- menu_close(ted, true);
+ menu_close(ted);
}
}
@@ -80,7 +80,7 @@ static void menu_update(Ted *ted, Menu menu) {
if (buffer) {
buffer_save_as(buffer, ted->warn_overwrite);
}
- menu_close(ted, true);
+ menu_close(ted);
} break;
case POPUP_NO:
// back to the file selector
@@ -89,7 +89,7 @@ static void menu_update(Ted *ted, Menu menu) {
break;
case POPUP_CANCEL:
// close "save as" menu
- menu_close(ted, true);
+ menu_close(ted);
break;
}
} else {
@@ -104,7 +104,7 @@ static void menu_update(Ted *ted, Menu menu) {
} else {
// create the new file.
buffer_save_as(buffer, selected_file);
- menu_close(ted, true);
+ menu_close(ted);
}
}
free(selected_file);
@@ -115,10 +115,8 @@ static void menu_update(Ted *ted, Menu menu) {
char *selected_file = file_selector_update(ted, &ted->file_selector);
if (selected_file) {
// open that file!
- if (ted_open_file(ted, selected_file)) {
- menu_close(ted, false);
- file_selector_free(&ted->file_selector);
- }
+ menu_close(ted);
+ ted_open_file(ted, selected_file);
free(selected_file);
}
} break;
@@ -129,7 +127,7 @@ static void menu_update(Ted *ted, Menu menu) {
// save changes
switch (ted->warn_unsaved) {
case CMD_TAB_CLOSE: {
- menu_close(ted, true);
+ menu_close(ted);
TextBuffer *buffer = ted->active_buffer;
command_execute(ted, CMD_SAVE, 1);
if (!buffer_unsaved_changes(buffer)) {
@@ -137,7 +135,7 @@ static void menu_update(Ted *ted, Menu menu) {
}
} break;
case CMD_QUIT:
- menu_close(ted, true);
+ menu_close(ted);
if (ted_save_all(ted)) {
command_execute(ted, CMD_QUIT, 1);
}
@@ -150,11 +148,11 @@ static void menu_update(Ted *ted, Menu menu) {
case POPUP_NO: {
// pass in an argument of 2 to override dialog
Command cmd = ted->warn_unsaved;
- menu_close(ted, true);
+ menu_close(ted);
command_execute(ted, cmd, 2);
} break;
case POPUP_CANCEL:
- menu_close(ted, true);
+ menu_close(ted);
break;
}
break;
diff --git a/ted.c b/ted.c
index bbb65d0..f5de990 100644
--- a/ted.c
+++ b/ted.c
@@ -173,6 +173,7 @@ static bool ted_open_file(Ted *ted, char const *filename) {
if (buffer_load_file(buffer, filename)) {
return true;
} else {
+ ted_seterr_to_buferr(ted, buffer);
node_tab_close(ted, ted->active_node, tab_idx);
ted_delete_buffer(ted, (u16)buffer_idx);
return false;
@@ -190,6 +191,7 @@ static bool ted_new_file(Ted *ted) {
if (!buffer_haserr(buffer)) {
return true;
} else {
+ ted_seterr_to_buferr(ted, buffer);
node_tab_close(ted, ted->active_node, tab_idx);
ted_delete_buffer(ted, (u16)buffer_idx);
return false;
@@ -219,18 +221,6 @@ static void ted_switch_to_buffer(Ted *ted, u16 buffer_idx) {
assert(0);
}
-// are there any unsaved changes in any buffers?
-static bool ted_any_unsaved_changes(Ted *ted) {
- bool *buffers_used = ted->buffers_used;
- for (u16 i = 0; i < TED_MAX_BUFFERS; ++i) {
- if (buffers_used[i]) {
- if (buffer_unsaved_changes(&ted->buffers[i]))
- return true;
- }
- }
- return false;
-}
-
// save all changes to all buffers with unsaved changes.
// returns true if all buffers were saved successfully
static bool ted_save_all(Ted *ted) {
diff --git a/ted.cfg b/ted.cfg
index c7d0307..8b576f4 100644
--- a/ted.cfg
+++ b/ted.cfg
@@ -94,6 +94,8 @@ cursor = #3ff
selection-bg = #36aa
hl = #ccc
text = #fff
+# less prominent text color
+text-secondary = #fff7
# For example, in the open menu it is nice to have a visual distinction between folders and files.
# This is the color used for folders.
text-folder = #88f