From 2c6f7adc17832c77b2353338b0c76c8a19f4112b Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Fri, 24 Jul 2020 18:20:26 +0200 Subject: config: add 'show-scrollback-position' option to footrc --- config.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'config.c') diff --git a/config.c b/config.c index 283a72ea..9666da61 100644 --- a/config.c +++ b/config.c @@ -291,6 +291,9 @@ parse_section_main(const char *key, const char *value, struct config *conf, conf->scrollback_lines = lines; } + else if (strcmp(key, "show-scrollback-position") == 0) + conf->show_scrollback_position = str_to_bool(value); + else { LOG_ERR("%s:%u: invalid key: %s", path, lineno, key); return false; @@ -918,6 +921,7 @@ config_load(struct config *conf, const char *conf_path) .startup_mode = STARTUP_WINDOWED, .fonts = tll_init(), .scrollback_lines = 1000, + .show_scrollback_position = true, .colors = { .fg = default_foreground, -- cgit v1.3 From e94506362028b57fa5d2c77f73a152a47cc06768 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Fri, 24 Jul 2020 18:26:44 +0200 Subject: config: rename show-scrollback-position to scrollback-indicator --- config.c | 6 +++--- config.h | 2 +- doc/foot.5.scd | 2 +- render.c | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) (limited to 'config.c') diff --git a/config.c b/config.c index 9666da61..e7ba74b2 100644 --- a/config.c +++ b/config.c @@ -291,8 +291,8 @@ parse_section_main(const char *key, const char *value, struct config *conf, conf->scrollback_lines = lines; } - else if (strcmp(key, "show-scrollback-position") == 0) - conf->show_scrollback_position = str_to_bool(value); + else if (strcmp(key, "scrollback-indicator") == 0) + conf->scrollback_indicator = str_to_bool(value); else { LOG_ERR("%s:%u: invalid key: %s", path, lineno, key); @@ -921,7 +921,7 @@ config_load(struct config *conf, const char *conf_path) .startup_mode = STARTUP_WINDOWED, .fonts = tll_init(), .scrollback_lines = 1000, - .show_scrollback_position = true, + .scrollback_indicator = true, .colors = { .fg = default_foreground, diff --git a/config.h b/config.h index c21e1160..f0f077be 100644 --- a/config.h +++ b/config.h @@ -40,7 +40,7 @@ struct config { tll(struct config_font) fonts; int scrollback_lines; - bool show_scrollback_position; + bool scrollback_indicator; struct { uint32_t fg; diff --git a/doc/foot.5.scd b/doc/foot.5.scd index fd5a5d42..1f71a8d3 100644 --- a/doc/foot.5.scd +++ b/doc/foot.5.scd @@ -68,7 +68,7 @@ in this order: *scrollback* Number of scrollback lines. Default: _1000_. -*show-scrollback-position* +*scrollback-indicator* Boolean. Enables a position indicator when the viewport is not at the bottom of the scrollback history. Default: _yes_. diff --git a/render.c b/render.c index 6611fbb9..d5cdb8dc 100644 --- a/render.c +++ b/render.c @@ -1290,7 +1290,7 @@ render_csd(struct terminal *term) static void render_scrollback_position(struct terminal *term) { - if (!term->conf->show_scrollback_position) + if (!term->conf->scrollback_indicator) return; /* Find absolute row number of the scrollback start */ -- cgit v1.3 From 5b868fd0c94af61e62a28a80a4bd337f9cbb25b4 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Fri, 24 Jul 2020 18:34:19 +0200 Subject: config: add 'scrollback-indicator-format' option The value of this option must be either 'percent', or 'line', and determines _how_ we render the scrollback indicator. --- config.c | 14 ++++++++++++++ config.h | 1 + doc/foot.5.scd | 5 +++++ 3 files changed, 20 insertions(+) (limited to 'config.c') diff --git a/config.c b/config.c index e7ba74b2..332fd11a 100644 --- a/config.c +++ b/config.c @@ -294,6 +294,19 @@ parse_section_main(const char *key, const char *value, struct config *conf, else if (strcmp(key, "scrollback-indicator") == 0) conf->scrollback_indicator = str_to_bool(value); + else if (strcmp(key, "scrollback-indicator-format") == 0) { + if (strcmp(value, "percent") == 0) + conf->scrollback_indicator_format = SCROLLBACK_INDICATOR_PERCENT; + else if (strcmp(value, "line") == 0) + conf->scrollback_indicator_format = SCROLLBACK_INDICATOR_LINENO; + else { + LOG_ERR("%s:%d: 'scrollback-indicator-format must be one " + "of 'percent' or 'line', not %s", + path, lineno, value); + return false; + } + } + else { LOG_ERR("%s:%u: invalid key: %s", path, lineno, key); return false; @@ -922,6 +935,7 @@ config_load(struct config *conf, const char *conf_path) .fonts = tll_init(), .scrollback_lines = 1000, .scrollback_indicator = true, + .scrollback_indicator_format = SCROLLBACK_INDICATOR_PERCENT, .colors = { .fg = default_foreground, diff --git a/config.h b/config.h index f0f077be..109eecb8 100644 --- a/config.h +++ b/config.h @@ -41,6 +41,7 @@ struct config { int scrollback_lines; bool scrollback_indicator; + enum {SCROLLBACK_INDICATOR_PERCENT, SCROLLBACK_INDICATOR_LINENO} scrollback_indicator_format; struct { uint32_t fg; diff --git a/doc/foot.5.scd b/doc/foot.5.scd index 1f71a8d3..485886fa 100644 --- a/doc/foot.5.scd +++ b/doc/foot.5.scd @@ -72,6 +72,11 @@ in this order: Boolean. Enables a position indicator when the viewport is not at the bottom of the scrollback history. Default: _yes_. +*scrollback-indicator-format* + Which format to use when displaying the scrollback position + indicator. Either _percent_ or _line_. This option is ignored if + *scrollback-indicator=no*. Default: _percent_. + *workers* Number of threads to use for rendering. Set to 0 to disable multithreading. Default: the number of available logical CPUs -- cgit v1.3 From c4679e474e0546ee8dad6e122c226ece85bdb134 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Sat, 25 Jul 2020 14:31:45 +0200 Subject: config: rename scrollback-indicator to scrollback-indicator-style And turn it from a boolean to an enum. It can be set to: * `none` - disables the indicator * `static` - always rendered near the top of the window * `moving` - position reflects the scrollback position --- config.c | 37 ++++++++++++++++++++++++++----------- config.h | 19 ++++++++++++++++--- doc/foot.5.scd | 12 ++++++++---- footrc | 2 ++ render.c | 2 +- terminal.c | 2 +- 6 files changed, 54 insertions(+), 20 deletions(-) (limited to 'config.c') diff --git a/config.c b/config.c index 332fd11a..7c4c9d9f 100644 --- a/config.c +++ b/config.c @@ -288,21 +288,33 @@ parse_section_main(const char *key, const char *value, struct config *conf, LOG_ERR("%s:%d: expected an integer: %s", path, lineno, value); return false; } - conf->scrollback_lines = lines; + conf->scrollback.lines = lines; } - else if (strcmp(key, "scrollback-indicator") == 0) - conf->scrollback_indicator = str_to_bool(value); + else if (strcmp(key, "scrollback-indicator") == 0) { + if (strcmp(value, "none") == 0) + conf->scrollback.indicator.style = SCROLLBACK_INDICATOR_STYLE_NONE; + else if (strcmp(value, "static") == 0) + conf->scrollback.indicator.style = SCROLLBACK_INDICATOR_STYLE_STATIC; + else if (strcmp(value, "moving") == 0) + conf->scrollback.indicator.style = SCROLLBACK_INDICATOR_STYLE_MOVING; + else { + LOG_ERR("%s:%d: scrollback-indicator-style must be one of " + "'none', 'static' or 'moving'", + path, lineno); + return false; + } + } else if (strcmp(key, "scrollback-indicator-format") == 0) { if (strcmp(value, "percent") == 0) - conf->scrollback_indicator_format = SCROLLBACK_INDICATOR_PERCENT; + conf->scrollback.indicator.format = SCROLLBACK_INDICATOR_FORMAT_PERCENT; else if (strcmp(value, "line") == 0) - conf->scrollback_indicator_format = SCROLLBACK_INDICATOR_LINENO; + conf->scrollback.indicator.format = SCROLLBACK_INDICATOR_FORMAT_LINENO; else { LOG_ERR("%s:%d: 'scrollback-indicator-format must be one " - "of 'percent' or 'line', not %s", - path, lineno, value); + "of 'percent' or 'line'", + path, lineno); return false; } } @@ -933,10 +945,13 @@ config_load(struct config *conf, const char *conf_path) .pad_y = 2, .startup_mode = STARTUP_WINDOWED, .fonts = tll_init(), - .scrollback_lines = 1000, - .scrollback_indicator = true, - .scrollback_indicator_format = SCROLLBACK_INDICATOR_PERCENT, - + .scrollback = { + .lines = 1000, + .indicator = { + .style = SCROLLBACK_INDICATOR_STYLE_MOVING, + .format = SCROLLBACK_INDICATOR_FORMAT_PERCENT, + }, + }, .colors = { .fg = default_foreground, .bg = default_background, diff --git a/config.h b/config.h index 109eecb8..9ff83b77 100644 --- a/config.h +++ b/config.h @@ -39,9 +39,22 @@ struct config { tll(struct config_font) fonts; - int scrollback_lines; - bool scrollback_indicator; - enum {SCROLLBACK_INDICATOR_PERCENT, SCROLLBACK_INDICATOR_LINENO} scrollback_indicator_format; + struct { + int lines; + + struct { + enum { + SCROLLBACK_INDICATOR_STYLE_NONE, + SCROLLBACK_INDICATOR_STYLE_STATIC, + SCROLLBACK_INDICATOR_STYLE_MOVING + } style; + + enum { + SCROLLBACK_INDICATOR_FORMAT_PERCENT, + SCROLLBACK_INDICATOR_FORMAT_LINENO + } format; + } indicator; + } scrollback; struct { uint32_t fg; diff --git a/doc/foot.5.scd b/doc/foot.5.scd index 485886fa..9813741c 100644 --- a/doc/foot.5.scd +++ b/doc/foot.5.scd @@ -68,14 +68,18 @@ in this order: *scrollback* Number of scrollback lines. Default: _1000_. -*scrollback-indicator* - Boolean. Enables a position indicator when the viewport is not at - the bottom of the scrollback history. Default: _yes_. +*scrollback-indicator-style* + Configures the style of the scrollback position indicator. One of + *none*, *static* or *moving*. *none* disables the indicator + completely. *static* always renders the indicator near the top at + the window, and *moving* renders the indicator at the position + corresponding to the current scrollback position. Default: + _moving_. *scrollback-indicator-format* Which format to use when displaying the scrollback position indicator. Either _percent_ or _line_. This option is ignored if - *scrollback-indicator=no*. Default: _percent_. + *scrollback-indicator-style=none*. Default: _percent_. *workers* Number of threads to use for rendering. Set to 0 to disable diff --git a/footrc b/footrc index 624c688b..911ebb28 100644 --- a/footrc +++ b/footrc @@ -2,6 +2,8 @@ # font=monospace # scrollback=1000 +# scrollback-indicator-style=moving +# scrollback-indicator-format=percent # geometry=700x500 # pad=2x2 # initial-window-mode=windowed diff --git a/render.c b/render.c index d5cdb8dc..bab87cf4 100644 --- a/render.c +++ b/render.c @@ -1290,7 +1290,7 @@ render_csd(struct terminal *term) static void render_scrollback_position(struct terminal *term) { - if (!term->conf->scrollback_indicator) + if (term->conf->scrollback.indicator.style == SCROLLBACK_INDICATOR_STYLE_NONE) return; /* Find absolute row number of the scrollback start */ diff --git a/terminal.c b/terminal.c index 86672f06..1e355fe3 100644 --- a/terminal.c +++ b/terminal.c @@ -909,7 +909,7 @@ term_init(const struct config *conf, struct fdm *fdm, struct reaper *reaper, .tab_stops = tll_init(), .wl = wayl, .render = { - .scrollback_lines = conf->scrollback_lines, + .scrollback_lines = conf->scrollback.lines, .app_sync_updates.timer_fd = app_sync_updates_fd, .workers = { .count = conf->render_worker_count, -- cgit v1.3 From e3be2cbd6f62baaa81dcae62b24731668ac764b5 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Sat, 25 Jul 2020 14:38:36 +0200 Subject: config: rename scrollback-indicator-style value 'moving' to 'relative' --- config.c | 4 ++-- config.h | 2 +- doc/foot.5.scd | 6 +++--- footrc | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) (limited to 'config.c') diff --git a/config.c b/config.c index 7c4c9d9f..59b824b8 100644 --- a/config.c +++ b/config.c @@ -297,7 +297,7 @@ parse_section_main(const char *key, const char *value, struct config *conf, else if (strcmp(value, "static") == 0) conf->scrollback.indicator.style = SCROLLBACK_INDICATOR_STYLE_STATIC; else if (strcmp(value, "moving") == 0) - conf->scrollback.indicator.style = SCROLLBACK_INDICATOR_STYLE_MOVING; + conf->scrollback.indicator.style = SCROLLBACK_INDICATOR_STYLE_RELATIVE; else { LOG_ERR("%s:%d: scrollback-indicator-style must be one of " "'none', 'static' or 'moving'", @@ -948,7 +948,7 @@ config_load(struct config *conf, const char *conf_path) .scrollback = { .lines = 1000, .indicator = { - .style = SCROLLBACK_INDICATOR_STYLE_MOVING, + .style = SCROLLBACK_INDICATOR_STYLE_RELATIVE, .format = SCROLLBACK_INDICATOR_FORMAT_PERCENT, }, }, diff --git a/config.h b/config.h index 9ff83b77..030bfc88 100644 --- a/config.h +++ b/config.h @@ -46,7 +46,7 @@ struct config { enum { SCROLLBACK_INDICATOR_STYLE_NONE, SCROLLBACK_INDICATOR_STYLE_STATIC, - SCROLLBACK_INDICATOR_STYLE_MOVING + SCROLLBACK_INDICATOR_STYLE_RELATIVE } style; enum { diff --git a/doc/foot.5.scd b/doc/foot.5.scd index 9813741c..496042b3 100644 --- a/doc/foot.5.scd +++ b/doc/foot.5.scd @@ -70,11 +70,11 @@ in this order: *scrollback-indicator-style* Configures the style of the scrollback position indicator. One of - *none*, *static* or *moving*. *none* disables the indicator + *none*, *static* or *relative*. *none* disables the indicator completely. *static* always renders the indicator near the top at - the window, and *moving* renders the indicator at the position + the window, and *relative* renders the indicator at the position corresponding to the current scrollback position. Default: - _moving_. + _relative_. *scrollback-indicator-format* Which format to use when displaying the scrollback position diff --git a/footrc b/footrc index 911ebb28..c2ee52e7 100644 --- a/footrc +++ b/footrc @@ -2,7 +2,7 @@ # font=monospace # scrollback=1000 -# scrollback-indicator-style=moving +# scrollback-indicator-style=relative # scrollback-indicator-format=percent # geometry=700x500 # pad=2x2 -- cgit v1.3 From 9edd71a741a3aeff89fe04f51582214d69bbde5d Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Sat, 25 Jul 2020 14:40:46 +0200 Subject: config: rename scrollback-indicator-style value 'static' to 'fixed' --- config.c | 6 +++--- config.h | 2 +- doc/foot.5.scd | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) (limited to 'config.c') diff --git a/config.c b/config.c index 59b824b8..b6af1d26 100644 --- a/config.c +++ b/config.c @@ -294,9 +294,9 @@ parse_section_main(const char *key, const char *value, struct config *conf, else if (strcmp(key, "scrollback-indicator") == 0) { if (strcmp(value, "none") == 0) conf->scrollback.indicator.style = SCROLLBACK_INDICATOR_STYLE_NONE; - else if (strcmp(value, "static") == 0) - conf->scrollback.indicator.style = SCROLLBACK_INDICATOR_STYLE_STATIC; - else if (strcmp(value, "moving") == 0) + else if (strcmp(value, "fixed") == 0) + conf->scrollback.indicator.style = SCROLLBACK_INDICATOR_STYLE_FIXED; + else if (strcmp(value, "relative") == 0) conf->scrollback.indicator.style = SCROLLBACK_INDICATOR_STYLE_RELATIVE; else { LOG_ERR("%s:%d: scrollback-indicator-style must be one of " diff --git a/config.h b/config.h index 030bfc88..57701606 100644 --- a/config.h +++ b/config.h @@ -45,7 +45,7 @@ struct config { struct { enum { SCROLLBACK_INDICATOR_STYLE_NONE, - SCROLLBACK_INDICATOR_STYLE_STATIC, + SCROLLBACK_INDICATOR_STYLE_FIXED, SCROLLBACK_INDICATOR_STYLE_RELATIVE } style; diff --git a/doc/foot.5.scd b/doc/foot.5.scd index 496042b3..573eb313 100644 --- a/doc/foot.5.scd +++ b/doc/foot.5.scd @@ -70,8 +70,8 @@ in this order: *scrollback-indicator-style* Configures the style of the scrollback position indicator. One of - *none*, *static* or *relative*. *none* disables the indicator - completely. *static* always renders the indicator near the top at + *none*, *fixed* or *relative*. *none* disables the indicator + completely. *fixed* always renders the indicator near the top at the window, and *relative* renders the indicator at the position corresponding to the current scrollback position. Default: _relative_. -- cgit v1.3 From be7d0a5615fafc81a0f88c45bc2e670339960e97 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Sun, 26 Jul 2020 09:43:58 +0200 Subject: config: fix key check for 'scrollback-indicator-style' --- config.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'config.c') diff --git a/config.c b/config.c index b6af1d26..18c88228 100644 --- a/config.c +++ b/config.c @@ -291,7 +291,7 @@ parse_section_main(const char *key, const char *value, struct config *conf, conf->scrollback.lines = lines; } - else if (strcmp(key, "scrollback-indicator") == 0) { + else if (strcmp(key, "scrollback-indicator-style") == 0) { if (strcmp(value, "none") == 0) conf->scrollback.indicator.style = SCROLLBACK_INDICATOR_STYLE_NONE; else if (strcmp(value, "fixed") == 0) -- cgit v1.3 From d180de00a9dab2ea2a8dbd9b48ab0e98f5595b33 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Sun, 26 Jul 2020 09:44:16 +0200 Subject: config: fix error message for 'scrollback-indicator-style' --- config.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'config.c') diff --git a/config.c b/config.c index 18c88228..f87eb67f 100644 --- a/config.c +++ b/config.c @@ -300,7 +300,7 @@ parse_section_main(const char *key, const char *value, struct config *conf, conf->scrollback.indicator.style = SCROLLBACK_INDICATOR_STYLE_RELATIVE; else { LOG_ERR("%s:%d: scrollback-indicator-style must be one of " - "'none', 'static' or 'moving'", + "'none', 'fixed' or 'moving'", path, lineno); return false; } -- cgit v1.3 From 50d116dcb9183047899d93095117632c669d5f03 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Sun, 26 Jul 2020 11:39:02 +0200 Subject: config: scrollback-indicator-format: percent -> percentage --- config.c | 14 ++++++++------ config.h | 2 +- doc/foot.5.scd | 4 ++-- footrc | 2 +- render.c | 2 +- 5 files changed, 13 insertions(+), 11 deletions(-) (limited to 'config.c') diff --git a/config.c b/config.c index f87eb67f..2b989d62 100644 --- a/config.c +++ b/config.c @@ -307,11 +307,13 @@ parse_section_main(const char *key, const char *value, struct config *conf, } else if (strcmp(key, "scrollback-indicator-format") == 0) { - if (strcmp(value, "percent") == 0) - conf->scrollback.indicator.format = SCROLLBACK_INDICATOR_FORMAT_PERCENT; - else if (strcmp(value, "line") == 0) - conf->scrollback.indicator.format = SCROLLBACK_INDICATOR_FORMAT_LINENO; - else { + if (strcmp(value, "percent") == 0) { + conf->scrollback.indicator.format + = SCROLLBACK_INDICATOR_FORMAT_PERCENTAGE; + } else if (strcmp(value, "line") == 0) { + conf->scrollback.indicator.format + = SCROLLBACK_INDICATOR_FORMAT_LINENO; + } else { LOG_ERR("%s:%d: 'scrollback-indicator-format must be one " "of 'percent' or 'line'", path, lineno); @@ -949,7 +951,7 @@ config_load(struct config *conf, const char *conf_path) .lines = 1000, .indicator = { .style = SCROLLBACK_INDICATOR_STYLE_RELATIVE, - .format = SCROLLBACK_INDICATOR_FORMAT_PERCENT, + .format = SCROLLBACK_INDICATOR_FORMAT_PERCENTAGE, }, }, .colors = { diff --git a/config.h b/config.h index 57701606..456019b5 100644 --- a/config.h +++ b/config.h @@ -50,7 +50,7 @@ struct config { } style; enum { - SCROLLBACK_INDICATOR_FORMAT_PERCENT, + SCROLLBACK_INDICATOR_FORMAT_PERCENTAGE, SCROLLBACK_INDICATOR_FORMAT_LINENO } format; } indicator; diff --git a/doc/foot.5.scd b/doc/foot.5.scd index 573eb313..c348391b 100644 --- a/doc/foot.5.scd +++ b/doc/foot.5.scd @@ -78,8 +78,8 @@ in this order: *scrollback-indicator-format* Which format to use when displaying the scrollback position - indicator. Either _percent_ or _line_. This option is ignored if - *scrollback-indicator-style=none*. Default: _percent_. + indicator. Either _percentage_ or _line_. This option is ignored + if *scrollback-indicator-style=none*. Default: _percentage_. *workers* Number of threads to use for rendering. Set to 0 to disable diff --git a/footrc b/footrc index c2ee52e7..3ab2e6c1 100644 --- a/footrc +++ b/footrc @@ -3,7 +3,7 @@ # font=monospace # scrollback=1000 # scrollback-indicator-style=relative -# scrollback-indicator-format=percent +# scrollback-indicator-format=percentage # geometry=700x500 # pad=2x2 # initial-window-mode=windowed diff --git a/render.c b/render.c index 55213408..6e8a56d4 100644 --- a/render.c +++ b/render.c @@ -1363,7 +1363,7 @@ render_scrollback_position(struct terminal *term) /* *What* to render */ switch (term->conf->scrollback.indicator.format) { - case SCROLLBACK_INDICATOR_FORMAT_PERCENT: + case SCROLLBACK_INDICATOR_FORMAT_PERCENTAGE: swprintf(text, sizeof(text) / sizeof(text[0]), L"%u%%", percent); cell_count = 3; break; -- cgit v1.3 From 718e5b4a7787cc9d68b9c422b8b6703f3b7c5c26 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Mon, 27 Jul 2020 20:02:51 +0200 Subject: config: rename scrollback-indicator-style to scrollback-indicator-position --- CHANGELOG.md | 2 +- config.c | 12 ++++++------ config.h | 8 ++++---- doc/foot.5.scd | 4 ++-- footrc | 2 +- render.c | 10 +++++----- 6 files changed, 19 insertions(+), 19 deletions(-) (limited to 'config.c') diff --git a/CHANGELOG.md b/CHANGELOG.md index 35669232..dc6fc301 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,7 +20,7 @@ * Mouse cursor is now always a `left_ptr` when inside the margins, to indicate it is not possible to start a selection. * Scrollback position indicator. This feature is optional and - controlled by the **scrollback-indicator-style** and + controlled by the **scrollback-indicator-position** and **scrollback-indicator-format** options in `footrc` (https://codeberg.org/dnkl/foot/issues/42). diff --git a/config.c b/config.c index 2b989d62..169b2b40 100644 --- a/config.c +++ b/config.c @@ -291,15 +291,15 @@ parse_section_main(const char *key, const char *value, struct config *conf, conf->scrollback.lines = lines; } - else if (strcmp(key, "scrollback-indicator-style") == 0) { + else if (strcmp(key, "scrollback-indicator-position") == 0) { if (strcmp(value, "none") == 0) - conf->scrollback.indicator.style = SCROLLBACK_INDICATOR_STYLE_NONE; + conf->scrollback.indicator.position = SCROLLBACK_INDICATOR_POSITION_NONE; else if (strcmp(value, "fixed") == 0) - conf->scrollback.indicator.style = SCROLLBACK_INDICATOR_STYLE_FIXED; + conf->scrollback.indicator.position = SCROLLBACK_INDICATOR_POSITION_FIXED; else if (strcmp(value, "relative") == 0) - conf->scrollback.indicator.style = SCROLLBACK_INDICATOR_STYLE_RELATIVE; + conf->scrollback.indicator.position = SCROLLBACK_INDICATOR_POSITION_RELATIVE; else { - LOG_ERR("%s:%d: scrollback-indicator-style must be one of " + LOG_ERR("%s:%d: scrollback-indicator-position must be one of " "'none', 'fixed' or 'moving'", path, lineno); return false; @@ -950,7 +950,7 @@ config_load(struct config *conf, const char *conf_path) .scrollback = { .lines = 1000, .indicator = { - .style = SCROLLBACK_INDICATOR_STYLE_RELATIVE, + .position = SCROLLBACK_INDICATOR_POSITION_RELATIVE, .format = SCROLLBACK_INDICATOR_FORMAT_PERCENTAGE, }, }, diff --git a/config.h b/config.h index 456019b5..eee01e65 100644 --- a/config.h +++ b/config.h @@ -44,10 +44,10 @@ struct config { struct { enum { - SCROLLBACK_INDICATOR_STYLE_NONE, - SCROLLBACK_INDICATOR_STYLE_FIXED, - SCROLLBACK_INDICATOR_STYLE_RELATIVE - } style; + SCROLLBACK_INDICATOR_POSITION_NONE, + SCROLLBACK_INDICATOR_POSITION_FIXED, + SCROLLBACK_INDICATOR_POSITION_RELATIVE + } position; enum { SCROLLBACK_INDICATOR_FORMAT_PERCENTAGE, diff --git a/doc/foot.5.scd b/doc/foot.5.scd index 188e8edf..949e2751 100644 --- a/doc/foot.5.scd +++ b/doc/foot.5.scd @@ -68,7 +68,7 @@ in this order: *scrollback* Number of scrollback lines. Default: _1000_. -*scrollback-indicator-style* +*scrollback-indicator-position* Configures the style of the scrollback position indicator. One of *none*, *fixed* or *relative*. *none* disables the indicator completely. *fixed* always renders the indicator near the top at @@ -79,7 +79,7 @@ in this order: *scrollback-indicator-format* Which format to use when displaying the scrollback position indicator. Either _percentage_ or _line_. This option is ignored - if *scrollback-indicator-style=none*. Default: _percentage_. + if *scrollback-indicator-position=none*. Default: _percentage_. *workers* Number of threads to use for rendering. Set to 0 to disable diff --git a/footrc b/footrc index 117b73fe..900ce149 100644 --- a/footrc +++ b/footrc @@ -2,7 +2,7 @@ # font=monospace # scrollback=1000 -# scrollback-indicator-style=relative +# scrollback-indicator-position=relative # scrollback-indicator-format=percentage # geometry=700x500 # pad=2x2 diff --git a/render.c b/render.c index 59601c05..195839fb 100644 --- a/render.c +++ b/render.c @@ -1290,7 +1290,7 @@ render_csd(struct terminal *term) static void render_scrollback_position(struct terminal *term) { - if (term->conf->scrollback.indicator.style == SCROLLBACK_INDICATOR_STYLE_NONE) + if (term->conf->scrollback.indicator.position == SCROLLBACK_INDICATOR_POSITION_NONE) return; struct wayland *wayl = term->wl; @@ -1414,16 +1414,16 @@ render_scrollback_position(struct terminal *term) /* *Where* to render - parent relative coordinates */ int surf_top = 0; - switch (term->conf->scrollback.indicator.style) { - case SCROLLBACK_INDICATOR_STYLE_NONE: + switch (term->conf->scrollback.indicator.position) { + case SCROLLBACK_INDICATOR_POSITION_NONE: assert(false); return; - case SCROLLBACK_INDICATOR_STYLE_FIXED: + case SCROLLBACK_INDICATOR_POSITION_FIXED: surf_top = term->cell_height - margin; break; - case SCROLLBACK_INDICATOR_STYLE_RELATIVE: { + case SCROLLBACK_INDICATOR_POSITION_RELATIVE: { int lines = term->rows - 3; /* Avoid using first and two last rows */ assert(lines > 0); -- cgit v1.3 From eadb5a4a88243098ddc8348b42c93be0553777dc Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Tue, 28 Jul 2020 19:55:09 +0200 Subject: config: handle trailing comments and empty values --- CHANGELOG.md | 1 + config.c | 48 ++++++++++++++++++++++++++++++++---------------- 2 files changed, 33 insertions(+), 16 deletions(-) (limited to 'config.c') diff --git a/CHANGELOG.md b/CHANGELOG.md index 57c01110..9c98fdba 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -29,6 +29,7 @@ ### Fixed * Crash when starting a selection inside the margins. +* Handle trailing comments in `footrc` ### Security diff --git a/config.c b/config.c index 169b2b40..8da9c258 100644 --- a/config.c +++ b/config.c @@ -822,7 +822,7 @@ parse_config_file(FILE *f, struct config *conf, const char *path) break; } - /* Strip whitespace */ + /* Strip leading whitespace */ char *line = _line; { while (isspace(*line)) @@ -839,11 +839,15 @@ parse_config_file(FILE *f, struct config *conf, const char *path) if (line[0] == '\0' || line[0] == '#') continue; + /* Split up into key/value pair + trailing comment */ + char *key_value = strtok(line, "#"); + char *comment __attribute__((unused)) = strtok(NULL, "\n"); + /* Check for new section */ - if (line[0] == '[') { - char *end = strchr(line, ']'); + if (key_value[0] == '[') { + char *end = strchr(key_value, ']'); if (end == NULL) { - LOG_ERR("%s:%d: syntax error: %s", path, lineno, line); + LOG_ERR("%s:%d: syntax error: %s", path, lineno, key_value); goto err; } @@ -851,13 +855,13 @@ parse_config_file(FILE *f, struct config *conf, const char *path) section = SECTION_COUNT; for (enum section i = 0; i < SECTION_COUNT; i++) { - if (strcmp(&line[1], section_info[i].name) == 0) { + if (strcmp(&key_value[1], section_info[i].name) == 0) { section = i; } } if (section == SECTION_COUNT) { - LOG_ERR("%s:%d: invalid section name: %s", path, lineno, &line[1]); + LOG_ERR("%s:%d: invalid section name: %s", path, lineno, &key_value[1]); goto err; } @@ -865,11 +869,20 @@ parse_config_file(FILE *f, struct config *conf, const char *path) continue; } - char *key = strtok(line, "="); + char *key = strtok(key_value, "="); + if (key == NULL) { + LOG_ERR("%s:%d: syntax error: no key specified", path, lineno); + goto err; + } + char *value = strtok(NULL, "\n"); + if (value == NULL) { + /* Empty value, i.e. "key=" */ + value = key + strlen(key); + } /* Strip trailing whitespace from key (leading stripped earlier) */ - { + if (key[0] != '\0') { assert(!isspace(*key)); char *end = key + strlen(key) - 1; @@ -880,25 +893,28 @@ parse_config_file(FILE *f, struct config *conf, const char *path) if (value == NULL) { if (key != NULL && strlen(key) > 0 && key[0] != '#') { - LOG_ERR("%s:%d: syntax error: %s", path, lineno, line); + LOG_ERR("%s:%d: syntax error: %s", path, lineno, key_value); goto err; } continue; } - /* Strip leading whitespace from value (trailing stripped earlier) */ + /* Strip leading+trailing whitespace from value */ { while (isspace(*value)) value++; - assert(!isspace(*(value + strlen(value) - 1))); - } - if (key[0] == '#') - continue; + if (value[0] != '\0') { + char *end = value + strlen(value) - 1; + while (isspace(*end)) + end--; + *(end + 1) = '\0'; + } + } - LOG_DBG("section=%s, key='%s', value='%s'", - section_names[section], key, value); + LOG_DBG("section=%s, key='%s', value='%s', comment='%s'", + section_info[section].name, key, value, comment); parser_fun_t section_parser = section_info[section].fun; assert(section_parser != NULL); -- cgit v1.3 From 2882fbb537f53feb33d407c3aac103d0189af725 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Tue, 28 Jul 2020 19:56:53 +0200 Subject: config: add free-form text variant to 'scrollback-indicator-format' And make the empty string the new default. --- config.c | 19 ++++++++++++++----- config.h | 5 ++++- doc/footrc.5.scd | 5 +++-- footrc | 2 +- render.c | 12 +++++++++--- 5 files changed, 31 insertions(+), 12 deletions(-) (limited to 'config.c') diff --git a/config.c b/config.c index 8da9c258..19e2a2ca 100644 --- a/config.c +++ b/config.c @@ -314,10 +314,17 @@ parse_section_main(const char *key, const char *value, struct config *conf, conf->scrollback.indicator.format = SCROLLBACK_INDICATOR_FORMAT_LINENO; } else { - LOG_ERR("%s:%d: 'scrollback-indicator-format must be one " - "of 'percent' or 'line'", - path, lineno); - return false; + free(conf->scrollback.indicator.text); + conf->scrollback.indicator.text = NULL; + + size_t len = mbstowcs(NULL, value, -1); + if (len < 0) { + LOG_ERRNO("%s:%d: invalid scrollback-indicator-format value", path, lineno); + return false; + } + + conf->scrollback.indicator.text = calloc(len + 1, sizeof(wchar_t)); + mbstowcs(conf->scrollback.indicator.text, value, len); } } @@ -967,7 +974,8 @@ config_load(struct config *conf, const char *conf_path) .lines = 1000, .indicator = { .position = SCROLLBACK_INDICATOR_POSITION_RELATIVE, - .format = SCROLLBACK_INDICATOR_FORMAT_PERCENTAGE, + .format = SCROLLBACK_INDICATOR_FORMAT_TEXT, + .text = wcsdup(L""), }, }, .colors = { @@ -1119,6 +1127,7 @@ config_free(struct config conf) free(conf.shell); free(conf.title); free(conf.app_id); + free(conf.scrollback.indicator.text); tll_foreach(conf.fonts, it) config_font_destroy(&it->item); tll_free(conf.fonts); diff --git a/config.h b/config.h index eee01e65..9de282a0 100644 --- a/config.h +++ b/config.h @@ -51,8 +51,11 @@ struct config { enum { SCROLLBACK_INDICATOR_FORMAT_PERCENTAGE, - SCROLLBACK_INDICATOR_FORMAT_LINENO + SCROLLBACK_INDICATOR_FORMAT_LINENO, + SCROLLBACK_INDICATOR_FORMAT_TEXT, } format; + + wchar_t *text; } indicator; } scrollback; diff --git a/doc/footrc.5.scd b/doc/footrc.5.scd index f23d7a36..6bba164f 100644 --- a/doc/footrc.5.scd +++ b/doc/footrc.5.scd @@ -78,8 +78,9 @@ in this order: *scrollback-indicator-format* Which format to use when displaying the scrollback position - indicator. Either _percentage_ or _line_. This option is ignored - if *scrollback-indicator-position=none*. Default: _percentage_. + indicator. Either _percentage_, _line_, or a custom fixed + string. This option is ignored if + *scrollback-indicator-position=none*. Default: _empty string_. *workers* Number of threads to use for rendering. Set to 0 to disable diff --git a/footrc b/footrc index 900ce149..30eeee39 100644 --- a/footrc +++ b/footrc @@ -3,7 +3,7 @@ # font=monospace # scrollback=1000 # scrollback-indicator-position=relative -# scrollback-indicator-format=percentage +# scrollback-indicator-format= # geometry=700x500 # pad=2x2 # initial-window-mode=windowed diff --git a/render.c b/render.c index 195839fb..92b546ed 100644 --- a/render.c +++ b/render.c @@ -1358,20 +1358,26 @@ render_scrollback_position(struct terminal *term) ? 1.0 : (double)rebased_view / term->grid->num_rows; - wchar_t text[64]; + wchar_t _text[64]; + const wchar_t *text = _text; int cell_count; /* *What* to render */ switch (term->conf->scrollback.indicator.format) { case SCROLLBACK_INDICATOR_FORMAT_PERCENTAGE: - swprintf(text, sizeof(text) / sizeof(text[0]), L"%u%%", (int)(100 * percent)); + swprintf(_text, sizeof(_text) / sizeof(_text[0]), L"%u%%", (int)(100 * percent)); cell_count = 3; break; case SCROLLBACK_INDICATOR_FORMAT_LINENO: - swprintf(text, sizeof(text) / sizeof(text[0]), L"%d", rebased_view + 1); + swprintf(_text, sizeof(_text) / sizeof(_text[0]), L"%d", rebased_view + 1); cell_count = 1 + (int)log10(term->grid->num_rows); break; + + case SCROLLBACK_INDICATOR_FORMAT_TEXT: + text = term->conf->scrollback.indicator.text; + cell_count = wcslen(text); + break; } const int scale = term->scale; -- cgit v1.3 From 47d9b947f0a7ae0eb3d87e291c06f1a66784a3a2 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Tue, 28 Jul 2020 19:57:26 +0200 Subject: config: fix check for scrollback-indicator-format=percentage --- config.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'config.c') diff --git a/config.c b/config.c index 19e2a2ca..5a1bc282 100644 --- a/config.c +++ b/config.c @@ -307,7 +307,7 @@ parse_section_main(const char *key, const char *value, struct config *conf, } else if (strcmp(key, "scrollback-indicator-format") == 0) { - if (strcmp(value, "percent") == 0) { + if (strcmp(value, "percentage") == 0) { conf->scrollback.indicator.format = SCROLLBACK_INDICATOR_FORMAT_PERCENTAGE; } else if (strcmp(value, "line") == 0) { -- cgit v1.3