NeoMutt  2019-11-11
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 "mutt.h"
#include "curs_lib.h"
#include "format_flags.h"
#include "keymap.h"
#include "mutt_menu.h"
#include "mutt_window.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 58 of file mutt_history.c.

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

79 {
80  char *entry = ((char **) menu->data)[line];
81 
82  mutt_expando_format(buf, buflen, 0, menu->indexwin->cols, "%s", history_format_str,
83  (unsigned long) entry, MUTT_FORMAT_ARROWCURSOR);
84 }
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:878
#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:58
const char * line
Definition: common.c:36
struct MuttWindow * indexwin
Definition: mutt_menu.h:95
void * data
Extra data for the current menu.
Definition: mutt_menu.h:86
+ 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 93 of file mutt_history.c.

94 {
95  bool done = false;
96  char helpstr[1024];
97  char title[256];
98 
99  snprintf(title, sizeof(title), _("History '%s'"), buf);
100 
101  struct Menu *menu = mutt_menu_new(MENU_GENERIC);
103  menu->title = title;
104  menu->help = mutt_compile_help(helpstr, sizeof(helpstr), MENU_GENERIC, HistoryHelp);
106 
107  menu->max = match_count;
108  menu->data = matches;
109 
110  while (!done)
111  {
112  switch (mutt_menu_loop(menu))
113  {
114  case OP_GENERIC_SELECT_ENTRY:
115  mutt_str_strfcpy(buf, matches[menu->current], buflen);
116  /* fall through */
117 
118  case OP_EXIT:
119  done = true;
120  break;
121  }
122  }
123 
124  mutt_menu_pop_current(menu);
125  mutt_menu_free(&menu);
126 }
GUI selectable list of items.
Definition: mutt_menu.h:82
#define _(a)
Definition: message.h:28
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
static const struct Mapping HistoryHelp[]
Definition: mutt_history.c:43
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 max
Number of entries in the menu.
Definition: mutt_menu.h:88
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:78
void * data
Extra data for the current menu.
Definition: mutt_menu.h:86
int current
Current entry.
Definition: mutt_menu.h:87
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
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 134 of file mutt_history.c.

135 {
136  char **matches = mutt_mem_calloc(C_History, sizeof(char *));
137  int match_count = mutt_hist_search(buf, hclass, matches);
138  if (match_count)
139  {
140  if (match_count == 1)
141  mutt_str_strfcpy(buf, matches[0], buflen);
142  else
143  history_menu(buf, buflen, matches, match_count);
144  }
145  FREE(&matches);
146 }
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:93
#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 151 of file mutt_history.c.

152 {
153  if (!nc)
154  return -1;
155 
156  struct EventConfig *ec = (struct EventConfig *) nc->event;
157 
158  if (mutt_str_strcmp(ec->name, "history") != 0)
159  return 0;
160 
161  mutt_hist_init();
162  return 0;
163 }
A config-change event.
Definition: set.h:199
intptr_t event
Send: event data.
Definition: observer.h:46
void mutt_hist_init(void)
Create a set of empty History ring buffers.
Definition: history.c:462
const char * name
Name of config item that changed.
Definition: set.h:203
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 43 of file mutt_history.c.