NeoMutt  2024-11-14-138-ge5ca67
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
window.c File Reference

Sidebar Window. More...

#include "config.h"
#include <stdbool.h>
#include <stdio.h>
#include <string.h>
#include "private.h"
#include "mutt/lib.h"
#include "config/lib.h"
#include "email/lib.h"
#include "core/lib.h"
#include "gui/lib.h"
#include "color/lib.h"
#include "expando/lib.h"
#include "index/lib.h"
#include "expando.h"
+ Include dependency graph for window.c:

Go to the source code of this file.

Functions

static int imap_is_prefix (const char *folder, const char *mbox)
 Check if folder matches the beginning of mbox.
 
static const char * abbrev_folder (const char *mbox, const char *folder, enum MailboxType type)
 Abbreviate a Mailbox path using a folder.
 
static const char * abbrev_url (const char *mbox, enum MailboxType type)
 Abbreviate a url-style Mailbox path.
 
static const struct AttrColorcalc_color (const struct Mailbox *m, bool current, bool highlight)
 Calculate the colour of a Sidebar row.
 
static int calc_path_depth (const char *mbox, const char *delims, const char **last_part)
 Calculate the depth of a Mailbox path.
 
static void make_sidebar_entry (char *buf, size_t buflen, int width, struct SbEntry *sbe, struct IndexSharedData *shared)
 Turn mailbox data into a sidebar string.
 
static void update_entries_visibility (struct SidebarWindowData *wdata)
 Should a SbEntry be displayed in the sidebar?
 
static bool prepare_sidebar (struct SidebarWindowData *wdata, int page_size)
 Prepare the list of SbEntry's for the sidebar display.
 
int sb_recalc (struct MuttWindow *win)
 Recalculate the Sidebar display - Implements MuttWindow::recalc() -.
 
static int draw_divider (struct SidebarWindowData *wdata, struct MuttWindow *win, int num_rows, int num_cols)
 Draw a line between the sidebar and the rest of neomutt.
 
static void fill_empty_space (struct MuttWindow *win, int first_row, int num_rows, int div_width, int num_cols)
 Wipe the remaining Sidebar space.
 
int sb_repaint (struct MuttWindow *win)
 Repaint the Sidebar display - Implements MuttWindow::repaint() -.
 

Detailed Description

Sidebar Window.

Authors
  • Kevin J. McCarthy
  • R Primus
  • Pietro Cerutti
  • Richard Russon
  • Ashish Panigrahi
  • Tóth János

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.

Definition in file window.c.

Function Documentation

◆ imap_is_prefix()

static int imap_is_prefix ( const char *  folder,
const char *  mbox 
)
static

Check if folder matches the beginning of mbox.

Parameters
folderFolder
mboxMailbox path
Return values
numLength of the prefix

Definition at line 90 of file window.c.

91{
92 int plen = 0;
93
94 struct Url *url_m = url_parse(mbox);
95 struct Url *url_f = url_parse(folder);
96 if (!url_m || !url_f)
97 goto done;
98
99 if (!mutt_istr_equal(url_m->host, url_f->host))
100 goto done;
101
102 if (url_m->user && url_f->user && !mutt_istr_equal(url_m->user, url_f->user))
103 goto done;
104
105 size_t mlen = mutt_str_len(url_m->path);
106 size_t flen = mutt_str_len(url_f->path);
107 if (flen > mlen)
108 goto done;
109
110 if (!mutt_strn_equal(url_m->path, url_f->path, flen))
111 goto done;
112
113 plen = strlen(mbox) - mlen + flen;
114
115done:
116 url_free(&url_m);
117 url_free(&url_f);
118
119 return plen;
120}
bool mutt_istr_equal(const char *a, const char *b)
Compare two strings, ignoring case.
Definition: string.c:672
bool mutt_strn_equal(const char *a, const char *b, size_t num)
Check for equality of two strings (to a maximum), safely.
Definition: string.c:425
size_t mutt_str_len(const char *a)
Calculate the length of a string, safely.
Definition: string.c:496
A parsed URL proto://user:password@host:port/path?a=1&b=2
Definition: url.h:69
char * user
Username.
Definition: url.h:71
char * host
Host.
Definition: url.h:73
char * path
Path.
Definition: url.h:75
struct Url * url_parse(const char *src)
Fill in Url.
Definition: url.c:239
void url_free(struct Url **ptr)
Free the contents of a URL.
Definition: url.c:124
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ abbrev_folder()

