Commit f4276944 authored by David Lawrence Ramsey's avatar David Lawrence Ramsey
Browse files

the last of the low-level input overhaul: make the global shortcut list
use NANO_NO_KEY to represent no key value, add the NANO_HISTORY_KEY
sentinel value, add support for many more escape sequences for those
terminals that generate them, add DB's extensibility tweaks to
do_yesno(), make ASCII 128 act like Backspace when -d is used, add
various cleanups to the low-level input functions, and make the last of
the low-level input routines use the new low-level input functions


git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@1599 35c25a1d-7b9e-4130-9fde-d3aeb78583b8
No related merge requests found
Showing with 685 additions and 350 deletions
+685 -350
......@@ -4,7 +4,7 @@ CVS code -
input, mostly adapted from the code in do_mouse() that handles
clicking on the shortcut list. New function do_mouseinput();
changes to do_mouse(). (DLR) David Benbennick: Add a few
efficiency tweaks.
efficiency/extensibility tweaks.
- Modify the shortcut structure so that instead of having two
miscellaneous key values (misc1 and misc2), there is one key
value reserved for function keys (func_key) and one
......@@ -18,18 +18,44 @@ CVS code -
readability, and eliminate use of adding 32 to values when
testing for toggles, as get_kbinput_accepted() converts toggle
values to lowercase before returning them. (DLR)
- Remove the workarounds for missing KEY_UP and KEY_DOWN, as
they appear to be holdovers of the old way of denoting the
search history shortcuts; if they aren't defined, KEY_LEFT and
KEY_RIGHT probably shouldn't work either, and all four appear
to be standard keys in termcap/terminfo in any case. Add new
special sentinel key values NANO_NO_KEY (for no shortcut key)
and NANO_HISTORY_KEY (for search history keys, both Up and
Down), modify the shortcut list to use them, and modify the
shortcut display routines to handle them. Also modify the
shortcut list code to not treat non-control character values
of val as Meta-sequences, and fix dependencies on that
behavior. (DLR)
- Hook up the verbatim input functions so that verbatim input
can be used in the edit window. New function
do_verbatim_input(); changes to do_char(). (DLR) Additional
minor tweaks to do_char() by David Benbennick.
- Clarify the description of the --rebinddelete option. (DLR)
- files.c:
do_writeout()
- Prompt the user if we're trying to save an existing file (and
not just a selection of it) under a different name. (DLR;
suggested by Jean-Philippe Guérard)
open_prevfile(), open_nextfile()
- For consistency with the rest of the multibuffer code, change
"No more open files" to "No more open file buffers". (DLR)
do_browser()
- Allow '?' to open the help browser, and readd the ability of
'G'/'g' to open the "Go to Directory" prompt (which was
erroneously removed before), for compatibility with Pico.
(DLR)
- global.c:
shortcut_init()
- Allow WHEREIS_NEXT_KEY to be used in view mode. (DLR)
- nano,c:
do_para_operation()
- Convert to use the new low-level input functions. (DLR)
main()
- Remove unused variable option_index. (DLR)
- search.c:
findnextstr(), do_replace_loop()
- Fix potential infinite loops and other misbehavior when doing
......@@ -39,9 +65,40 @@ CVS code -
that such regexes are only found once per line. (DLR; found by
Mike Frysinger and DLR)
- winio.c:
get_kbinput(), get_accepted_kbinput()
- Don't pass in the value of the REBIND_DELETE flag anymore.
Instead, handle it directly inside the functions. (DLR)
get_accepted_kbinput()
- Translate Ctrl-8 into NANO_DELETE_KEY, since it apparently is
generated at the statusbar prompt sometimes on Linux. (DLR)
- Translate Ctrl-8 into NANO_DELETE_KEY (or NANO_BACKSPACE_KEY
if REBIND_DELETE is set), since it apparently is generated
sometimes even when keypad() is TRUE. (DLR)
- Translate KEY_SLEFT into NANO_BACK_KEY and KEY_SRIGHT into
NANO_FORWARD_KEY, since they are sometimes generated by
Shift-Left and Shift-Right. (DLR)
get_ascii_kbinput()
- Tweak to make it slightly more readable. (DLR)
get_verbatim_kbinput()
- Modify to take an extra parameter indicating if we should
interpret ASCII codes or not. (DLR)
get_escape_seq_kbinput()
- Expand to deal with more broken terminals that don't generate
keypad values. Support the escape sequences for Insert,
Delete, Home, End, PageUp, and PageDown, [arrow key],
Ctrl-[arrow key], and Shift-[arrow key] when needed in the
Linux console, the FreeBSD console, the Hurd console, xterm,
rxvt, and Eterm. Also, use get_verbatim_kbinput(), with ASCII
interpretation disabled, to read in the sequences. (DLR)
get_skip_tilde_kbinput()
- Removed, as it is unneeded due to the expansion of
get_escape_seq_kbinput(). (DLR)
get_mouseinput()
- Modify to take an extra parameter indicating if we should
ungetch() the key equivalents of shortcuts we click on or not.
(DLR)
do_yesno()
- Add a few efficiency/extensibility tweaks. (David Benbennick)
- Convert to use the new low-level input functions, and remove
two last hardcoded widths left after the above tweaks. (DLR)
- configure.ac:
- Check for glib 2.x and then 1.2.x if we need glib. (DLR)
- nano.spec.in:
......
......@@ -66,7 +66,7 @@
## You can get old nano quoted-justify behavior via:
# set quotestr "(> )+"
## Fix Backspace if it acts like Delete
## Fix Backspace/Delete confusion problem
# set rebinddelete
## Do extended regular expression searches by default
......
......@@ -878,7 +878,7 @@ int open_prevfile(int closing_file)
/* only one file open */
if (!closing_file)
statusbar(_("No more open files"));
statusbar(_("No more open file buffers"));
return 1;
}
......@@ -941,7 +941,7 @@ int open_nextfile(int closing_file)
/* only one file open */
if (!closing_file)
statusbar(_("No more open files"));
statusbar(_("No more open file buffers"));
return 1;
}
......@@ -1835,7 +1835,7 @@ int do_writeout(const char *path, int exiting, int append)
struct stat st;
if (!stat(answer, &st)) {
i = do_yesno(0, 0, _("File exists, OVERWRITE ?"));
i = do_yesno(0, _("File exists, OVERWRITE ?"));
if (i == 0 || i == -1)
continue;
} else if (filename[0] != '\0'
......@@ -1843,7 +1843,7 @@ int do_writeout(const char *path, int exiting, int append)
&& (!ISSET(MARK_ISSET) || exiting)
#endif
) {
i = do_yesno(0, 0, _("Save file under DIFFERENT NAME ?"));
i = do_yesno(0, _("Save file under DIFFERENT NAME ?"));
if (i == 0 || i == -1)
continue;
}
......@@ -2599,7 +2599,7 @@ char *do_browser(const char *inpath)
break;
case NANO_PREVPAGE_KEY:
case NANO_PREVPAGE_FKEY:
case '-':
case '-': /* Pico compatibility */
if (selected >= (editwinrows + lineno % editwinrows) * width)
selected -= (editwinrows + lineno % editwinrows) * width;
else
......@@ -2607,18 +2607,19 @@ char *do_browser(const char *inpath)
break;
case NANO_NEXTPAGE_KEY:
case NANO_NEXTPAGE_FKEY:
case ' ':
case ' ': /* Pico compatibility */
selected += (editwinrows - lineno % editwinrows) * width;
if (selected >= numents)
selected = numents - 1;
break;
case NANO_HELP_KEY:
case NANO_HELP_FKEY:
case '?': /* Pico compatibility */
do_help();
break;
case NANO_ENTER_KEY:
case 's': /* More Pico compatibility */
case 'S':
case 'S': /* Pico compatibility */
case 's':
/* You can't cd up from / */
if (!strcmp(filelist[selected], "/..") && !strcmp(path, "/")) {
statusbar(_("Can't move up a directory"));
......@@ -2627,10 +2628,9 @@ char *do_browser(const char *inpath)
}
#ifndef DISABLE_OPERATINGDIR
/*
* Note: the selected file can be outside the operating
* directory if it is .. or if it is a symlink to a directory
* outside the opdir. */
/* Note: the selected file can be outside the operating
* directory if it is .. or if it is a symlink to
* directory outside the operating directory. */
if (check_operating_dir(filelist[selected], FALSE)) {
statusbar(_("Can't go outside of %s in restricted mode"), operating_dir);
beep();
......@@ -2680,6 +2680,8 @@ char *do_browser(const char *inpath)
/* Goto a specific directory */
case NANO_GOTO_KEY:
case NANO_GOTO_FKEY:
case 'G': /* Pico compatibility */
case 'g':
curs_set(1);
j = statusq(0, gotodir_list, "",
#ifndef NANO_SMALL
......@@ -2724,11 +2726,11 @@ char *do_browser(const char *inpath)
return do_browser(path);
/* Stuff we want to abort the browser */
case 'e': /* Pico compatibility, yeech */
case 'E':
case NANO_CANCEL_KEY:
case NANO_EXIT_KEY:
case NANO_EXIT_FKEY:
case 'E': /* Pico compatibility */
case 'e':
abort = 1;
break;
}
......@@ -2803,7 +2805,7 @@ char *do_browser(const char *inpath)
}
}
wrefresh(edit);
} while ((kbinput = get_kbinput(edit, &meta, ISSET(REBIND_DELETE))) != NANO_EXIT_KEY && kbinput != NANO_EXIT_FKEY);
} while ((kbinput = get_kbinput(edit, &meta)) != NANO_EXIT_KEY && kbinput != NANO_EXIT_FKEY);
curs_set(1);
blank_edit();
titlebar(NULL);
......
This diff is collapsed.
......@@ -406,43 +406,39 @@ void help_init(void)
/* true if the character in s->altval is shown in first column */
int meta_shortcut = 0;
if (s->val != NANO_NO_KEY) {
#ifndef NANO_SMALL
if (s->val == NANO_UP_KEY && s->misc == NANO_DOWN_KEY)
ptr += sprintf(ptr, "%.2s", _("Up"));
else
if (s->val == NANO_HISTORY_KEY)
ptr += sprintf(ptr, "%.2s", _("Up"));
else
#endif
if (is_cntrl_char(s->val)) {
if (s->val == NANO_CONTROL_SPACE)
ptr += sprintf(ptr, "^%.6s", _("Space"));
ptr += sprintf(ptr, "^%.5s", _("Space"));
else if (s->val == NANO_CONTROL_8)
ptr += sprintf(ptr, "^?");
else
ptr += sprintf(ptr, "^%c", s->val + 64);
}
#ifndef NANO_SMALL
else if (s->altval == NANO_ALT_SPACE) {
else if (s->altval != NANO_NO_KEY) {
meta_shortcut = 1;
ptr += sprintf(ptr, "M-%.5s", _("Space"));
if (s->altval == NANO_ALT_SPACE)
ptr += snprintf(ptr, 8, "M-%.5s", _("Space"));
else
ptr += sprintf(ptr, "M-%c", toupper(s->altval));
}
#endif
else if (s->val > 0) {
meta_shortcut = 1;
ptr += sprintf(ptr, "M-%c", toupper(s->val));
} else if (s->altval > 0) {
meta_shortcut = 1;
ptr += sprintf(ptr, "M-%c", toupper(s->altval));
}
*(ptr++) = '\t';
if (s->func_key > KEY_F0 && s->func_key <= KEY_F(64))
if (s->func_key != NANO_NO_KEY)
ptr += sprintf(ptr, "(F%d)", s->func_key - KEY_F0);
*(ptr++) = '\t';
if (!meta_shortcut && s->altval > 0)
if (!meta_shortcut && s->altval != NANO_NO_KEY)
ptr += sprintf(ptr, "(M-%c)", toupper(s->altval));
else if (meta_shortcut && s->misc > 0)
else if (meta_shortcut && s->misc != NANO_NO_KEY)
ptr += sprintf(ptr, "(M-%c)", toupper(s->misc));
*(ptr++) = '\t';
......@@ -663,7 +659,7 @@ void usage(void)
#endif
print1opt("-c", "--const", _("Constantly show cursor position"));
#ifndef NANO_SMALL
print1opt("-d", "--rebinddelete", _("Fix Backspace if it acts like Delete"));
print1opt("-d", "--rebinddelete", _("Fix Backspace/Delete confusion problem"));
print1opt("-i", "--autoindent", _("Automatically indent new lines"));
print1opt("-k", "--cut", _("Let ^K cut from cursor to end of line"));
#endif
......@@ -896,7 +892,7 @@ void do_mouse(void)
{
int mouse_x, mouse_y;
if (get_mouseinput(&mouse_x, &mouse_y) == 0) {
if (get_mouseinput(&mouse_x, &mouse_y, 1) == 0) {
/* Click in the edit window to move the cursor, but only when
we're not in a subfunction. */
......@@ -1019,7 +1015,7 @@ int do_verbatim_input(void)
signal_init();
statusbar(_("Verbatim input"));
verbatim_kbinput = get_verbatim_kbinput(edit, &verbatim_len);
verbatim_kbinput = get_verbatim_kbinput(edit, &verbatim_len, 1);
/* Turn on DISABLE_CURPOS while inserting character(s) and turn it
* off afterwards, so that if constant cursor position display is
......@@ -2238,8 +2234,7 @@ int do_para_operation(int operation)
*
* A contiguous set of lines is a "paragraph" if each line is part of
* a paragraph and only the first line is the beginning of a
* paragraph.
*/
* paragraph. */
size_t quote_len;
/* Length of the initial quotation of the paragraph we
......@@ -2656,17 +2651,22 @@ int do_para_operation(int operation)
/* Now get a keystroke and see if it's unjustify; if not, unget the
* keystroke and return. */
{
int meta;
i = get_kbinput(edit, &meta);
#ifndef DISABLE_MOUSE
/* If it was a mouse click, parse it with do_mouse() and it might
* become the unjustify key. Else give it back to the input
* stream. */
if ((i = wgetch(edit)) == KEY_MOUSE)
do_mouse();
else
ungetch(i);
/* If it was a mouse click, parse it with do_mouse() and it
* might become the unjustify key. Else give it back to the
* input stream. */
if (i == KEY_MOUSE)
do_mouse();
else
ungetch(i);
i = get_kbinput(edit, &meta);
#endif
}
if ((i = wgetch(edit)) != NANO_UNJUSTIFY_KEY) {
if (i != NANO_UNJUSTIFY_KEY) {
ungetch(i);
/* Did we back up anything at all? */
if (cutbuffer != cutbuffer_save)
......@@ -2761,14 +2761,11 @@ int do_exit(void)
finish(0);
}
if (ISSET(TEMP_OPT)) {
if (ISSET(TEMP_OPT))
i = 1;
} else {
i = do_yesno(0, 0,
_
("Save modified buffer (ANSWERING \"No\" WILL DESTROY CHANGES) ? "));
}
else
i = do_yesno(0, _("Save modified buffer (ANSWERING \"No\" WILL DESTROY CHANGES) ? "));
#ifdef DEBUG
dump_buffer(fileage);
#endif
......@@ -3066,7 +3063,6 @@ int main(int argc, char *argv[])
struct termios term;
#endif
#ifdef HAVE_GETOPT_LONG
int option_index = 0;
const struct option long_options[] = {
{"help", 0, 0, 'h'},
#ifdef ENABLE_MULTIBUFFER
......@@ -3140,7 +3136,7 @@ int main(int argc, char *argv[])
#ifdef HAVE_GETOPT_LONG
while ((optchr = getopt_long(argc, argv, "h?BDFHIMNQ:RST:VY:abcdefgijklmo:pr:s:tvwxz",
long_options, &option_index)) != -1) {
long_options, NULL)) != -1) {
#else
while ((optchr =
getopt(argc, argv, "h?BDFHIMNQ:RST:VY:abcdefgijklmo:pr:s:tvwxz")) != -1) {
......@@ -3515,7 +3511,7 @@ int main(int argc, char *argv[])
raw();
#endif
kbinput = get_kbinput(edit, &meta, ISSET(REBIND_DELETE));
kbinput = get_kbinput(edit, &meta);
#ifdef DEBUG
fprintf(stderr, "AHA! %c (%d)\n", kbinput, kbinput);
#endif
......@@ -3558,8 +3554,8 @@ int main(int argc, char *argv[])
#else
for (s = main_list; s != NULL && !keyhandled; s = s->next) {
#endif
if ((s->val >= 0 && kbinput == s->val) ||
(s->func_key > 0 && kbinput == s->func_key)) {
if ((s->val != NANO_NO_KEY && kbinput == s->val) ||
(s->func_key != NANO_NO_KEY && kbinput == s->func_key)) {
if (ISSET(VIEW_MODE) && !s->viewok)
print_view_warning();
else {
......
......@@ -90,8 +90,9 @@
#endif
/* Assume ERR is defined as -1. To avoid duplicate case values when
some key definitions are missing, we have to set these all to
different negative values other than -1. */
some key definitions are missing, we have to set all of these, and
all of the special sentinel values below, to different negative
values other than -1. */
/* HP-UX 10 & 11 do not seem to support KEY_HOME and KEY_END */
#ifndef KEY_HOME
......@@ -107,18 +108,18 @@
#define KEY_RESIZE -4
#endif
/* Slang does not seem to support KEY_SUSPEND */
/* Slang does not seem to support KEY_SUSPEND, KEY_SLEFT, or
KEY_SRIGHT */
#ifndef KEY_SUSPEND
#define KEY_SUSPEND -5
#endif
/* Non-ncurses may not support KEY_UP and KEY_DOWN */
#ifndef KEY_UP
#define KEY_UP -6
#ifndef KEY_SLEFT
#define KEY_SLEFT -6
#endif
#ifndef KEY_DOWN
#define KEY_DOWN -7
#ifndef KEY_SRIGHT
#define KEY_SRIGHT -7
#endif
#define VERMSG "GNU nano " VERSION
......@@ -168,18 +169,19 @@ typedef struct openfilestruct {
#endif
typedef struct shortcut {
int val; /* Actual sequence that generates the keystroke,
or -1 for none */
int altval; /* Alt key for this function, or 0 for none */
int func_key; /* Function key we want bound */
int misc; /* Other Alt key we want bound, or 0 for none */
int viewok; /* is this function legal in view mode? */
int (*func) (void); /* Function to call when we catch this key */
const char *desc; /* Description, e.g. "Page Up" */
/* Key values that aren't used should be set to NANO_NO_KEY */
int val; /* Special sentinel key or control key we want
* bound */
int altval; /* Alt key we want bound */
int func_key; /* Function key we want bound */
int misc; /* Other Alt key we want bound */
int viewok; /* Is this function legal in view mode? */
int (*func) (void); /* Function to call when we catch this key */
const char *desc; /* Description, e.g. "Page Up" */
#ifndef DISABLE_HELP
const char *help; /* Help file entry text */
const char *help; /* Help file entry text */
#endif
struct shortcut *next;
struct shortcut *next;
} shortcut;
#ifndef NANO_SMALL
......@@ -348,10 +350,17 @@ typedef struct historyheadtype {
/* Some semi-changeable keybindings; don't play with unless you're sure
you know what you're doing */
/* No key at all. */
#define NANO_NO_KEY -8
/* Special sentinel key. */
#define NANO_HISTORY_KEY -9
/* Normal keys. */
#define NANO_INSERTFILE_KEY NANO_CONTROL_R
#define NANO_INSERTFILE_FKEY KEY_F(5)
#define NANO_EXIT_KEY NANO_CONTROL_X
#define NANO_EXIT_FKEY KEY_F(2)
#define NANO_EXIT_KEY NANO_CONTROL_X
#define NANO_EXIT_FKEY KEY_F(2)
#define NANO_WRITEOUT_KEY NANO_CONTROL_O
#define NANO_WRITEOUT_FKEY KEY_F(3)
#define NANO_GOTO_KEY NANO_CONTROL_7
......
......@@ -436,15 +436,15 @@ int check_wildcard_match(const char *text, const char *pattern);
#endif
/* Public functions in winio.c */
int get_kbinput(WINDOW *win, int *meta, int rebind_delete);
char *get_verbatim_kbinput(WINDOW *win, int *kbinput_len);
int get_kbinput(WINDOW *win, int *meta);
char *get_verbatim_kbinput(WINDOW *win, int *kbinput_len,
int allow_ascii);
int get_ignored_kbinput(WINDOW *win);
int get_accepted_kbinput(WINDOW *win, int kbinput, int *meta,
int rebind_delete);
int get_accepted_kbinput(WINDOW *win, int kbinput, int *meta);
int get_ascii_kbinput(WINDOW *win, int kbinput);
int get_escape_seq_kbinput(WINDOW *win, int kbinput);
int get_skip_tilde_kbinput(WINDOW *win, int errval, int retval);
int get_mouseinput(int *mouse_x, int *mouse_y);
int get_escape_seq_kbinput(WINDOW *win, char *escape_seq, int
escape_seq_len);
int get_mouseinput(int *mouse_x, int *mouse_y, int shortcut);
int do_first_line(void);
int do_last_line(void);
int xpt(const filestruct *fileptr, int index);
......@@ -493,7 +493,7 @@ int statusq(int tabs, const shortcut *s, const char *def,
historyheadtype *history_list,
#endif
const char *msg, ...);
int do_yesno(int all, int leavecursor, const char *msg, ...);
int do_yesno(int all, const char *msg);
int total_refresh(void);
void display_main_list(void);
void statusbar(const char *msg, ...);
......
......@@ -711,7 +711,7 @@ int do_replace_loop(const char *prevanswer, const filestruct *begin,
curs_set(0);
do_replace_highlight(TRUE, exp_word);
*i = do_yesno(1, 1, _("Replace this instance?"));
*i = do_yesno(1, _("Replace this instance?"));
do_replace_highlight(FALSE, exp_word);
free(exp_word);
......
This diff is collapsed.
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment