NeoMutt  2021-02-05-666-ge300cd
Teaching an old dog new tricks
DOXYGEN
helpbar.c File Reference

Help Bar. More...

#include "config.h"
#include <stddef.h>
#include <stdbool.h>
#include <stdio.h>
#include "private.h"
#include "mutt/lib.h"
#include "config/lib.h"
#include "core/lib.h"
#include "gui/lib.h"
#include "lib.h"
#include "menu/lib.h"
#include "keymap.h"
+ Include dependency graph for helpbar.c:

Go to the source code of this file.

Functions

static bool make_help (char *buf, size_t buflen, const char *txt, enum MenuType menu, int op)
 Create one entry for the Help Bar. More...
 
static char * compile_help (char *buf, size_t buflen, enum MenuType menu, const struct Mapping *items)
 Create the text for the help menu. More...
 
static int helpbar_recalc (struct MuttWindow *win)
 Recalculate the display of the Help Bar - Implements MuttWindow::recalc() -Generate the help string from data on the focused Window. More...
 
static int helpbar_repaint (struct MuttWindow *win)
 Redraw the Help Bar - Implements MuttWindow::repaint() -The Help Bar is drawn from the data cached in the HelpbarWindowData. More...
 
static int helpbar_binding_observer (struct NotifyCallback *nc)
 Notification that a Key Binding has changed - Implements observer_t. More...
 
static int helpbar_color_observer (struct NotifyCallback *nc)
 Notification that a Color has changed - Implements observer_t. More...
 
static int helpbar_config_observer (struct NotifyCallback *nc)
 Notification that a Config Variable has changed - Implements observer_t. More...
 
static int helpbar_window_observer (struct NotifyCallback *nc)
 Notification that a Window has changed - Implements observer_t. More...
 
struct MuttWindowhelpbar_new (void)
 Create the Help Bar Window. More...
 

Detailed Description

Help Bar.

Authors
  • Richard Russon

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 helpbar.c.

Function Documentation

◆ make_help()

static bool make_help ( char *  buf,
size_t  buflen,
const char *  txt,
enum MenuType  menu,
int  op 
)
static

Create one entry for the Help Bar.

Parameters
bufBuffer for the result
buflenLength of buffer
txtText part, e.g. "delete"
menuCurrent Menu, e.g. MENU_PAGER
opOperation, e.g. OP_DELETE
Return values
trueThe keybinding exists

This will return something like: "d:delete"

Definition at line 93 of file helpbar.c.

94 {
95  char tmp[128];
96 
97  if (km_expand_key(tmp, sizeof(tmp), km_find_func(menu, op)) ||
98  km_expand_key(tmp, sizeof(tmp), km_find_func(MENU_GENERIC, op)))
99  {
100  snprintf(buf, buflen, "%s:%s", tmp, txt);
101  return true;
102  }
103 
104  buf[0] = '\0';
105  return false;
106 }
struct Keymap * km_find_func(enum MenuType mtype, int func)
Find a function&#39;s mapping in a Menu.
Definition: keymap.c:946
Generic selection list.
Definition: type.h:45
int km_expand_key(char *s, size_t len, struct Keymap *map)
Get the key string bound to a Keymap.
Definition: keymap.c:918
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ compile_help()

static char* compile_help ( char *  buf,
size_t  buflen,
enum MenuType  menu,
const struct Mapping items 
)
static

Create the text for the help menu.

Parameters
bufBuffer for the result
buflenLength of buffer
menuCurrent Menu, e.g. MENU_PAGER
itemsMap of functions to display in the Help Bar
Return values
ptrBuffer containing result

Definition at line 116 of file helpbar.c.

118 {
119  char *pbuf = buf;
120 
121  for (int i = 0; items[i].name && (buflen > 2); i++)
122  {
123  if (!make_help(pbuf, buflen, _(items[i].name), menu, items[i].value))
124  continue;
125 
126  const size_t len = mutt_str_len(pbuf);
127  pbuf += len;
128  buflen -= len;
129 
130  *pbuf++ = ' ';
131  *pbuf++ = ' ';
132  buflen -= 2;
133  }
134  return buf;
135 }
#define _(a)
Definition: message.h:28
size_t mutt_str_len(const char *a)
Calculate the length of a string, safely.
Definition: string.c:664
const char * name
Definition: mapping.h:33
static unsigned char * pbuf
Cache PGP data packet.
Definition: pgppacket.c:38
static bool make_help(char *buf, size_t buflen, const char *txt, enum MenuType menu, int op)
Create one entry for the Help Bar.
Definition: helpbar.c:93
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ helpbar_binding_observer()

static int helpbar_binding_observer ( struct NotifyCallback nc)
static

Notification that a Key Binding has changed - Implements observer_t.