static const char * abbrev_folder ( const char *  mbox,
const char *  folder,
enum MailboxType  type 
)
static

Abbreviate a Mailbox path using a folder.

Parameters
mboxMailbox path to shorten
folderFolder path to use
typeMailbox type
Return values
ptrPointer into the mbox param

Definition at line 129 of file window.c.

130{
131 if (!mbox || !folder)
132 return NULL;
133
134 if (type == MUTT_IMAP)
135 {
136 int prefix = imap_is_prefix(folder, mbox);
137 if (prefix == 0)
138 return NULL;
139 return mbox + prefix;
140 }
141
142 const char *const c_sidebar_delim_chars = cs_subset_string(NeoMutt->sub, "sidebar_delim_chars");
143 if (!c_sidebar_delim_chars)
144 return NULL;
145
146 size_t flen = mutt_str_len(folder);
147 if (flen == 0)
148 return NULL;
149 if (strchr(c_sidebar_delim_chars, folder[flen - 1])) // folder ends with a delimiter
150 flen--;
151
152 size_t mlen = mutt_str_len(mbox);
153 if (mlen < flen)
154 return NULL;
155
156 if (!mutt_strn_equal(folder, mbox, flen))
157 return NULL;
158
159 // After the match, check that mbox has a delimiter
160 if (!strchr(c_sidebar_delim_chars, mbox[flen]))
161 return NULL;
162
163 if (mlen > flen)
164 {
165 return mbox + flen + 1;
166 }
167
168 // mbox and folder are equal, use the chunk after the last delimiter
169 while (mlen--)
170 {
171 if (strchr(c_sidebar_delim_chars, mbox[mlen]))
172 {
173 return mbox + mlen + 1;
174 }
175 }
176
177 return NULL;
178}
const char * cs_subset_string(const struct ConfigSubset *sub, const char *name)
Get a string config item by name.
Definition: helpers.c:291
@ MUTT_IMAP
'IMAP' Mailbox type
Definition: mailbox.h:50
static int imap_is_prefix(const char *folder, const char *mbox)
Check if folder matches the beginning of mbox.
Definition: window.c:90
Container for Accounts, Notifications.
Definition: neomutt.h:42
struct ConfigSubset * sub
Inherited config items.
Definition: neomutt.h:46
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ abbrev_url()

static const char * abbrev_url ( const char *  mbox,
enum MailboxType  type 
)
static

Abbreviate a url-style Mailbox path.

Parameters
mboxMailbox path to shorten
typeMailbox type
Return values
ptrmbox unchanged

Use heuristics to shorten a non-local Mailbox path. Strip the host part (or database part for Notmuch).

e.g.

  • imap://user@host.com/apple/banana becomes apple/banana
  • notmuch:///home/user/db?query=hello becomes query=hello

Definition at line 193 of file window.c.

194{
195 /* This is large enough to skip `notmuch://`,
196 * but not so large that it will go past the host part. */
197 const int scheme_len = 10;
198
199 size_t len = mutt_str_len(mbox);
200 if ((len < scheme_len) || ((type != MUTT_NNTP) && (type != MUTT_IMAP) &&
201 (type != MUTT_NOTMUCH) && (type != MUTT_POP)))
202 {
203 return mbox;
204 }
205
206 const char split = (type == MUTT_NOTMUCH) ? '?' : '/';
207
208 // Skip over the scheme, e.g. `imaps://`, `notmuch://`
209 const char *last = strchr(mbox + scheme_len, split);
210 if (last)
211 mbox = last + 1;
212 return mbox;
213}
@ MUTT_NOTMUCH
'Notmuch' (virtual) Mailbox type
Definition: mailbox.h:51
@ MUTT_POP
'POP3' Mailbox type
Definition: mailbox.h:52
@ MUTT_NNTP
'NNTP' (Usenet) Mailbox type
Definition: mailbox.h:49
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ calc_color()

