summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--buffer.c29
-rw-r--r--config.c29
-rw-r--r--main.c7
-rw-r--r--ted.cfg7
4 files changed, 57 insertions, 15 deletions
diff --git a/buffer.c b/buffer.c
index 7d4827d..2e72e54 100644
--- a/buffer.c
+++ b/buffer.c
@@ -3,7 +3,7 @@
// a position in the buffer
typedef struct {
u32 line;
- u32 index; // index of character in line (not the same as column, since a tab is buffer->tab_size columns)
+ u32 index; // index of character in line (not the same as column, since a tab is settings->tab_width columns)
} BufferPos;
typedef struct {
@@ -29,7 +29,6 @@ typedef struct {
BufferPos cursor_pos;
BufferPos selection_pos; // if selection is true, the text between selection_pos and cursor_pos is selected.
bool selection;
- u8 tab_width;
bool store_undo_events; // set to false to disable undo events
float x1, y1, x2, y2;
u32 nlines;
@@ -44,7 +43,6 @@ typedef struct {
void buffer_create(TextBuffer *buffer, Font *font, Settings *settings) {
util_zero_memory(buffer, sizeof *buffer);
buffer->font = font;
- buffer->tab_width = 4;
buffer->store_undo_events = true;
buffer->settings = settings;
}
@@ -382,7 +380,7 @@ static bool buffer_edit_does_anything(TextBuffer *buffer, BufferEdit *edit) {
// has enough time passed since the last edit that we should create a new one?
static bool buffer_edit_split(TextBuffer *buffer) {
double curr_time = time_get_seconds();
- double undo_time_cutoff = 6.0; // only keep around edits for this long (in seconds). @SETTINGS
+ double undo_time_cutoff = buffer->settings->undo_save_time; // only keep around edits for this long (in seconds).
BufferEdit *last_edit = arr_lastp(buffer->undo_history);
if (!last_edit) return true;
return curr_time - last_edit->time > undo_time_cutoff;
@@ -600,11 +598,12 @@ static u32 buffer_index_to_column(TextBuffer *buffer, u32 line, u32 index) {
u32 col = 0;
for (u32 i = 0; i < index; ++i) {
switch (str[i]) {
- case U'\t':
+ case U'\t': {
+ uint tab_width = buffer->settings->tab_width;
do
++col;
- while (col % buffer->tab_width);
- break;
+ while (col % tab_width);
+ } break;
default:
++col;
break;
@@ -623,13 +622,14 @@ static u32 buffer_column_to_index(TextBuffer *buffer, u32 line, u32 column) {
u32 col = 0;
for (u32 i = 0; i < len; ++i) {
switch (str[i]) {
- case U'\t':
+ case U'\t': {
+ uint tab_width = buffer->settings->tab_width;
do {
if (col == column)
return i;
++col;
- } while (col % buffer->tab_width);
- break;
+ } while (col % tab_width);
+ } break;
default:
if (col == column)
return i;
@@ -1591,7 +1591,7 @@ void buffer_render(TextBuffer *buffer, float x1, float y1, float x2, float y2) {
// get screen coordinates of cursor
v2 cursor_display_pos = buffer_pos_to_pixels(buffer, buffer->cursor_pos);
// the rectangle that the cursor is rendered as
- Rect cursor_rect = rect(cursor_display_pos, V2(1.0f, char_height)); // @SETTINGS: cursor width
+ Rect cursor_rect = rect(cursor_display_pos, V2(settings->cursor_width, char_height));
u32 border_color = colors[COLOR_BORDER]; // color of border around buffer
@@ -1722,12 +1722,13 @@ void buffer_render(TextBuffer *buffer, float x1, float y1, float x2, float y2) {
switch (c) {
case U'\n': assert(0);
case U'\r': break; // for CRLF line endings
- case U'\t':
+ case U'\t': {
+ uint tab_width = buffer->settings->tab_width;
do {
text_render_char(font, &text_state, U' ');
++column;
- } while (column % buffer->tab_width);
- break;
+ } while (column % tab_width);
+ } break;
default:
text_render_char(font, &text_state, c);
++column;
diff --git a/config.c b/config.c
index eb38cfd..6dc821e 100644
--- a/config.c
+++ b/config.c
@@ -9,6 +9,7 @@
typedef enum {
SECTION_NONE,
+ SECTION_CORE,
SECTION_KEYBOARD,
SECTION_COLORS
} Section;
@@ -179,6 +180,8 @@ void config_read(Ted *ted, char const *filename) {
section = SECTION_KEYBOARD;
} else if (streq(section_name, "colors")) {
section = SECTION_COLORS;
+ } else if (streq(section_name, "core")) {
+ section = SECTION_CORE;
} else {
config_err(cfg, "Unrecognized section: [%s].", section_name);
}
@@ -251,6 +254,32 @@ void config_read(Ted *ted, char const *filename) {
config_err(cfg, "Expected ':' for key action. This line should look something like: %s = :command.", key);
}
} break;
+ case SECTION_CORE:
+ if (streq(key, "tab-width")) {
+ int n = atoi(value);
+ if (n > 0 && n < 100) {
+ settings->tab_width = (u8)n;
+ } else {
+ config_err(cfg, "Invalid tab width: %s.", value);
+ }
+ } else if (streq(key, "cursor-width")) {
+ int n = atoi(value);
+ if (n > 0 && n < 100) {
+ settings->cursor_width = (u8)n;
+ } else {
+ config_err(cfg, "Invalid cursor width: %s.", value);
+ }
+ } else if (streq(key, "undo-save-time")) {
+ int n = atoi(value);
+ if (n > 0 && n < 200) {
+ settings->undo_save_time = (u8)n;
+ } else {
+ config_err(cfg, "Invalid undo save time: %s.", value);
+ }
+ } else {
+ config_err(cfg, "Unrecognized core setting: %s.", key);
+ }
+ break;
}
}
} else {
diff --git a/main.c b/main.c
index dfd78fa..b76d69f 100644
--- a/main.c
+++ b/main.c
@@ -1,4 +1,3 @@
-// @TODO: page up, page down (buffer_page_up, buffer_page_down)
#include "base.h"
no_warn_start
#if _WIN32
@@ -14,8 +13,14 @@ no_warn_end
#include "command.h"
#include "util.c"
#include "colors.c"
+// @TODO:
+// - blinking cursor (cursor-blink-time)
+// - text size
typedef struct {
u32 colors[COLOR_COUNT];
+ u8 tab_width;
+ u8 cursor_width;
+ u8 undo_save_time;
} Settings;
#include "time.c"
#include "unicode.h"
diff --git a/ted.cfg b/ted.cfg
index c8b6099..219ce43 100644
--- a/ted.cfg
+++ b/ted.cfg
@@ -1,3 +1,10 @@
+[core]
+tab-width = 4
+cursor-width = 1
+# if you do a bunch of typing, then undo, it will generally
+# undo the past this many seconds of editing.
+undo-save-time = 6
+
[keyboard]
# motion keys
Left = :left