NeoMutt  2020-06-26-30-g76c339
Teaching an old dog new tricks
DOXYGEN
mutt_history.c File Reference

Read/write command history from/to a file. More...

#include "config.h"
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include "mutt/lib.h"
#include "config/lib.h"
#include "gui/lib.h"
#include "mutt.h"
#include "mutt_history.h"
#include "format_flags.h"
#include "globals.h"
#include "keymap.h"
#include "mutt_menu.h"
#include "muttlib.h"
#include "opcodes.h"
#include "history/lib.h"
+ Include dependency graph for mutt_history.c:

Go to the source code of this file.

Functions

static const char * history_format_str (char *buf, size_t buflen, size_t col, int cols, char op, const char *src, const char *prec, const char *if_str, const char *else_str, intptr_t data, MuttFormatFlags flags)
 Format a string for the history list - Implements format_t. More...
 
static void history_make_entry (char *buf, size_t buflen, struct Menu *menu, int line)
 Format a menu item for the history list - Implements Menu::make_entry() More...
 
static void history_menu (char *buf, size_t buflen, char **matches, int match_count)
 Select an item from a history list. More...
 
void mutt_hist_complete (char *buf, size_t buflen, enum HistoryClass hclass)
 Complete a string from a history list. More...
 
int mutt_hist_observer (struct NotifyCallback *nc)
 Listen for config changes affecting the history - Implements observer_t. More...
 

Variables

static const struct Mapping HistoryHelp []
 

Detailed Description

Read/write command history from/to a file.

Authors
  • Michael R. Elkins

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

Function Documentation

◆ history_format_str()

static const char* history_format_str ( char *  buf,
size_t  buflen,
size_t  col,
int  cols,
char  op,
const char *  src,
const char *  prec,
const char *  if_str,
const char *  else_str,
intptr_t  data,
MuttFormatFlags  flags 
)
static

Format a string for the history list - Implements format_t.

Expando Description
%s History match

Definition at line 61 of file mutt_history.c.

65 {
66  char *match = (char *) data;
67 
68  switch (op)
69  {
70  case 's':
71  mutt_format_s(buf, buflen, prec, match);
72  break;
73  }
74 
75  return src;
76 }
void mutt_format_s(char *buf, size_t buflen, const char *prec, const char *s)
Format a simple string.
Definition: curs_lib.c:1223
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ history_make_entry()

static void history_make_entry ( char *  buf,
size_t  buflen,
struct Menu menu,
int  line 
)
static

Format a menu item for the history list - Implements Menu::make_entry()

Definition at line 81 of file mutt_history.c.

82 {
83  char *entry = ((char **) menu->mdata)[line];
84 
85  mutt_expando_format(buf, buflen, 0, menu->win_index->state.cols, "%s",
86  history_format_str, (intptr_t) entry, MUTT_FORMAT_ARROWCURSOR);
87 }
#define MUTT_FORMAT_ARROWCURSOR
Reserve space for arrow_cursor.
Definition: format_flags.h:35
static const char * history_format_str(char *buf, size_t buflen, size_t col, int cols, char op, const char *src, const char *prec, const char *if_str, const char *else_str, intptr_t data, MuttFormatFlags flags)
Format a string for the history list - Implements format_t.
Definition: mutt_history.c:61
void mutt_expando_format(char *buf, size_t buflen, size_t col, int cols, const char *src, format_t *callback, intptr_t data, MuttFormatFlags flags)
Expand expandos (x) in a string.
Definition: muttlib.c:862
short cols
Number of columns, can be MUTT_WIN_SIZE_UNLIMITED.
Definition: mutt_window.h:57
struct WindowState state
Current state of the Window.
Definition: mutt_window.h:113
void * mdata
Extra data for the current menu.
Definition: mutt_menu.h:84
int const char int line
Definition: acutest.h:617
struct MuttWindow * win_index
Definition: mutt_menu.h:92
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ history_menu()