static const struct AttrColor * calc_color ( const struct Mailbox m,
bool  current,
bool  highlight 
)
static

Calculate the colour of a Sidebar row.

Parameters
mMailbox
currenttrue, if this is the current Mailbox
highlighttrue, if this Mailbox has the highlight on it
Return values
enumColorId, e.g. MT_COLOR_SIDEBAR_NEW

Definition at line 222 of file window.c.

223{
224 const struct AttrColor *ac = NULL;
225
226 const char *const c_spool_file = cs_subset_string(NeoMutt->sub, "spool_file");
228 mutt_str_equal(mailbox_path(m), c_spool_file))
229 {
231 }
232
234 {
236 }
237
239 {
241 }
242
244 {
246 }
247
249 {
251 }
252
253 const struct AttrColor *ac_bg = simple_color_get(MT_COLOR_NORMAL);
255 ac = merged_color_overlay(ac_bg, ac);
256
257 if (current || highlight)
258 {
259 int color;
260 if (current)
261 {
264 else
265 color = MT_COLOR_INDICATOR;
266 }
267 else
268 {
270 }
271
272 ac = merged_color_overlay(ac, simple_color_get(color));
273 }
274
275 return ac;
276}
bool simple_color_is_set(enum ColorId cid)
Is the object coloured?
Definition: simple.c:109
struct AttrColor * simple_color_get(enum ColorId cid)
Get the colour of an object by its ID.
Definition: simple.c:88
@ MT_COLOR_SIDEBAR_NEW
Mailbox with new mail.
Definition: color.h:70
@ MT_COLOR_SIDEBAR_UNREAD
Mailbox with unread mail.
Definition: color.h:73
@ MT_COLOR_INDICATOR
Selected item in list.
Definition: color.h:54
@ MT_COLOR_SIDEBAR_SPOOLFILE
$spool_file (Spool mailbox)
Definition: color.h:72
@ MT_COLOR_SIDEBAR_ORDINARY
Mailbox with no new or flagged messages.
Definition: color.h:71
@ MT_COLOR_SIDEBAR_BACKGROUND
Background colour for the Sidebar.
Definition: color.h:65
@ MT_COLOR_NORMAL
Plain text.
Definition: color.h:59
@ MT_COLOR_SIDEBAR_INDICATOR
Current open mailbox.
Definition: color.h:69
@ MT_COLOR_SIDEBAR_HIGHLIGHT
Select cursor.
Definition: color.h:68
@ MT_COLOR_SIDEBAR_FLAGGED
Mailbox with flagged messages.
Definition: color.h:67
static const char * mailbox_path(const struct Mailbox *m)
Get the Mailbox's path string.
Definition: mailbox.h:223
const struct AttrColor * merged_color_overlay(const struct AttrColor *base, const struct AttrColor *over)
Combine two colours.
Definition: merged.c:107
bool mutt_str_equal(const char *a, const char *b)
Compare two strings.
Definition: string.c:660
A curses colour and its attributes.
Definition: attr.h:66
bool has_new
Mailbox has new mail.
Definition: mailbox.h:85
int msg_flagged
Number of flagged messages.
Definition: mailbox.h:90
int msg_unread
Number of unread messages.
Definition: mailbox.h:89
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ calc_path_depth()

static int calc_path_depth ( const char *  mbox,
const char *  delims,
const char **  last_part 
)
static

Calculate the depth of a Mailbox path.

Parameters
[in]mboxMailbox path to examine
[in]delimsDelimiter characters
[out]last_partLast path component
Return values
numDepth

Definition at line 285 of file window.c.

286{
287 if (!mbox || !delims || !last_part)
288 return 0;
289
290 int depth = 0;
291 const char *match = NULL;
292 while ((match = strpbrk(mbox, delims)))
293 {
294 depth++;
295 mbox = match + 1;
296 }
297
298 *last_part = mbox;
299 return depth;
300}
+ Here is the caller graph for this function:

