NeoMutt  2019-12-07-60-g0cfa53
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 <stdio.h>
#include "mutt/mutt.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 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, unsigned long 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::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,
unsigned long  data,
MuttFormatFlags  flags 
)
static

Format a string for the history list - Implements format_t.

Expando Description
%s History match

Definition at line 59 of file mutt_history.c.

63 {
64  char *match = (char *) data;
65 
66  switch (op)
67  {
68  case 's':
69  mutt_format_s(buf, buflen, prec, match);
70  break;
71  }
72 
73  return src;
74 }
void mutt_format_s(char *buf, size_t buflen, const char *prec, const char *s)
Format a simple string.
Definition: curs_lib.c:1244
+ 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::menu_make_entry()

Definition at line 79 of file mutt_history.c.

80 {
81  char *entry = ((char **) menu->data)[line];
82 
83  mutt_expando_format(buf, buflen, 0, menu->win_index->state.cols, "%s", history_format_str,
84  (unsigned long) entry, MUTT_FORMAT_ARROWCURSOR);
85 }
void mutt_expando_format(char *buf, size_t buflen, size_t col, int cols, const char *src, format_t *callback, unsigned long data, MuttFormatFlags flags)
Expand expandos (x) in a string.
Definition: muttlib.c:877
#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, unsigned long data, MuttFormatFlags flags)
Format a string for the history list - Implements format_t.
Definition: mutt_history.c:59
short cols
Number of columns, can be MUTT_WIN_SIZE_UNLIMITED.
Definition: mutt_window.h:56
const char * line
Definition: common.c:36
struct WindowState state
Current state of the Window.
Definition: mutt_window.h:91
void * data
Extra data for the current menu.
Definition: mutt_menu.h:86
struct MuttWindow * win_index
Definition: mutt_menu.h:95
+ 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 94 of file mutt_history.c.

95 {
96  bool done = false;
97  char helpstr[1024];
98  char title[256];
99 
100  snprintf(title, sizeof(title), _("History '%s'"), buf);
101 
102  struct MuttWindow *dlg =
105  dlg->type = WT_DIALOG;
106  struct MuttWindow *index =
109  index->type = WT_INDEX;
110  struct MuttWindow *ibar = mutt_window_new(
112  ibar->type = WT_INDEX_BAR;
113 
114  if (C_StatusOnTop)
115  {
116  mutt_window_add_child(dlg, ibar);
117  mutt_window_add_child(dlg, index);
118  }
119  else
120  {
121  mutt_window_add_child(dlg, index);
122  mutt_window_add_child(dlg, ibar);
123  }
124 
125  dialog_push(dlg);
126 
127  struct Menu *menu = mutt_menu_new(MENU_GENERIC);
128 
129  menu->pagelen = index->state.rows;
130  menu->win_index = index;
131  menu->win_ibar = ibar;
132 
134  menu->title = title;
135  menu->help = mutt_compile_help(helpstr, sizeof(helpstr), MENU_GENERIC, HistoryHelp);
137 
138  menu->max = match_count;
139  menu->data = matches;
140 
141  while (!done)
142  {
143  switch (mutt_menu_loop(menu))
144  {
145  case OP_GENERIC_SELECT_ENTRY:
146  mutt_str_strfcpy(buf, matches[menu->current], buflen);
147  /* fall through */
148 
149  case OP_EXIT:
150  done = true;
151  break;
152  }
153  }
154 
155  mutt_menu_pop_current(menu);
156  mutt_menu_free(&menu);
157  dialog_pop();
158  mutt_window_free(&dlg);
159 }
WHERE bool C_StatusOnTop
Config: Display the status bar at the top.
Definition: globals.h:255
GUI selectable list of items.
Definition: mutt_menu.h:82
Dialog (nested Windows) displayed to the user.
Definition: mutt_window.h:68
Window uses all available vertical space.
Definition: mutt_window.h:33
void dialog_pop(void)
Hide a Window from the user.
Definition: mutt_window.c:623
void dialog_push(struct MuttWindow *dlg)
Display a Window to the user.
Definition: mutt_window.c:603
#define _(a)
Definition: message.h:28
A division of the screen.
Definition: mutt_window.h:86
void(* menu_make_entry)(char *buf, size_t buflen, struct Menu *menu, int line)
Format a item for a menu.
Definition: mutt_menu.h:120
An Index Window containing a selection list.
Definition: mutt_window.h:72
static const struct Mapping HistoryHelp[]
Definition: mutt_history.c:44
void mutt_window_free(struct MuttWindow **ptr)
Free a Window and its children.
Definition: mutt_window.c:75
struct MuttWindow * win_ibar
Definition: mutt_menu.h:96
Window has a fixed size.
Definition: mutt_window.h:42
struct WindowState state
Current state of the Window.
Definition: mutt_window.h:91
struct MuttWindow * mutt_window_new(enum MuttWindowOrientation orient, enum MuttWindowSize size, int rows, int cols)
Create a new Window.
Definition: mutt_window.c:57
#define MUTT_WIN_SIZE_UNLIMITED
Use as much space as possible.
Definition: mutt_window.h:47
short rows
Number of rows, can be MUTT_WIN_SIZE_UNLIMITED.
Definition: mutt_window.h:55
size_t mutt_str_strfcpy(char *dest, const char *src, size_t dsize)
Copy a string into a buffer (guaranteeing NUL-termination)
Definition: string.c:750
int pagelen
Number of entries per screen.
Definition: mutt_menu.h:92
int max
Number of entries in the menu.
Definition: mutt_menu.h:88
void mutt_window_add_child(struct MuttWindow *parent, struct MuttWindow *child)
Add a child to Window.
Definition: mutt_window.c:471
char * title
Title of this menu.
Definition: mutt_menu.h:84
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::menu_make_entry()
Definition: mutt_history.c:79
void * data
Extra data for the current menu.
Definition: mutt_menu.h:86
int current
Current entry.
Definition: mutt_menu.h:87
struct MuttWindow * win_index
Definition: mutt_menu.h:95
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:115
Window wants as much space as possible.
Definition: mutt_window.h:43
Index Bar containing status info about the Index.
Definition: mutt_window.h:73
enum WindowType type
Window type, e.g. WT_SIDEBAR.
Definition: mutt_window.h:101
char * help
Quickref for the current menu.
Definition: mutt_menu.h:85
Generic selection list.
Definition: keymap.h:76
+ 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 167 of file mutt_history.c.

168 {
169  char **matches = mutt_mem_calloc(C_History, sizeof(char *));
170  int match_count = mutt_hist_search(buf, hclass, matches);
171  if (match_count)
172  {
173  if (match_count == 1)
174  mutt_str_strfcpy(buf, matches[0], buflen);
175  else
176  history_menu(buf, buflen, matches, match_count);
177  }
178  FREE(&matches);
179 }
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:86
size_t mutt_str_strfcpy(char *dest, const char *src, size_t dsize)
Copy a string into a buffer (guaranteeing NUL-termination)
Definition: string.c:750
int mutt_hist_search(const char *search_buf, enum HistoryClass hclass, char **matches)
Find matches in a history list.
Definition: history.c:411
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:94
#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 184 of file mutt_history.c.

185 {
186  if (!nc->event_data)
187  return -1;
188  if (nc->event_type != NT_CONFIG)
189  return 0;
190 
191  struct EventConfig *ec = nc->event_data;
192 
193  if (mutt_str_strcmp(ec->name, "history") != 0)
194  return 0;
195 
196  mutt_hist_init();
197  return 0;
198 }
A config-change event.
Definition: subset.h:68
enum NotifyType event_type
Send: Event type, e.g. NT_ACCOUNT.
Definition: observer.h:42
void mutt_hist_init(void)
Create a set of empty History ring buffers.
Definition: history.c:462
void * event_data
Data from notify_send()
Definition: observer.h:44
Config has changed.
Definition: notify_type.h:34
const char * name
Name of config item that changed.
Definition: subset.h:71
int mutt_str_strcmp(const char *a, const char *b)
Compare two strings, safely.
Definition: string.c:615
+ 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 44 of file mutt_history.c.