static void history_menu ( char *  buf,
size_t  buflen,
char **  matches,
int  match_count 
)
static

Select an item from a history list.

Parameters
[in]bufBuffer in which to save string
[in]buflenBuffer length
[out]matchesItems to choose from
[in]match_countNumber of items

Definition at line 96 of file mutt_history.c.

97 {
98  bool done = false;
99  char helpstr[1024];
100  char title[256];
101 
102  snprintf(title, sizeof(title), _("History '%s'"), buf);
103 
104  struct MuttWindow *dlg =
107  dlg->notify = notify_new();
108 
109  struct MuttWindow *index =
112  index->notify = notify_new();
113  notify_set_parent(index->notify, dlg->notify);
114 
115  struct MuttWindow *ibar =
118  ibar->notify = notify_new();
119  notify_set_parent(ibar->notify, dlg->notify);
120 
121  if (C_StatusOnTop)
122  {
123  mutt_window_add_child(dlg, ibar);
124  mutt_window_add_child(dlg, index);
125  }
126  else
127  {
128  mutt_window_add_child(dlg, index);
129  mutt_window_add_child(dlg, ibar);
130  }
131 
132  dialog_push(dlg);
133 
134  struct Menu *menu = mutt_menu_new(MENU_GENERIC);
135 
136  menu->pagelen = index->state.rows;
137  menu->win_index = index;
138  menu->win_ibar = ibar;
139 
141  menu->title = title;
142  menu->help = mutt_compile_help(helpstr, sizeof(helpstr), MENU_GENERIC, HistoryHelp);
144 
145  menu->max = match_count;
146  menu->mdata = matches;
147 
148  while (!done)
149  {
150  switch (mutt_menu_loop(menu))
151  {
152  case OP_GENERIC_SELECT_ENTRY:
153  mutt_str_copy(buf, matches[menu->current], buflen);
154  /* fall through */
155 
156  case OP_EXIT:
157  done = true;
158  break;
159  }
160  }
161 
162  mutt_menu_pop_current(menu);
163  mutt_menu_free(&menu);
164  dialog_pop();
165  mutt_window_free(&dlg);
166 }
WHERE bool C_StatusOnTop
Config: Display the status bar at the top.
Definition: globals.h:247
History Dialog, history_menu()
Definition: mutt_window.h:82
GUI selectable list of items.
Definition: mutt_menu.h:80
Window uses all available vertical space.
Definition: mutt_window.h:35
void dialog_pop(void)
Hide a Window from the user.
Definition: mutt_window.c:722
void dialog_push(struct MuttWindow *dlg)
Display a Window to the user.
Definition: mutt_window.c:697
#define _(a)
Definition: message.h:28
A division of the screen.
Definition: mutt_window.h:108
An Index Window containing a selection list.
Definition: mutt_window.h:93
static const struct Mapping HistoryHelp[]
Definition: mutt_history.c:46
void mutt_window_free(struct MuttWindow **ptr)
Free a Window and its children.
Definition: mutt_window.c:150
struct Notify * notify
Notifications system.
Definition: mutt_window.h:123
struct MuttWindow * win_ibar
Definition: mutt_menu.h:93
const char * title
Title of this menu.
Definition: mutt_menu.h:82
Window has a fixed size.
Definition: mutt_window.h:44
const char * help
Quickref for the current menu.
Definition: mutt_menu.h:83
struct Notify * notify_new(void)
Create a new notifications handler.
Definition: notify.c:49
struct WindowState state
Current state of the Window.
Definition: mutt_window.h:113
void * mdata
Extra data for the current menu.
Definition: mutt_menu.h:84
#define MUTT_WIN_SIZE_UNLIMITED
Use as much space as possible.
Definition: mutt_window.h:49
short rows
Number of rows, can be MUTT_WIN_SIZE_UNLIMITED.
Definition: mutt_window.h:58
int pagelen
Number of entries per screen.
Definition: mutt_menu.h:89
int max
Number of entries in the menu.
Definition: mutt_menu.h:86
void mutt_window_add_child(struct MuttWindow *parent, struct MuttWindow *child)
Add a child to Window.
Definition: mutt_window.c:564
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:724
static void history_make_entry(char *buf, size_t buflen, struct Menu *menu, int line)
Format a menu item for the history list - Implements Menu::make_entry()
Definition: mutt_history.c:81
void notify_set_parent(struct Notify *notify, struct Notify *parent)
Set the parent notification handler.
Definition: notify.c:82
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:131
int current
Current entry.
Definition: mutt_menu.h:85
struct MuttWindow * win_index
Definition: mutt_menu.h:92
char * mutt_compile_help(char *buf, size_t buflen, enum MenuType menu, const struct Mapping *items)
Create the text for the help menu.
Definition: help.c:110
Window wants as much space as possible.
Definition: mutt_window.h:45
Index Bar containing status info about the Index.
Definition: mutt_window.h:94
void(* make_entry)(char *buf, size_t buflen, struct Menu *menu, int line)
Format a item for a menu.
Definition: mutt_menu.h:117
Generic selection list.
Definition: keymap.h:77
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_hist_complete()