This function is triggered by changes to the key bindings, from either of the bind or macro commands.

Definition at line 204 of file helpbar.c.

205 {
206  if ((nc->event_type != NT_BINDING) || !nc->global_data || !nc->event_data)
207  return -1;
208 
209  if (nc->event_subtype >= NT_MACRO_ADD)
210  return 0;
211 
212  struct MuttWindow *win_helpbar = nc->global_data;
213  struct HelpbarWindowData *wdata = helpbar_wdata_get(win_helpbar);
214  if (!wdata)
215  return 0;
216 
217  struct EventBinding *ev_b = nc->event_data;
218  if (wdata->help_menu != ev_b->menu)
219  return 0;
220 
221  win_helpbar->actions |= WA_RECALC;
222  mutt_debug(LL_DEBUG5, "binding done, request WA_RECALC\n");
223  return 0;
224 }
Key macro has been added.
Definition: keymap.h:121
struct HelpbarWindowData * helpbar_wdata_get(struct MuttWindow *win)
Get the Helpbar data for this window.
Definition: wdata.c:61
int event_subtype
Send: Event subtype, e.g. NT_ACCOUNT_ADD.
Definition: observer.h:43
enum NotifyType event_type
Send: Event type, e.g. NT_ACCOUNT.
Definition: observer.h:42
WindowActionFlags actions
Actions to be performed, e.g. WA_RECALC.
Definition: mutt_window.h:132
Key binding has changed, NotifyBinding, EventBinding.
Definition: notify_type.h:38
int help_menu
Menu for key bindings, e.g. MENU_PAGER.
Definition: private.h:35
void * global_data
Data from notify_observer_add()
Definition: observer.h:45
enum MenuType menu
Menu, e.g. MENU_PAGER.
Definition: keymap.h:103
Help Bar Window data -.
Definition: private.h:33
#define mutt_debug(LEVEL,...)
Definition: logging.h:85
void * event_data
Data from notify_send()
Definition: observer.h:44
Log at debug level 5.
Definition: logging.h:44
void * wdata
Private data.
Definition: mutt_window.h:145
A key binding Event.
Definition: keymap.h:101
#define WA_RECALC
Recalculate the contents of the Window.
Definition: mutt_window.h:110
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ helpbar_color_observer()

static int helpbar_color_observer ( struct NotifyCallback nc)
static

Notification that a Color has changed - Implements observer_t.

This function is triggered by changes to the colour settings, from the color or uncolor, mono or unmono commands.

Definition at line 232 of file helpbar.c.

233 {
234  if ((nc->event_type != NT_COLOR) || !nc->global_data || !nc->event_data)
235  return -1;
236 
237  struct EventColor *ev_c = nc->event_data;
238 
239  // MT_COLOR_MAX is sent on `uncolor *`
240  if ((ev_c->color != MT_COLOR_STATUS) && (ev_c->color != MT_COLOR_MAX))
241  return 0;
242 
243  struct MuttWindow *win_helpbar = nc->global_data;
244 
245  win_helpbar->actions |= WA_REPAINT;
246  mutt_debug(LL_DEBUG5, "color done, request WA_REPAINT\n");
247  return 0;
248 }
#define WA_REPAINT
Redraw the contents of the Window.
Definition: mutt_window.h:111
An Event that happened to a Colour.
Definition: color.h:122
enum NotifyType event_type
Send: Event type, e.g. NT_ACCOUNT.
Definition: observer.h:42
WindowActionFlags actions
Actions to be performed, e.g. WA_RECALC.
Definition: mutt_window.h:132
void * global_data
Data from notify_observer_add()
Definition: observer.h:45
Colour has changed, NotifyColor, EventColor.
Definition: notify_type.h:39
Status bar (takes a pattern)
Definition: color.h:75
enum ColorId color
Definition: color.h:124
#define mutt_debug(LEVEL,...)
Definition: logging.h:85
void * event_data
Data from notify_send()
Definition: observer.h:44
Log at debug level 5.
Definition: logging.h:44
+ Here is the caller graph for this function:

◆ helpbar_config_observer()

static int helpbar_config_observer ( struct NotifyCallback nc)
static

Notification that a Config Variable has changed - Implements observer_t.

This function is triggered by changes to the config by the set, unset, reset, toggle, etc commands.

Definition at line 256 of file helpbar.c.

257 {
258  if ((nc->event_type != NT_CONFIG) || !nc->global_data || !nc->event_data)
259  return -1;
260 
261  struct EventConfig *ev_c = nc->event_data;
262  if (!mutt_str_equal(ev_c->name, "help"))
263  return 0;
264 
265  struct MuttWindow *win_helpbar = nc->global_data;
266  win_helpbar->state.visible = cs_subset_bool(NeoMutt->sub, "help");
267 
268  mutt_window_reflow(win_helpbar->parent);
269  mutt_debug(LL_DEBUG5, "config done: '%s', request WA_REFLOW on parent\n", ev_c->name);
270  return 0;
271 }
bool mutt_str_equal(const char *a, const char *b)
Compare two strings.
Definition: string.c:904
bool cs_subset_bool(const struct ConfigSubset *sub, const char *name)
Get a boolean config item by name.
Definition: helpers.c:73
A config-change event.
Definition: subset.h:69
Container for Accounts, Notifications.
Definition: neomutt.h:36
enum NotifyType event_type
Send: Event type, e.g. NT_ACCOUNT.
Definition: observer.h:42
void * global_data
Data from notify_observer_add()
Definition: observer.h:45
struct WindowState state
Current state of the Window.
Definition: mutt_window.h:127
bool visible
Window is visible.
Definition: mutt_window.h:59
#define mutt_debug(LEVEL,...)
Definition: logging.h:85
void * event_data
Data from notify_send()
Definition: observer.h:44
Config has changed, NotifyConfig, EventConfig.
Definition: notify_type.h:42
void mutt_window_reflow(struct MuttWindow *win)
Resize a Window and its children.
Definition: mutt_window.c:361
struct MuttWindow * parent
Parent Window.
Definition: mutt_window.h:135
struct ConfigSubset * sub
Inherited config items.
Definition: neomutt.h:39
Log at debug level 5.
Definition: logging.h:44
const char * name
Name of config item that changed.
Definition: subset.h:72
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ helpbar_window_observer()

static int helpbar_window_observer ( struct NotifyCallback nc)
static

Notification that a Window has changed - Implements observer_t.

This function is triggered by changes to the windows.

  • Focus (global): regenerate the list of key bindings
  • State (this window): regenerate the list of key bindings
  • Delete (this window): clean up the resources held by the Help Bar

Definition at line 282 of file helpbar.c.

283 {
284  if ((nc->event_type != NT_WINDOW) || !nc->global_data || !nc->event_data)
285  return -1;
286 
287  struct MuttWindow *win_helpbar = nc->global_data;
288 
289  if (nc->event_subtype == NT_WINDOW_FOCUS)
290  {
291  if (!mutt_window_is_visible(win_helpbar))
292  return 0;
293 
294  win_helpbar->actions |= WA_RECALC;
295  mutt_debug(LL_DEBUG5, "window focus: request WA_RECALC\n");
296  return 0;
297  }
298 
299  // The next two notifications must be specifically for us
300  struct EventWindow *ew = nc->event_data;
301  if (ew->win != win_helpbar)
302  return 0;
303 
304  if (nc->event_subtype == NT_WINDOW_STATE)
305  {
306  win_helpbar->actions |= WA_RECALC;
307  mutt_debug(LL_DEBUG5, "window state: request WA_RECALC\n");
308  }
309  else if (nc->event_subtype == NT_WINDOW_DELETE)
310  {
315  mutt_debug(LL_DEBUG5, "window delete done\n");
316  }
317 
318  return 0;
319 }
struct MuttWindow * win
Window that changed.
Definition: mutt_window.h:217
An Event that happened to a Window.
Definition: mutt_window.h:215
Window is about to be deleted.
Definition: mutt_window.h:206
Window focus has changed.
Definition: mutt_window.h:209
Container for Accounts, Notifications.
Definition: neomutt.h:36
MuttWindow has changed, NotifyWindow, EventWindow.
Definition: notify_type.h:53
int event_subtype
Send: Event subtype, e.g. NT_ACCOUNT_ADD.
Definition: observer.h:43
enum NotifyType event_type
Send: Event type, e.g. NT_ACCOUNT.
Definition: observer.h:42
WindowActionFlags actions
Actions to be performed, e.g. WA_RECALC.
Definition: mutt_window.h:132
struct Notify * notify
Notifications: NotifyWindow, EventWindow.
Definition: mutt_window.h:138
static int helpbar_config_observer(struct NotifyCallback *nc)
Notification that a Config Variable has changed - Implements observer_t.
Definition: helpbar.c:256
void * global_data
Data from notify_observer_add()
Definition: observer.h:45
static int helpbar_color_observer(struct NotifyCallback *nc)
Notification that a Color has changed - Implements observer_t.
Definition: helpbar.c:232
Window state has changed, e.g. WN_VISIBLE.
Definition: mutt_window.h:207
bool mutt_window_is_visible(struct MuttWindow *win)
Is the Window visible?
Definition: mutt_window.c:529
struct Notify * notify
Notifications handler.
Definition: neomutt.h:38
#define mutt_debug(LEVEL,...)
Definition: logging.h:85
void * event_data
Data from notify_send()
Definition: observer.h:44
static int helpbar_window_observer(struct NotifyCallback *nc)
Notification that a Window has changed - Implements observer_t.
Definition: helpbar.c:282
struct MuttWindow * RootWindow
Parent of all Windows.
Definition: rootwin.c:105
bool notify_observer_remove(struct Notify *notify, observer_t callback, void *global_data)
Remove an observer from an object.
Definition: notify.c:228
Log at debug level 5.
Definition: logging.h:44
static int helpbar_binding_observer(struct NotifyCallback *nc)
Notification that a Key Binding has changed - Implements observer_t.
Definition: helpbar.c:204
#define WA_RECALC
Recalculate the contents of the Window.
Definition: mutt_window.h:110
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ helpbar_new()

