summaryrefslogtreecommitdiff
path: root/src/help.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/help.c')
-rw-r--r--src/help.c226
1 files changed, 94 insertions, 132 deletions
diff --git a/src/help.c b/src/help.c
index 0eede72..6b00fa2 100644
--- a/src/help.c
+++ b/src/help.c
@@ -1,9 +1,9 @@
-/* $Id: help.c 4453 2009-12-02 03:36:22Z astyanax $ */
+/* $Id: help.c 5051 2014-07-02 09:29:05Z bens $ */
/**************************************************************************
* help.c *
* *
* Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, *
- * 2009 Free Software Foundation, Inc. *
+ * 2009, 2010, 2011, 2013, 2014 Free Software Foundation, Inc. *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 3, or (at your option) *
@@ -37,29 +37,24 @@ static char *help_text = NULL;
void do_help(void (*refresh_func)(void))
{
int kbinput = ERR;
- bool meta_key, func_key, old_no_help = ISSET(NO_HELP);
- bool abort = FALSE;
- /* Whether we should abort the help browser. */
+ bool old_no_help = ISSET(NO_HELP);
size_t line = 0;
/* The line number in help_text of the first displayed help
* line. This variable is zero-based. */
size_t last_line = 0;
/* The line number in help_text of the last help line. This
* variable is zero-based. */
-#ifndef DISABLE_MOUSE
- /* The current shortcut list. */
int oldmenu = currmenu;
-#endif
+ /* The menu we were called from. */
const char *ptr;
/* The current line of the help text. */
size_t old_line = (size_t)-1;
/* The line we were on before the current line. */
- const sc *s;
- const subnfunc *f;
+ functionptrtype func;
+ /* The function of the key the user typed in. */
curs_set(0);
blank_edit();
- wattroff(bottomwin, reverse_attr);
blank_statusbar();
/* Set help_text as the string to display. */
@@ -67,11 +62,9 @@ void do_help(void (*refresh_func)(void))
assert(help_text != NULL);
-#ifndef DISABLE_MOUSE
/* Set currmenu to allow clicking on the help screen's shortcut
* list, after help_init() is called. */
currmenu = MHELP;
-#endif
if (ISSET(NO_HELP)) {
/* Make sure that the help screen's shortcut list will actually
@@ -94,7 +87,7 @@ void do_help(void (*refresh_func)(void))
if (last_line > 0)
last_line--;
- while (!abort) {
+ while (TRUE) {
size_t i;
/* Display the help text if we don't have a key, or if the help
@@ -126,62 +119,46 @@ void do_help(void (*refresh_func)(void))
old_line = line;
- kbinput = get_kbinput(edit, &meta_key, &func_key);
+ kbinput = get_kbinput(edit);
#ifndef DISABLE_MOUSE
- if (kbinput == KEY_MOUSE) {
- int mouse_x, mouse_y;
- get_mouseinput(&mouse_x, &mouse_y, TRUE);
- continue;
- /* Redraw the screen. */
+ if (kbinput == KEY_MOUSE) {
+ int mouse_x, mouse_y;
+ get_mouseinput(&mouse_x, &mouse_y, TRUE);
+ continue; /* Redraw the screen. */
}
#endif
- parse_help_input(&kbinput, &meta_key, &func_key);
- s = get_shortcut(MHELP, &kbinput, &meta_key, &func_key);
- if (!s)
- continue;
- f = sctofunc((sc *) s);
- if (!f)
- continue;
-
- if (f->scfunc == TOTAL_REFRESH) {
- total_redraw();
- break;
- } else if (f->scfunc == DO_PAGE_UP) {
- if (line > editwinrows - 2)
- line -= editwinrows - 2;
- else
- line = 0;
- } else if (f->scfunc == DO_PAGE_DOWN) {
- if (line + (editwinrows - 1) < last_line)
- line += editwinrows - 2;
- } else if (f->scfunc == DO_UP_VOID) {
- if (line > 0)
- line--;
- } else if (f->scfunc == DO_DOWN_VOID) {
- if (line + (editwinrows - 1) < last_line)
- line++;
- } else if (f->scfunc == DO_FIRST_LINE) {
- if (meta_key)
- line = 0;
- break;
- } else if (f->scfunc == DO_LAST_LINE) {
- if (meta_key) {
- if (line + (editwinrows - 1) < last_line)
- line = last_line - (editwinrows - 1);
- }
- break;
- /* Abort the help browser. */
- } else if (f->scfunc == DO_EXIT) {
- abort = TRUE;
- break;
+ func = parse_help_input(&kbinput);
+
+ if (func == total_refresh) {
+ total_redraw();
+ } else if (func == do_page_up) {
+ if (line > editwinrows - 2)
+ line -= editwinrows - 2;
+ else
+ line = 0;
+ } else if (func == do_page_down) {
+ if (line + (editwinrows - 1) < last_line)
+ line += editwinrows - 2;
+ } else if (func == do_up_void) {
+ if (line > 0)
+ line--;
+ } else if (func == do_down_void) {
+ if (line + (editwinrows - 1) < last_line)
+ line++;
+ } else if (func == do_first_line) {
+ line = 0;
+ } else if (func == do_last_line) {
+ if (line + (editwinrows - 1) < last_line)
+ line = last_line - (editwinrows - 1);
+ } else if (func == do_exit) {
+ /* Exit from the help browser. */
+ break;
}
}
-#ifndef DISABLE_MOUSE
currmenu = oldmenu;
-#endif
if (old_no_help) {
blank_bottombars();
@@ -201,14 +178,6 @@ void do_help(void (*refresh_func)(void))
help_text = NULL;
}
-#ifndef DISABLE_BROWSER
-/* Start the help browser for the file browser. */
-void do_browser_help(void)
-{
- do_help(&browser_refresh);
-}
-#endif
-
/* This function allocates help_text, and stores the help string in it.
* help_text should be NULL initially. */
void help_init(void)
@@ -224,7 +193,7 @@ void help_init(void)
int scsfound = 0;
#ifndef NANO_TINY
-#ifdef ENABLE_NANORC
+#ifndef DISABLE_NANORC
bool old_whitespace = ISSET(WHITESPACE_DISPLAY);
UNSET(WHITESPACE_DISPLAY);
@@ -232,7 +201,7 @@ void help_init(void)
#endif
/* First, set up the initial help text for the current function. */
- if (currmenu == MWHEREIS || currmenu == MREPLACE || currmenu == MREPLACE2) {
+ if (currmenu == MWHEREIS || currmenu == MREPLACE || currmenu == MREPLACEWITH) {
htx[0] = N_("Search Command Help Text\n\n "
"Enter the words or characters you would like to "
"search for, and then press Enter. If there is a "
@@ -392,24 +361,23 @@ void help_init(void)
if (htx[2] != NULL)
allocsize += strlen(htx[2]);
- /* Count the shortcut help text. Each entry has up to three keys,
- * which fill 24 columns, plus translated text, plus one or two
- * \n's. */
+ /* Calculate the length of the shortcut help text. Each entry has
+ * one or two keys, which fill 16 columns, plus translated text,
+ * plus one or two \n's. */
for (f = allfuncs; f != NULL; f = f->next)
- if (f->menus & currmenu)
- allocsize += (24 * mb_cur_max()) + strlen(f->help) + 2;
+ if (f->menus & currmenu)
+ allocsize += (16 * mb_cur_max()) + strlen(f->help) + 2;
#ifndef NANO_TINY
/* If we're on the main list, we also count the toggle help text.
- * Each entry has "M-%c\t\t\t", which fills 24 columns, plus a
- * space, plus translated text, plus one or two '\n's. */
+ * Each entry has "M-%c\t\t", five chars which fill 16 columns,
+ * plus a space, plus translated text, plus one or two '\n's. */
if (currmenu == MMAIN) {
size_t endis_len = strlen(_("enable/disable"));
for (s = sclist; s != NULL; s = s->next)
- if (s->scfunc == DO_TOGGLE)
- allocsize += strlen(_(flagtostr(s->toggle))) + endis_len + 9;
-
+ if (s->scfunc == do_toggle_void)
+ allocsize += strlen(_(flagtostr(s->toggle))) + endis_len + 8;
}
#endif
@@ -433,39 +401,36 @@ void help_init(void)
/* Now add our shortcut info. */
for (f = allfuncs; f != NULL; f = f->next) {
- if ((f->menus & currmenu) == 0)
+ if ((f->menus & currmenu) == 0)
continue;
- if (!f->desc || !strcmp(f->desc, ""))
- continue;
-
- /* Lets just try and use the first 3 shortcuts
- from the new struct... */
- for (s = sclist, scsfound = 0; s != NULL; s = s->next) {
+ /* Let's simply show the first two shortcuts from the list. */
+ for (s = sclist, scsfound = 0; s != NULL; s = s->next) {
- if (scsfound == 3)
- continue;
-
- if (s->type == RAW)
+ if (s->type == RAWINPUT)
continue;
if ((s->menu & currmenu) == 0)
continue;
- if (s->scfunc == f->scfunc) {
+ if (s->scfunc == f->scfunc) {
scsfound++;
-
- if (scsfound == 1)
- ptr += sprintf(ptr, "%s", s->keystr);
- else
- ptr += sprintf(ptr, "(%s)", s->keystr);
- *(ptr++) = '\t';
+ /* Make the first column narrower (6) than the second (10),
+ * but allow it to spill into the second, for "M-Space". */
+ if (scsfound == 1) {
+ sprintf(ptr, "%s ", s->keystr);
+ ptr += 6;
+ } else {
+ ptr += sprintf(ptr, "(%s)\t", s->keystr);
+ break;
+ }
}
}
- /* Pad with tabs if we didnt find 3 */
- for (; scsfound < 3; scsfound++) {
- *(ptr++) = '\t';
- }
+
+ if (scsfound == 0)
+ ptr += sprintf(ptr, "\t\t");
+ else if (scsfound == 1)
+ ptr += 10;
/* The shortcut's help text. */
ptr += sprintf(ptr, "%s\n", _(f->help));
@@ -477,48 +442,41 @@ void help_init(void)
#ifndef NANO_TINY
/* And the toggles... */
if (currmenu == MMAIN)
- for (s = sclist; s != NULL; s = s->next)
- if (s->scfunc == DO_TOGGLE)
- ptr += sprintf(ptr, "(%s)\t\t\t%s %s\n",
- s->keystr, _(flagtostr(s->toggle)), _("enable/disable"));
-
+ for (s = sclist; s != NULL; s = s->next) {
+ if (s->scfunc == do_toggle_void)
+ ptr += sprintf(ptr, "%s\t\t%s %s\n", (s->menu == MMAIN ? s->keystr : ""),
+ _(flagtostr(s->toggle)), _("enable/disable"));
+ if (s->toggle == NO_COLOR_SYNTAX || s->toggle == TABS_TO_SPACES)
+ ptr += sprintf(ptr, "\n");
+ }
-#ifdef ENABLE_NANORC
+#ifndef DISABLE_NANORC
if (old_whitespace)
SET(WHITESPACE_DISPLAY);
#endif
-#endif
+#endif /* !NANO_TINY */
/* If all went well, we didn't overwrite the allocated space for
* help_text. */
assert(strlen(help_text) <= allocsize + 1);
}
-/* Determine the shortcut key corresponding to the values of kbinput
- * (the key itself), meta_key (whether the key is a meta sequence), and
- * func_key (whether the key is a function key), if any. In the
- * process, convert certain non-shortcut keys into their corresponding
- * shortcut keys. */
-void parse_help_input(int *kbinput, bool *meta_key, bool *func_key)
+/* Return the function that is bound to the given key, accepting certain
+ * plain characters too, for consistency with the file browser. */
+functionptrtype parse_help_input(int *kbinput)
{
- get_shortcut(MHELP, kbinput, meta_key, func_key);
-
- if (!*meta_key) {
+ if (!meta_key) {
switch (*kbinput) {
- /* For consistency with the file browser. */
case ' ':
- *kbinput = sc_seq_or(DO_PAGE_UP, 0);
- break;
+ return do_page_down;
case '-':
- *kbinput = sc_seq_or(DO_PAGE_DOWN, 0);;
- break;
- /* Cancel is equivalent to Exit here. */
+ return do_page_up;
case 'E':
case 'e':
- *kbinput = sc_seq_or(DO_EXIT, 0);;
- break;
+ return do_exit;
}
}
+ return func_from_key(kbinput);
}
/* Calculate the next line of help_text, starting at ptr. */
@@ -547,17 +505,21 @@ size_t help_line_len(const char *ptr)
#endif /* !DISABLE_HELP */
-/* Start the help browser for the edit window. */
+/* Start the help browser. */
void do_help_void(void)
{
-
#ifndef DISABLE_HELP
- /* Start the help browser for the edit window. */
- do_help(&edit_refresh);
+ /* Start the help browser, with the correct refresher for afterwards. */
+#ifndef DISABLE_BROWSER
+ if (currmenu == MBROWSER || currmenu == MWHEREISFILE || currmenu == MGOTODIR)
+ do_help(&browser_refresh);
+ else
+#endif
+ do_help(&edit_refresh);
#else
if (currmenu == MMAIN)
nano_disabled_msg();
else
beep();
-#endif
+#endif /* !DISABLE_HELP */
}