void mutt_hist_complete ( char *  buf,
size_t  buflen,
enum HistoryClass  hclass 
)

Complete a string from a history list.

Parameters
bufBuffer in which to save string
buflenBuffer length
hclassHistory list to use

Definition at line 174 of file mutt_history.c.

175 {
176  char **matches = mutt_mem_calloc(C_History, sizeof(char *));
177  int match_count = mutt_hist_search(buf, hclass, matches);
178  if (match_count)
179  {
180  if (match_count == 1)
181  mutt_str_copy(buf, matches[0], buflen);
182  else
183  history_menu(buf, buflen, matches, match_count);
184  }
185  FREE(&matches);
186 }
void * mutt_mem_calloc(size_t nmemb, size_t size)
Allocate zeroed memory on the heap.
Definition: memory.c:50
short C_History
Config: Number of history entries to keep in memory per category.
Definition: history.c:80
int mutt_hist_search(const char *search_buf, enum HistoryClass hclass, char **matches)
Find matches in a history list.
Definition: history.c:402
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:724
static void history_menu(char *buf, size_t buflen, char **matches, int match_count)
Select an item from a history list.
Definition: mutt_history.c:96
#define FREE(x)
Definition: memory.h:40
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_hist_observer()

int mutt_hist_observer ( struct NotifyCallback nc)

Listen for config changes affecting the history - Implements observer_t.

Definition at line 191 of file mutt_history.c.

192 {
193  if (!nc->event_data)
194  return -1;
195  if (nc->event_type != NT_CONFIG)
196  return 0;
197 
198  struct EventConfig *ec = nc->event_data;
199 
200  if (!mutt_str_equal(ec->name, "history"))
201  return 0;
202 
203  mutt_hist_init();
204  return 0;
205 }
bool mutt_str_equal(const char *a, const char *b)
Compare two strings.
Definition: string.c:879
A config-change event.
Definition: subset.h:70
enum NotifyType event_type
Send: Event type, e.g. NT_ACCOUNT.
Definition: observer.h:41
void mutt_hist_init(void)
Create a set of empty History ring buffers.
Definition: history.c:453
void * event_data
Data from notify_send()
Definition: observer.h:43
Config has changed, NotifyConfig, EventConfig.
Definition: notify_type.h:36
const char * name
Name of config item that changed.
Definition: subset.h:73
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Variable Documentation

◆ HistoryHelp

const struct Mapping HistoryHelp[]
static
Initial value:
= {
{ N_("Exit"), OP_EXIT },
{ N_("Select"), OP_GENERIC_SELECT_ENTRY },
{ N_("Search"), OP_SEARCH },
{ N_("Help"), OP_HELP },
{ NULL, 0 },
}
#define N_(a)
Definition: message.h:32

Definition at line 46 of file mutt_history.c.