◆ make_sidebar_entry()

static void make_sidebar_entry ( char *  buf,
size_t  buflen,
int  width,
struct SbEntry sbe,
struct IndexSharedData shared 
)
static

Turn mailbox data into a sidebar string.

Parameters
[out]bufBuffer in which to save string
[in]buflenBuffer length
[in]widthDesired width in screen cells
[in]sbeMailbox object
[in]sharedShared Index Data

Take all the relevant mailbox data and the desired screen width and then get expando_render() to do the actual work.

See also
$sidebar_format

Definition at line 315 of file window.c.

317{
318 struct SidebarData sdata = { sbe, shared };
319
320 struct Buffer *tmp = buf_pool_get();
321 const struct Expando *c_sidebar_format = cs_subset_expando(NeoMutt->sub, "sidebar_format");
322 expando_filter(c_sidebar_format, SidebarRenderCallbacks, &sdata,
323 MUTT_FORMAT_NO_FLAGS, width, tmp);
324 mutt_str_copy(buf, buf_string(tmp), buflen);
325 buf_pool_release(&tmp);
326
327 /* Force string to be exactly the right width */
328 int w = mutt_strwidth(buf);
329 int s = mutt_str_len(buf);
330 width = MIN(buflen, width);
331 if (w < width)
332 {
333 /* Pad with spaces */
334 memset(buf + s, ' ', width - w);
335 buf[s + width - w] = '\0';
336 }
337 else if (w > width)
338 {
339 /* Truncate to fit */
340 size_t len = mutt_wstr_trunc(buf, buflen, width, NULL);
341 buf[len] = '\0';
342 }
343}
static const char * buf_string(const struct Buffer *buf)
Convert a buffer to a const char * "string".
Definition: buffer.h:96
const struct Expando * cs_subset_expando(const struct ConfigSubset *sub, const char *name)
Get an Expando config item by name.
Definition: config_type.c:357
size_t mutt_wstr_trunc(const char *src, size_t maxlen, size_t maxwid, size_t *width)
Work out how to truncate a widechar string.
Definition: curs_lib.c:383
size_t mutt_strwidth(const char *s)
Measure a string's width in screen cells.
Definition: curs_lib.c:443
int expando_filter(const struct Expando *exp, const struct ExpandoRenderCallback *erc, void *data, MuttFormatFlags flags, int max_cols, struct Buffer *buf)
Render an Expando and run the result through a filter.
Definition: filter.c:138
#define MIN(a, b)
Definition: memory.h:32
size_t mutt_str_copy(char *dest, const char *src, size_t dsize)
Copy a string into a buffer (guaranteeing NUL-termination)
Definition: string.c:581
struct Buffer * buf_pool_get(void)
Get a Buffer from the pool.
Definition: pool.c:82
void buf_pool_release(struct Buffer **ptr)
Return a Buffer to the pool.
Definition: pool.c:96
#define MUTT_FORMAT_NO_FLAGS
No flags are set.
Definition: render.h:33
const struct ExpandoRenderCallback SidebarRenderCallbacks[]
Callbacks for Sidebar Expandos.
Definition: expando.c:312
String manipulation buffer.
Definition: buffer.h:36
Parsed Expando trees.
Definition: expando.h:41
Data passed to sidebar_format_str()
Definition: expando.h:34
struct IndexSharedData * shared
Shared Index Data.
Definition: expando.h:36
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ update_entries_visibility()

static void update_entries_visibility ( struct SidebarWindowData wdata)
static

Should a SbEntry be displayed in the sidebar?

Parameters
wdataSidebar data

For each SbEntry in the entries array, check whether we should display it. This is determined by several criteria. If the Mailbox:

  • is the currently open mailbox
  • is the currently highlighted mailbox
  • has unread messages
  • has flagged messages
  • is pinned

Definition at line 357 of file window.c.

