URI:
       tSupport displaying the keyboard layout in the bottom bar - ledit - Text editor (WIP)
  HTML git clone git://lumidify.org/ledit.git (fast, but not encrypted)
  HTML git clone https://lumidify.org/git/ledit.git (encrypted, but very slow)
   DIR Log
   DIR Files
   DIR Refs
   DIR README
   DIR LICENSE
       ---
   DIR commit 1e7b988b795deff7e31c7a5c28a5c669b388fb3a
   DIR parent d8b6431785a46807eca08c11b4c79ac540e0e718
  HTML Author: lumidify <nobody@lumidify.org>
       Date:   Fri,  2 Sep 2022 15:17:07 +0200
       
       Support displaying the keyboard layout in the bottom bar
       
       Diffstat:
         M configparser.c                      |       7 +++++++
         M configparser.h                      |       1 +
         M ledit.c                             |       2 +-
         M leditrc.5                           |       8 +++++---
         M leditrc.example                     |       2 +-
         M theme_config.h                      |       2 +-
         M view.c                              |       4 ++--
         M view.h                              |       3 ++-
         M window.c                            |      26 +++++++++++++++++++++-----
         M window.h                            |       2 +-
       
       10 files changed, 42 insertions(+), 15 deletions(-)
       ---
   DIR diff --git a/configparser.c b/configparser.c
       t@@ -1816,3 +1816,10 @@ config_get_language_index(char *lang, size_t *idx_ret) {
                }
                return 1;
        }
       +
       +char *
       +config_get_language_string(size_t lang_index) {
       +        if (lang_index >= config.num_langs)
       +                return NULL;
       +        return config.langs[lang_index];
       +}
   DIR diff --git a/configparser.h b/configparser.h
       t@@ -77,5 +77,6 @@ command_array *config_get_commands(size_t lang_index);
        int config_get_language_index(char *lang, size_t *idx_ret);
        int config_loadfile(ledit_common *common, char *filename, char **errstr);
        void config_cleanup(ledit_common *common);
       +char *config_get_language_string(size_t lang_index);
        
        #endif
   DIR diff --git a/ledit.c b/ledit.c
       t@@ -461,7 +461,7 @@ ledit_cleanup(void) {
        static void
        redraw(void) {
                for (size_t i = 0; i < buffer->views_num; i++) {
       -                view_redraw(buffer->views[i]);
       +                view_redraw(buffer->views[i], cur_lang);
                }
        }
        
   DIR diff --git a/leditrc.5 b/leditrc.5
       t@@ -140,11 +140,13 @@ The character
        .Ql %
        itself.
        .It %l
       -The current line position of the cursor.
       +The current line index of the cursor (1-indexed).
        .It %b
       -The current byte position of the cursor.
       +The current byte index of the cursor (1-indexed).
        Note that this is really only the raw byte position.
        There currently is no way to get the unicode character position in the format string.
       +.It %k
       +The current keyboard layout used for mapping keys.
        .It %m
        The current mode.
        .It %h
       t@@ -154,7 +156,7 @@ A separator.
        The remaining space is divided equally between all separators.
        .El
        .Pp
       -Default: %l,%b%s%m|%h
       +Default: %k%s%l,%b%s%m|%h
        .It Ar scrollbar-width
        Width of scrollbar in pixels.
        Default: 10
   DIR diff --git a/leditrc.example b/leditrc.example
       t@@ -13,7 +13,7 @@ theme = {
                bar-fg = 000000
                bar-bg = CCCCCC
                bar-cursor = 000000
       -        bar-fmt = "%l,%b%s%m|%h"
       +        bar-fmt = "%k%s%l,%b%s%m|%h"
                scrollbar-width = 10
                scrollbar-step = 20
                scrollbar-bg = CCCCCC
   DIR diff --git a/theme_config.h b/theme_config.h
       t@@ -34,7 +34,7 @@ static const char *BAR_BG = "#CCCCCC";
        /* color of text cursor in line editor */
        static const char *BAR_CURSOR = "#000000";
        /* format of bottom bar */
       -static const char *BAR_FMT = "%l,%b%s%m|%h";
       +static const char *BAR_FMT = "%k%s%l,%b%s%m|%h";
        
        /* FIXME: give in units other than pixels */
        /* scrollbar width in pixels */
   DIR diff --git a/view.c b/view.c
       t@@ -1990,10 +1990,10 @@ view_redraw_text(ledit_view *view) {
        }
        
        void
       -view_redraw(ledit_view *view) {
       +view_redraw(ledit_view *view, size_t lang_index) {
                window_set_format_args(
                    view->window, view->mode, view->buffer->hard_line_based,
       -            view->cur_line + 1, view->cur_index + 1
       +            view->cur_line + 1, view->cur_index + 1, lang_index
                );
                if (view->redraw || view->window->redraw) {
                        window_clear(view->window);
   DIR diff --git a/view.h b/view.h
       t@@ -471,7 +471,8 @@ void view_set_selection(ledit_view *view, size_t line1, size_t byte1, size_t lin
         * This only redraws if the redraw bit of the view or window are set.
         * This should all be set automatically.
         */
       -void view_redraw(ledit_view *view);
       +void view_redraw(ledit_view *view, size_t lang_index);
       +/* FIXME: kind of ugly to pass lang_index here, but the window needs it - maybe store centrally somewhere? */
        
        /*
         * Perform up to num undo steps.
   DIR diff --git a/window.c b/window.c
       t@@ -30,7 +30,8 @@ enum bb_itemtype {
                BB_HLMODE,
                BB_LINE,
                BB_BYTE,
       -        BB_SEP
       +        BB_SEP,
       +        BB_LANG
        };
        
        struct bb_item {
       t@@ -91,7 +92,7 @@ set_item_text(ledit_window *window, ledit_theme *theme, struct bb_item *item, ch
        }
        
        void
       -window_set_format_args(ledit_window *window, ledit_mode mode, int hl_mode, size_t line, size_t byte) {
       +window_set_format_args(ledit_window *window, ledit_mode mode, int hl_mode, size_t line, size_t byte, size_t lang_index) {
                struct bb_item *items = window->bb->items;
                char *text;
                int changed = 0;
       t@@ -149,6 +150,16 @@ window_set_format_args(ledit_window *window, ledit_mode mode, int hl_mode, size_
                                changed = 1;
                                items[i].val.sz = byte;
                                break;
       +                case BB_LANG:
       +                        if (lang_index == items[i].val.sz)
       +                                continue;
       +                        text = config_get_language_string(lang_index);
       +                        if (!text)
       +                                text = "(invalid language)";
       +                        set_item_text(window, theme, &items[i], text);
       +                        changed = 1;
       +                        items[i].val.sz = lang_index;
       +                        break;
                        default:
                                break;
                        }
       t@@ -710,12 +721,17 @@ window_create(ledit_common *common, ledit_clipboard *clipboard) {
                                        case 'l':
                                                item = push_bb_item(window);
                                                item->type = BB_LINE;
       -                                        item->val.sz = 0;
       +                                        item->val.sz = SIZE_MAX;
                                                break;
                                        case 'b':
                                                item = push_bb_item(window);
                                                item->type = BB_BYTE;
       -                                        item->val.sz = 0;
       +                                        item->val.sz = SIZE_MAX;
       +                                        break;
       +                                case 'k':
       +                                        item = push_bb_item(window);
       +                                        item->type = BB_LANG;
       +                                        item->val.sz = SIZE_MAX;
                                                break;
                                        case 'm':
                                                item = push_bb_item(window);
       t@@ -756,7 +772,7 @@ window_create(ledit_common *common, ledit_clipboard *clipboard) {
                }
        end:
                free(fmt);
       -        window_set_format_args(window, NORMAL, 1, 1, 1);
       +        window_set_format_args(window, NORMAL, 1, 1, 1, 0);
        
                return window;
        }
   DIR diff --git a/window.h b/window.h
       t@@ -208,7 +208,7 @@ void window_hide_message(ledit_window *window);
        int window_message_shown(ledit_window *window);
        
        /* FIXME: document */
       -void window_set_format_args(ledit_window *window, ledit_mode mode, int hl_mode, size_t line, size_t byte);
       +void window_set_format_args(ledit_window *window, ledit_mode mode, int hl_mode, size_t line, size_t byte, size_t lang_index);
        
        /*
         * Set the total pixel height of the text.