aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Eklöf <daniel@ekloef.se>2019-07-22 18:15:14 +0000
committerDaniel Eklöf <daniel@ekloef.se>2019-07-22 18:15:14 +0000
commit3ccdef3498fd1bb37c8bedfaa91f0a74047dc26f (patch)
tree11250d7347125ed89cc8fe58c7d982f15bf6968c
parentrender: implement cursor styles 'bar' and 'underline' (diff)
conf: make cursor's default style configurable
-rw-r--r--config.c35
-rw-r--r--config.h6
-rw-r--r--footrc3
-rw-r--r--main.c1
-rw-r--r--terminal.h4
5 files changed, 48 insertions, 1 deletions
diff --git a/config.c b/config.c
index 77ce70b1..c3867d2d 100644
--- a/config.c
+++ b/config.c
@@ -182,11 +182,38 @@ parse_section_colors(const char *key, const char *value, struct config *conf,
}
static bool
+parse_section_cursor(const char *key, const char *value, struct config *conf,
+ const char *path, unsigned lineno)
+{
+ if (strcmp(key, "style") == 0) {
+ if (strcmp(value, "block") == 0)
+ conf->cursor.style = CURSOR_BLOCK;
+ else if (strcmp(value, "bar") == 0)
+ conf->cursor.style = CURSOR_BAR;
+ else if (strcmp(value, "underline") == 0)
+ conf->cursor.style = CURSOR_UNDERLINE;
+
+ else {
+ LOG_ERR("%s:%d: invalid 'style': %s", path, lineno, value);
+ return false;
+ }
+ }
+
+ else {
+ LOG_ERR("%s:%d: invalid key: %s", path, lineno, key);
+ return false;
+ }
+
+ return true;
+}
+
+static bool
parse_config_file(FILE *f, struct config *conf, const char *path)
{
enum section {
SECTION_MAIN,
SECTION_COLORS,
+ SECTION_CURSOR,
} section = SECTION_MAIN;
/* Function pointer, called for each key/value line */
@@ -198,12 +225,14 @@ parse_config_file(FILE *f, struct config *conf, const char *path)
static const parser_fun_t section_parser_map[] = {
[SECTION_MAIN] = &parse_section_main,
[SECTION_COLORS] = &parse_section_colors,
+ [SECTION_CURSOR] = &parse_section_cursor,
};
#if defined(_DEBUG) && defined(LOG_ENABLE_DBG) && LOG_ENABLE_DBG
static const char *const section_names[] = {
[SECTION_MAIN] = "main",
[SECTION_COLORS] = "colors",
+ [SECTION_CURSOR] = "cursor",
};
#endif
@@ -257,6 +286,8 @@ parse_config_file(FILE *f, struct config *conf, const char *path)
if (strcmp(&line[1], "colors") == 0)
section = SECTION_COLORS;
+ else if (strcmp(&line[1], "cursor") == 0)
+ section = SECTION_CURSOR;
else {
LOG_ERR("%s:%d: invalid section name: %s", path, lineno, &line[1]);
goto err;
@@ -354,6 +385,10 @@ config_load(struct config *conf)
default_bright[7],
},
},
+
+ .cursor = {
+ .style = CURSOR_BLOCK,
+ },
};
char *path = get_config_path();
diff --git a/config.h b/config.h
index 0db93269..85ce15c1 100644
--- a/config.h
+++ b/config.h
@@ -3,6 +3,8 @@
#include <stdint.h>
#include <stdbool.h>
+#include "terminal.h"
+
struct config {
char *term;
char *shell;
@@ -14,6 +16,10 @@ struct config {
uint32_t regular[8];
uint32_t bright[8];
} colors;
+
+ struct {
+ enum cursor_style style;
+ } cursor;
};
bool config_load(struct config *conf);
diff --git a/footrc b/footrc
index b5d0a2f3..8f3a871e 100644
--- a/footrc
+++ b/footrc
@@ -2,6 +2,9 @@
# shell=/usr/bin/zsh
# font=monospace
+[cursor]
+# style=block
+
[colors]
# foreground=dcdccc
# background=111111
diff --git a/main.c b/main.c
index 1690d5c0..f725c9e5 100644
--- a/main.c
+++ b/main.c
@@ -371,6 +371,7 @@ main(int argc, char *const *argv)
conf.colors.bright[7],
},
},
+ .cursor_style = conf.cursor.style,
.selection = {
.start = {-1, -1},
.end = {-1, -1},
diff --git a/terminal.h b/terminal.h
index 0232388c..ad46a44e 100644
--- a/terminal.h
+++ b/terminal.h
@@ -222,6 +222,8 @@ struct font {
struct glyph_cache glyph_cache[256];
};
+enum cursor_style { CURSOR_BLOCK, CURSOR_UNDERLINE, CURSOR_BAR };
+
struct terminal {
pid_t slave;
int ptmx;
@@ -291,7 +293,7 @@ struct terminal {
struct coord cursor;
struct coord saved_cursor;
struct coord alt_saved_cursor;
- enum { CURSOR_BLOCK, CURSOR_UNDERLINE, CURSOR_BAR } cursor_style;
+ enum cursor_style cursor_style;
bool cursor_blinking;
uint32_t input_serial;