358{
359 /* Aliases for readability */
360 const bool c_sidebar_new_mail_only = cs_subset_bool(NeoMutt->sub, "sidebar_new_mail_only");
361 const bool c_sidebar_non_empty_mailbox_only = cs_subset_bool(NeoMutt->sub, "sidebar_non_empty_mailbox_only");
362 struct SbEntry *sbe = NULL;
363
364 struct IndexSharedData *shared = wdata->shared;
365 struct SbEntry **sbep = NULL;
366 ARRAY_FOREACH(sbep, &wdata->entries)
367 {
368 int i = ARRAY_FOREACH_IDX;
369 sbe = *sbep;
370
371 sbe->is_hidden = false;
372
373 if (!sbe->mailbox->visible)
374 {
375 sbe->is_hidden = true;
376 continue;
377 }
378
379 if (shared->mailbox &&
381 {
382 /* Spool directories are always visible */
383 continue;
384 }
385
388 {
389 /* Explicitly asked to be visible */
390 continue;
391 }
392
393 if (c_sidebar_non_empty_mailbox_only && (i != wdata->opn_index) &&
394 (sbe->mailbox->msg_count == 0))
395 {
396 sbe->is_hidden = true;
397 }
398
399 if (c_sidebar_new_mail_only && (i != wdata->opn_index) &&
400 (sbe->mailbox->msg_unread == 0) && (sbe->mailbox->msg_flagged == 0) &&
401 !sbe->mailbox->has_new)
402 {
403 sbe->is_hidden = true;
404 }
405 }
406}
#define ARRAY_FOREACH(elem, head)
Iterate over all elements of the array.
Definition: array.h:212
bool cs_subset_bool(const struct ConfigSubset *sub, const char *name)
Get a boolean config item by name.
Definition: helpers.c:47
struct ListNode * mutt_list_find(const struct ListHead *h, const char *data)
Find a string in a List.
Definition: list.c:103
struct ListHead SidebarPinned
List of mailboxes to always display in the sidebar.
Definition: sidebar.c:43
Data shared between Index, Pager and Sidebar.
Definition: shared_data.h:37
struct Mailbox * mailbox
Current Mailbox.
Definition: shared_data.h:41
char * realpath
Used for duplicate detection, context comparison, and the sidebar.
Definition: mailbox.h:81
int msg_count
Total number of messages.
Definition: mailbox.h:88
char * name
A short name for the Mailbox.
Definition: mailbox.h:82
bool visible
True if a result of "mailboxes".
Definition: mailbox.h:130
Info about folders in the sidebar.
Definition: private.h:41
struct Mailbox * mailbox
Mailbox this represents.
Definition: private.h:45
bool is_hidden
Don't show, e.g. $sidebar_new_mail_only.
Definition: private.h:46
struct IndexSharedData * shared
Shared Index Data.
Definition: private.h:90
int opn_index
Current (open) mailbox.
Definition: private.h:94
struct SbEntryArray entries
Items to display in the sidebar.
Definition: private.h:91
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ prepare_sidebar()

static bool prepare_sidebar ( struct SidebarWindowData wdata,
int  page_size 
)
static

Prepare the list of SbEntry's for the sidebar display.

Parameters
wdataSidebar data
page_sizeNumber of lines on a page
Return values
falseNo, don't draw the sidebar
trueYes, draw the sidebar

Before painting the sidebar, we determine which are visible, sort them and set up our page pointers.

This is a lot of work to do each refresh, but there are many things that can change outside of the sidebar that we don't hear about.

Definition at line 421 of file window.c.

422{
423 if (ARRAY_EMPTY(&wdata->entries) || (page_size <= 0))
424 return false;
425
426 struct SbEntry **sbep = NULL;
427 const bool c_sidebar_new_mail_only = cs_subset_bool(NeoMutt->sub, "sidebar_new_mail_only");
428 const bool c_sidebar_non_empty_mailbox_only = cs_subset_bool(NeoMutt->sub, "sidebar_non_empty_mailbox_only");
429
430 sbep = (wdata->opn_index >= 0) ? ARRAY_GET(&wdata->entries, wdata->opn_index) : NULL;
431 const struct SbEntry *opn_entry = sbep ? *sbep : NULL;
432 sbep = (wdata->hil_index >= 0) ? ARRAY_GET(&wdata->entries, wdata->hil_index) : NULL;
433 const struct SbEntry *hil_entry = sbep ? *sbep : NULL;
434
436 const enum EmailSortType c_sidebar_sort = cs_subset_sort(NeoMutt->sub, "sidebar_sort");
437 sb_sort_entries(wdata, c_sidebar_sort);
438
439 if (opn_entry || hil_entry)
440 {
441 ARRAY_FOREACH(sbep, &wdata->entries)
442 {
443 if ((opn_entry == *sbep) && (*sbep)->mailbox->visible)
444 wdata->opn_index = ARRAY_FOREACH_IDX;
445 if ((hil_entry == *sbep) && (*sbep)->mailbox->visible)
446 wdata->hil_index = ARRAY_FOREACH_IDX;
447 }
448 }
449
450 if ((wdata->hil_index < 0) || (hil_entry && hil_entry->is_hidden) ||
451 (c_sidebar_sort != wdata->previous_sort))
452 {
453 if (wdata->opn_index >= 0)
454 {
455 wdata->hil_index = wdata->opn_index;
456 }
457 else
458 {
459 wdata->hil_index = 0;
460 /* Note is_hidden will only be set when `$sidebar_new_mail_only` */
461 if ((*ARRAY_GET(&wdata->entries, 0))->is_hidden && !sb_next(wdata))
462 wdata->hil_index = -1;
463 }
464 }
465
466 /* Set the Top and Bottom to frame the wdata->hil_index in groups of page_size */
467
468 /* If `$sidebar_new_mail_only` or `$sidebar_non_empty_mailbox_only` is set,
469 * some entries may be hidden so we need to scan for the framing interval */
470 if (c_sidebar_new_mail_only || c_sidebar_non_empty_mailbox_only)
471 {
472 wdata->top_index = -1;
473 wdata->bot_index = -1;
474 while (wdata->bot_index < wdata->hil_index)
475 {
476 wdata->top_index = wdata->bot_index + 1;
477 int page_entries = 0;
478 while (page_entries < page_size)
479 {
480 wdata->bot_index++;
481 if (wdata->bot_index >= ARRAY_SIZE(&wdata->entries))
482 break;
483 if (!(*ARRAY_GET(&wdata->entries, wdata->bot_index))->is_hidden)
484 page_entries++;
485 }
486 }
487 }
488 else
489 {
490 /* Otherwise we can just calculate the interval */
491 wdata->top_index = (wdata->hil_index / page_size) * page_size;
492 wdata->bot_index = wdata->top_index + page_size - 1;
493 }
494
495 if (wdata->bot_index > (ARRAY_SIZE(&wdata->entries) - 1))
496 wdata->bot_index = ARRAY_SIZE(&wdata->entries) - 1;
497
498 wdata->previous_sort = c_sidebar_sort;
499
500 return (wdata->hil_index >= 0);
501}
#define ARRAY_EMPTY(head)
Check if an array is empty.
Definition: array.h:74
#define ARRAY_SIZE(head)
The number of elements stored.
Definition: array.h:87
#define ARRAY_GET(head, idx)
Return the element at index.
Definition: array.h:109
short cs_subset_sort(const struct ConfigSubset *sub, const char *name)
Get a sort config item by name.
Definition: helpers.c:266
EmailSortType
Methods for sorting Emails.
Definition: sort.h:53
bool sb_next(struct SidebarWindowData *wdata)
Find the next unhidden Mailbox.
Definition: functions.c:47
void sb_sort_entries(struct SidebarWindowData *wdata, enum EmailSortType sort)
Sort the Sidebar entries.
Definition: sort.c:161
static void update_entries_visibility(struct SidebarWindowData *wdata)
Should a SbEntry be displayed in the sidebar?
Definition: window.c:357
short previous_sort
Old $sidebar_sort
Definition: private.h:98
int top_index
First mailbox visible in sidebar.
Definition: private.h:93
int bot_index
Last mailbox visible in sidebar.
Definition: private.h:96
int hil_index
Highlighted mailbox.
Definition: private.h:95
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ draw_divider()

static int draw_divider ( struct SidebarWindowData wdata,
struct MuttWindow win,
int  num_rows,
int  num_cols 
)
static

Draw a line between the sidebar and the rest of neomutt.

Parameters
wdataSidebar data
winWindow to draw on
num_rowsHeight of the Sidebar
num_colsWidth of the Sidebar
Return values
0Empty string
numCharacter occupies n screen columns

Draw a divider using characters from the config option "sidebar_divider_char". This can be an ASCII or Unicode character. We calculate these characters' width in screen columns.

If the user hasn't set $sidebar_divider_char we pick a character for them, respecting the value of $ascii_chars.

Definition at line 627 of file window.c.

629{
630 if ((num_rows < 1) || (num_cols < 1) || (wdata->divider_width > num_cols) ||
631 (wdata->divider_width == 0))
632 {
633 return 0;
634 }
635
636 const int width = wdata->divider_width;
637 const char *const c_sidebar_divider_char = cs_subset_string(NeoMutt->sub, "sidebar_divider_char");
638
639 const struct AttrColor *ac = simple_color_get(MT_COLOR_NORMAL);
643
644 const bool c_sidebar_on_right = cs_subset_bool(NeoMutt->sub, "sidebar_on_right");
645 const int col = c_sidebar_on_right ? 0 : (num_cols - width);
646
647 for (int i = 0; i < num_rows; i++)
648 {
649 mutt_window_move(win, col, i);
650
651 if (wdata->divider_type == SB_DIV_USER)
652 mutt_window_addstr(win, NONULL(c_sidebar_divider_char));
653 else
654 mutt_window_addch(win, '|');
655 }
656
658 return width;
659}
@ MT_COLOR_SIDEBAR_DIVIDER
Line dividing sidebar from the index/pager.
Definition: color.h:66
const struct AttrColor * mutt_curses_set_color_by_id(enum ColorId cid)
Set the colour and attributes by the colour id.
Definition: mutt_curses.c:79
void mutt_curses_set_color(const struct AttrColor *ac)
Set the colour and attributes for text.
Definition: mutt_curses.c:38
int mutt_window_move(struct MuttWindow *win, int col, int row)
Move the cursor in a Window.
Definition: mutt_window.c:297
int mutt_window_addstr(struct MuttWindow *win, const char *str)
Write a string to a Window.
Definition: mutt_window.c:416
int mutt_window_addch(struct MuttWindow *win, int ch)
Write one character to a Window.
Definition: mutt_window.c:388
@ SB_DIV_USER
User configured using $sidebar_divider_char.
Definition: private.h:80
#define NONULL(x)
Definition: string2.h:37
short divider_width
Width of the divider in screen columns.
Definition: private.h:100
enum DivType divider_type
Type of divider to use, e.g. SB_DIV_ASCII.
Definition: private.h:99
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fill_empty_space()

static void fill_empty_space ( struct MuttWindow win,
int  first_row,
int  num_rows,
int  div_width,
int  num_cols 
)
static

Wipe the remaining Sidebar space.

Parameters
winWindow to draw on
first_rowWindow line to start (0-based)
num_rowsNumber of rows to fill
div_widthWidth in screen characters taken by the divider
num_colsNumber of columns to fill

Write spaces over the area the sidebar isn't using.

Definition at line 671 of file window.c.

673{
674 /* Fill the remaining rows with blank space */
675 const struct AttrColor *ac = simple_color_get(MT_COLOR_NORMAL);
678
679 const bool c_sidebar_on_right = cs_subset_bool(NeoMutt->sub, "sidebar_on_right");
680 if (!c_sidebar_on_right)
681 div_width = 0;
682 for (int r = 0; r < num_rows; r++)
683 {
684 mutt_window_move(win, div_width, first_row + r);
686
687 for (int i = 0; i < num_cols; i++)
688 mutt_window_addch(win, ' ');
689 }
690}
+ Here is the call graph for this function:
+ Here is the caller graph for this function: