From: Ivan Tham Date: Sun, 16 Oct 2016 14:50:08 +0000 (+0800) Subject: fix: pick smarter default for $sidebar_divider_char X-Git-Tag: neomutt-20170113~27 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=3d3bc6fc289afbcd3144a85256a28fc9f4993254;p=neomutt fix: pick smarter default for $sidebar_divider_char If the user hasn't set $sidebar_divider_char, then pick a character for them, whilst respecting $ascii_chars. Closes: #183 --- diff --git a/init.h b/init.h index 4818062c8..4135dbf10 100644 --- a/init.h +++ b/init.h @@ -3115,7 +3115,7 @@ struct option_t MuttVars[] = { ** .pp ** \fBSee also:\fP $$sidebar_short_path, $$sidebar_folder_indent, $$sidebar_indent_string. */ - { "sidebar_divider_char", DT_STR, R_SIDEBAR, UL &SidebarDividerChar, UL "|" }, + { "sidebar_divider_char", DT_STR, R_SIDEBAR, UL &SidebarDividerChar, 0 }, /* ** .pp ** This specifies the characters to be drawn between the sidebar (when diff --git a/sidebar.c b/sidebar.c index e00d19c5a..ad0464423 100644 --- a/sidebar.c +++ b/sidebar.c @@ -55,6 +55,13 @@ static int BotIndex = -1; /* Last mailbox visible in sidebar */ static int select_next (void); +/* The source of the sidebar divider character. */ +enum div_type +{ + SB_DIV_USER, + SB_DIV_ASCII, + SB_DIV_UTF8 +}; enum { @@ -513,39 +520,87 @@ static int prepare_sidebar (int page_size) * @num_cols: Width of the Sidebar * * Draw a divider using characters from the config option "sidebar_divider_char". - * This can be an ASCII or Unicode character. First we calculate this - * characters' width in screen columns, then subtract that from the config - * option "sidebar_width". + * This can be an ASCII or Unicode character. + * We calculate these characters' width in screen columns. * - * Returns: - * -1: Error: bad character, etc - * 0: Error: 0 width character - * n: Success: character occupies n screen columns + * If the user hasn't set $sidebar_divider_char we pick a character for them, + * respecting the value of $ascii_chars. + * + * @return: + * * 0: Empty string + * * n: Character occupies n screen columns */ static int draw_divider (int num_rows, int num_cols) { + if ((num_rows < 1) || (num_rows < 1)) + return 0; + + int i; + int delim_len; + enum div_type altchar = SB_DIV_UTF8; + /* Calculate the width of the delimiter in screen cells */ - int delim_len = mutt_strwidth (SidebarDividerChar); + delim_len = mutt_strwidth (SidebarDividerChar); + if (delim_len < 0) + { + delim_len = 1; /* Bad character */ + } + else if (delim_len == 0) + { + if (SidebarDividerChar) + return 0; /* User has set empty string */ - if (delim_len < 1) - return delim_len; + delim_len = 1; /* Unset variable */ + } + else + { + altchar = SB_DIV_USER; /* User config */ + } + + if (option (OPTASCIICHARS) && (altchar != SB_DIV_ASCII)) + { + /* $ascii_chars overrides Unicode divider chars */ + if (altchar == SB_DIV_UTF8) + { + altchar = SB_DIV_ASCII; + } + else if (SidebarDividerChar) + { + for (i = 0; i < delim_len; i++) + { + if (SidebarDividerChar[i] & ~0x7F) /* high-bit is set */ + { + altchar = SB_DIV_ASCII; + delim_len = 1; + break; + } + } + } + } if (delim_len > num_cols) return 0; SETCOLOR(MT_COLOR_DIVIDER); - int col; - if (option (OPTSIDEBARONRIGHT)) - col = 0; - else - col = SidebarWidth - delim_len; + int col = option (OPTSIDEBARONRIGHT) ? 0 : (SidebarWidth - delim_len); - int i; for (i = 0; i < num_rows; i++) { mutt_window_move (MuttSidebarWindow, i, col); - addstr (NONULL(SidebarDividerChar)); + + switch (altchar) + { + case SB_DIV_USER: + addstr (NONULL(SidebarDividerChar)); + break; + case SB_DIV_ASCII: + addch ('|'); + break; + case SB_DIV_UTF8: + addch (ACS_VLINE); + break; + } } return delim_len; @@ -758,8 +813,6 @@ void mutt_sb_draw (void) int num_cols = MuttSidebarWindow->cols; int div_width = draw_divider (num_rows, num_cols); - if (div_width < 0) - return; BUFFY *b; if (Entries == NULL)