struct MuttWindow* helpbar_new ( void  )

Create the Help Bar Window.

Return values
ptrNew Window
Note
The Window can be freed with mutt_window_free().

Definition at line 327 of file helpbar.c.

328 {
329  struct MuttWindow *win =
332  win->state.visible = cs_subset_bool(NeoMutt->sub, "help");
333 
334  win->recalc = helpbar_recalc;
335  win->repaint = helpbar_repaint;
336 
337  win->wdata = helpbar_wdata_new();
339 
344  return win;
345 }
bool cs_subset_bool(const struct ConfigSubset *sub, const char *name)
Get a boolean config item by name.
Definition: helpers.c:73
void(* wdata_free)(struct MuttWindow *win, void **ptr)
Definition: mutt_window.h:160
Window uses all available vertical space.
Definition: mutt_window.h:38
struct HelpbarWindowData * helpbar_wdata_new(void)
Create new Window data for the Helpbar.
Definition: wdata.c:39
Container for Accounts, Notifications.
Definition: neomutt.h:36
MuttWindow has changed, NotifyWindow, EventWindow.
Definition: notify_type.h:53
struct Notify * notify
Notifications: NotifyWindow, EventWindow.
Definition: mutt_window.h:138
static int helpbar_config_observer(struct NotifyCallback *nc)
Notification that a Config Variable has changed - Implements observer_t.
Definition: helpbar.c:256
Key binding has changed, NotifyBinding, EventBinding.
Definition: notify_type.h:38
bool notify_observer_add(struct Notify *notify, enum NotifyType type, observer_t callback, void *global_data)
Add an observer to an object.
Definition: notify.c:189
Window has a fixed size.
Definition: mutt_window.h:47
static int helpbar_color_observer(struct NotifyCallback *nc)
Notification that a Color has changed - Implements observer_t.
Definition: helpbar.c:232
Colour has changed, NotifyColor, EventColor.
Definition: notify_type.h:39
struct WindowState state
Current state of the Window.
Definition: mutt_window.h:127
bool visible
Window is visible.
Definition: mutt_window.h:59
#define MUTT_WIN_SIZE_UNLIMITED
Use as much space as possible.
Definition: mutt_window.h:52
Help Bar containing list of useful key bindings.
Definition: mutt_window.h:96
struct Notify * notify
Notifications handler.
Definition: neomutt.h:38
Config has changed, NotifyConfig, EventConfig.
Definition: notify_type.h:42
static int helpbar_window_observer(struct NotifyCallback *nc)
Notification that a Window has changed - Implements observer_t.
Definition: helpbar.c:282
struct MuttWindow * RootWindow
Parent of all Windows.
Definition: rootwin.c:105
void helpbar_wdata_free(struct MuttWindow *win, void **ptr)
Free Helpbar Window data - Implements MuttWindow::wdata_free() -.
Definition: wdata.c:47
int(* repaint)(struct MuttWindow *win)
Definition: mutt_window.h:182
static int helpbar_recalc(struct MuttWindow *win)
Recalculate the display of the Help Bar - Implements MuttWindow::recalc() -Generate the help string f...
Definition: helpbar.c:143
int(* recalc)(struct MuttWindow *win)
Definition: mutt_window.h:171
struct ConfigSubset * sub
Inherited config items.
Definition: neomutt.h:39
static int helpbar_repaint(struct MuttWindow *win)
Redraw the Help Bar - Implements MuttWindow::repaint() -The Help Bar is drawn from the data cached in...
Definition: helpbar.c:180
struct MuttWindow * mutt_window_new(enum WindowType type, enum MuttWindowOrientation orient, enum MuttWindowSize size, int cols, int rows)
Create a new Window.
Definition: mutt_window.c:180
void * wdata
Private data.
Definition: mutt_window.h:145
static int helpbar_binding_observer(struct NotifyCallback *nc)
Notification that a Key Binding has changed - Implements observer_t.
Definition: helpbar.c:204
+ Here is the call graph for this function:
+ Here is the caller graph for this function: