NeoMutt  2020-03-20-65-g141838
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/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, 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::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 60 of file mutt_history.c.

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

81 {
82  char *entry = ((char **) menu->data)[line];
83 
84  mutt_expando_format(buf, buflen, 0, menu->win_index->state.cols, "%s", history_format_str,
85  (unsigned long) entry, MUTT_FORMAT_ARROWCURSOR);
86 }
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:863
#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:60
short cols
Number of columns, can be MUTT_WIN_SIZE_UNLIMITED.
Definition: mutt_window.h:58
struct WindowState state
Current state of the Window.
Definition: mutt_window.h:93
void * data
Extra data for the current menu.
Definition: mutt_menu.h:86
int const char int line
Definition: acutest.h:602
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 95 of file mutt_history.c.

96 {
97  bool done = false;
98  char helpstr[1024];
99  char title[256];
100 
101  snprintf(title, sizeof(title), _("History '%s'"), buf);
102 
103  struct MuttWindow *dlg =
106 #ifdef USE_DEBUG_WINDOW
107  dlg->name = "history";
108 #endif
109  dlg->type = WT_DIALOG;
110  struct MuttWindow *index =
113  index->type = WT_INDEX;
114  struct MuttWindow *ibar = mutt_window_new(
116  ibar->type = WT_INDEX_BAR;
117 
118  if (C_StatusOnTop)
119  {
120  mutt_window_add_child(dlg, ibar);
121  mutt_window_add_child(dlg, index);
122  }
123  else
124  {
125  mutt_window_add_child(dlg, index);
126  mutt_window_add_child(dlg, ibar);
127  }
128 
129  dialog_push(dlg);
130 
131  struct Menu *menu = mutt_menu_new(MENU_GENERIC);
132 
133  menu->pagelen = index->state.rows;
134  menu->win_index = index;
135  menu->win_ibar = ibar;
136 
138  menu->title = title;
139  menu->help = mutt_compile_help(helpstr, sizeof(helpstr), MENU_GENERIC, HistoryHelp);
141 
142  menu->max = match_count;
143  menu->data = matches;
144 
145  while (!done)
146  {
147  switch (mutt_menu_loop(menu))
148  {
149  case OP_GENERIC_SELECT_ENTRY:
150  mutt_str_strfcpy(buf, matches[menu->current], buflen);
151  /* fall through */
152 
153  case OP_EXIT:
154  done = true;
155  break;
156  }
157  }
158 
159  mutt_menu_pop_current(menu);
160  mutt_menu_free(&menu);
161  dialog_pop();
162  mutt_window_free(&dlg);
163 }
WHERE bool C_StatusOnTop
Config: Display the status bar at the top.
Definition: globals.h:252
GUI selectable list of items.
Definition: mutt_menu.h:82
Dialog (nested Windows) displayed to the user.
Definition: mutt_window.h:70
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:628
void dialog_push(struct MuttWindow *dlg)
Display a Window to the user.
Definition: mutt_window.c:605
#define _(a)
Definition: message.h:28
A division of the screen.
Definition: mutt_window.h:88
An Index Window containing a selection list.
Definition: mutt_window.h:74
static const struct Mapping HistoryHelp[]
Definition: mutt_history.c:45
void mutt_window_free(struct MuttWindow **ptr)
Free a Window and its children.
Definition: mutt_window.c:74
struct MuttWindow * win_ibar
Definition: mutt_menu.h:96
const char * title
Title of this menu.
Definition: mutt_menu.h:84
Window has a fixed size.
Definition: mutt_window.h:44
const char * help
Quickref for the current menu.
Definition: mutt_menu.h:85
struct WindowState state
Current state of the Window.
Definition: mutt_window.h:93
struct MuttWindow * mutt_window_new(enum MuttWindowOrientation orient, enum MuttWindowSize size, int rows, int cols)
Create a new Window.
Definition: mutt_window.c:56
#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:57
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:773
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:473
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:80
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:116
Window wants as much space as possible.
Definition: mutt_window.h:45
Index Bar containing status info about the Index.
Definition: mutt_window.h:75
enum WindowType type
Window type, e.g. WT_SIDEBAR.
Definition: mutt_window.h:103
void(* make_entry)(char *buf, size_t buflen, struct Menu *menu, int line)
Format a item for a menu.
Definition: mutt_menu.h:120
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 171 of file mutt_history.c.

172 {
173  char **matches = mutt_mem_calloc(C_History, sizeof(char *));
174  int match_count = mutt_hist_search(buf, hclass, matches);
175  if (match_count)
176  {
177  if (match_count == 1)
178  mutt_str_strfcpy(buf, matches[0], buflen);
179  else
180  history_menu(buf, buflen, matches, match_count);
181  }
182  FREE(&matches);
183 }
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
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:773
int mutt_hist_search(const char *search_buf, enum HistoryClass hclass, char **matches)
Find matches in a history list.
Definition: history.c:402
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:95
#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 188 of file mutt_history.c.

189 {
190  if (!nc->event_data)
191  return -1;
192  if (nc->event_type != NT_CONFIG)
193  return 0;
194 
195  struct EventConfig *ec = nc->event_data;
196 
197  if (mutt_str_strcmp(ec->name, "history") != 0)
198  return 0;
199 
200  mutt_hist_init();
201  return 0;
202 }
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.
Definition: notify_type.h:34
const char * name
Name of config item that changed.
Definition: subset.h:73
int mutt_str_strcmp(const char *a, const char *b)
Compare two strings, safely.
Definition: string.c:638
+ 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 45 of file mutt_history.c.