2005-11-01 19:32:45 +00:00
|
|
|
/**************************************************************************
|
|
|
|
* help.c *
|
|
|
|
* *
|
2009-12-02 03:36:22 +00:00
|
|
|
* Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, *
|
2014-04-30 20:18:26 +00:00
|
|
|
* 2009, 2010, 2011, 2013, 2014 Free Software Foundation, Inc. *
|
2005-11-01 19:32:45 +00:00
|
|
|
* 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 *
|
2007-08-11 05:17:36 +00:00
|
|
|
* the Free Software Foundation; either version 3, or (at your option) *
|
2005-11-01 19:32:45 +00:00
|
|
|
* any later version. *
|
|
|
|
* *
|
|
|
|
* 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, write to the Free Software *
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
|
|
|
|
* 02110-1301, USA. *
|
|
|
|
* *
|
|
|
|
**************************************************************************/
|
|
|
|
|
2005-12-08 02:47:10 +00:00
|
|
|
#include "proto.h"
|
2005-11-01 19:32:45 +00:00
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <ctype.h>
|
|
|
|
|
|
|
|
#ifndef DISABLE_HELP
|
|
|
|
|
|
|
|
static char *help_text = NULL;
|
|
|
|
/* The text displayed in the help window. */
|
|
|
|
|
2015-08-16 08:43:56 +00:00
|
|
|
static char *end_of_intro = NULL;
|
|
|
|
/* The point in the help text where the introductory paragraphs end
|
|
|
|
* and the shortcut descriptions begin. */
|
|
|
|
|
2015-08-16 09:28:33 +00:00
|
|
|
/* Our main help-viewer function. */
|
|
|
|
void do_help(void)
|
2005-11-01 23:00:56 +00:00
|
|
|
{
|
2006-06-30 21:13:55 +00:00
|
|
|
int kbinput = ERR;
|
2014-06-30 18:04:33 +00:00
|
|
|
bool old_no_help = ISSET(NO_HELP);
|
2006-05-06 02:26:18 +00:00
|
|
|
size_t line = 0;
|
2005-11-01 23:00:56 +00:00
|
|
|
/* The line number in help_text of the first displayed help
|
|
|
|
* line. This variable is zero-based. */
|
2006-05-06 02:42:42 +00:00
|
|
|
size_t last_line = 0;
|
2006-05-06 02:26:18 +00:00
|
|
|
/* The line number in help_text of the last help line. This
|
|
|
|
* variable is zero-based. */
|
2008-03-05 07:34:01 +00:00
|
|
|
int oldmenu = currmenu;
|
2014-04-14 09:57:06 +00:00
|
|
|
/* The menu we were called from. */
|
2006-05-06 02:26:18 +00:00
|
|
|
const char *ptr;
|
2007-01-01 05:15:32 +00:00
|
|
|
/* The current line of the help text. */
|
2006-07-05 02:24:23 +00:00
|
|
|
size_t old_line = (size_t)-1;
|
|
|
|
/* The line we were on before the current line. */
|
2014-07-02 09:29:05 +00:00
|
|
|
functionptrtype func;
|
|
|
|
/* The function of the key the user typed in. */
|
2005-11-01 23:00:56 +00:00
|
|
|
|
2016-02-13 19:41:12 +00:00
|
|
|
/* Don't show a cursor in the help screen. */
|
2005-11-01 23:00:56 +00:00
|
|
|
curs_set(0);
|
|
|
|
blank_edit();
|
|
|
|
blank_statusbar();
|
|
|
|
|
|
|
|
/* Set help_text as the string to display. */
|
|
|
|
help_init();
|
|
|
|
|
|
|
|
assert(help_text != NULL);
|
|
|
|
|
|
|
|
if (ISSET(NO_HELP)) {
|
|
|
|
/* Make sure that the help screen's shortcut list will actually
|
|
|
|
* be displayed. */
|
|
|
|
UNSET(NO_HELP);
|
|
|
|
window_init();
|
|
|
|
}
|
|
|
|
|
2008-03-05 07:34:01 +00:00
|
|
|
bottombars(MHELP);
|
2006-07-05 06:38:47 +00:00
|
|
|
wnoutrefresh(bottomwin);
|
2005-11-01 23:00:56 +00:00
|
|
|
|
2015-05-28 13:02:29 +00:00
|
|
|
while (TRUE) {
|
|
|
|
size_t i;
|
|
|
|
|
2015-05-28 13:28:37 +00:00
|
|
|
ptr = help_text;
|
2006-05-06 02:26:18 +00:00
|
|
|
|
2015-08-16 09:14:42 +00:00
|
|
|
/* Find the line number of the last line of the help text. */
|
2015-05-28 13:28:37 +00:00
|
|
|
for (last_line = 0; *ptr != '\0'; last_line++) {
|
|
|
|
ptr += help_line_len(ptr);
|
|
|
|
if (*ptr == '\n')
|
|
|
|
ptr++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (last_line > 0)
|
|
|
|
last_line--;
|
2006-05-06 02:26:18 +00:00
|
|
|
|
2015-08-16 09:14:42 +00:00
|
|
|
/* Redisplay if the text was scrolled or an invalid key was pressed. */
|
|
|
|
if (line != old_line || kbinput == ERR) {
|
2006-07-05 01:10:18 +00:00
|
|
|
blank_edit();
|
|
|
|
|
|
|
|
ptr = help_text;
|
|
|
|
|
2015-08-16 09:14:42 +00:00
|
|
|
/* Advance in the text to the first line to be displayed. */
|
2006-07-05 01:10:18 +00:00
|
|
|
for (i = 0; i < line; i++) {
|
|
|
|
ptr += help_line_len(ptr);
|
|
|
|
if (*ptr == '\n')
|
|
|
|
ptr++;
|
|
|
|
}
|
|
|
|
|
2015-08-16 09:14:42 +00:00
|
|
|
/* Now display as many lines as the window will hold. */
|
2006-07-05 01:10:18 +00:00
|
|
|
for (i = 0; i < editwinrows && *ptr != '\0'; i++) {
|
|
|
|
size_t j = help_line_len(ptr);
|
|
|
|
|
|
|
|
mvwaddnstr(edit, i, 0, ptr, j);
|
|
|
|
ptr += j;
|
|
|
|
if (*ptr == '\n')
|
|
|
|
ptr++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
wnoutrefresh(edit);
|
|
|
|
|
2006-07-05 02:24:23 +00:00
|
|
|
old_line = line;
|
|
|
|
|
2016-05-19 18:43:08 +00:00
|
|
|
lastmessage = HUSH;
|
2016-04-30 15:31:43 +00:00
|
|
|
|
2014-06-30 18:04:33 +00:00
|
|
|
kbinput = get_kbinput(edit);
|
2005-11-01 23:00:56 +00:00
|
|
|
|
2015-05-28 13:02:29 +00:00
|
|
|
#ifndef NANO_TINY
|
|
|
|
if (kbinput == KEY_WINCH) {
|
|
|
|
kbinput = ERR;
|
2015-08-16 09:14:42 +00:00
|
|
|
continue; /* Redraw the screen. */
|
2015-05-28 13:02:29 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2008-03-11 04:52:57 +00:00
|
|
|
#ifndef DISABLE_MOUSE
|
2014-04-14 09:57:06 +00:00
|
|
|
if (kbinput == KEY_MOUSE) {
|
2014-06-23 20:22:42 +00:00
|
|
|
int mouse_x, mouse_y;
|
|
|
|
get_mouseinput(&mouse_x, &mouse_y, TRUE);
|
|
|
|
continue; /* Redraw the screen. */
|
2008-03-11 04:52:57 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2014-07-02 09:29:05 +00:00
|
|
|
func = parse_help_input(&kbinput);
|
2008-03-05 07:34:01 +00:00
|
|
|
|
2014-07-02 09:29:05 +00:00
|
|
|
if (func == total_refresh) {
|
2014-06-23 20:22:42 +00:00
|
|
|
total_redraw();
|
2016-07-01 10:41:35 +00:00
|
|
|
} else if (func == do_up_void) {
|
|
|
|
if (line > 0)
|
|
|
|
line--;
|
|
|
|
} else if (func == do_down_void) {
|
|
|
|
if (line + (editwinrows - 1) < last_line)
|
|
|
|
line++;
|
2014-07-02 09:29:05 +00:00
|
|
|
} else if (func == do_page_up) {
|
2014-06-23 20:22:42 +00:00
|
|
|
if (line > editwinrows - 2)
|
|
|
|
line -= editwinrows - 2;
|
|
|
|
else
|
|
|
|
line = 0;
|
2014-07-02 09:29:05 +00:00
|
|
|
} else if (func == do_page_down) {
|
2014-06-23 20:22:42 +00:00
|
|
|
if (line + (editwinrows - 1) < last_line)
|
|
|
|
line += editwinrows - 2;
|
2014-07-02 09:29:05 +00:00
|
|
|
} else if (func == do_first_line) {
|
2014-06-25 09:17:38 +00:00
|
|
|
line = 0;
|
2014-07-02 09:29:05 +00:00
|
|
|
} else if (func == do_last_line) {
|
2014-06-25 09:17:38 +00:00
|
|
|
if (line + (editwinrows - 1) < last_line)
|
|
|
|
line = last_line - (editwinrows - 1);
|
2014-07-02 09:29:05 +00:00
|
|
|
} else if (func == do_exit) {
|
2015-08-16 09:14:42 +00:00
|
|
|
/* Exit from the help viewer. */
|
2014-04-15 19:32:45 +00:00
|
|
|
break;
|
2016-04-27 12:37:31 +00:00
|
|
|
} else
|
|
|
|
unbound_key(kbinput);
|
2006-06-30 22:28:37 +00:00
|
|
|
}
|
2005-11-01 23:00:56 +00:00
|
|
|
|
|
|
|
if (old_no_help) {
|
|
|
|
blank_bottombars();
|
|
|
|
wnoutrefresh(bottomwin);
|
2015-04-07 14:16:07 +00:00
|
|
|
currmenu = oldmenu;
|
2005-11-01 23:00:56 +00:00
|
|
|
SET(NO_HELP);
|
|
|
|
window_init();
|
|
|
|
} else
|
2015-04-07 14:16:07 +00:00
|
|
|
bottombars(oldmenu);
|
2005-11-01 23:00:56 +00:00
|
|
|
|
2015-08-16 09:28:33 +00:00
|
|
|
#ifndef DISABLE_BROWSER
|
|
|
|
if (oldmenu == MBROWSER || oldmenu == MWHEREISFILE || oldmenu == MGOTODIR)
|
|
|
|
browser_refresh();
|
|
|
|
else
|
|
|
|
#endif
|
|
|
|
edit_refresh();
|
2005-11-01 23:00:56 +00:00
|
|
|
|
2015-08-16 17:53:28 +00:00
|
|
|
/* We're exiting from the help screen. */
|
2005-11-01 23:00:56 +00:00
|
|
|
free(help_text);
|
|
|
|
}
|
|
|
|
|
2015-08-16 17:53:28 +00:00
|
|
|
/* Allocate space for the help text for the current menu, and concatenate
|
|
|
|
* the different pieces of text into it. */
|
2005-11-01 19:32:45 +00:00
|
|
|
void help_init(void)
|
|
|
|
{
|
2015-08-16 09:14:42 +00:00
|
|
|
size_t allocsize = 0;
|
|
|
|
/* Space needed for help_text. */
|
|
|
|
const char *htx[3];
|
|
|
|
/* Untranslated help introduction. We break it up into three chunks
|
|
|
|
* in case the full string is too long for the compiler to handle. */
|
2005-11-01 19:32:45 +00:00
|
|
|
char *ptr;
|
2008-03-05 07:34:01 +00:00
|
|
|
const subnfunc *f;
|
|
|
|
const sc *s;
|
|
|
|
|
2005-11-15 03:17:35 +00:00
|
|
|
#ifndef NANO_TINY
|
2005-11-01 19:32:45 +00:00
|
|
|
bool old_whitespace = ISSET(WHITESPACE_DISPLAY);
|
|
|
|
|
|
|
|
UNSET(WHITESPACE_DISPLAY);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* First, set up the initial help text for the current function. */
|
2014-04-16 09:26:15 +00:00
|
|
|
if (currmenu == MWHEREIS || currmenu == MREPLACE || currmenu == MREPLACEWITH) {
|
2005-11-01 19:32:45 +00:00
|
|
|
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 "
|
|
|
|
"match for the text you entered, the screen will be "
|
|
|
|
"updated to the location of the nearest match for the "
|
|
|
|
"search string.\n\n The previous search string will be "
|
|
|
|
"shown in brackets after the search prompt. Hitting "
|
|
|
|
"Enter without entering any text will perform the "
|
|
|
|
"previous search. ");
|
|
|
|
htx[1] = N_("If you have selected text with the mark and then "
|
|
|
|
"search to replace, only matches in the selected text "
|
|
|
|
"will be replaced.\n\n The following function keys are "
|
|
|
|
"available in Search mode:\n\n");
|
|
|
|
htx[2] = NULL;
|
2008-03-05 07:34:01 +00:00
|
|
|
} else if (currmenu == MGOTOLINE) {
|
2005-11-01 19:32:45 +00:00
|
|
|
htx[0] = N_("Go To Line Help Text\n\n "
|
|
|
|
"Enter the line number that you wish to go to and hit "
|
|
|
|
"Enter. If there are fewer lines of text than the "
|
|
|
|
"number you entered, you will be brought to the last "
|
|
|
|
"line of the file.\n\n The following function keys are "
|
|
|
|
"available in Go To Line mode:\n\n");
|
|
|
|
htx[1] = NULL;
|
|
|
|
htx[2] = NULL;
|
2008-03-05 07:34:01 +00:00
|
|
|
} else if (currmenu == MINSERTFILE) {
|
2005-11-01 19:32:45 +00:00
|
|
|
htx[0] = N_("Insert File Help Text\n\n "
|
|
|
|
"Type in the name of a file to be inserted into the "
|
|
|
|
"current file buffer at the current cursor "
|
|
|
|
"location.\n\n If you have compiled nano with multiple "
|
|
|
|
"file buffer support, and enable multiple file buffers "
|
|
|
|
"with the -F or --multibuffer command line flags, the "
|
|
|
|
"Meta-F toggle, or a nanorc file, inserting a file "
|
|
|
|
"will cause it to be loaded into a separate buffer "
|
|
|
|
"(use Meta-< and > to switch between file buffers). ");
|
|
|
|
htx[1] = N_("If you need another blank buffer, do not enter "
|
|
|
|
"any filename, or type in a nonexistent filename at "
|
|
|
|
"the prompt and press Enter.\n\n The following "
|
|
|
|
"function keys are available in Insert File mode:\n\n");
|
|
|
|
htx[2] = NULL;
|
2008-03-05 07:34:01 +00:00
|
|
|
} else if (currmenu == MWRITEFILE) {
|
2005-11-01 19:32:45 +00:00
|
|
|
htx[0] = N_("Write File Help Text\n\n "
|
|
|
|
"Type the name that you wish to save the current file "
|
|
|
|
"as and press Enter to save the file.\n\n If you have "
|
|
|
|
"selected text with the mark, you will be prompted to "
|
|
|
|
"save only the selected portion to a separate file. To "
|
|
|
|
"reduce the chance of overwriting the current file with "
|
|
|
|
"just a portion of it, the current filename is not the "
|
|
|
|
"default in this mode.\n\n The following function keys "
|
|
|
|
"are available in Write File mode:\n\n");
|
|
|
|
htx[1] = NULL;
|
|
|
|
htx[2] = NULL;
|
|
|
|
}
|
|
|
|
#ifndef DISABLE_BROWSER
|
2008-03-05 07:34:01 +00:00
|
|
|
else if (currmenu == MBROWSER) {
|
2005-11-01 19:32:45 +00:00
|
|
|
htx[0] = N_("File Browser Help Text\n\n "
|
|
|
|
"The file browser is used to visually browse the "
|
|
|
|
"directory structure to select a file for reading "
|
|
|
|
"or writing. You may use the arrow keys or Page Up/"
|
|
|
|
"Down to browse through the files, and S or Enter to "
|
|
|
|
"choose the selected file or enter the selected "
|
|
|
|
"directory. To move up one level, select the "
|
|
|
|
"directory called \"..\" at the top of the file "
|
|
|
|
"list.\n\n The following function keys are available "
|
|
|
|
"in the file browser:\n\n");
|
|
|
|
htx[1] = NULL;
|
|
|
|
htx[2] = NULL;
|
2008-03-05 07:34:01 +00:00
|
|
|
} else if (currmenu == MWHEREISFILE) {
|
2006-03-30 07:03:04 +00:00
|
|
|
htx[0] = N_("Browser 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 "
|
|
|
|
"match for the text you entered, the screen will be "
|
|
|
|
"updated to the location of the nearest match for the "
|
|
|
|
"search string.\n\n The previous search string will be "
|
|
|
|
"shown in brackets after the search prompt. Hitting "
|
|
|
|
"Enter without entering any text will perform the "
|
2006-06-09 12:44:34 +00:00
|
|
|
"previous search.\n\n");
|
|
|
|
htx[1] = N_(" The following function keys are available in "
|
2006-03-30 07:03:04 +00:00
|
|
|
"Browser Search mode:\n\n");
|
|
|
|
htx[2] = NULL;
|
2008-03-05 07:34:01 +00:00
|
|
|
} else if (currmenu == MGOTODIR) {
|
2005-11-01 19:32:45 +00:00
|
|
|
htx[0] = N_("Browser Go To Directory Help Text\n\n "
|
|
|
|
"Enter the name of the directory you would like to "
|
|
|
|
"browse to.\n\n If tab completion has not been "
|
|
|
|
"disabled, you can use the Tab key to (attempt to) "
|
|
|
|
"automatically complete the directory name.\n\n The "
|
|
|
|
"following function keys are available in Browser Go "
|
|
|
|
"To Directory mode:\n\n");
|
|
|
|
htx[1] = NULL;
|
|
|
|
htx[2] = NULL;
|
|
|
|
}
|
2006-03-25 15:23:55 +00:00
|
|
|
#endif /* !DISABLE_BROWSER */
|
2005-11-01 19:32:45 +00:00
|
|
|
#ifndef DISABLE_SPELLER
|
2008-03-05 07:34:01 +00:00
|
|
|
else if (currmenu == MSPELL) {
|
2005-11-01 19:32:45 +00:00
|
|
|
htx[0] = N_("Spell Check Help Text\n\n "
|
|
|
|
"The spell checker checks the spelling of all text in "
|
|
|
|
"the current file. When an unknown word is "
|
|
|
|
"encountered, it is highlighted and a replacement can "
|
|
|
|
"be edited. It will then prompt to replace every "
|
|
|
|
"instance of the given misspelled word in the current "
|
|
|
|
"file, or, if you have selected text with the mark, in "
|
2006-05-19 23:07:02 +00:00
|
|
|
"the selected text.\n\n The following function keys "
|
2005-11-01 19:32:45 +00:00
|
|
|
"are available in Spell Check mode:\n\n");
|
|
|
|
htx[1] = NULL;
|
|
|
|
htx[2] = NULL;
|
|
|
|
}
|
2006-03-25 15:23:55 +00:00
|
|
|
#endif /* !DISABLE_SPELLER */
|
2005-11-15 03:17:35 +00:00
|
|
|
#ifndef NANO_TINY
|
2008-03-05 07:34:01 +00:00
|
|
|
else if (currmenu == MEXTCMD) {
|
2005-11-01 19:32:45 +00:00
|
|
|
htx[0] = N_("Execute Command Help Text\n\n "
|
2006-06-08 02:16:37 +00:00
|
|
|
"This mode allows you to insert the output of a "
|
2005-11-01 19:32:45 +00:00
|
|
|
"command run by the shell into the current buffer (or "
|
2007-01-29 15:34:45 +00:00
|
|
|
"a new buffer in multiple file buffer mode). If you "
|
2005-11-01 19:32:45 +00:00
|
|
|
"need another blank buffer, do not enter any "
|
2006-05-19 23:07:02 +00:00
|
|
|
"command.\n\n The following function keys are "
|
|
|
|
"available in Execute Command mode:\n\n");
|
2005-11-01 19:32:45 +00:00
|
|
|
htx[1] = NULL;
|
|
|
|
htx[2] = NULL;
|
|
|
|
}
|
2006-03-25 15:23:55 +00:00
|
|
|
#endif /* !NANO_TINY */
|
2005-11-01 19:32:45 +00:00
|
|
|
else {
|
|
|
|
/* Default to the main help list. */
|
2006-07-31 01:30:31 +00:00
|
|
|
htx[0] = N_("Main nano help text\n\n "
|
2005-11-01 19:32:45 +00:00
|
|
|
"The nano editor is designed to emulate the "
|
|
|
|
"functionality and ease-of-use of the UW Pico text "
|
|
|
|
"editor. There are four main sections of the editor. "
|
|
|
|
"The top line shows the program version, the current "
|
|
|
|
"filename being edited, and whether or not the file "
|
|
|
|
"has been modified. Next is the main editor window "
|
|
|
|
"showing the file being edited. The status line is "
|
|
|
|
"the third line from the bottom and shows important "
|
2006-08-19 11:11:51 +00:00
|
|
|
"messages. ");
|
|
|
|
htx[1] = N_("The bottom two lines show the most commonly used "
|
2016-04-05 13:42:58 +00:00
|
|
|
"shortcuts in the editor.\n\n Shortcuts are written as "
|
|
|
|
"follows: Control-key sequences are notated with a '^' "
|
|
|
|
"and can be entered either by using the Ctrl key or "
|
|
|
|
"pressing the Esc key twice. Meta-key sequences are "
|
|
|
|
"notated with 'M-' and can be entered using either the "
|
|
|
|
"Alt, Cmd, or Esc key, depending on your keyboard setup. ");
|
2005-11-01 19:32:45 +00:00
|
|
|
htx[2] = N_("Also, pressing Esc twice and then typing a "
|
|
|
|
"three-digit decimal number from 000 to 255 will enter "
|
|
|
|
"the character with the corresponding value. The "
|
|
|
|
"following keystrokes are available in the main editor "
|
|
|
|
"window. Alternative keys are shown in "
|
|
|
|
"parentheses:\n\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
htx[0] = _(htx[0]);
|
|
|
|
if (htx[1] != NULL)
|
|
|
|
htx[1] = _(htx[1]);
|
|
|
|
if (htx[2] != NULL)
|
|
|
|
htx[2] = _(htx[2]);
|
|
|
|
|
|
|
|
allocsize += strlen(htx[0]);
|
|
|
|
if (htx[1] != NULL)
|
|
|
|
allocsize += strlen(htx[1]);
|
|
|
|
if (htx[2] != NULL)
|
|
|
|
allocsize += strlen(htx[2]);
|
|
|
|
|
2014-05-13 20:14:01 +00:00
|
|
|
/* 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. */
|
2015-08-16 09:14:42 +00:00
|
|
|
for (f = allfuncs; f != NULL; f = f->next)
|
|
|
|
if (f->menus & currmenu)
|
|
|
|
allocsize += (16 * mb_cur_max()) + strlen(f->help) + 2;
|
2005-11-01 19:32:45 +00:00
|
|
|
|
2005-11-15 03:17:35 +00:00
|
|
|
#ifndef NANO_TINY
|
2005-11-01 19:32:45 +00:00
|
|
|
/* If we're on the main list, we also count the toggle help text.
|
2014-05-13 20:14:01 +00:00
|
|
|
* 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. */
|
2008-03-05 07:34:01 +00:00
|
|
|
if (currmenu == MMAIN) {
|
2006-06-19 16:04:42 +00:00
|
|
|
size_t endis_len = strlen(_("enable/disable"));
|
2005-11-01 19:32:45 +00:00
|
|
|
|
2008-03-05 07:34:01 +00:00
|
|
|
for (s = sclist; s != NULL; s = s->next)
|
2014-04-15 15:02:43 +00:00
|
|
|
if (s->scfunc == do_toggle_void)
|
2014-05-13 20:14:01 +00:00
|
|
|
allocsize += strlen(_(flagtostr(s->toggle))) + endis_len + 8;
|
2005-11-01 19:32:45 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Allocate space for the help text. */
|
|
|
|
help_text = charalloc(allocsize + 1);
|
|
|
|
|
|
|
|
/* Now add the text we want. */
|
|
|
|
strcpy(help_text, htx[0]);
|
|
|
|
if (htx[1] != NULL)
|
|
|
|
strcat(help_text, htx[1]);
|
|
|
|
if (htx[2] != NULL)
|
|
|
|
strcat(help_text, htx[2]);
|
|
|
|
|
|
|
|
ptr = help_text + strlen(help_text);
|
|
|
|
|
2015-08-16 08:43:56 +00:00
|
|
|
/* Remember this end-of-introduction, start-of-shortcuts. */
|
|
|
|
end_of_intro = ptr;
|
|
|
|
|
2008-03-05 07:34:01 +00:00
|
|
|
/* Now add our shortcut info. */
|
|
|
|
for (f = allfuncs; f != NULL; f = f->next) {
|
2015-08-16 08:49:29 +00:00
|
|
|
int scsfound = 0;
|
2005-11-01 19:32:45 +00:00
|
|
|
|
2014-04-14 09:57:06 +00:00
|
|
|
if ((f->menus & currmenu) == 0)
|
2008-03-05 07:34:01 +00:00
|
|
|
continue;
|
2005-11-01 19:32:45 +00:00
|
|
|
|
2014-04-22 20:10:43 +00:00
|
|
|
/* Let's simply show the first two shortcuts from the list. */
|
2015-08-16 08:49:29 +00:00
|
|
|
for (s = sclist; s != NULL; s = s->next) {
|
2005-11-01 19:32:45 +00:00
|
|
|
|
2015-07-15 20:13:05 +00:00
|
|
|
if ((s->menus & currmenu) == 0)
|
2008-03-05 07:34:01 +00:00
|
|
|
continue;
|
|
|
|
|
2014-04-14 09:57:06 +00:00
|
|
|
if (s->scfunc == f->scfunc) {
|
2008-03-05 07:34:01 +00:00
|
|
|
scsfound++;
|
2014-04-22 20:10:43 +00:00
|
|
|
/* 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);
|
2014-05-13 20:34:15 +00:00
|
|
|
break;
|
2014-04-22 20:10:43 +00:00
|
|
|
}
|
2006-04-20 22:29:02 +00:00
|
|
|
}
|
2005-11-01 19:32:45 +00:00
|
|
|
}
|
2014-04-22 20:10:43 +00:00
|
|
|
|
|
|
|
if (scsfound == 0)
|
|
|
|
ptr += sprintf(ptr, "\t\t");
|
|
|
|
else if (scsfound == 1)
|
|
|
|
ptr += 10;
|
2005-11-01 19:32:45 +00:00
|
|
|
|
2006-06-19 16:04:42 +00:00
|
|
|
/* The shortcut's help text. */
|
2008-03-16 23:57:14 +00:00
|
|
|
ptr += sprintf(ptr, "%s\n", _(f->help));
|
2006-04-22 19:45:26 +00:00
|
|
|
|
2008-03-05 07:34:01 +00:00
|
|
|
if (f->blank_after)
|
2006-04-22 19:45:26 +00:00
|
|
|
ptr += sprintf(ptr, "\n");
|
2005-11-01 19:32:45 +00:00
|
|
|
}
|
|
|
|
|
2005-11-15 03:17:35 +00:00
|
|
|
#ifndef NANO_TINY
|
2005-11-01 19:32:45 +00:00
|
|
|
/* And the toggles... */
|
2015-07-06 17:51:17 +00:00
|
|
|
if (currmenu == MMAIN) {
|
|
|
|
int maximum = 0, counter = 0;
|
|
|
|
|
|
|
|
/* First see how many toggles there are. */
|
2015-07-06 19:17:27 +00:00
|
|
|
for (s = sclist; s != NULL; s = s->next)
|
2016-05-30 07:09:36 +00:00
|
|
|
maximum = (s->toggle && s->ordinal > maximum) ? s->ordinal : maximum;
|
2015-07-06 17:51:17 +00:00
|
|
|
|
|
|
|
/* Now show them in the original order. */
|
|
|
|
while (counter < maximum) {
|
|
|
|
counter++;
|
2015-07-06 19:17:27 +00:00
|
|
|
for (s = sclist; s != NULL; s = s->next)
|
2015-07-06 17:51:17 +00:00
|
|
|
if (s->toggle && s->ordinal == counter) {
|
2015-07-15 20:13:05 +00:00
|
|
|
ptr += sprintf(ptr, "%s\t\t%s %s\n", (s->menus == MMAIN ? s->keystr : ""),
|
2016-05-30 07:09:36 +00:00
|
|
|
_(flagtostr(s->toggle)), _("enable/disable"));
|
2015-07-06 19:17:27 +00:00
|
|
|
if (s->toggle == NO_COLOR_SYNTAX || s->toggle == TABS_TO_SPACES)
|
|
|
|
ptr += sprintf(ptr, "\n");
|
2015-07-06 17:51:17 +00:00
|
|
|
break;
|
2015-07-06 19:17:27 +00:00
|
|
|
}
|
2014-04-22 20:26:58 +00:00
|
|
|
}
|
2015-07-06 17:51:17 +00:00
|
|
|
}
|
2006-04-22 19:45:26 +00:00
|
|
|
|
2005-11-01 19:32:45 +00:00
|
|
|
if (old_whitespace)
|
|
|
|
SET(WHITESPACE_DISPLAY);
|
2014-05-13 20:14:01 +00:00
|
|
|
#endif /* !NANO_TINY */
|
2005-11-01 19:32:45 +00:00
|
|
|
|
2015-08-16 17:53:28 +00:00
|
|
|
/* If all went well, we didn't overwrite the allocated space. */
|
2005-11-01 19:32:45 +00:00
|
|
|
assert(strlen(help_text) <= allocsize + 1);
|
|
|
|
}
|
|
|
|
|
2014-07-02 09:29:05 +00:00
|
|
|
/* 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)
|
2006-04-24 23:03:21 +00:00
|
|
|
{
|
2014-06-30 18:04:33 +00:00
|
|
|
if (!meta_key) {
|
2006-04-24 23:03:21 +00:00
|
|
|
switch (*kbinput) {
|
2006-04-27 23:39:49 +00:00
|
|
|
case ' ':
|
2014-07-02 09:29:05 +00:00
|
|
|
return do_page_down;
|
2006-04-27 23:39:49 +00:00
|
|
|
case '-':
|
2014-07-02 09:29:05 +00:00
|
|
|
return do_page_up;
|
2006-10-02 21:25:41 +00:00
|
|
|
case 'E':
|
|
|
|
case 'e':
|
2014-07-02 09:29:05 +00:00
|
|
|
return do_exit;
|
2006-04-24 23:03:21 +00:00
|
|
|
}
|
|
|
|
}
|
2014-07-02 09:29:05 +00:00
|
|
|
return func_from_key(kbinput);
|
2006-04-24 23:03:21 +00:00
|
|
|
}
|
|
|
|
|
2015-08-16 09:14:42 +00:00
|
|
|
/* Calculate the displayable length of the help-text line starting at ptr. */
|
2005-11-01 20:11:55 +00:00
|
|
|
size_t help_line_len(const char *ptr)
|
|
|
|
{
|
2015-08-16 12:20:24 +00:00
|
|
|
size_t wrapping_point = (COLS > 24) ? COLS - 1 : 24;
|
2015-08-16 08:43:56 +00:00
|
|
|
/* The target width for wrapping long lines. */
|
2015-08-16 12:20:24 +00:00
|
|
|
ssize_t wrap_location;
|
|
|
|
/* Actual position where the line can be wrapped. */
|
|
|
|
size_t length = 0;
|
|
|
|
/* Full length of the line, until the first newline. */
|
2015-08-16 08:43:56 +00:00
|
|
|
|
|
|
|
/* Avoid overwide paragraphs in the introductory text. */
|
|
|
|
if (ptr < end_of_intro && COLS > 74)
|
2015-08-16 12:20:24 +00:00
|
|
|
wrapping_point = 74;
|
2005-11-01 20:11:55 +00:00
|
|
|
|
2015-08-16 12:20:24 +00:00
|
|
|
wrap_location = break_line(ptr, wrapping_point, TRUE);
|
2015-08-16 12:15:11 +00:00
|
|
|
|
2005-11-01 20:11:55 +00:00
|
|
|
/* Get the length of the entire line up to a null or a newline. */
|
2015-08-16 12:20:24 +00:00
|
|
|
while (*(ptr + length) != '\0' && *(ptr + length) != '\n')
|
|
|
|
length = move_mbright(ptr, length);
|
|
|
|
|
|
|
|
/* If the entire line will just fit the screen, don't wrap it. */
|
|
|
|
if (strnlenpt(ptr, length) <= wrapping_point + 1)
|
|
|
|
return length;
|
|
|
|
else if (wrap_location > 0)
|
|
|
|
return wrap_location;
|
|
|
|
else
|
|
|
|
return 0;
|
2005-11-01 20:11:55 +00:00
|
|
|
}
|
|
|
|
|
2005-11-01 19:32:45 +00:00
|
|
|
#endif /* !DISABLE_HELP */
|
2008-08-30 21:00:00 +00:00
|
|
|
|
2015-08-16 09:28:33 +00:00
|
|
|
/* Start the help viewer. */
|
2008-08-30 21:00:00 +00:00
|
|
|
void do_help_void(void)
|
|
|
|
{
|
|
|
|
#ifndef DISABLE_HELP
|
2015-08-16 09:28:33 +00:00
|
|
|
do_help();
|
2008-08-30 21:00:00 +00:00
|
|
|
#else
|
|
|
|
if (currmenu == MMAIN)
|
2015-07-30 18:10:16 +00:00
|
|
|
say_there_is_no_help();
|
2008-08-30 21:00:00 +00:00
|
|
|
else
|
|
|
|
beep();
|
2014-03-26 19:59:45 +00:00
|
|
|
#endif /* !DISABLE_HELP */
|
2008-08-30 21:00:00 +00:00
|
|
|
}
|