summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--command.c4
-rw-r--r--main.c1
-rw-r--r--ted.h55
-rw-r--r--ui.c63
4 files changed, 62 insertions, 61 deletions
diff --git a/command.c b/command.c
index 4900c07..0347544 100644
--- a/command.c
+++ b/command.c
@@ -1,3 +1,5 @@
+#include "ted.h"
+
typedef struct {
const char *name;
Command cmd;
@@ -106,7 +108,7 @@ const char *command_to_str(Command c) {
}
// get the string corresponding to this argument; returns NULL if it's not a string argument
-const char *arg_get_string(Ted *ted, i64 argument) {
+static const char *arg_get_string(Ted *ted, i64 argument) {
if (argument < 0) return NULL;
if (argument & ARG_STRING) {
argument -= ARG_STRING;
diff --git a/main.c b/main.c
index 871d203..9c60cab 100644
--- a/main.c
+++ b/main.c
@@ -86,7 +86,6 @@ no_warn_end
#error "Unrecognized operating system."
#endif
-#include "ted.h"
#include "gl.c"
#include "text.c"
#include "colors.c"
diff --git a/ted.h b/ted.h
index 8118a36..84b161b 100644
--- a/ted.h
+++ b/ted.h
@@ -326,8 +326,18 @@ typedef struct {
bool create_menu; // this is for creating files, not opening files
} FileSelector;
+typedef enum {
+ POPUP_NONE,
+ POPUP_YES = 1<<1,
+ POPUP_NO = 1<<2,
+ POPUP_CANCEL = 1<<3,
+} PopupOption;
+
+#define POPUP_YES_NO (POPUP_YES | POPUP_NO)
+#define POPUP_YES_NO_CANCEL (POPUP_YES | POPUP_NO | POPUP_CANCEL)
+
// a node is a collection of tabs OR a split of two nodes
-typedef struct Node {
+typedef struct {
u16 *tabs; // dynamic array of indices into ted->buffers, or NULL if this is a split
float split_pos; // number from 0 to 1 indicating where the split is.
u16 active_tab; // index of active tab in tabs.
@@ -738,6 +748,11 @@ const char *color_setting_to_str(ColorSetting s);
Status color_from_str(const char *str, u32 *color);
ColorSetting color_for_symbol_kind(SymbolKind kind);
+// === command.c ===
+Command command_from_str(const char *str);
+const char *command_to_str(Command c);
+void command_execute(Ted *ted, Command c, i64 argument);
+
// === gl.c ===
GlRcSAB *gl_rc_sab_new(GLuint shader, GLuint array, GLuint buffer);
void gl_rc_sab_incref(GlRcSAB *s);
@@ -796,6 +811,7 @@ const char *ted_geterr(Ted *ted);
void ted_clearerr(Ted *ted);
char *ted_get_root_dir_of(Ted *ted, const char *path);
char *ted_get_root_dir(Ted *ted);
+// the settings of the active buffer, or the default settings if there is no active buffer
Settings *ted_active_settings(Ted *ted);
Settings *ted_get_settings(Ted *ted, const char *path, Language language);
LSP *ted_get_lsp_by_id(Ted *ted, LSPID id);
@@ -813,21 +829,30 @@ void ted_go_to_position(Ted *ted, const char *path, u32 line, u32 index, bool is
void ted_go_to_lsp_document_position(Ted *ted, LSP *lsp, LSPDocumentPosition position);
void ted_cancel_lsp_request(Ted *ted, LSPID lsp, LSPRequestID request);
+// === ui.c ===
+void selector_up(Ted *ted, Selector *s, i64 n);
+void selector_down(Ted *ted, Selector *s, i64 n);
+// sort entries alphabetically
+void selector_sort_entries_by_name(Selector *s);
+// returns a null-terminated UTF-8 string of the option selected, or NULL if none was.
+// you should call free() on the return value.
+char *selector_update(Ted *ted, Selector *s);
+// NOTE: also renders the line buffer
+void selector_render(Ted *ted, Selector *s);
+void file_selector_free(FileSelector *fs);
+// returns the name of the selected file, or NULL if none was selected.
+// the returned pointer should be freed.
+char *file_selector_update(Ted *ted, FileSelector *fs);
+void file_selector_render(Ted *ted, FileSelector *fs);
+v2 button_get_size(Ted *ted, const char *text);
+void button_render(Ted *ted, Rect button, const char *text, u32 color);
+// returns true if the button was clicked on.
+bool button_update(Ted *ted, Rect button);
+PopupOption popup_update(Ted *ted, u32 options);
+void popup_render(Ted *ted, u32 options, const char *title, const char *body);
+v2 checkbox_frame(Ted *ted, bool *value, const char *label, v2 pos);
+
-char *buffer_contents_utf8_alloc(TextBuffer *buffer);
-Command command_from_str(const char *str);
-const char *command_to_str(Command command);
-// Returns string representation of command
-const char *command_to_str(Command c);
-void command_execute(Ted *ted, Command c, i64 argument);
-void ted_switch_to_buffer(Ted *ted, TextBuffer *buffer);
-// the settings of the active buffer, or the default settings if there is no active buffer
-Settings *ted_active_settings(Ted *ted);
-Settings *ted_get_settings(Ted *ted, const char *path, Language lang);
-void ted_load_configs(Ted *ted, bool reloading);
-LSP *ted_get_lsp(Ted *ted, const char *path, Language lang);
-LSP *ted_active_lsp(Ted *ted);
-LSP *ted_get_lsp_by_id(Ted *ted, u32 id);
TextBuffer *find_search_buffer(Ted *ted);
// first, we read all config files, then we parse them.
// this is because we want less specific settings (e.g. settings applied
diff --git a/ui.c b/ui.c
index c75a11b..d9ac83f 100644
--- a/ui.c
+++ b/ui.c
@@ -1,7 +1,11 @@
+#include "ted.h"
+
#if __unix__
#include <fcntl.h>
#endif
+static Status file_selector_cd_(Ted *ted, FileSelector *fs, const char *path, int symlink_depth);
+
static float selector_entries_start_y(Ted *ted, const Selector *s) {
float padding = ted_active_settings(ted)->padding;
@@ -43,7 +47,7 @@ static bool selector_entry_pos(Ted *ted, const Selector *s, u32 i, Rect *r) {
return rect_clip_to_rect(r, bounds);
}
-static void selector_up(Ted *ted, Selector *s, i64 n) {
+void selector_up(Ted *ted, Selector *s, i64 n) {
if (!s->enable_cursor || s->n_entries == 0) {
// can't do anything
return;
@@ -52,23 +56,20 @@ static void selector_up(Ted *ted, Selector *s, i64 n) {
selector_scroll_to_cursor(ted, s);
}
-static void selector_down(Ted *ted, Selector *s, i64 n) {
+void selector_down(Ted *ted, Selector *s, i64 n) {
selector_up(ted, s, -n);
}
static int selectory_entry_cmp_name(const void *av, const void *bv) {
SelectorEntry const *a = av, *b = bv;
- return strcmp(a->name, b->name);
+ return strcoll(a->name, b->name);
}
-// sort entries alphabetically
-static void selector_sort_entries_by_name(Selector *s) {
+void selector_sort_entries_by_name(Selector *s) {
qsort(s->entries, s->n_entries, sizeof *s->entries, selectory_entry_cmp_name);
}
-// returns a null-terminated UTF-8 string of the option selected, or NULL if none was.
-// you should call free() on the return value.
-static char *selector_update(Ted *ted, Selector *s) {
+char *selector_update(Ted *ted, Selector *s) {
char *ret = NULL;
TextBuffer *line_buffer = &ted->line_buffer;
@@ -109,8 +110,7 @@ static char *selector_update(Ted *ted, Selector *s) {
return ret;
}
-// NOTE: also renders the line buffer
-static void selector_render(Ted *ted, Selector *s) {
+void selector_render(Ted *ted, Selector *s) {
const Settings *settings = ted_active_settings(ted);
const u32 *colors = settings->colors;
Font *font = ted->font;
@@ -185,17 +185,7 @@ static void file_selector_clear_entries(FileSelector *fs) {
fs->n_entries = fs->sel.n_entries = 0;
}
-// returns true if there are any directory entries
-static bool file_selector_any_directories(const FileSelector *fs) {
- const FileEntry *entries = fs->entries;
- for (u32 i = 0, n_entries = fs->n_entries; i < n_entries; ++i) {
- if (entries[i].type == FS_DIRECTORY)
- return true;
- }
- return false;
-}
-
-static void file_selector_free(FileSelector *fs) {
+void file_selector_free(FileSelector *fs) {
file_selector_clear_entries(fs);
memset(fs, 0, sizeof *fs);
}
@@ -224,8 +214,6 @@ static int qsort_file_entry_cmp(void *search_termv, const void *av, const void *
return strcmp_case_insensitive(a->name, b->name);
}
-static Status file_selector_cd_(Ted *ted, FileSelector *fs, const char *path, int symlink_depth);
-
// cd to the directory `name`. `name` cannot include any path separators.
static Status file_selector_cd1(Ted *ted, FileSelector *fs, const char *name, size_t name_len, int symlink_depth) {
char *const cwd = fs->cwd;
@@ -342,9 +330,7 @@ static bool file_selector_cd(Ted *ted, FileSelector *fs, const char *path) {
return file_selector_cd_(ted, fs, path, 0);
}
-// returns the name of the selected file, or NULL
-// if none was selected. the returned pointer should be freed.
-static char *file_selector_update(Ted *ted, FileSelector *fs) {
+char *file_selector_update(Ted *ted, FileSelector *fs) {
TextBuffer *line_buffer = &ted->line_buffer;
String32 search_term32 = buffer_get_line(line_buffer, 0);
@@ -498,7 +484,7 @@ static char *file_selector_update(Ted *ted, FileSelector *fs) {
return NULL;
}
-static void file_selector_render(Ted *ted, FileSelector *fs) {
+void file_selector_render(Ted *ted, FileSelector *fs) {
const Settings *settings = ted_active_settings(ted);
const u32 *colors = settings->colors;
Rect bounds = fs->bounds;
@@ -538,12 +524,12 @@ static void file_selector_render(Ted *ted, FileSelector *fs) {
selector_render(ted, sel);
}
-static v2 button_get_size(Ted *ted, const char *text) {
+v2 button_get_size(Ted *ted, const char *text) {
float border_thickness = ted_active_settings(ted)->border_thickness;
return v2_add_const(text_get_size_v2(ted->font, text), 2 * border_thickness);
}
-static void button_render(Ted *ted, Rect button, const char *text, u32 color) {
+void button_render(Ted *ted, Rect button, const char *text, u32 color) {
const u32 *colors = ted_active_settings(ted)->colors;
if (rect_contains_point(button, ted->mouse_pos)) {
@@ -560,8 +546,7 @@ static void button_render(Ted *ted, Rect button, const char *text, u32 color) {
text_render(ted->font);
}
-// returns true if the button was clicked on.
-static bool button_update(Ted *ted, Rect button) {
+bool button_update(Ted *ted, Rect button) {
for (u16 i = 0; i < ted->nmouse_clicks[SDL_BUTTON_LEFT]; ++i) {
if (rect_contains_point(button, ted->mouse_clicks[SDL_BUTTON_LEFT][i])) {
return true;
@@ -570,16 +555,6 @@ static bool button_update(Ted *ted, Rect button) {
return false;
}
-typedef enum {
- POPUP_NONE,
- POPUP_YES = 1<<1,
- POPUP_NO = 1<<2,
- POPUP_CANCEL = 1<<3,
-} PopupOption;
-
-#define POPUP_YES_NO (POPUP_YES | POPUP_NO)
-#define POPUP_YES_NO_CANCEL (POPUP_YES | POPUP_NO | POPUP_CANCEL)
-
static void popup_get_rects(Ted const *ted, u32 options, Rect *popup, Rect *button_yes, Rect *button_no, Rect *button_cancel) {
float window_width = ted->window_width, window_height = ted->window_height;
@@ -603,7 +578,7 @@ static void popup_get_rects(Ted const *ted, u32 options, Rect *popup, Rect *butt
}
}
-static PopupOption popup_update(Ted *ted, u32 options) {
+PopupOption popup_update(Ted *ted, u32 options) {
Rect r = {0}, button_yes = {0}, button_no = {0}, button_cancel = {0};
popup_get_rects(ted, options, &r, &button_yes, &button_no, &button_cancel);
if (button_update(ted, button_yes))
@@ -615,7 +590,7 @@ static PopupOption popup_update(Ted *ted, u32 options) {
return POPUP_NONE;
}
-static void popup_render(Ted *ted, u32 options, const char *title, const char *body) {
+void popup_render(Ted *ted, u32 options, const char *title, const char *body) {
float window_width = ted->window_width;
Font *font = ted->font;
Font *font_bold = ted->font_bold;
@@ -665,7 +640,7 @@ static void popup_render(Ted *ted, u32 options, const char *title, const char *b
}
// returns the size of the checkbox, including the label
-static v2 checkbox_frame(Ted *ted, bool *value, const char *label, v2 pos) {
+v2 checkbox_frame(Ted *ted, bool *value, const char *label, v2 pos) {
Font *font = ted->font;
float char_height = text_font_char_height(font);
float checkbox_size = char_height;