diff options
author | Leo Tenenbaum <pommicket@gmail.com> | 2021-01-02 18:25:03 -0500 |
---|---|---|
committer | Leo Tenenbaum <pommicket@gmail.com> | 2021-01-02 18:25:03 -0500 |
commit | 35cb8b8cfbd141d4ba2e3f1435a9550864d9e2e1 (patch) | |
tree | 192554fde4ce14df9163fdb453fe8932e94dba83 | |
parent | 6bafd0d45f63a7618d7822f31b01da7443d9c5e8 (diff) |
blinking cursor
-rw-r--r-- | buffer.c | 22 | ||||
-rw-r--r-- | config.c | 41 | ||||
-rw-r--r-- | main.c | 3 | ||||
-rw-r--r-- | ted.cfg | 5 |
4 files changed, 51 insertions, 20 deletions
@@ -1774,11 +1774,23 @@ void buffer_render(TextBuffer *buffer, float x1, float y1, float x2, float y2) { text_chars_end(font); { // render cursor - if (buffer_clip_rect(buffer, &cursor_rect)) { - gl_color_rgba(colors[COLOR_CURSOR]); - glBegin(GL_QUADS); - rect_render(cursor_rect); - glEnd(); + float time_on = settings->cursor_blink_time_on; + float time_off = settings->cursor_blink_time_off; + bool is_on = true; + if (time_off > 0) { + double absolute_time = time_get_seconds(); + float period = time_on + time_off; + // time in period + double t = fmod(absolute_time, period); + is_on = t < time_on; // are we in the "on" part of the period? + } + if (is_on) { + if (buffer_clip_rect(buffer, &cursor_rect)) { + gl_color_rgba(colors[COLOR_CURSOR]); + glBegin(GL_QUADS); + rect_render(cursor_rect); + glEnd(); + } } } } @@ -190,9 +190,9 @@ void config_read(Ted *ted, char const *filename) { default: { char *equals = strchr(line, '='); if (equals) { - char *key = line; + char const *key = line; *equals = '\0'; - char *value = equals + 1; + char const *value = equals + 1; while (isspace(*key)) ++key; while (isspace(*value)) ++value; if (equals != line) { @@ -254,32 +254,47 @@ 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: + case SECTION_CORE: { + char const *endptr; + long long const integer = strtoll(value, (char **)&endptr, 10); + bool const is_integer = *endptr == '\0'; + double const floating = strtod(value, (char **)&endptr); + bool const is_floating = *endptr == '\0'; + if (streq(key, "tab-width")) { - int n = atoi(value); - if (n > 0 && n < 100) { - settings->tab_width = (u8)n; + if (is_integer && integer > 0 && integer < 100) { + settings->tab_width = (u8)integer; } 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; + if (is_integer && integer > 0 && integer < 100) { + settings->cursor_width = (u8)integer; } 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; + if (is_integer && integer > 0 && integer < 200) { + settings->undo_save_time = (u8)integer; } else { config_err(cfg, "Invalid undo save time: %s.", value); } + } else if (streq(key, "cursor-blink-time-on")) { + if (is_floating && floating >= 0 && floating < 1000) { + settings->cursor_blink_time_on = (float)floating; + } else { + config_err(cfg, "Invalid cursor blink time: %s.", value); + } + } else if (streq(key, "cursor-blink-time-off")) { + if (is_floating && floating >= 0 && floating < 1000) { + settings->cursor_blink_time_off = (float)floating; + } else { + config_err(cfg, "Invalid cursor blink time: %s.", value); + } } else { config_err(cfg, "Unrecognized core setting: %s.", key); } - break; + } break; } } } else { @@ -1,6 +1,4 @@ // @TODO: -// - select all (:select-all) -// - blinking cursor (cursor-blink-time) // - text size (text-size, :increase-text-size, :decrease-text-size) #include "base.h" no_warn_start @@ -18,6 +16,7 @@ no_warn_end #include "util.c" #include "colors.c" typedef struct { + float cursor_blink_time_on, cursor_blink_time_off; u32 colors[COLOR_COUNT]; u8 tab_width; u8 cursor_width; @@ -1,6 +1,11 @@ [core] tab-width = 4 +# cursor width in pixels cursor-width = 1 +# time to blink cursor for (i.e. it will be on for cursor-blink-time-on seconds, then off for cursor-blink-time-off seconds) +# set -off to 0 to disable blinking +cursor-blink-time-on = 0.5 +cursor-blink-time-off = 0.3 # if you do a bunch of typing, then undo, it will generally # undo the past this many seconds of editing. undo-save-time = 6 |