2000-08-06 21:13:45 +00:00
|
|
|
/* $Id$ */
|
2000-06-06 05:53:49 +00:00
|
|
|
/**************************************************************************
|
|
|
|
* winio.c *
|
|
|
|
* *
|
2009-12-02 03:36:22 +00:00
|
|
|
* Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, *
|
2014-04-30 20:18:26 +00:00
|
|
|
* 2008, 2009, 2010, 2011, 2013, 2014 Free Software Foundation, Inc. *
|
2000-06-06 05:53:49 +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) *
|
2000-06-06 05:53:49 +00:00
|
|
|
* any later version. *
|
|
|
|
* *
|
2005-05-15 19:57:17 +00:00
|
|
|
* 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. *
|
2000-06-06 05:53:49 +00:00
|
|
|
* *
|
|
|
|
* You should have received a copy of the GNU General Public License *
|
|
|
|
* along with this program; if not, write to the Free Software *
|
2005-05-15 19:57:17 +00:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
|
|
|
|
* 02110-1301, USA. *
|
2000-06-06 05:53:49 +00:00
|
|
|
* *
|
|
|
|
**************************************************************************/
|
|
|
|
|
2005-12-08 02:47:10 +00:00
|
|
|
#include "proto.h"
|
2002-09-13 18:14:04 +00:00
|
|
|
|
2005-11-01 18:35:47 +00:00
|
|
|
#include <stdio.h>
|
2000-06-06 05:53:49 +00:00
|
|
|
#include <stdarg.h>
|
|
|
|
#include <string.h>
|
2000-11-24 20:45:14 +00:00
|
|
|
#include <unistd.h>
|
2002-06-13 00:40:19 +00:00
|
|
|
#include <ctype.h>
|
2000-06-06 05:53:49 +00:00
|
|
|
|
2005-01-12 03:25:57 +00:00
|
|
|
static int *key_buffer = NULL;
|
2007-01-01 05:15:32 +00:00
|
|
|
/* The keystroke buffer, containing all the keystrokes we
|
|
|
|
* haven't handled yet at a given point. */
|
2004-12-04 17:41:52 +00:00
|
|
|
static size_t key_buffer_len = 0;
|
2006-05-26 03:22:44 +00:00
|
|
|
/* The length of the keystroke buffer. */
|
2005-06-25 20:56:36 +00:00
|
|
|
static int statusblank = 0;
|
2006-05-14 18:22:01 +00:00
|
|
|
/* The number of keystrokes left after we call statusbar(),
|
|
|
|
* before we actually blank the statusbar. */
|
2005-06-17 18:27:00 +00:00
|
|
|
static bool disable_cursorpos = FALSE;
|
2006-05-14 18:22:01 +00:00
|
|
|
/* Should we temporarily disable constant cursor position
|
|
|
|
* display? */
|
2000-06-06 23:04:06 +00:00
|
|
|
|
2015-05-28 13:02:29 +00:00
|
|
|
static sig_atomic_t sigwinch_counter_save = 0;
|
|
|
|
|
2004-05-01 01:21:38 +00:00
|
|
|
/* Control character compatibility:
|
|
|
|
*
|
|
|
|
* - NANO_BACKSPACE_KEY is Ctrl-H, which is Backspace under ASCII, ANSI,
|
|
|
|
* VT100, and VT220.
|
|
|
|
* - NANO_TAB_KEY is Ctrl-I, which is Tab under ASCII, ANSI, VT100,
|
|
|
|
* VT220, and VT320.
|
|
|
|
* - NANO_ENTER_KEY is Ctrl-M, which is Enter under ASCII, ANSI, VT100,
|
|
|
|
* VT220, and VT320.
|
|
|
|
* - NANO_XON_KEY is Ctrl-Q, which is XON under ASCII, ANSI, VT100,
|
|
|
|
* VT220, and VT320.
|
|
|
|
* - NANO_XOFF_KEY is Ctrl-S, which is XOFF under ASCII, ANSI, VT100,
|
|
|
|
* VT220, and VT320.
|
2004-05-01 04:13:06 +00:00
|
|
|
* - NANO_CONTROL_8 is Ctrl-8 (Ctrl-?), which is Delete under ASCII,
|
2004-05-01 01:21:38 +00:00
|
|
|
* ANSI, VT100, and VT220, and which is Backspace under VT320.
|
|
|
|
*
|
2004-06-22 14:30:18 +00:00
|
|
|
* Note: VT220 and VT320 also generate Esc [ 3 ~ for Delete. By
|
2004-05-01 04:13:06 +00:00
|
|
|
* default, xterm assumes it's running on a VT320 and generates Ctrl-8
|
|
|
|
* (Ctrl-?) for Backspace and Esc [ 3 ~ for Delete. This causes
|
2004-05-01 01:21:38 +00:00
|
|
|
* problems for VT100-derived terminals such as the FreeBSD console,
|
2004-05-01 04:13:06 +00:00
|
|
|
* which expect Ctrl-H for Backspace and Ctrl-8 (Ctrl-?) for Delete, and
|
2004-05-01 01:21:38 +00:00
|
|
|
* on which the VT320 sequences are translated by the keypad to KEY_DC
|
|
|
|
* and [nothing]. We work around this conflict via the REBIND_DELETE
|
|
|
|
* flag: if it's not set, we assume VT320 compatibility, and if it is,
|
|
|
|
* we assume VT100 compatibility. Thanks to Lee Nelson and Wouter van
|
|
|
|
* Hemel for helping work this conflict out.
|
|
|
|
*
|
|
|
|
* Escape sequence compatibility:
|
|
|
|
*
|
|
|
|
* We support escape sequences for ANSI, VT100, VT220, VT320, the Linux
|
2007-04-04 20:36:56 +00:00
|
|
|
* console, the FreeBSD console, the Mach console, xterm, rxvt, Eterm,
|
|
|
|
* and Terminal. Among these, there are several conflicts and
|
|
|
|
* omissions, outlined as follows:
|
2004-05-01 01:21:38 +00:00
|
|
|
*
|
|
|
|
* - Tab on ANSI == PageUp on FreeBSD console; the former is omitted.
|
|
|
|
* (Ctrl-I is also Tab on ANSI, which we already support.)
|
|
|
|
* - PageDown on FreeBSD console == Center (5) on numeric keypad with
|
|
|
|
* NumLock off on Linux console; the latter is omitted. (The editing
|
|
|
|
* keypad key is more important to have working than the numeric
|
2004-05-28 17:23:33 +00:00
|
|
|
* keypad key, because the latter has no value when NumLock is off.)
|
2004-05-01 01:21:38 +00:00
|
|
|
* - F1 on FreeBSD console == the mouse key on xterm/rxvt/Eterm; the
|
|
|
|
* latter is omitted. (Mouse input will only work properly if the
|
|
|
|
* extended keypad value KEY_MOUSE is generated on mouse events
|
|
|
|
* instead of the escape sequence.)
|
2004-10-24 22:51:39 +00:00
|
|
|
* - F9 on FreeBSD console == PageDown on Mach console; the former is
|
2004-05-01 01:21:38 +00:00
|
|
|
* omitted. (The editing keypad is more important to have working
|
|
|
|
* than the function keys, because the functions of the former are not
|
|
|
|
* arbitrary and the functions of the latter are.)
|
2004-10-24 22:51:39 +00:00
|
|
|
* - F10 on FreeBSD console == PageUp on Mach console; the former is
|
2004-05-01 01:21:38 +00:00
|
|
|
* omitted. (Same as above.)
|
2004-10-24 22:51:39 +00:00
|
|
|
* - F13 on FreeBSD console == End on Mach console; the former is
|
2004-05-01 01:21:38 +00:00
|
|
|
* omitted. (Same as above.)
|
2004-11-01 22:40:02 +00:00
|
|
|
* - F15 on FreeBSD console == Shift-Up on rxvt/Eterm; the former is
|
|
|
|
* omitted. (The arrow keys, with or without modifiers, are more
|
|
|
|
* important to have working than the function keys, because the
|
|
|
|
* functions of the former are not arbitrary and the functions of the
|
|
|
|
* latter are.)
|
|
|
|
* - F16 on FreeBSD console == Shift-Down on rxvt/Eterm; the former is
|
2006-07-31 23:29:22 +00:00
|
|
|
* omitted. (Same as above.) */
|
2004-04-23 18:02:37 +00:00
|
|
|
|
2004-12-04 17:41:52 +00:00
|
|
|
/* Read in a sequence of keystrokes from win and save them in the
|
2006-05-26 03:22:44 +00:00
|
|
|
* keystroke buffer. This should only be called when the keystroke
|
|
|
|
* buffer is empty. */
|
2005-07-13 20:18:46 +00:00
|
|
|
void get_key_buffer(WINDOW *win)
|
2004-08-25 16:37:06 +00:00
|
|
|
{
|
2006-03-19 19:26:52 +00:00
|
|
|
int input;
|
|
|
|
size_t errcount;
|
2004-12-04 17:41:52 +00:00
|
|
|
|
|
|
|
/* If the keystroke buffer isn't empty, get out. */
|
|
|
|
if (key_buffer != NULL)
|
|
|
|
return;
|
|
|
|
|
2005-07-26 14:42:57 +00:00
|
|
|
/* Just before reading in the first character, display any pending
|
|
|
|
* screen updates. */
|
|
|
|
doupdate();
|
|
|
|
|
2014-04-15 11:25:29 +00:00
|
|
|
/* Read in the first character using whatever mode we're in. */
|
2006-03-19 19:25:29 +00:00
|
|
|
errcount = 0;
|
2009-01-24 22:40:41 +00:00
|
|
|
if (nodelay_mode) {
|
2014-05-16 11:03:04 +00:00
|
|
|
if ((input = wgetch(win)) == ERR)
|
2014-06-27 20:01:27 +00:00
|
|
|
return;
|
2015-05-28 13:02:29 +00:00
|
|
|
} else {
|
2009-01-24 22:40:41 +00:00
|
|
|
while ((input = wgetch(win)) == ERR) {
|
2015-05-28 13:02:29 +00:00
|
|
|
#ifndef NANO_TINY
|
|
|
|
/* Did we get SIGWINCH since we were last here? */
|
|
|
|
if (sigwinch_counter != sigwinch_counter_save) {
|
|
|
|
sigwinch_counter_save = sigwinch_counter;
|
|
|
|
regenerate_screen();
|
|
|
|
input = KEY_WINCH;
|
|
|
|
break;
|
|
|
|
} else
|
|
|
|
#endif
|
2009-01-24 22:40:41 +00:00
|
|
|
errcount++;
|
|
|
|
|
|
|
|
/* If we've failed to get a character MAX_BUF_SIZE times in a
|
|
|
|
* row, assume that the input source we were using is gone and
|
|
|
|
* die gracefully. We could check if errno is set to EIO
|
|
|
|
* ("Input/output error") and die gracefully in that case, but
|
|
|
|
* it's not always set properly. Argh. */
|
|
|
|
if (errcount == MAX_BUF_SIZE)
|
|
|
|
handle_hupterm(0);
|
|
|
|
}
|
2015-05-28 13:02:29 +00:00
|
|
|
}
|
2004-02-16 20:32:40 +00:00
|
|
|
|
2007-05-25 16:54:06 +00:00
|
|
|
/* Increment the length of the keystroke buffer, and save the value
|
|
|
|
* of the keystroke at the end of it. */
|
2004-12-04 17:41:52 +00:00
|
|
|
key_buffer_len++;
|
2005-01-12 03:25:57 +00:00
|
|
|
key_buffer = (int *)nmalloc(sizeof(int));
|
|
|
|
key_buffer[0] = input;
|
2003-08-17 02:48:43 +00:00
|
|
|
|
2015-05-28 13:02:29 +00:00
|
|
|
#ifndef NANO_TINY
|
|
|
|
/* If we got SIGWINCH, get out immediately since the win argument is
|
|
|
|
* no longer valid. */
|
|
|
|
if (input == KEY_WINCH)
|
|
|
|
return;
|
|
|
|
#endif
|
|
|
|
|
2004-12-04 17:41:52 +00:00
|
|
|
/* Read in the remaining characters using non-blocking input. */
|
|
|
|
nodelay(win, TRUE);
|
|
|
|
|
|
|
|
while (TRUE) {
|
2005-01-12 03:25:57 +00:00
|
|
|
input = wgetch(win);
|
2004-12-12 19:04:56 +00:00
|
|
|
|
2004-12-04 17:41:52 +00:00
|
|
|
/* If there aren't any more characters, stop reading. */
|
2005-01-12 03:25:57 +00:00
|
|
|
if (input == ERR)
|
2004-12-04 17:41:52 +00:00
|
|
|
break;
|
|
|
|
|
2007-05-25 16:54:06 +00:00
|
|
|
/* Otherwise, increment the length of the keystroke buffer, and
|
|
|
|
* save the value of the keystroke at the end of it. */
|
2004-12-04 17:41:52 +00:00
|
|
|
key_buffer_len++;
|
2005-01-12 03:25:57 +00:00
|
|
|
key_buffer = (int *)nrealloc(key_buffer, key_buffer_len *
|
|
|
|
sizeof(int));
|
|
|
|
key_buffer[key_buffer_len - 1] = input;
|
2004-12-04 17:41:52 +00:00
|
|
|
}
|
|
|
|
|
2014-04-15 11:25:29 +00:00
|
|
|
/* Switch back to waiting mode for input. */
|
2004-12-04 17:41:52 +00:00
|
|
|
nodelay(win, FALSE);
|
2005-03-16 14:39:42 +00:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
2015-06-11 19:01:28 +00:00
|
|
|
{
|
|
|
|
size_t i;
|
|
|
|
fprintf(stderr, "get_key_buffer(): the series of codes:");
|
|
|
|
for (i = 0; i < key_buffer_len; i++)
|
|
|
|
fprintf(stderr, " %3x", key_buffer[i]);
|
|
|
|
fprintf(stderr, "\n");
|
|
|
|
}
|
2005-03-16 14:39:42 +00:00
|
|
|
#endif
|
2004-12-04 17:41:52 +00:00
|
|
|
}
|
2003-08-17 02:48:43 +00:00
|
|
|
|
2006-05-26 03:22:44 +00:00
|
|
|
/* Return the length of the keystroke buffer. */
|
2005-07-13 20:18:46 +00:00
|
|
|
size_t get_key_buffer_len(void)
|
2004-12-04 17:41:52 +00:00
|
|
|
{
|
|
|
|
return key_buffer_len;
|
|
|
|
}
|
|
|
|
|
2006-05-26 03:22:44 +00:00
|
|
|
/* Add the keystrokes in input to the keystroke buffer. */
|
2005-01-12 03:25:57 +00:00
|
|
|
void unget_input(int *input, size_t input_len)
|
2004-12-04 17:41:52 +00:00
|
|
|
{
|
|
|
|
/* If input is empty, get out. */
|
2005-01-12 03:25:57 +00:00
|
|
|
if (input_len == 0)
|
2004-12-04 17:41:52 +00:00
|
|
|
return;
|
|
|
|
|
2006-05-26 03:22:44 +00:00
|
|
|
/* If adding input would put the keystroke buffer beyond maximum
|
|
|
|
* capacity, only add enough of input to put it at maximum
|
2004-12-04 17:41:52 +00:00
|
|
|
* capacity. */
|
2005-01-12 03:25:57 +00:00
|
|
|
if (key_buffer_len + input_len < key_buffer_len)
|
|
|
|
input_len = (size_t)-1 - key_buffer_len;
|
2004-12-04 17:41:52 +00:00
|
|
|
|
2006-05-26 03:22:44 +00:00
|
|
|
/* Add the length of input to the length of the keystroke buffer,
|
|
|
|
* and reallocate the keystroke buffer so that it has enough room
|
|
|
|
* for input. */
|
2005-01-12 03:25:57 +00:00
|
|
|
key_buffer_len += input_len;
|
|
|
|
key_buffer = (int *)nrealloc(key_buffer, key_buffer_len *
|
|
|
|
sizeof(int));
|
2004-12-04 17:41:52 +00:00
|
|
|
|
2006-05-26 03:22:44 +00:00
|
|
|
/* If the keystroke buffer wasn't empty before, move its beginning
|
|
|
|
* forward far enough so that we can add input to its beginning. */
|
2005-01-12 03:25:57 +00:00
|
|
|
if (key_buffer_len > input_len)
|
|
|
|
memmove(key_buffer + input_len, key_buffer,
|
|
|
|
(key_buffer_len - input_len) * sizeof(int));
|
2004-12-04 17:41:52 +00:00
|
|
|
|
2006-05-26 03:22:44 +00:00
|
|
|
/* Copy input to the beginning of the keystroke buffer. */
|
2005-01-12 03:25:57 +00:00
|
|
|
memcpy(key_buffer, input, input_len * sizeof(int));
|
2004-12-04 17:41:52 +00:00
|
|
|
}
|
|
|
|
|
2005-01-12 03:25:57 +00:00
|
|
|
/* Put back the character stored in kbinput, putting it in byte range
|
2014-06-30 18:04:33 +00:00
|
|
|
* beforehand. If metakey is TRUE, put back the Escape character after
|
|
|
|
* putting back kbinput. If funckey is TRUE, put back the function key
|
2005-01-12 03:25:57 +00:00
|
|
|
* (a value outside byte range) without putting it in byte range. */
|
2014-06-30 18:04:33 +00:00
|
|
|
void unget_kbinput(int kbinput, bool metakey, bool funckey)
|
2004-12-04 17:41:52 +00:00
|
|
|
{
|
2014-06-30 18:04:33 +00:00
|
|
|
if (!funckey)
|
2005-01-12 03:25:57 +00:00
|
|
|
kbinput = (char)kbinput;
|
2004-12-04 17:41:52 +00:00
|
|
|
|
2005-01-12 03:25:57 +00:00
|
|
|
unget_input(&kbinput, 1);
|
2004-12-04 17:41:52 +00:00
|
|
|
|
2014-06-30 18:04:33 +00:00
|
|
|
if (metakey) {
|
2005-01-12 03:25:57 +00:00
|
|
|
kbinput = NANO_CONTROL_3;
|
|
|
|
unget_input(&kbinput, 1);
|
2004-12-04 17:41:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-05-26 03:22:44 +00:00
|
|
|
/* Try to read input_len characters from the keystroke buffer. If the
|
|
|
|
* keystroke buffer is empty and win isn't NULL, try to read in more
|
|
|
|
* characters from win and add them to the keystroke buffer before doing
|
|
|
|
* anything else. If the keystroke buffer is empty and win is NULL,
|
|
|
|
* return NULL. */
|
2005-01-12 03:25:57 +00:00
|
|
|
int *get_input(WINDOW *win, size_t input_len)
|
2004-12-04 17:41:52 +00:00
|
|
|
{
|
2005-01-12 03:25:57 +00:00
|
|
|
int *input;
|
2004-12-04 17:41:52 +00:00
|
|
|
|
|
|
|
if (key_buffer_len == 0) {
|
2006-08-30 13:52:33 +00:00
|
|
|
if (win != NULL) {
|
2005-07-13 20:18:46 +00:00
|
|
|
get_key_buffer(win);
|
2004-12-04 17:41:52 +00:00
|
|
|
|
2006-08-30 13:52:33 +00:00
|
|
|
if (key_buffer_len == 0)
|
|
|
|
return NULL;
|
|
|
|
} else
|
2004-12-04 17:41:52 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2006-05-26 03:22:44 +00:00
|
|
|
/* If input_len is greater than the length of the keystroke buffer,
|
|
|
|
* only read the number of characters in the keystroke buffer. */
|
2004-12-04 17:41:52 +00:00
|
|
|
if (input_len > key_buffer_len)
|
|
|
|
input_len = key_buffer_len;
|
|
|
|
|
2006-05-26 03:22:44 +00:00
|
|
|
/* Subtract input_len from the length of the keystroke buffer, and
|
|
|
|
* allocate input so that it has enough room for input_len
|
|
|
|
* keystrokes. */
|
2004-12-04 17:41:52 +00:00
|
|
|
key_buffer_len -= input_len;
|
2005-01-12 03:25:57 +00:00
|
|
|
input = (int *)nmalloc(input_len * sizeof(int));
|
2004-12-04 17:41:52 +00:00
|
|
|
|
2006-05-26 03:22:44 +00:00
|
|
|
/* Copy input_len keystrokes from the beginning of the keystroke
|
|
|
|
* buffer into input. */
|
2005-01-12 03:25:57 +00:00
|
|
|
memcpy(input, key_buffer, input_len * sizeof(int));
|
2004-12-04 17:41:52 +00:00
|
|
|
|
2006-05-26 03:22:44 +00:00
|
|
|
/* If the keystroke buffer is empty, mark it as such. */
|
2004-12-04 17:41:52 +00:00
|
|
|
if (key_buffer_len == 0) {
|
|
|
|
free(key_buffer);
|
|
|
|
key_buffer = NULL;
|
2006-05-26 03:22:44 +00:00
|
|
|
/* If the keystroke buffer isn't empty, move its beginning forward
|
|
|
|
* far enough so that the keystrokes in input are no longer at its
|
|
|
|
* beginning. */
|
2004-12-04 17:41:52 +00:00
|
|
|
} else {
|
|
|
|
memmove(key_buffer, key_buffer + input_len, key_buffer_len *
|
2005-01-12 03:25:57 +00:00
|
|
|
sizeof(int));
|
|
|
|
key_buffer = (int *)nrealloc(key_buffer, key_buffer_len *
|
|
|
|
sizeof(int));
|
2004-12-04 17:41:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return input;
|
2003-08-17 02:48:43 +00:00
|
|
|
}
|
|
|
|
|
2004-12-04 17:41:52 +00:00
|
|
|
/* Read in a single character. If it's ignored, swallow it and go on.
|
|
|
|
* Otherwise, try to translate it from ASCII, meta key sequences, escape
|
2014-06-30 18:04:33 +00:00
|
|
|
* sequences, and/or extended keypad values. Supported extended keypad
|
|
|
|
* values consist of
|
2004-12-04 17:41:52 +00:00
|
|
|
* [arrow key], Ctrl-[arrow key], Shift-[arrow key], Enter, Backspace,
|
|
|
|
* the editing keypad (Insert, Delete, Home, End, PageUp, and PageDown),
|
|
|
|
* the function keypad (F1-F16), and the numeric keypad with NumLock
|
2014-04-15 11:25:29 +00:00
|
|
|
* off. */
|
2014-06-30 18:04:33 +00:00
|
|
|
int get_kbinput(WINDOW *win)
|
2004-12-04 17:41:52 +00:00
|
|
|
{
|
|
|
|
int kbinput;
|
|
|
|
|
|
|
|
/* Read in a character and interpret it. Continue doing this until
|
|
|
|
* we get a recognized value or sequence. */
|
2014-06-30 18:04:33 +00:00
|
|
|
while ((kbinput = parse_kbinput(win)) == ERR)
|
2014-05-13 20:14:01 +00:00
|
|
|
;
|
2004-12-04 17:41:52 +00:00
|
|
|
|
2006-05-22 01:29:30 +00:00
|
|
|
/* If we read from the edit window, blank the statusbar if we need
|
|
|
|
* to. */
|
|
|
|
if (win == edit)
|
2006-05-21 21:23:21 +00:00
|
|
|
check_statusblank();
|
|
|
|
|
2004-12-04 17:41:52 +00:00
|
|
|
return kbinput;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Translate ASCII characters, extended keypad values, and escape
|
|
|
|
* sequences into their corresponding key values. Set meta_key to TRUE
|
|
|
|
* when we get a meta key sequence, and set func_key to TRUE when we get
|
2014-04-15 11:25:29 +00:00
|
|
|
* a function key. */
|
2014-06-30 18:04:33 +00:00
|
|
|
int parse_kbinput(WINDOW *win)
|
2003-08-17 02:48:43 +00:00
|
|
|
{
|
2005-01-03 19:56:56 +00:00
|
|
|
static int escapes = 0, byte_digits = 0;
|
2005-01-12 03:25:57 +00:00
|
|
|
int *kbinput, retval = ERR;
|
2003-08-17 02:48:43 +00:00
|
|
|
|
2014-06-30 18:04:33 +00:00
|
|
|
meta_key = FALSE;
|
|
|
|
func_key = FALSE;
|
2003-08-17 02:48:43 +00:00
|
|
|
|
2004-12-04 17:41:52 +00:00
|
|
|
/* Read in a character. */
|
2009-01-24 22:40:41 +00:00
|
|
|
if (nodelay_mode) {
|
|
|
|
kbinput = get_input(win, 1);
|
|
|
|
if (kbinput == 0)
|
|
|
|
return 0;
|
|
|
|
} else
|
2014-05-13 20:14:01 +00:00
|
|
|
while ((kbinput = get_input(win, 1)) == NULL)
|
|
|
|
;
|
2004-12-04 17:41:52 +00:00
|
|
|
|
2005-01-12 03:25:57 +00:00
|
|
|
switch (*kbinput) {
|
|
|
|
case ERR:
|
|
|
|
break;
|
|
|
|
case NANO_CONTROL_3:
|
|
|
|
/* Increment the escape counter. */
|
|
|
|
escapes++;
|
|
|
|
switch (escapes) {
|
|
|
|
case 1:
|
|
|
|
/* One escape: wait for more input. */
|
|
|
|
case 2:
|
|
|
|
/* Two escapes: wait for more input. */
|
2006-07-24 18:53:54 +00:00
|
|
|
case 3:
|
|
|
|
/* Three escapes: wait for more input. */
|
2005-01-12 03:25:57 +00:00
|
|
|
break;
|
|
|
|
default:
|
2006-07-24 18:53:54 +00:00
|
|
|
/* More than three escapes: limit the escape counter
|
|
|
|
* to no more than two, and wait for more input. */
|
|
|
|
escapes %= 3;
|
2005-01-12 03:25:57 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
switch (escapes) {
|
|
|
|
case 0:
|
2006-07-23 17:25:38 +00:00
|
|
|
/* One non-escape: normal input mode. Save the
|
|
|
|
* non-escape character as the result. */
|
|
|
|
retval = *kbinput;
|
2005-01-12 03:25:57 +00:00
|
|
|
break;
|
|
|
|
case 1:
|
2006-07-23 16:00:03 +00:00
|
|
|
/* Reset the escape counter. */
|
2005-01-12 03:25:57 +00:00
|
|
|
escapes = 0;
|
2005-07-13 20:18:46 +00:00
|
|
|
if (get_key_buffer_len() == 0) {
|
2006-07-23 16:00:03 +00:00
|
|
|
/* One escape followed by a non-escape, and
|
2006-07-23 17:25:38 +00:00
|
|
|
* there aren't any other keystrokes waiting:
|
|
|
|
* meta key sequence mode. Set meta_key to
|
|
|
|
* TRUE, and save the lowercase version of the
|
|
|
|
* non-escape character as the result. */
|
2014-06-30 18:04:33 +00:00
|
|
|
meta_key = TRUE;
|
2005-01-12 03:25:57 +00:00
|
|
|
retval = tolower(*kbinput);
|
2006-07-24 21:22:49 +00:00
|
|
|
} else
|
2006-07-23 16:00:03 +00:00
|
|
|
/* One escape followed by a non-escape, and
|
2006-07-23 17:25:38 +00:00
|
|
|
* there are other keystrokes waiting: escape
|
|
|
|
* sequence mode. Interpret the escape
|
|
|
|
* sequence. */
|
2006-07-23 17:54:35 +00:00
|
|
|
retval = parse_escape_seq_kbinput(win,
|
|
|
|
*kbinput);
|
2005-01-12 03:25:57 +00:00
|
|
|
break;
|
|
|
|
case 2:
|
2006-07-23 16:00:03 +00:00
|
|
|
if (get_key_buffer_len() == 0) {
|
|
|
|
if (('0' <= *kbinput && *kbinput <= '2' &&
|
|
|
|
byte_digits == 0) || ('0' <= *kbinput &&
|
|
|
|
*kbinput <= '9' && byte_digits > 0)) {
|
|
|
|
/* Two escapes followed by one or more
|
|
|
|
* decimal digits, and there aren't any
|
2006-07-23 17:25:38 +00:00
|
|
|
* other keystrokes waiting: byte sequence
|
|
|
|
* mode. If the byte sequence's range is
|
|
|
|
* limited to 2XX (the first digit is in the
|
|
|
|
* '0' to '2' range and it's the first
|
|
|
|
* digit, or it's in the '0' to '9' range
|
|
|
|
* and it's not the first digit), increment
|
|
|
|
* the byte sequence counter and interpret
|
|
|
|
* the digit. If the byte sequence's range
|
|
|
|
* is not limited to 2XX, fall through. */
|
2006-07-23 16:00:03 +00:00
|
|
|
int byte;
|
|
|
|
|
|
|
|
byte_digits++;
|
|
|
|
byte = get_byte_kbinput(*kbinput);
|
|
|
|
|
|
|
|
if (byte != ERR) {
|
|
|
|
char *byte_mb;
|
|
|
|
int byte_mb_len, *seq, i;
|
|
|
|
|
|
|
|
/* If we've read in a complete byte
|
|
|
|
* sequence, reset the escape counter
|
|
|
|
* and the byte sequence counter, and
|
|
|
|
* put back the corresponding byte
|
|
|
|
* value. */
|
|
|
|
escapes = 0;
|
|
|
|
byte_digits = 0;
|
|
|
|
|
|
|
|
/* Put back the multibyte equivalent of
|
|
|
|
* the byte value. */
|
|
|
|
byte_mb = make_mbchar((long)byte,
|
|
|
|
&byte_mb_len);
|
|
|
|
|
|
|
|
seq = (int *)nmalloc(byte_mb_len *
|
|
|
|
sizeof(int));
|
|
|
|
|
|
|
|
for (i = 0; i < byte_mb_len; i++)
|
|
|
|
seq[i] = (unsigned char)byte_mb[i];
|
|
|
|
|
|
|
|
unget_input(seq, byte_mb_len);
|
|
|
|
|
|
|
|
free(byte_mb);
|
|
|
|
free(seq);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/* Reset the escape counter. */
|
2004-12-04 17:41:52 +00:00
|
|
|
escapes = 0;
|
2006-07-23 16:00:03 +00:00
|
|
|
if (byte_digits == 0)
|
|
|
|
/* Two escapes followed by a non-decimal
|
|
|
|
* digit or a decimal digit that would
|
|
|
|
* create a byte sequence greater than
|
|
|
|
* 2XX, we're not in the middle of a
|
|
|
|
* byte sequence, and there aren't any
|
2006-07-23 17:25:38 +00:00
|
|
|
* other keystrokes waiting: control
|
|
|
|
* character sequence mode. Interpret
|
|
|
|
* the control sequence and save the
|
|
|
|
* corresponding control character as
|
|
|
|
* the result. */
|
2006-07-23 16:00:03 +00:00
|
|
|
retval = get_control_kbinput(*kbinput);
|
|
|
|
else {
|
|
|
|
/* If we're in the middle of a byte
|
|
|
|
* sequence, reset the byte sequence
|
|
|
|
* counter and save the character we got
|
|
|
|
* as the result. */
|
|
|
|
byte_digits = 0;
|
|
|
|
retval = *kbinput;
|
|
|
|
}
|
2004-11-29 00:30:07 +00:00
|
|
|
}
|
2006-05-30 20:51:15 +00:00
|
|
|
} else {
|
2006-07-23 16:00:03 +00:00
|
|
|
/* Two escapes followed by a non-escape, and
|
2006-07-23 17:25:38 +00:00
|
|
|
* there are other keystrokes waiting: combined
|
|
|
|
* meta and escape sequence mode. Reset the
|
|
|
|
* escape counter, set meta_key to TRUE, and
|
|
|
|
* interpret the escape sequence. */
|
2005-01-12 03:25:57 +00:00
|
|
|
escapes = 0;
|
2014-06-30 18:04:33 +00:00
|
|
|
meta_key = TRUE;
|
2006-07-23 17:54:35 +00:00
|
|
|
retval = parse_escape_seq_kbinput(win,
|
|
|
|
*kbinput);
|
2006-05-30 20:51:15 +00:00
|
|
|
}
|
2005-01-12 03:25:57 +00:00
|
|
|
break;
|
2006-07-24 18:53:54 +00:00
|
|
|
case 3:
|
|
|
|
/* Reset the escape counter. */
|
|
|
|
escapes = 0;
|
|
|
|
if (get_key_buffer_len() == 0)
|
|
|
|
/* Three escapes followed by a non-escape, and
|
|
|
|
* there aren't any other keystrokes waiting:
|
|
|
|
* normal input mode. Save the non-escape
|
|
|
|
* character as the result. */
|
|
|
|
retval = *kbinput;
|
|
|
|
else
|
|
|
|
/* Three escapes followed by a non-escape, and
|
|
|
|
* there are other keystrokes waiting: combined
|
|
|
|
* control character and escape sequence mode.
|
|
|
|
* Interpret the escape sequence, and interpret
|
|
|
|
* the result as a control sequence. */
|
|
|
|
retval = get_control_kbinput(
|
|
|
|
parse_escape_seq_kbinput(win,
|
|
|
|
*kbinput));
|
2006-12-02 17:17:09 +00:00
|
|
|
break;
|
2005-01-12 03:25:57 +00:00
|
|
|
}
|
|
|
|
}
|
2003-08-17 02:48:43 +00:00
|
|
|
|
2006-04-28 19:27:41 +00:00
|
|
|
if (retval != ERR) {
|
2006-07-23 17:25:38 +00:00
|
|
|
switch (retval) {
|
|
|
|
case NANO_CONTROL_8:
|
2011-02-07 14:45:56 +00:00
|
|
|
retval = ISSET(REBIND_DELETE) ? sc_seq_or(do_delete, 0) :
|
|
|
|
sc_seq_or(do_backspace, 0);
|
2006-07-23 17:25:38 +00:00
|
|
|
break;
|
|
|
|
case KEY_DOWN:
|
2008-03-05 07:34:01 +00:00
|
|
|
#ifdef KEY_SDOWN
|
|
|
|
/* ncurses and Slang don't support KEY_SDOWN. */
|
|
|
|
case KEY_SDOWN:
|
|
|
|
#endif
|
2011-02-07 14:45:56 +00:00
|
|
|
retval = sc_seq_or(do_down_void, *kbinput);
|
2006-07-23 17:25:38 +00:00
|
|
|
break;
|
|
|
|
case KEY_UP:
|
2008-03-05 07:34:01 +00:00
|
|
|
#ifdef KEY_SUP
|
|
|
|
/* ncurses and Slang don't support KEY_SUP. */
|
|
|
|
case KEY_SUP:
|
|
|
|
#endif
|
2011-02-07 14:45:56 +00:00
|
|
|
retval = sc_seq_or(do_up_void, *kbinput);
|
2006-07-23 17:25:38 +00:00
|
|
|
break;
|
|
|
|
case KEY_LEFT:
|
2008-03-05 07:34:01 +00:00
|
|
|
#ifdef KEY_SLEFT
|
|
|
|
/* Slang doesn't support KEY_SLEFT. */
|
|
|
|
case KEY_SLEFT:
|
|
|
|
#endif
|
2011-02-07 14:45:56 +00:00
|
|
|
retval = sc_seq_or(do_left, *kbinput);
|
2006-07-23 17:25:38 +00:00
|
|
|
break;
|
|
|
|
case KEY_RIGHT:
|
2008-03-05 07:34:01 +00:00
|
|
|
#ifdef KEY_SRIGHT
|
|
|
|
/* Slang doesn't support KEY_SRIGHT. */
|
|
|
|
case KEY_SRIGHT:
|
|
|
|
#endif
|
2011-02-07 14:45:56 +00:00
|
|
|
retval = sc_seq_or(do_right, *kbinput);
|
2006-07-23 17:25:38 +00:00
|
|
|
break;
|
2008-03-05 07:34:01 +00:00
|
|
|
#ifdef KEY_SHOME
|
|
|
|
/* HP-UX 10-11 and Slang don't support KEY_SHOME. */
|
|
|
|
case KEY_SHOME:
|
|
|
|
#endif
|
|
|
|
case KEY_A1: /* Home (7) on numeric keypad with
|
|
|
|
* NumLock off. */
|
2011-02-07 14:45:56 +00:00
|
|
|
retval = sc_seq_or(do_home, *kbinput);
|
2008-03-05 07:34:01 +00:00
|
|
|
break;
|
2006-07-23 17:25:38 +00:00
|
|
|
case KEY_BACKSPACE:
|
2011-02-07 14:45:56 +00:00
|
|
|
retval = sc_seq_or(do_backspace, *kbinput);
|
2006-07-23 17:25:38 +00:00
|
|
|
break;
|
2008-03-05 07:34:01 +00:00
|
|
|
#ifdef KEY_SDC
|
|
|
|
/* Slang doesn't support KEY_SDC. */
|
|
|
|
case KEY_SDC:
|
|
|
|
if (ISSET(REBIND_DELETE))
|
2014-06-10 19:12:14 +00:00
|
|
|
retval = sc_seq_or(do_delete, *kbinput);
|
2008-03-05 07:34:01 +00:00
|
|
|
else
|
2014-06-10 19:12:14 +00:00
|
|
|
retval = sc_seq_or(do_backspace, *kbinput);
|
2006-07-23 17:25:38 +00:00
|
|
|
break;
|
2008-03-11 03:03:53 +00:00
|
|
|
#endif
|
2008-03-05 07:34:01 +00:00
|
|
|
#ifdef KEY_SIC
|
|
|
|
/* Slang doesn't support KEY_SIC. */
|
|
|
|
case KEY_SIC:
|
2011-02-07 14:45:56 +00:00
|
|
|
retval = sc_seq_or(do_insertfile_void, *kbinput);
|
2006-07-23 17:25:38 +00:00
|
|
|
break;
|
2008-03-11 03:03:53 +00:00
|
|
|
#endif
|
2008-03-05 07:34:01 +00:00
|
|
|
case KEY_C3: /* PageDown (4) on numeric keypad with
|
2006-07-23 17:25:38 +00:00
|
|
|
* NumLock off. */
|
2011-02-07 14:45:56 +00:00
|
|
|
retval = sc_seq_or(do_page_down, *kbinput);
|
2006-07-23 17:25:38 +00:00
|
|
|
break;
|
|
|
|
case KEY_A3: /* PageUp (9) on numeric keypad with
|
|
|
|
* NumLock off. */
|
2011-02-07 14:45:56 +00:00
|
|
|
retval = sc_seq_or(do_page_up, *kbinput);
|
2008-03-05 07:34:01 +00:00
|
|
|
break;
|
|
|
|
case KEY_ENTER:
|
2011-02-07 14:45:56 +00:00
|
|
|
retval = sc_seq_or(do_enter_void, *kbinput);
|
2006-07-23 17:25:38 +00:00
|
|
|
break;
|
|
|
|
case KEY_B2: /* Center (5) on numeric keypad with
|
|
|
|
* NumLock off. */
|
|
|
|
retval = ERR;
|
|
|
|
break;
|
|
|
|
case KEY_C1: /* End (1) on numeric keypad with
|
|
|
|
* NumLock off. */
|
2008-03-05 07:34:01 +00:00
|
|
|
#ifdef KEY_SEND
|
|
|
|
/* HP-UX 10-11 and Slang don't support KEY_SEND. */
|
|
|
|
case KEY_SEND:
|
|
|
|
#endif
|
2011-02-07 14:45:56 +00:00
|
|
|
retval = sc_seq_or(do_end, *kbinput);
|
2006-07-23 17:25:38 +00:00
|
|
|
break;
|
|
|
|
#ifdef KEY_BEG
|
|
|
|
/* Slang doesn't support KEY_BEG. */
|
|
|
|
case KEY_BEG: /* Center (5) on numeric keypad with
|
|
|
|
* NumLock off. */
|
|
|
|
retval = ERR;
|
|
|
|
break;
|
|
|
|
#endif
|
2007-04-18 14:06:34 +00:00
|
|
|
#ifdef KEY_CANCEL
|
|
|
|
/* Slang doesn't support KEY_CANCEL. */
|
|
|
|
case KEY_CANCEL:
|
2008-03-05 07:34:01 +00:00
|
|
|
#ifdef KEY_SCANCEL
|
|
|
|
/* Slang doesn't support KEY_SCANCEL. */
|
|
|
|
case KEY_SCANCEL:
|
2007-04-18 14:06:34 +00:00
|
|
|
#endif
|
2011-02-07 14:45:56 +00:00
|
|
|
retval = first_sc_for(currmenu, do_cancel)->seq;
|
2006-07-23 17:25:38 +00:00
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
#ifdef KEY_SBEG
|
|
|
|
/* Slang doesn't support KEY_SBEG. */
|
|
|
|
case KEY_SBEG: /* Center (5) on numeric keypad with
|
|
|
|
* NumLock off. */
|
|
|
|
retval = ERR;
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
#ifdef KEY_SSUSPEND
|
|
|
|
/* Slang doesn't support KEY_SSUSPEND. */
|
|
|
|
case KEY_SSUSPEND:
|
2011-02-07 14:45:56 +00:00
|
|
|
retval = sc_seq_or(do_suspend_void, 0);
|
2006-07-23 17:25:38 +00:00
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
#ifdef KEY_SUSPEND
|
|
|
|
/* Slang doesn't support KEY_SUSPEND. */
|
|
|
|
case KEY_SUSPEND:
|
2014-05-16 11:03:04 +00:00
|
|
|
retval = sc_seq_or(do_suspend_void, 0);
|
2006-07-23 17:25:38 +00:00
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
#ifdef PDCURSES
|
|
|
|
case KEY_SHIFT_L:
|
|
|
|
case KEY_SHIFT_R:
|
|
|
|
case KEY_CONTROL_L:
|
|
|
|
case KEY_CONTROL_R:
|
|
|
|
case KEY_ALT_L:
|
|
|
|
case KEY_ALT_R:
|
|
|
|
retval = ERR;
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
#if !defined(NANO_TINY) && defined(KEY_RESIZE)
|
|
|
|
/* Since we don't change the default SIGWINCH handler when
|
|
|
|
* NANO_TINY is defined, KEY_RESIZE is never generated.
|
|
|
|
* Also, Slang and SunOS 5.7-5.9 don't support
|
|
|
|
* KEY_RESIZE. */
|
|
|
|
case KEY_RESIZE:
|
|
|
|
retval = ERR;
|
|
|
|
break;
|
|
|
|
#endif
|
2014-06-29 20:53:00 +00:00
|
|
|
case CONTROL_LEFT:
|
|
|
|
#ifndef NANO_TINY
|
|
|
|
retval = sc_seq_or(do_prev_word_void, 0);
|
|
|
|
#endif
|
|
|
|
break;
|
|
|
|
case CONTROL_RIGHT:
|
|
|
|
#ifndef NANO_TINY
|
|
|
|
retval = sc_seq_or(do_next_word_void, 0);
|
|
|
|
#endif
|
|
|
|
break;
|
2015-05-28 13:02:29 +00:00
|
|
|
#ifndef NANO_TINY
|
|
|
|
case KEY_WINCH:
|
|
|
|
retval = KEY_WINCH;
|
|
|
|
break;
|
|
|
|
#endif
|
2006-07-23 17:25:38 +00:00
|
|
|
}
|
2006-04-28 19:27:41 +00:00
|
|
|
|
2006-07-28 17:06:27 +00:00
|
|
|
/* If our result is an extended keypad value (i.e. a value
|
2006-04-28 19:27:41 +00:00
|
|
|
* outside of byte range), set func_key to TRUE. */
|
2006-07-23 17:25:38 +00:00
|
|
|
if (retval != ERR)
|
2014-06-30 18:04:33 +00:00
|
|
|
func_key = !is_byte(retval);
|
2006-04-28 19:27:41 +00:00
|
|
|
}
|
2004-05-28 17:23:33 +00:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
2014-06-30 18:04:33 +00:00
|
|
|
fprintf(stderr, "parse_kbinput(): kbinput = %d, meta_key = %s, func_key = %s, escapes = %d, byte_digits = %d, retval = %d\n", *kbinput, meta_key ? "TRUE" : "FALSE", func_key ? "TRUE" : "FALSE", escapes, byte_digits, retval);
|
2004-05-28 17:23:33 +00:00
|
|
|
#endif
|
|
|
|
|
2006-12-02 17:22:21 +00:00
|
|
|
free(kbinput);
|
|
|
|
|
2004-12-04 17:41:52 +00:00
|
|
|
/* Return the result. */
|
2003-08-17 02:48:43 +00:00
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
2004-01-27 07:12:47 +00:00
|
|
|
/* Translate escape sequences, most of which correspond to extended
|
2004-11-27 23:28:39 +00:00
|
|
|
* keypad values, into their corresponding key values. These sequences
|
2006-07-25 19:23:35 +00:00
|
|
|
* are generated when the keypad doesn't support the needed keys.
|
|
|
|
* Assume that Escape has already been read in. */
|
|
|
|
int get_escape_seq_kbinput(const int *seq, size_t seq_len)
|
2003-08-17 02:48:43 +00:00
|
|
|
{
|
2004-05-28 17:23:33 +00:00
|
|
|
int retval = ERR;
|
2003-12-24 03:33:09 +00:00
|
|
|
|
2004-12-04 17:41:52 +00:00
|
|
|
if (seq_len > 1) {
|
2005-01-12 03:25:57 +00:00
|
|
|
switch (seq[0]) {
|
2003-12-24 03:33:09 +00:00
|
|
|
case 'O':
|
2005-01-12 03:25:57 +00:00
|
|
|
switch (seq[1]) {
|
2007-04-04 20:36:56 +00:00
|
|
|
case '1':
|
|
|
|
if (seq_len >= 3) {
|
|
|
|
switch (seq[2]) {
|
|
|
|
case ';':
|
|
|
|
if (seq_len >= 4) {
|
|
|
|
switch (seq[3]) {
|
|
|
|
case '2':
|
|
|
|
if (seq_len >= 5) {
|
|
|
|
switch (seq[4]) {
|
|
|
|
case 'A': /* Esc O 1 ; 2 A == Shift-Up on
|
|
|
|
* Terminal. */
|
|
|
|
case 'B': /* Esc O 1 ; 2 B == Shift-Down on
|
|
|
|
* Terminal. */
|
|
|
|
case 'C': /* Esc O 1 ; 2 C == Shift-Right on
|
|
|
|
* Terminal. */
|
|
|
|
case 'D': /* Esc O 1 ; 2 D == Shift-Left on
|
|
|
|
* Terminal. */
|
|
|
|
retval = get_escape_seq_abcd(seq[4]);
|
|
|
|
break;
|
2015-04-28 20:09:40 +00:00
|
|
|
case 'P': /* Esc O 1 ; 2 P == F13 on Terminal. */
|
2007-04-04 20:36:56 +00:00
|
|
|
retval = KEY_F(13);
|
|
|
|
break;
|
2015-04-28 20:09:40 +00:00
|
|
|
case 'Q': /* Esc O 1 ; 2 Q == F14 on Terminal. */
|
2007-04-04 20:36:56 +00:00
|
|
|
retval = KEY_F(14);
|
|
|
|
break;
|
2015-04-28 20:09:40 +00:00
|
|
|
case 'R': /* Esc O 1 ; 2 R == F15 on Terminal. */
|
2007-04-04 20:36:56 +00:00
|
|
|
retval = KEY_F(15);
|
|
|
|
break;
|
2015-04-28 20:09:40 +00:00
|
|
|
case 'S': /* Esc O 1 ; 2 S == F16 on Terminal. */
|
2007-04-04 20:36:56 +00:00
|
|
|
retval = KEY_F(16);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case '5':
|
|
|
|
if (seq_len >= 5) {
|
|
|
|
switch (seq[4]) {
|
2015-04-28 20:09:40 +00:00
|
|
|
case 'A': /* Esc O 1 ; 5 A == Ctrl-Up on Terminal. */
|
|
|
|
case 'B': /* Esc O 1 ; 5 B == Ctrl-Down on Terminal. */
|
2014-06-29 20:53:00 +00:00
|
|
|
retval = get_escape_seq_abcd(seq[4]);
|
|
|
|
break;
|
2015-04-28 20:09:40 +00:00
|
|
|
case 'C': /* Esc O 1 ; 5 C == Ctrl-Right on Terminal. */
|
2014-06-29 20:53:00 +00:00
|
|
|
retval = CONTROL_RIGHT;
|
|
|
|
break;
|
2015-04-28 20:09:40 +00:00
|
|
|
case 'D': /* Esc O 1 ; 5 D == Ctrl-Left on Terminal. */
|
2014-06-29 20:53:00 +00:00
|
|
|
retval = CONTROL_LEFT;
|
2007-04-04 20:36:56 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2004-01-23 19:26:17 +00:00
|
|
|
case '2':
|
2004-12-04 17:41:52 +00:00
|
|
|
if (seq_len >= 3) {
|
2005-01-12 03:25:57 +00:00
|
|
|
switch (seq[2]) {
|
2015-04-28 20:09:40 +00:00
|
|
|
case 'P': /* Esc O 2 P == F13 on xterm. */
|
2004-05-28 17:23:33 +00:00
|
|
|
retval = KEY_F(13);
|
2004-01-23 19:26:17 +00:00
|
|
|
break;
|
2015-04-28 20:09:40 +00:00
|
|
|
case 'Q': /* Esc O 2 Q == F14 on xterm. */
|
2004-05-28 17:23:33 +00:00
|
|
|
retval = KEY_F(14);
|
2004-01-23 19:26:17 +00:00
|
|
|
break;
|
2015-04-28 20:09:40 +00:00
|
|
|
case 'R': /* Esc O 2 R == F15 on xterm. */
|
2004-11-01 22:40:02 +00:00
|
|
|
retval = KEY_F(15);
|
|
|
|
break;
|
2015-04-28 20:09:40 +00:00
|
|
|
case 'S': /* Esc O 2 S == F16 on xterm. */
|
2004-11-01 22:40:02 +00:00
|
|
|
retval = KEY_F(16);
|
|
|
|
break;
|
2004-01-23 19:26:17 +00:00
|
|
|
}
|
|
|
|
}
|
2003-12-24 03:33:09 +00:00
|
|
|
break;
|
2004-05-01 01:21:38 +00:00
|
|
|
case 'A': /* Esc O A == Up on VT100/VT320/xterm. */
|
2015-04-28 20:09:40 +00:00
|
|
|
case 'B': /* Esc O B == Down on VT100/VT320/xterm. */
|
|
|
|
case 'C': /* Esc O C == Right on VT100/VT320/xterm. */
|
|
|
|
case 'D': /* Esc O D == Left on VT100/VT320/xterm. */
|
2005-01-12 03:25:57 +00:00
|
|
|
retval = get_escape_seq_abcd(seq[1]);
|
2003-12-24 03:33:09 +00:00
|
|
|
break;
|
2004-04-23 18:02:37 +00:00
|
|
|
case 'E': /* Esc O E == Center (5) on numeric keypad
|
|
|
|
* with NumLock off on xterm. */
|
2006-07-25 19:23:35 +00:00
|
|
|
retval = KEY_B2;
|
2004-04-23 18:02:37 +00:00
|
|
|
break;
|
2007-04-04 20:36:56 +00:00
|
|
|
case 'F': /* Esc O F == End on xterm/Terminal. */
|
2011-02-07 14:45:56 +00:00
|
|
|
retval = sc_seq_or(do_end, 0);
|
2003-12-24 03:33:09 +00:00
|
|
|
break;
|
2007-04-04 20:36:56 +00:00
|
|
|
case 'H': /* Esc O H == Home on xterm/Terminal. */
|
2014-04-23 19:33:03 +00:00
|
|
|
retval = sc_seq_or(do_home, 0);
|
2003-12-24 03:33:09 +00:00
|
|
|
break;
|
2004-04-23 18:02:37 +00:00
|
|
|
case 'M': /* Esc O M == Enter on numeric keypad with
|
2004-06-22 14:30:18 +00:00
|
|
|
* NumLock off on VT100/VT220/VT320/xterm/
|
2006-05-30 20:51:15 +00:00
|
|
|
* rxvt/Eterm. */
|
2014-04-23 19:33:03 +00:00
|
|
|
retval = sc_seq_or(do_home, 0);
|
2004-04-23 18:02:37 +00:00
|
|
|
break;
|
2004-10-24 22:51:39 +00:00
|
|
|
case 'P': /* Esc O P == F1 on VT100/VT220/VT320/Mach
|
2004-05-01 01:21:38 +00:00
|
|
|
* console. */
|
2004-05-28 17:23:33 +00:00
|
|
|
retval = KEY_F(1);
|
2003-12-24 03:33:09 +00:00
|
|
|
break;
|
2004-10-24 22:51:39 +00:00
|
|
|
case 'Q': /* Esc O Q == F2 on VT100/VT220/VT320/Mach
|
2004-05-01 01:21:38 +00:00
|
|
|
* console. */
|
2004-05-28 17:23:33 +00:00
|
|
|
retval = KEY_F(2);
|
2003-12-24 03:33:09 +00:00
|
|
|
break;
|
2004-10-24 22:51:39 +00:00
|
|
|
case 'R': /* Esc O R == F3 on VT100/VT220/VT320/Mach
|
2004-05-01 01:21:38 +00:00
|
|
|
* console. */
|
2004-05-28 17:23:33 +00:00
|
|
|
retval = KEY_F(3);
|
2004-01-23 19:26:17 +00:00
|
|
|
break;
|
2004-10-24 22:51:39 +00:00
|
|
|
case 'S': /* Esc O S == F4 on VT100/VT220/VT320/Mach
|
2004-05-01 01:21:38 +00:00
|
|
|
* console. */
|
2004-05-28 17:23:33 +00:00
|
|
|
retval = KEY_F(4);
|
2004-01-23 19:26:17 +00:00
|
|
|
break;
|
2004-10-24 22:51:39 +00:00
|
|
|
case 'T': /* Esc O T == F5 on Mach console. */
|
2004-05-28 17:23:33 +00:00
|
|
|
retval = KEY_F(5);
|
2004-01-23 19:26:17 +00:00
|
|
|
break;
|
2004-10-24 22:51:39 +00:00
|
|
|
case 'U': /* Esc O U == F6 on Mach console. */
|
2004-05-28 17:23:33 +00:00
|
|
|
retval = KEY_F(6);
|
2004-01-23 19:26:17 +00:00
|
|
|
break;
|
2004-10-24 22:51:39 +00:00
|
|
|
case 'V': /* Esc O V == F7 on Mach console. */
|
2004-05-28 17:23:33 +00:00
|
|
|
retval = KEY_F(7);
|
2004-01-23 19:26:17 +00:00
|
|
|
break;
|
2004-10-24 22:51:39 +00:00
|
|
|
case 'W': /* Esc O W == F8 on Mach console. */
|
2004-05-28 17:23:33 +00:00
|
|
|
retval = KEY_F(8);
|
2003-12-24 03:33:09 +00:00
|
|
|
break;
|
2004-10-24 22:51:39 +00:00
|
|
|
case 'X': /* Esc O X == F9 on Mach console. */
|
2004-05-28 17:23:33 +00:00
|
|
|
retval = KEY_F(9);
|
2004-01-23 19:26:17 +00:00
|
|
|
break;
|
2004-10-24 22:51:39 +00:00
|
|
|
case 'Y': /* Esc O Y == F10 on Mach console. */
|
2004-05-28 17:23:33 +00:00
|
|
|
retval = KEY_F(10);
|
2004-01-23 19:26:17 +00:00
|
|
|
break;
|
|
|
|
case 'a': /* Esc O a == Ctrl-Up on rxvt. */
|
|
|
|
case 'b': /* Esc O b == Ctrl-Down on rxvt. */
|
2014-06-29 20:53:00 +00:00
|
|
|
retval = get_escape_seq_abcd(seq[1]);
|
|
|
|
break;
|
2004-01-23 19:26:17 +00:00
|
|
|
case 'c': /* Esc O c == Ctrl-Right on rxvt. */
|
2014-06-29 20:53:00 +00:00
|
|
|
retval = CONTROL_RIGHT;
|
|
|
|
break;
|
2003-12-24 03:33:09 +00:00
|
|
|
case 'd': /* Esc O d == Ctrl-Left on rxvt. */
|
2014-06-29 20:53:00 +00:00
|
|
|
retval = CONTROL_LEFT;
|
2003-12-24 03:33:09 +00:00
|
|
|
break;
|
2004-04-23 18:02:37 +00:00
|
|
|
case 'j': /* Esc O j == '*' on numeric keypad with
|
2004-06-22 14:30:18 +00:00
|
|
|
* NumLock off on VT100/VT220/VT320/xterm/
|
2007-04-04 20:36:56 +00:00
|
|
|
* rxvt/Eterm/Terminal. */
|
2004-05-28 17:23:33 +00:00
|
|
|
retval = '*';
|
2004-04-23 18:02:37 +00:00
|
|
|
break;
|
|
|
|
case 'k': /* Esc O k == '+' on numeric keypad with
|
2004-06-22 14:30:18 +00:00
|
|
|
* NumLock off on VT100/VT220/VT320/xterm/
|
2007-04-04 20:36:56 +00:00
|
|
|
* rxvt/Eterm/Terminal. */
|
2004-05-28 17:23:33 +00:00
|
|
|
retval = '+';
|
2004-04-23 18:02:37 +00:00
|
|
|
break;
|
|
|
|
case 'l': /* Esc O l == ',' on numeric keypad with
|
2004-06-22 14:30:18 +00:00
|
|
|
* NumLock off on VT100/VT220/VT320/xterm/
|
2007-04-04 20:36:56 +00:00
|
|
|
* rxvt/Eterm/Terminal. */
|
2005-09-24 19:42:48 +00:00
|
|
|
retval = ',';
|
2004-04-23 18:02:37 +00:00
|
|
|
break;
|
|
|
|
case 'm': /* Esc O m == '-' on numeric keypad with
|
2004-06-22 14:30:18 +00:00
|
|
|
* NumLock off on VT100/VT220/VT320/xterm/
|
2007-04-04 20:36:56 +00:00
|
|
|
* rxvt/Eterm/Terminal. */
|
2004-05-28 17:23:33 +00:00
|
|
|
retval = '-';
|
2004-04-23 18:02:37 +00:00
|
|
|
break;
|
|
|
|
case 'n': /* Esc O n == Delete (.) on numeric keypad
|
2004-06-22 14:30:18 +00:00
|
|
|
* with NumLock off on VT100/VT220/VT320/
|
2007-04-04 20:36:56 +00:00
|
|
|
* xterm/rxvt/Eterm/Terminal. */
|
2014-04-23 19:33:03 +00:00
|
|
|
retval = sc_seq_or(do_delete, 0);
|
2004-04-23 18:02:37 +00:00
|
|
|
break;
|
|
|
|
case 'o': /* Esc O o == '/' on numeric keypad with
|
2004-06-22 14:30:18 +00:00
|
|
|
* NumLock off on VT100/VT220/VT320/xterm/
|
2007-04-04 20:36:56 +00:00
|
|
|
* rxvt/Eterm/Terminal. */
|
2004-05-28 17:23:33 +00:00
|
|
|
retval = '/';
|
2004-04-23 18:02:37 +00:00
|
|
|
break;
|
|
|
|
case 'p': /* Esc O p == Insert (0) on numeric keypad
|
2004-06-22 14:30:18 +00:00
|
|
|
* with NumLock off on VT100/VT220/VT320/
|
2007-04-04 20:36:56 +00:00
|
|
|
* rxvt/Eterm/Terminal. */
|
2014-04-23 19:33:03 +00:00
|
|
|
retval = sc_seq_or(do_insertfile_void, 0);
|
2004-04-23 18:02:37 +00:00
|
|
|
break;
|
|
|
|
case 'q': /* Esc O q == End (1) on numeric keypad
|
2004-06-22 14:30:18 +00:00
|
|
|
* with NumLock off on VT100/VT220/VT320/
|
2007-04-04 20:36:56 +00:00
|
|
|
* rxvt/Eterm/Terminal. */
|
2014-04-23 19:33:03 +00:00
|
|
|
retval = sc_seq_or(do_end, 0);
|
2004-04-23 18:02:37 +00:00
|
|
|
break;
|
|
|
|
case 'r': /* Esc O r == Down (2) on numeric keypad
|
2004-06-22 14:30:18 +00:00
|
|
|
* with NumLock off on VT100/VT220/VT320/
|
2007-04-04 20:36:56 +00:00
|
|
|
* rxvt/Eterm/Terminal. */
|
2014-04-23 19:33:03 +00:00
|
|
|
retval = sc_seq_or(do_down_void, 0);
|
2004-04-23 18:02:37 +00:00
|
|
|
break;
|
|
|
|
case 's': /* Esc O s == PageDown (3) on numeric
|
2004-06-22 14:30:18 +00:00
|
|
|
* keypad with NumLock off on VT100/VT220/
|
2007-04-04 20:36:56 +00:00
|
|
|
* VT320/rxvt/Eterm/Terminal. */
|
2014-04-23 19:33:03 +00:00
|
|
|
retval = sc_seq_or(do_page_down, 0);
|
2004-04-23 18:02:37 +00:00
|
|
|
break;
|
|
|
|
case 't': /* Esc O t == Left (4) on numeric keypad
|
2004-06-22 14:30:18 +00:00
|
|
|
* with NumLock off on VT100/VT220/VT320/
|
2007-04-04 20:36:56 +00:00
|
|
|
* rxvt/Eterm/Terminal. */
|
2014-04-23 19:33:03 +00:00
|
|
|
retval = sc_seq_or(do_left, 0);
|
2004-04-23 18:02:37 +00:00
|
|
|
break;
|
|
|
|
case 'u': /* Esc O u == Center (5) on numeric keypad
|
2004-06-22 14:30:18 +00:00
|
|
|
* with NumLock off on VT100/VT220/VT320/
|
|
|
|
* rxvt/Eterm. */
|
2006-07-25 19:23:35 +00:00
|
|
|
retval = KEY_B2;
|
2004-04-23 18:02:37 +00:00
|
|
|
break;
|
|
|
|
case 'v': /* Esc O v == Right (6) on numeric keypad
|
2004-06-22 14:30:18 +00:00
|
|
|
* with NumLock off on VT100/VT220/VT320/
|
2007-04-04 20:36:56 +00:00
|
|
|
* rxvt/Eterm/Terminal. */
|
2011-02-07 14:45:56 +00:00
|
|
|
retval = sc_seq_or(do_right, 0);
|
2004-04-23 18:02:37 +00:00
|
|
|
break;
|
|
|
|
case 'w': /* Esc O w == Home (7) on numeric keypad
|
2004-06-22 14:30:18 +00:00
|
|
|
* with NumLock off on VT100/VT220/VT320/
|
2007-04-04 20:36:56 +00:00
|
|
|
* rxvt/Eterm/Terminal. */
|
2011-02-07 14:45:56 +00:00
|
|
|
retval = sc_seq_or(do_home, 0);
|
2004-04-23 18:02:37 +00:00
|
|
|
break;
|
|
|
|
case 'x': /* Esc O x == Up (8) on numeric keypad
|
2004-06-22 14:30:18 +00:00
|
|
|
* with NumLock off on VT100/VT220/VT320/
|
2007-04-04 20:36:56 +00:00
|
|
|
* rxvt/Eterm/Terminal. */
|
2011-02-07 14:45:56 +00:00
|
|
|
retval = sc_seq_or(do_up_void, 0);
|
2004-04-23 18:02:37 +00:00
|
|
|
break;
|
|
|
|
case 'y': /* Esc O y == PageUp (9) on numeric keypad
|
2004-06-22 14:30:18 +00:00
|
|
|
* with NumLock off on VT100/VT220/VT320/
|
2007-04-04 20:36:56 +00:00
|
|
|
* rxvt/Eterm/Terminal. */
|
2011-02-07 14:45:56 +00:00
|
|
|
retval = sc_seq_or(do_page_up, 0);
|
2004-04-23 18:02:37 +00:00
|
|
|
break;
|
2003-12-24 03:33:09 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'o':
|
2005-01-12 03:25:57 +00:00
|
|
|
switch (seq[1]) {
|
2003-12-24 03:33:09 +00:00
|
|
|
case 'a': /* Esc o a == Ctrl-Up on Eterm. */
|
|
|
|
case 'b': /* Esc o b == Ctrl-Down on Eterm. */
|
2014-06-29 20:53:00 +00:00
|
|
|
retval = get_escape_seq_abcd(seq[1]);
|
|
|
|
break;
|
2003-12-24 03:33:09 +00:00
|
|
|
case 'c': /* Esc o c == Ctrl-Right on Eterm. */
|
2014-06-29 20:53:00 +00:00
|
|
|
retval = CONTROL_RIGHT;
|
|
|
|
break;
|
2003-12-24 03:33:09 +00:00
|
|
|
case 'd': /* Esc o d == Ctrl-Left on Eterm. */
|
2014-06-29 20:53:00 +00:00
|
|
|
retval = CONTROL_LEFT;
|
2003-12-24 03:33:09 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case '[':
|
2005-01-12 03:25:57 +00:00
|
|
|
switch (seq[1]) {
|
2003-12-24 03:33:09 +00:00
|
|
|
case '1':
|
2004-12-04 17:41:52 +00:00
|
|
|
if (seq_len >= 3) {
|
2005-01-12 03:25:57 +00:00
|
|
|
switch (seq[2]) {
|
2015-04-28 20:09:40 +00:00
|
|
|
case '1': /* Esc [ 1 1 ~ == F1 on rxvt/Eterm. */
|
2004-05-28 17:23:33 +00:00
|
|
|
retval = KEY_F(1);
|
2004-01-23 19:26:17 +00:00
|
|
|
break;
|
2015-04-28 20:09:40 +00:00
|
|
|
case '2': /* Esc [ 1 2 ~ == F2 on rxvt/Eterm. */
|
2004-05-28 17:23:33 +00:00
|
|
|
retval = KEY_F(2);
|
2004-01-23 19:26:17 +00:00
|
|
|
break;
|
2015-04-28 20:09:40 +00:00
|
|
|
case '3': /* Esc [ 1 3 ~ == F3 on rxvt/Eterm. */
|
2004-05-28 17:23:33 +00:00
|
|
|
retval = KEY_F(3);
|
2004-01-23 19:26:17 +00:00
|
|
|
break;
|
2015-04-28 20:09:40 +00:00
|
|
|
case '4': /* Esc [ 1 4 ~ == F4 on rxvt/Eterm. */
|
2004-05-28 17:23:33 +00:00
|
|
|
retval = KEY_F(4);
|
2004-01-23 19:26:17 +00:00
|
|
|
break;
|
2004-06-22 14:30:18 +00:00
|
|
|
case '5': /* Esc [ 1 5 ~ == F5 on xterm/
|
|
|
|
* rxvt/Eterm. */
|
2004-05-28 17:23:33 +00:00
|
|
|
retval = KEY_F(5);
|
2004-01-23 19:26:17 +00:00
|
|
|
break;
|
2004-05-01 01:21:38 +00:00
|
|
|
case '7': /* Esc [ 1 7 ~ == F6 on
|
2004-06-22 14:30:18 +00:00
|
|
|
* VT220/VT320/Linux console/
|
|
|
|
* xterm/rxvt/Eterm. */
|
2004-05-28 17:23:33 +00:00
|
|
|
retval = KEY_F(6);
|
2004-01-23 19:26:17 +00:00
|
|
|
break;
|
2004-05-01 01:21:38 +00:00
|
|
|
case '8': /* Esc [ 1 8 ~ == F7 on
|
2004-06-22 14:30:18 +00:00
|
|
|
* VT220/VT320/Linux console/
|
|
|
|
* xterm/rxvt/Eterm. */
|
2004-05-28 17:23:33 +00:00
|
|
|
retval = KEY_F(7);
|
2004-01-23 19:26:17 +00:00
|
|
|
break;
|
2004-05-01 01:21:38 +00:00
|
|
|
case '9': /* Esc [ 1 9 ~ == F8 on
|
2004-06-22 14:30:18 +00:00
|
|
|
* VT220/VT320/Linux console/
|
|
|
|
* xterm/rxvt/Eterm. */
|
2004-05-28 17:23:33 +00:00
|
|
|
retval = KEY_F(8);
|
2004-01-23 19:26:17 +00:00
|
|
|
break;
|
2004-02-06 03:07:10 +00:00
|
|
|
case ';':
|
2004-12-04 17:41:52 +00:00
|
|
|
if (seq_len >= 4) {
|
2005-01-12 03:25:57 +00:00
|
|
|
switch (seq[3]) {
|
2004-02-06 03:07:10 +00:00
|
|
|
case '2':
|
2004-12-04 17:41:52 +00:00
|
|
|
if (seq_len >= 5) {
|
2005-01-12 03:25:57 +00:00
|
|
|
switch (seq[4]) {
|
2015-04-28 20:09:40 +00:00
|
|
|
case 'A': /* Esc [ 1 ; 2 A == Shift-Up on xterm. */
|
|
|
|
case 'B': /* Esc [ 1 ; 2 B == Shift-Down on xterm. */
|
|
|
|
case 'C': /* Esc [ 1 ; 2 C == Shift-Right on xterm. */
|
|
|
|
case 'D': /* Esc [ 1 ; 2 D == Shift-Left on xterm. */
|
2005-01-12 03:25:57 +00:00
|
|
|
retval = get_escape_seq_abcd(seq[4]);
|
2004-02-06 03:07:10 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case '5':
|
2004-12-04 17:41:52 +00:00
|
|
|
if (seq_len >= 5) {
|
2005-01-12 03:25:57 +00:00
|
|
|
switch (seq[4]) {
|
2015-04-28 20:09:40 +00:00
|
|
|
case 'A': /* Esc [ 1 ; 5 A == Ctrl-Up on xterm. */
|
|
|
|
case 'B': /* Esc [ 1 ; 5 B == Ctrl-Down on xterm. */
|
2014-06-29 20:53:00 +00:00
|
|
|
retval = get_escape_seq_abcd(seq[4]);
|
|
|
|
break;
|
2015-04-28 20:09:40 +00:00
|
|
|
case 'C': /* Esc [ 1 ; 5 C == Ctrl-Right on xterm. */
|
2014-06-29 20:53:00 +00:00
|
|
|
retval = CONTROL_RIGHT;
|
|
|
|
break;
|
2015-04-28 20:09:40 +00:00
|
|
|
case 'D': /* Esc [ 1 ; 5 D == Ctrl-Left on xterm. */
|
2014-06-29 20:53:00 +00:00
|
|
|
retval = CONTROL_LEFT;
|
2004-02-06 03:07:10 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2004-05-01 01:21:38 +00:00
|
|
|
default: /* Esc [ 1 ~ == Home on
|
|
|
|
* VT320/Linux console. */
|
2014-04-23 19:33:03 +00:00
|
|
|
retval = sc_seq_or(do_home, 0);
|
2004-01-23 19:26:17 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case '2':
|
2004-12-04 17:41:52 +00:00
|
|
|
if (seq_len >= 3) {
|
2005-01-12 03:25:57 +00:00
|
|
|
switch (seq[2]) {
|
2015-04-28 20:09:40 +00:00
|
|
|
case '0': /* Esc [ 2 0 ~ == F9 on VT220/VT320/
|
|
|
|
* Linux console/xterm/rxvt/Eterm. */
|
2004-05-28 17:23:33 +00:00
|
|
|
retval = KEY_F(9);
|
2004-01-23 19:26:17 +00:00
|
|
|
break;
|
2015-04-28 20:09:40 +00:00
|
|
|
case '1': /* Esc [ 2 1 ~ == F10 on VT220/VT320/
|
|
|
|
* Linux console/xterm/rxvt/Eterm. */
|
2004-05-28 17:23:33 +00:00
|
|
|
retval = KEY_F(10);
|
2004-01-23 19:26:17 +00:00
|
|
|
break;
|
2015-04-28 20:09:40 +00:00
|
|
|
case '3': /* Esc [ 2 3 ~ == F11 on VT220/VT320/
|
|
|
|
* Linux console/xterm/rxvt/Eterm. */
|
2004-05-28 17:23:33 +00:00
|
|
|
retval = KEY_F(11);
|
2004-01-23 19:26:17 +00:00
|
|
|
break;
|
2015-04-28 20:09:40 +00:00
|
|
|
case '4': /* Esc [ 2 4 ~ == F12 on VT220/VT320/
|
|
|
|
* Linux console/xterm/rxvt/Eterm. */
|
2004-05-28 17:23:33 +00:00
|
|
|
retval = KEY_F(12);
|
2004-01-23 19:26:17 +00:00
|
|
|
break;
|
2015-04-28 20:09:40 +00:00
|
|
|
case '5': /* Esc [ 2 5 ~ == F13 on VT220/VT320/
|
|
|
|
* Linux console/rxvt/Eterm. */
|
2004-05-28 17:23:33 +00:00
|
|
|
retval = KEY_F(13);
|
2004-01-23 19:26:17 +00:00
|
|
|
break;
|
2015-04-28 20:09:40 +00:00
|
|
|
case '6': /* Esc [ 2 6 ~ == F14 on VT220/VT320/
|
|
|
|
* Linux console/rxvt/Eterm. */
|
2004-05-28 17:23:33 +00:00
|
|
|
retval = KEY_F(14);
|
2004-01-23 19:26:17 +00:00
|
|
|
break;
|
2015-04-28 20:09:40 +00:00
|
|
|
case '8': /* Esc [ 2 8 ~ == F15 on VT220/VT320/
|
|
|
|
* Linux console/rxvt/Eterm. */
|
2004-11-01 22:40:02 +00:00
|
|
|
retval = KEY_F(15);
|
|
|
|
break;
|
2015-04-28 20:09:40 +00:00
|
|
|
case '9': /* Esc [ 2 9 ~ == F16 on VT220/VT320/
|
|
|
|
* Linux console/rxvt/Eterm. */
|
2004-11-01 22:40:02 +00:00
|
|
|
retval = KEY_F(16);
|
|
|
|
break;
|
2015-04-28 20:09:40 +00:00
|
|
|
default: /* Esc [ 2 ~ == Insert on VT220/VT320/
|
|
|
|
* Linux console/xterm/Terminal. */
|
2014-04-23 19:33:03 +00:00
|
|
|
retval = sc_seq_or(do_insertfile_void, 0);
|
2004-01-23 19:26:17 +00:00
|
|
|
break;
|
|
|
|
}
|
2003-12-24 03:33:09 +00:00
|
|
|
}
|
|
|
|
break;
|
2004-06-22 14:30:18 +00:00
|
|
|
case '3': /* Esc [ 3 ~ == Delete on VT220/VT320/
|
2007-04-04 20:36:56 +00:00
|
|
|
* Linux console/xterm/Terminal. */
|
2014-04-23 19:33:03 +00:00
|
|
|
retval = sc_seq_or(do_delete, 0);
|
2003-12-24 03:33:09 +00:00
|
|
|
break;
|
2004-05-01 01:21:38 +00:00
|
|
|
case '4': /* Esc [ 4 ~ == End on VT220/VT320/Linux
|
2003-12-24 03:33:09 +00:00
|
|
|
* console/xterm. */
|
2014-04-23 19:33:03 +00:00
|
|
|
retval = sc_seq_or(do_end, 0);
|
2003-12-24 03:33:09 +00:00
|
|
|
break;
|
2004-06-22 14:30:18 +00:00
|
|
|
case '5': /* Esc [ 5 ~ == PageUp on VT220/VT320/
|
2007-04-04 20:36:56 +00:00
|
|
|
* Linux console/xterm/Terminal;
|
|
|
|
* Esc [ 5 ^ == PageUp on Eterm. */
|
2014-04-23 19:33:03 +00:00
|
|
|
retval = sc_seq_or(do_page_up, 0);
|
2003-12-24 03:33:09 +00:00
|
|
|
break;
|
2004-06-22 14:30:18 +00:00
|
|
|
case '6': /* Esc [ 6 ~ == PageDown on VT220/VT320/
|
2007-04-04 20:36:56 +00:00
|
|
|
* Linux console/xterm/Terminal;
|
2014-06-04 16:02:51 +00:00
|
|
|
* Esc [ 6 ^ == PageDown on Eterm. */
|
2014-04-23 19:33:03 +00:00
|
|
|
retval = sc_seq_or(do_page_down, 0);
|
2003-12-24 03:33:09 +00:00
|
|
|
break;
|
|
|
|
case '7': /* Esc [ 7 ~ == Home on rxvt. */
|
2011-02-07 14:45:56 +00:00
|
|
|
retval = sc_seq_or(do_home, 0);
|
2003-12-24 03:33:09 +00:00
|
|
|
break;
|
|
|
|
case '8': /* Esc [ 8 ~ == End on rxvt. */
|
2011-02-07 14:45:56 +00:00
|
|
|
retval = sc_seq_or(do_end, 0);
|
2003-12-24 03:33:09 +00:00
|
|
|
break;
|
2004-10-24 22:51:39 +00:00
|
|
|
case '9': /* Esc [ 9 == Delete on Mach console. */
|
2014-04-23 19:33:03 +00:00
|
|
|
retval = sc_seq_or(do_delete, 0);
|
2003-12-24 03:33:09 +00:00
|
|
|
break;
|
2004-10-24 22:51:39 +00:00
|
|
|
case '@': /* Esc [ @ == Insert on Mach console. */
|
2014-04-23 19:33:03 +00:00
|
|
|
retval = sc_seq_or(do_insertfile_void, 0);
|
2003-12-24 03:33:09 +00:00
|
|
|
break;
|
2004-05-01 01:21:38 +00:00
|
|
|
case 'A': /* Esc [ A == Up on ANSI/VT220/Linux
|
2004-10-24 22:51:39 +00:00
|
|
|
* console/FreeBSD console/Mach console/
|
2007-04-18 13:48:37 +00:00
|
|
|
* rxvt/Eterm/Terminal. */
|
2004-05-01 01:21:38 +00:00
|
|
|
case 'B': /* Esc [ B == Down on ANSI/VT220/Linux
|
2004-10-24 22:51:39 +00:00
|
|
|
* console/FreeBSD console/Mach console/
|
2007-04-18 13:48:37 +00:00
|
|
|
* rxvt/Eterm/Terminal. */
|
2004-05-01 01:21:38 +00:00
|
|
|
case 'C': /* Esc [ C == Right on ANSI/VT220/Linux
|
2004-10-24 22:51:39 +00:00
|
|
|
* console/FreeBSD console/Mach console/
|
2007-04-18 13:48:37 +00:00
|
|
|
* rxvt/Eterm/Terminal. */
|
2004-05-01 01:21:38 +00:00
|
|
|
case 'D': /* Esc [ D == Left on ANSI/VT220/Linux
|
2004-10-24 22:51:39 +00:00
|
|
|
* console/FreeBSD console/Mach console/
|
2007-04-18 13:48:37 +00:00
|
|
|
* rxvt/Eterm/Terminal. */
|
2005-01-12 03:25:57 +00:00
|
|
|
retval = get_escape_seq_abcd(seq[1]);
|
2003-12-24 03:33:09 +00:00
|
|
|
break;
|
2004-04-23 18:02:37 +00:00
|
|
|
case 'E': /* Esc [ E == Center (5) on numeric keypad
|
2007-04-04 20:36:56 +00:00
|
|
|
* with NumLock off on FreeBSD console/
|
|
|
|
* Terminal. */
|
2006-07-25 19:23:35 +00:00
|
|
|
retval = KEY_B2;
|
2004-04-23 18:02:37 +00:00
|
|
|
break;
|
2015-04-28 20:09:40 +00:00
|
|
|
case 'F': /* Esc [ F == End on FreeBSD console/Eterm. */
|
2011-02-07 14:45:56 +00:00
|
|
|
retval = sc_seq_or(do_end, 0);
|
2003-12-24 03:33:09 +00:00
|
|
|
break;
|
2015-04-28 20:09:40 +00:00
|
|
|
case 'G': /* Esc [ G == PageDown on FreeBSD console. */
|
2011-02-07 14:45:56 +00:00
|
|
|
retval = sc_seq_or(do_page_down, 0);
|
2003-12-24 03:33:09 +00:00
|
|
|
break;
|
2004-05-01 01:21:38 +00:00
|
|
|
case 'H': /* Esc [ H == Home on ANSI/VT220/FreeBSD
|
2004-10-24 22:51:39 +00:00
|
|
|
* console/Mach console/Eterm. */
|
2011-02-07 14:45:56 +00:00
|
|
|
retval = sc_seq_or(do_home, 0);
|
2003-12-24 03:33:09 +00:00
|
|
|
break;
|
2015-04-28 20:09:40 +00:00
|
|
|
case 'I': /* Esc [ I == PageUp on FreeBSD console. */
|
2011-02-07 14:45:56 +00:00
|
|
|
retval = sc_seq_or(do_page_up, 0);
|
2003-12-24 03:33:09 +00:00
|
|
|
break;
|
2015-04-28 20:09:40 +00:00
|
|
|
case 'L': /* Esc [ L == Insert on ANSI/FreeBSD console. */
|
2011-02-07 14:45:56 +00:00
|
|
|
retval = sc_seq_or(do_insertfile_void, 0);
|
2003-12-24 03:33:09 +00:00
|
|
|
break;
|
2004-01-23 19:26:17 +00:00
|
|
|
case 'M': /* Esc [ M == F1 on FreeBSD console. */
|
2004-05-28 17:23:33 +00:00
|
|
|
retval = KEY_F(1);
|
2004-01-23 19:26:17 +00:00
|
|
|
break;
|
|
|
|
case 'N': /* Esc [ N == F2 on FreeBSD console. */
|
2004-05-28 17:23:33 +00:00
|
|
|
retval = KEY_F(2);
|
2004-01-23 19:26:17 +00:00
|
|
|
break;
|
|
|
|
case 'O':
|
2004-12-04 17:41:52 +00:00
|
|
|
if (seq_len >= 3) {
|
2005-01-12 03:25:57 +00:00
|
|
|
switch (seq[2]) {
|
2015-04-28 20:09:40 +00:00
|
|
|
case 'P': /* Esc [ O P == F1 on xterm. */
|
2004-05-28 17:23:33 +00:00
|
|
|
retval = KEY_F(1);
|
2004-01-23 19:26:17 +00:00
|
|
|
break;
|
2015-04-28 20:09:40 +00:00
|
|
|
case 'Q': /* Esc [ O Q == F2 on xterm. */
|
2004-05-28 17:23:33 +00:00
|
|
|
retval = KEY_F(2);
|
2004-01-23 19:26:17 +00:00
|
|
|
break;
|
2015-04-28 20:09:40 +00:00
|
|
|
case 'R': /* Esc [ O R == F3 on xterm. */
|
2004-05-28 17:23:33 +00:00
|
|
|
retval = KEY_F(3);
|
2004-01-23 19:26:17 +00:00
|
|
|
break;
|
2015-04-28 20:09:40 +00:00
|
|
|
case 'S': /* Esc [ O S == F4 on xterm. */
|
2004-05-28 17:23:33 +00:00
|
|
|
retval = KEY_F(4);
|
2004-01-23 19:26:17 +00:00
|
|
|
break;
|
|
|
|
}
|
2005-09-25 18:42:05 +00:00
|
|
|
} else
|
2004-06-22 14:30:18 +00:00
|
|
|
/* Esc [ O == F3 on FreeBSD console. */
|
|
|
|
retval = KEY_F(3);
|
2004-01-23 19:26:17 +00:00
|
|
|
break;
|
|
|
|
case 'P': /* Esc [ P == F4 on FreeBSD console. */
|
2004-05-28 17:23:33 +00:00
|
|
|
retval = KEY_F(4);
|
2004-01-23 19:26:17 +00:00
|
|
|
break;
|
|
|
|
case 'Q': /* Esc [ Q == F5 on FreeBSD console. */
|
2004-05-28 17:23:33 +00:00
|
|
|
retval = KEY_F(5);
|
2004-01-23 19:26:17 +00:00
|
|
|
break;
|
|
|
|
case 'R': /* Esc [ R == F6 on FreeBSD console. */
|
2004-05-28 17:23:33 +00:00
|
|
|
retval = KEY_F(6);
|
2004-01-23 19:26:17 +00:00
|
|
|
break;
|
|
|
|
case 'S': /* Esc [ S == F7 on FreeBSD console. */
|
2004-05-28 17:23:33 +00:00
|
|
|
retval = KEY_F(7);
|
2004-01-23 19:26:17 +00:00
|
|
|
break;
|
|
|
|
case 'T': /* Esc [ T == F8 on FreeBSD console. */
|
2004-05-28 17:23:33 +00:00
|
|
|
retval = KEY_F(8);
|
2004-01-23 19:26:17 +00:00
|
|
|
break;
|
2004-10-24 22:51:39 +00:00
|
|
|
case 'U': /* Esc [ U == PageDown on Mach console. */
|
2011-02-07 14:45:56 +00:00
|
|
|
retval = sc_seq_or(do_page_down, 0);
|
2003-12-24 03:33:09 +00:00
|
|
|
break;
|
2004-10-24 22:51:39 +00:00
|
|
|
case 'V': /* Esc [ V == PageUp on Mach console. */
|
2011-02-07 14:45:56 +00:00
|
|
|
retval = sc_seq_or(do_page_up, 0);
|
2003-12-24 03:33:09 +00:00
|
|
|
break;
|
2004-01-23 19:26:17 +00:00
|
|
|
case 'W': /* Esc [ W == F11 on FreeBSD console. */
|
2004-05-28 17:23:33 +00:00
|
|
|
retval = KEY_F(11);
|
2004-01-23 19:26:17 +00:00
|
|
|
break;
|
|
|
|
case 'X': /* Esc [ X == F12 on FreeBSD console. */
|
2004-05-28 17:23:33 +00:00
|
|
|
retval = KEY_F(12);
|
2004-01-23 19:26:17 +00:00
|
|
|
break;
|
2004-10-24 22:51:39 +00:00
|
|
|
case 'Y': /* Esc [ Y == End on Mach console. */
|
2011-02-07 14:45:56 +00:00
|
|
|
retval = sc_seq_or(do_end, 0);
|
2003-12-24 03:33:09 +00:00
|
|
|
break;
|
2004-01-23 19:26:17 +00:00
|
|
|
case 'Z': /* Esc [ Z == F14 on FreeBSD console. */
|
2004-05-28 17:23:33 +00:00
|
|
|
retval = KEY_F(14);
|
2003-12-24 03:33:09 +00:00
|
|
|
break;
|
2004-01-23 19:26:17 +00:00
|
|
|
case 'a': /* Esc [ a == Shift-Up on rxvt/Eterm. */
|
2004-01-06 01:45:04 +00:00
|
|
|
case 'b': /* Esc [ b == Shift-Down on rxvt/Eterm. */
|
2015-04-28 20:09:40 +00:00
|
|
|
case 'c': /* Esc [ c == Shift-Right on rxvt/Eterm. */
|
2004-01-06 01:45:04 +00:00
|
|
|
case 'd': /* Esc [ d == Shift-Left on rxvt/Eterm. */
|
2005-01-12 03:25:57 +00:00
|
|
|
retval = get_escape_seq_abcd(seq[1]);
|
2004-01-23 19:26:17 +00:00
|
|
|
break;
|
|
|
|
case '[':
|
2004-12-04 17:41:52 +00:00
|
|
|
if (seq_len >= 3) {
|
2005-01-12 03:25:57 +00:00
|
|
|
switch (seq[2]) {
|
2004-01-23 19:26:17 +00:00
|
|
|
case 'A': /* Esc [ [ A == F1 on Linux
|
|
|
|
* console. */
|
2004-05-28 17:23:33 +00:00
|
|
|
retval = KEY_F(1);
|
2004-01-23 19:26:17 +00:00
|
|
|
break;
|
|
|
|
case 'B': /* Esc [ [ B == F2 on Linux
|
|
|
|
* console. */
|
2004-05-28 17:23:33 +00:00
|
|
|
retval = KEY_F(2);
|
2004-01-23 19:26:17 +00:00
|
|
|
break;
|
|
|
|
case 'C': /* Esc [ [ C == F3 on Linux
|
|
|
|
* console. */
|
2004-05-28 17:23:33 +00:00
|
|
|
retval = KEY_F(3);
|
2004-01-23 19:26:17 +00:00
|
|
|
break;
|
|
|
|
case 'D': /* Esc [ [ D == F4 on Linux
|
|
|
|
* console. */
|
2004-05-28 17:23:33 +00:00
|
|
|
retval = KEY_F(4);
|
2004-01-23 19:26:17 +00:00
|
|
|
break;
|
|
|
|
case 'E': /* Esc [ [ E == F5 on Linux
|
|
|
|
* console. */
|
2004-05-28 17:23:33 +00:00
|
|
|
retval = KEY_F(5);
|
2004-01-23 19:26:17 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2003-12-24 03:33:09 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2003-08-17 02:48:43 +00:00
|
|
|
}
|
|
|
|
|
2004-05-28 17:23:33 +00:00
|
|
|
#ifdef DEBUG
|
2006-07-25 19:23:35 +00:00
|
|
|
fprintf(stderr, "get_escape_seq_kbinput(): retval = %d\n", retval);
|
2004-05-28 17:23:33 +00:00
|
|
|
#endif
|
2003-12-24 03:33:09 +00:00
|
|
|
|
2004-05-28 17:23:33 +00:00
|
|
|
return retval;
|
2003-08-17 02:48:43 +00:00
|
|
|
}
|
|
|
|
|
2004-01-23 19:26:17 +00:00
|
|
|
/* Return the equivalent arrow key value for the case-insensitive
|
2004-02-07 03:39:48 +00:00
|
|
|
* letters A (up), B (down), C (right), and D (left). These are common
|
2004-01-23 19:26:17 +00:00
|
|
|
* to many escape sequences. */
|
|
|
|
int get_escape_seq_abcd(int kbinput)
|
|
|
|
{
|
|
|
|
switch (tolower(kbinput)) {
|
|
|
|
case 'a':
|
2014-04-23 19:33:03 +00:00
|
|
|
return sc_seq_or(do_up_void, 0);
|
2004-01-23 19:26:17 +00:00
|
|
|
case 'b':
|
2014-04-23 19:33:03 +00:00
|
|
|
return sc_seq_or(do_down_void, 0);
|
2004-01-23 19:26:17 +00:00
|
|
|
case 'c':
|
2014-04-23 19:33:03 +00:00
|
|
|
return sc_seq_or(do_right, 0);
|
2004-01-23 19:26:17 +00:00
|
|
|
case 'd':
|
2014-04-23 19:33:03 +00:00
|
|
|
return sc_seq_or(do_left, 0);
|
2004-01-23 19:26:17 +00:00
|
|
|
default:
|
|
|
|
return ERR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-05-25 22:10:27 +00:00
|
|
|
/* Interpret the escape sequence in the keystroke buffer, the first
|
2006-07-23 17:54:35 +00:00
|
|
|
* character of which is kbinput. Assume that the keystroke buffer
|
|
|
|
* isn't empty, and that the initial escape has already been read in. */
|
|
|
|
int parse_escape_seq_kbinput(WINDOW *win, int kbinput)
|
2006-05-25 22:10:27 +00:00
|
|
|
{
|
|
|
|
int retval, *seq;
|
|
|
|
size_t seq_len;
|
|
|
|
|
|
|
|
/* Put back the non-escape character, get the complete escape
|
|
|
|
* sequence, translate the sequence into its corresponding key
|
|
|
|
* value, and save that as the result. */
|
|
|
|
unget_input(&kbinput, 1);
|
|
|
|
seq_len = get_key_buffer_len();
|
|
|
|
seq = get_input(NULL, seq_len);
|
2006-07-25 19:23:35 +00:00
|
|
|
retval = get_escape_seq_kbinput(seq, seq_len);
|
2006-05-25 22:10:27 +00:00
|
|
|
|
|
|
|
free(seq);
|
|
|
|
|
2006-07-25 19:23:35 +00:00
|
|
|
/* If we got an unrecognized escape sequence, throw it out. */
|
|
|
|
if (retval == ERR) {
|
2006-07-23 18:00:50 +00:00
|
|
|
if (win == edit) {
|
2006-07-23 17:54:35 +00:00
|
|
|
statusbar(_("Unknown Command"));
|
|
|
|
beep();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-05-25 22:10:27 +00:00
|
|
|
#ifdef DEBUG
|
2006-07-25 19:23:35 +00:00
|
|
|
fprintf(stderr, "parse_escape_seq_kbinput(): kbinput = %d, seq_len = %lu, retval = %d\n", kbinput, (unsigned long)seq_len, retval);
|
2006-05-25 22:10:27 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
2006-05-27 15:52:26 +00:00
|
|
|
/* Translate a byte sequence: turn a three-digit decimal number (from
|
|
|
|
* 000 to 255) into its corresponding byte value. */
|
2006-05-10 13:41:53 +00:00
|
|
|
int get_byte_kbinput(int kbinput)
|
2004-05-28 17:23:33 +00:00
|
|
|
{
|
2005-01-12 03:25:57 +00:00
|
|
|
static int byte_digits = 0, byte = 0;
|
2004-12-04 17:41:52 +00:00
|
|
|
int retval = ERR;
|
2004-05-28 17:23:33 +00:00
|
|
|
|
2005-01-03 19:56:56 +00:00
|
|
|
/* Increment the byte digit counter. */
|
|
|
|
byte_digits++;
|
2004-05-28 17:23:33 +00:00
|
|
|
|
2005-01-03 19:56:56 +00:00
|
|
|
switch (byte_digits) {
|
2004-12-04 17:41:52 +00:00
|
|
|
case 1:
|
2006-05-27 15:52:26 +00:00
|
|
|
/* First digit: This must be from zero to two. Put it in
|
|
|
|
* the 100's position of the byte sequence holder. */
|
2005-01-03 19:56:56 +00:00
|
|
|
if ('0' <= kbinput && kbinput <= '2')
|
2006-05-27 15:52:26 +00:00
|
|
|
byte = (kbinput - '0') * 100;
|
2004-12-04 17:41:52 +00:00
|
|
|
else
|
2006-05-27 15:52:26 +00:00
|
|
|
/* This isn't the start of a byte sequence. Return this
|
|
|
|
* character as the result. */
|
2004-12-04 17:41:52 +00:00
|
|
|
retval = kbinput;
|
|
|
|
break;
|
|
|
|
case 2:
|
2006-05-27 15:52:26 +00:00
|
|
|
/* Second digit: This must be from zero to five if the first
|
|
|
|
* was two, and may be any decimal value if the first was
|
|
|
|
* zero or one. Put it in the 10's position of the byte
|
|
|
|
* sequence holder. */
|
2005-01-12 03:25:57 +00:00
|
|
|
if (('0' <= kbinput && kbinput <= '5') || (byte < 200 &&
|
|
|
|
'6' <= kbinput && kbinput <= '9'))
|
|
|
|
byte += (kbinput - '0') * 10;
|
2004-12-04 17:41:52 +00:00
|
|
|
else
|
2006-05-27 15:52:26 +00:00
|
|
|
/* This isn't the second digit of a byte sequence.
|
|
|
|
* Return this character as the result. */
|
2004-12-04 17:41:52 +00:00
|
|
|
retval = kbinput;
|
|
|
|
break;
|
|
|
|
case 3:
|
2006-05-27 15:52:26 +00:00
|
|
|
/* Third digit: This must be from zero to five if the first
|
2014-04-15 11:25:29 +00:00
|
|
|
* was two and the second was five, and may be any decimal
|
|
|
|
* value otherwise. Put it in the 1's position of the byte
|
|
|
|
* sequence holder. */
|
2005-01-12 03:25:57 +00:00
|
|
|
if (('0' <= kbinput && kbinput <= '5') || (byte < 250 &&
|
|
|
|
'6' <= kbinput && kbinput <= '9')) {
|
2006-05-30 20:51:15 +00:00
|
|
|
byte += kbinput - '0';
|
2014-04-15 11:25:29 +00:00
|
|
|
/* The byte sequence is complete. */
|
2005-01-12 03:25:57 +00:00
|
|
|
retval = byte;
|
2005-01-03 19:56:56 +00:00
|
|
|
} else
|
2006-05-27 15:52:26 +00:00
|
|
|
/* This isn't the third digit of a byte sequence.
|
|
|
|
* Return this character as the result. */
|
2004-12-04 17:41:52 +00:00
|
|
|
retval = kbinput;
|
|
|
|
break;
|
2005-01-03 19:56:56 +00:00
|
|
|
default:
|
2006-05-27 15:52:26 +00:00
|
|
|
/* If there are more than three digits, return this
|
|
|
|
* character as the result. (Maybe we should produce an
|
|
|
|
* error instead?) */
|
2005-01-03 19:56:56 +00:00
|
|
|
retval = kbinput;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If we have a result, reset the byte digit counter and the byte
|
|
|
|
* sequence holder. */
|
|
|
|
if (retval != ERR) {
|
|
|
|
byte_digits = 0;
|
2005-01-12 03:25:57 +00:00
|
|
|
byte = 0;
|
2005-01-03 19:56:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
2005-01-12 03:25:57 +00:00
|
|
|
fprintf(stderr, "get_byte_kbinput(): kbinput = %d, byte_digits = %d, byte = %d, retval = %d\n", kbinput, byte_digits, byte, retval);
|
2005-01-03 19:56:56 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
2006-05-27 17:39:19 +00:00
|
|
|
#ifdef ENABLE_UTF8
|
2006-05-28 17:30:28 +00:00
|
|
|
/* If the character in kbinput is a valid hexadecimal digit, multiply it
|
|
|
|
* by factor and add the result to uni. */
|
|
|
|
long add_unicode_digit(int kbinput, long factor, long *uni)
|
|
|
|
{
|
|
|
|
long retval = ERR;
|
|
|
|
|
|
|
|
if ('0' <= kbinput && kbinput <= '9')
|
|
|
|
*uni += (kbinput - '0') * factor;
|
|
|
|
else if ('a' <= tolower(kbinput) && tolower(kbinput) <= 'f')
|
|
|
|
*uni += (tolower(kbinput) - 'a' + 10) * factor;
|
|
|
|
else
|
|
|
|
/* If this character isn't a valid hexadecimal value, save it as
|
|
|
|
* the result. */
|
|
|
|
retval = kbinput;
|
|
|
|
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
2005-08-08 23:47:28 +00:00
|
|
|
/* Translate a Unicode sequence: turn a six-digit hexadecimal number
|
2006-05-27 15:52:26 +00:00
|
|
|
* (from 000000 to 10FFFF, case-insensitive) into its corresponding
|
2005-08-08 23:47:28 +00:00
|
|
|
* multibyte value. */
|
2006-05-10 13:41:53 +00:00
|
|
|
long get_unicode_kbinput(int kbinput)
|
2005-01-03 19:56:56 +00:00
|
|
|
{
|
2005-08-08 23:03:25 +00:00
|
|
|
static int uni_digits = 0;
|
|
|
|
static long uni = 0;
|
|
|
|
long retval = ERR;
|
2005-01-03 19:56:56 +00:00
|
|
|
|
2005-08-08 23:47:28 +00:00
|
|
|
/* Increment the Unicode digit counter. */
|
2005-08-01 19:12:05 +00:00
|
|
|
uni_digits++;
|
2005-01-03 19:56:56 +00:00
|
|
|
|
2005-08-01 19:12:05 +00:00
|
|
|
switch (uni_digits) {
|
2005-01-03 19:56:56 +00:00
|
|
|
case 1:
|
2006-05-27 15:52:26 +00:00
|
|
|
/* First digit: This must be zero or one. Put it in the
|
|
|
|
* 0x100000's position of the Unicode sequence holder. */
|
2005-08-08 23:47:28 +00:00
|
|
|
if ('0' <= kbinput && kbinput <= '1')
|
2006-05-27 15:52:26 +00:00
|
|
|
uni = (kbinput - '0') * 0x100000;
|
2005-08-08 23:47:28 +00:00
|
|
|
else
|
2006-05-27 15:52:26 +00:00
|
|
|
/* This isn't the first digit of a Unicode sequence.
|
|
|
|
* Return this character as the result. */
|
2005-08-08 23:47:28 +00:00
|
|
|
retval = kbinput;
|
|
|
|
break;
|
|
|
|
case 2:
|
2006-05-27 15:52:26 +00:00
|
|
|
/* Second digit: This must be zero if the first was one, and
|
|
|
|
* may be any hexadecimal value if the first was zero. Put
|
|
|
|
* it in the 0x10000's position of the Unicode sequence
|
|
|
|
* holder. */
|
|
|
|
if (uni == 0 || '0' == kbinput)
|
|
|
|
retval = add_unicode_digit(kbinput, 0x10000, &uni);
|
2005-08-08 23:47:28 +00:00
|
|
|
else
|
2006-05-27 15:52:26 +00:00
|
|
|
/* This isn't the second digit of a Unicode sequence.
|
|
|
|
* Return this character as the result. */
|
2005-08-08 23:47:28 +00:00
|
|
|
retval = kbinput;
|
|
|
|
break;
|
|
|
|
case 3:
|
2006-05-27 15:52:26 +00:00
|
|
|
/* Third digit: This may be any hexadecimal value. Put it
|
|
|
|
* in the 0x1000's position of the Unicode sequence
|
|
|
|
* holder. */
|
|
|
|
retval = add_unicode_digit(kbinput, 0x1000, &uni);
|
2005-01-03 19:56:56 +00:00
|
|
|
break;
|
2005-08-08 23:47:28 +00:00
|
|
|
case 4:
|
2006-05-27 15:52:26 +00:00
|
|
|
/* Fourth digit: This may be any hexadecimal value. Put it
|
|
|
|
* in the 0x100's position of the Unicode sequence
|
|
|
|
* holder. */
|
|
|
|
retval = add_unicode_digit(kbinput, 0x100, &uni);
|
2004-12-04 17:41:52 +00:00
|
|
|
break;
|
2005-08-08 23:47:28 +00:00
|
|
|
case 5:
|
2006-05-27 15:52:26 +00:00
|
|
|
/* Fifth digit: This may be any hexadecimal value. Put it
|
|
|
|
* in the 0x10's position of the Unicode sequence holder. */
|
|
|
|
retval = add_unicode_digit(kbinput, 0x10, &uni);
|
2005-01-03 19:56:56 +00:00
|
|
|
break;
|
2005-08-08 23:47:28 +00:00
|
|
|
case 6:
|
2006-05-27 15:52:26 +00:00
|
|
|
/* Sixth digit: This may be any hexadecimal value. Put it
|
|
|
|
* in the 0x1's position of the Unicode sequence holder. */
|
|
|
|
retval = add_unicode_digit(kbinput, 0x1, &uni);
|
|
|
|
/* If this character is a valid hexadecimal value, then the
|
|
|
|
* Unicode sequence is complete. */
|
|
|
|
if (retval == ERR)
|
2005-08-01 19:12:05 +00:00
|
|
|
retval = uni;
|
2004-12-04 17:41:52 +00:00
|
|
|
break;
|
|
|
|
default:
|
2006-05-27 15:52:26 +00:00
|
|
|
/* If there are more than six digits, return this character
|
|
|
|
* as the result. (Maybe we should produce an error
|
|
|
|
* instead?) */
|
2004-12-04 17:41:52 +00:00
|
|
|
retval = kbinput;
|
|
|
|
break;
|
|
|
|
}
|
2004-05-28 17:23:33 +00:00
|
|
|
|
2005-08-08 23:47:28 +00:00
|
|
|
/* If we have a result, reset the Unicode digit counter and the
|
|
|
|
* Unicode sequence holder. */
|
2004-12-04 17:41:52 +00:00
|
|
|
if (retval != ERR) {
|
2005-08-01 19:12:05 +00:00
|
|
|
uni_digits = 0;
|
|
|
|
uni = 0;
|
2004-12-04 17:41:52 +00:00
|
|
|
}
|
2004-11-29 00:30:07 +00:00
|
|
|
|
2004-05-28 17:23:33 +00:00
|
|
|
#ifdef DEBUG
|
2005-08-08 23:03:25 +00:00
|
|
|
fprintf(stderr, "get_unicode_kbinput(): kbinput = %d, uni_digits = %d, uni = %ld, retval = %ld\n", kbinput, uni_digits, uni, retval);
|
2004-05-28 17:23:33 +00:00
|
|
|
#endif
|
|
|
|
|
2004-12-04 17:41:52 +00:00
|
|
|
return retval;
|
|
|
|
}
|
2006-05-27 17:39:19 +00:00
|
|
|
#endif /* ENABLE_UTF8 */
|
2006-05-27 15:52:26 +00:00
|
|
|
|
2004-12-04 17:41:52 +00:00
|
|
|
/* Translate a control character sequence: turn an ASCII non-control
|
|
|
|
* character into its corresponding control character. */
|
|
|
|
int get_control_kbinput(int kbinput)
|
|
|
|
{
|
|
|
|
int retval;
|
|
|
|
|
2006-04-28 18:26:07 +00:00
|
|
|
/* Ctrl-Space (Ctrl-2, Ctrl-@, Ctrl-`) */
|
2006-05-27 15:52:26 +00:00
|
|
|
if (kbinput == ' ' || kbinput == '2')
|
|
|
|
retval = NANO_CONTROL_SPACE;
|
2006-04-28 18:26:07 +00:00
|
|
|
/* Ctrl-/ (Ctrl-7, Ctrl-_) */
|
|
|
|
else if (kbinput == '/')
|
2006-05-27 15:52:26 +00:00
|
|
|
retval = NANO_CONTROL_7;
|
2006-04-28 18:26:07 +00:00
|
|
|
/* Ctrl-3 (Ctrl-[, Esc) to Ctrl-7 (Ctrl-/, Ctrl-_) */
|
2004-12-04 17:41:52 +00:00
|
|
|
else if ('3' <= kbinput && kbinput <= '7')
|
|
|
|
retval = kbinput - 24;
|
|
|
|
/* Ctrl-8 (Ctrl-?) */
|
2006-05-27 15:52:26 +00:00
|
|
|
else if (kbinput == '8' || kbinput == '?')
|
|
|
|
retval = NANO_CONTROL_8;
|
2006-05-20 17:19:09 +00:00
|
|
|
/* Ctrl-@ (Ctrl-Space, Ctrl-2, Ctrl-`) to Ctrl-_ (Ctrl-/, Ctrl-7) */
|
|
|
|
else if ('@' <= kbinput && kbinput <= '_')
|
2006-05-27 15:52:26 +00:00
|
|
|
retval = kbinput - '@';
|
2006-04-28 18:26:07 +00:00
|
|
|
/* Ctrl-` (Ctrl-2, Ctrl-Space, Ctrl-@) to Ctrl-~ (Ctrl-6, Ctrl-^) */
|
|
|
|
else if ('`' <= kbinput && kbinput <= '~')
|
2006-05-27 15:52:26 +00:00
|
|
|
retval = kbinput - '`';
|
2004-12-04 17:41:52 +00:00
|
|
|
else
|
|
|
|
retval = kbinput;
|
|
|
|
|
2004-05-28 17:23:33 +00:00
|
|
|
#ifdef DEBUG
|
2004-12-04 17:41:52 +00:00
|
|
|
fprintf(stderr, "get_control_kbinput(): kbinput = %d, retval = %d\n", kbinput, retval);
|
2004-05-28 17:23:33 +00:00
|
|
|
#endif
|
|
|
|
|
2004-12-04 17:41:52 +00:00
|
|
|
return retval;
|
|
|
|
}
|
2004-05-28 17:23:33 +00:00
|
|
|
|
2006-05-26 03:22:44 +00:00
|
|
|
/* Put the output-formatted characters in output back into the keystroke
|
|
|
|
* buffer, so that they can be parsed and displayed as output again. */
|
2005-01-12 03:25:57 +00:00
|
|
|
void unparse_kbinput(char *output, size_t output_len)
|
2005-01-02 22:35:31 +00:00
|
|
|
{
|
2005-01-12 03:25:57 +00:00
|
|
|
int *input;
|
|
|
|
size_t i;
|
2005-01-02 22:35:31 +00:00
|
|
|
|
2005-01-12 03:25:57 +00:00
|
|
|
if (output_len == 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
input = (int *)nmalloc(output_len * sizeof(int));
|
2006-12-02 23:39:16 +00:00
|
|
|
|
2005-01-12 03:25:57 +00:00
|
|
|
for (i = 0; i < output_len; i++)
|
|
|
|
input[i] = (int)output[i];
|
2006-12-02 23:39:16 +00:00
|
|
|
|
2005-01-12 03:25:57 +00:00
|
|
|
unget_input(input, output_len);
|
2006-12-02 23:39:16 +00:00
|
|
|
|
2005-01-12 03:25:57 +00:00
|
|
|
free(input);
|
2005-01-02 22:35:31 +00:00
|
|
|
}
|
|
|
|
|
2005-01-12 03:25:57 +00:00
|
|
|
/* Read in a stream of characters verbatim, and return the length of the
|
2004-12-04 17:41:52 +00:00
|
|
|
* string in kbinput_len. Assume nodelay(win) is FALSE. */
|
|
|
|
int *get_verbatim_kbinput(WINDOW *win, size_t *kbinput_len)
|
|
|
|
{
|
|
|
|
int *retval;
|
2004-05-28 17:23:33 +00:00
|
|
|
|
2004-12-04 17:41:52 +00:00
|
|
|
/* Turn off flow control characters if necessary so that we can type
|
2005-08-10 21:22:15 +00:00
|
|
|
* them in verbatim, and turn the keypad off if necessary so that we
|
|
|
|
* don't get extended keypad values. */
|
2004-12-04 17:41:52 +00:00
|
|
|
if (ISSET(PRESERVE))
|
|
|
|
disable_flow_control();
|
2005-08-10 21:22:15 +00:00
|
|
|
if (!ISSET(REBIND_KEYPAD))
|
|
|
|
keypad(win, FALSE);
|
2004-12-04 17:41:52 +00:00
|
|
|
|
|
|
|
/* Read in a stream of characters and interpret it if possible. */
|
|
|
|
retval = parse_verbatim_kbinput(win, kbinput_len);
|
2004-05-28 17:23:33 +00:00
|
|
|
|
|
|
|
/* Turn flow control characters back on if necessary and turn the
|
2005-08-10 21:22:15 +00:00
|
|
|
* keypad back on if necessary now that we're done. */
|
2004-05-28 17:23:33 +00:00
|
|
|
if (ISSET(PRESERVE))
|
|
|
|
enable_flow_control();
|
2005-08-10 21:22:15 +00:00
|
|
|
if (!ISSET(REBIND_KEYPAD))
|
|
|
|
keypad(win, TRUE);
|
2004-05-28 17:23:33 +00:00
|
|
|
|
2004-12-04 17:41:52 +00:00
|
|
|
return retval;
|
2004-05-28 17:23:33 +00:00
|
|
|
}
|
|
|
|
|
2005-01-12 03:25:57 +00:00
|
|
|
/* Read in a stream of all available characters, and return the length
|
|
|
|
* of the string in kbinput_len. Translate the first few characters of
|
2005-08-01 19:12:05 +00:00
|
|
|
* the input into the corresponding multibyte value if possible. After
|
2007-04-19 03:15:04 +00:00
|
|
|
* that, leave the input as-is. */
|
2004-12-04 17:41:52 +00:00
|
|
|
int *parse_verbatim_kbinput(WINDOW *win, size_t *kbinput_len)
|
2004-05-28 17:23:33 +00:00
|
|
|
{
|
2005-08-08 23:03:25 +00:00
|
|
|
int *kbinput, *retval;
|
2004-05-28 17:23:33 +00:00
|
|
|
|
2004-12-04 17:41:52 +00:00
|
|
|
/* Read in the first keystroke. */
|
2014-05-13 20:14:01 +00:00
|
|
|
while ((kbinput = get_input(win, 1)) == NULL)
|
|
|
|
;
|
2004-12-04 17:41:52 +00:00
|
|
|
|
2006-05-27 17:39:19 +00:00
|
|
|
#ifdef ENABLE_UTF8
|
2006-05-28 16:25:15 +00:00
|
|
|
if (using_utf8()) {
|
|
|
|
/* Check whether the first keystroke is a valid hexadecimal
|
|
|
|
* digit. */
|
2006-05-28 17:09:49 +00:00
|
|
|
long uni = get_unicode_kbinput(*kbinput);
|
2006-05-28 16:25:15 +00:00
|
|
|
|
|
|
|
/* If the first keystroke isn't a valid hexadecimal digit, put
|
|
|
|
* back the first keystroke. */
|
|
|
|
if (uni != ERR)
|
|
|
|
unget_input(kbinput, 1);
|
|
|
|
|
|
|
|
/* Otherwise, read in keystrokes until we have a complete
|
|
|
|
* Unicode sequence, and put back the corresponding Unicode
|
|
|
|
* value. */
|
|
|
|
else {
|
|
|
|
char *uni_mb;
|
|
|
|
int uni_mb_len, *seq, i;
|
|
|
|
|
|
|
|
if (win == edit)
|
|
|
|
/* TRANSLATORS: This is displayed during the input of a
|
|
|
|
* six-digit hexadecimal Unicode character code. */
|
|
|
|
statusbar(_("Unicode Input"));
|
|
|
|
|
|
|
|
while (uni == ERR) {
|
2014-05-13 20:14:01 +00:00
|
|
|
while ((kbinput = get_input(win, 1)) == NULL)
|
|
|
|
;
|
2006-05-28 16:25:15 +00:00
|
|
|
uni = get_unicode_kbinput(*kbinput);
|
|
|
|
}
|
2004-12-04 17:41:52 +00:00
|
|
|
|
2006-05-28 16:25:15 +00:00
|
|
|
/* Put back the multibyte equivalent of the Unicode
|
|
|
|
* value. */
|
|
|
|
uni_mb = make_mbchar(uni, &uni_mb_len);
|
2006-05-27 17:39:19 +00:00
|
|
|
|
2006-05-28 16:25:15 +00:00
|
|
|
seq = (int *)nmalloc(uni_mb_len * sizeof(int));
|
2006-05-27 17:39:19 +00:00
|
|
|
|
2006-05-28 16:25:15 +00:00
|
|
|
for (i = 0; i < uni_mb_len; i++)
|
|
|
|
seq[i] = (unsigned char)uni_mb[i];
|
2004-05-28 17:23:33 +00:00
|
|
|
|
2006-05-28 16:25:15 +00:00
|
|
|
unget_input(seq, uni_mb_len);
|
2006-05-27 15:52:26 +00:00
|
|
|
|
2006-05-28 16:25:15 +00:00
|
|
|
free(seq);
|
|
|
|
free(uni_mb);
|
2004-12-04 17:41:52 +00:00
|
|
|
}
|
2006-05-28 16:25:15 +00:00
|
|
|
} else
|
2006-05-28 17:09:49 +00:00
|
|
|
#endif /* ENABLE_UTF8 */
|
|
|
|
|
2006-05-28 16:25:15 +00:00
|
|
|
/* Put back the first keystroke. */
|
|
|
|
unget_input(kbinput, 1);
|
2004-12-04 17:41:52 +00:00
|
|
|
|
2006-12-02 17:22:21 +00:00
|
|
|
free(kbinput);
|
|
|
|
|
2005-01-12 03:25:57 +00:00
|
|
|
/* Get the complete sequence, and save the characters in it as the
|
2004-12-04 17:41:52 +00:00
|
|
|
* result. */
|
2005-07-13 20:18:46 +00:00
|
|
|
*kbinput_len = get_key_buffer_len();
|
2005-01-12 03:25:57 +00:00
|
|
|
retval = get_input(NULL, *kbinput_len);
|
2004-05-28 17:23:33 +00:00
|
|
|
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
2003-11-28 19:47:42 +00:00
|
|
|
#ifndef DISABLE_MOUSE
|
2007-12-08 04:21:15 +00:00
|
|
|
/* Handle any mouse event that may have occurred. We currently handle
|
2007-05-29 17:01:12 +00:00
|
|
|
* releases/clicks of the first mouse button. If allow_shortcuts is
|
|
|
|
* TRUE, releasing/clicking on a visible shortcut will put back the
|
|
|
|
* keystroke associated with that shortcut. If NCURSES_MOUSE_VERSION is
|
|
|
|
* at least 2, we also currently handle presses of the fourth mouse
|
|
|
|
* button (upward rolls of the mouse wheel) by putting back the
|
|
|
|
* keystrokes to move up, and presses of the fifth mouse button
|
|
|
|
* (downward rolls of the mouse wheel) by putting back the keystrokes to
|
2007-12-08 04:21:15 +00:00
|
|
|
* move down. We also store the coordinates of a mouse event that needs
|
|
|
|
* to be handled in mouse_x and mouse_y, relative to the entire screen.
|
|
|
|
* Return -1 on error, 0 if the mouse event needs to be handled, 1 if
|
|
|
|
* it's been handled by putting back keystrokes that need to be handled.
|
|
|
|
* or 2 if it's been ignored. Assume that KEY_MOUSE has already been
|
|
|
|
* read in. */
|
2007-05-20 23:41:56 +00:00
|
|
|
int get_mouseinput(int *mouse_x, int *mouse_y, bool allow_shortcuts)
|
2003-11-28 19:47:42 +00:00
|
|
|
{
|
|
|
|
MEVENT mevent;
|
2007-12-08 04:21:15 +00:00
|
|
|
bool in_bottomwin;
|
2008-03-05 07:34:01 +00:00
|
|
|
subnfunc *f;
|
2003-11-28 19:47:42 +00:00
|
|
|
|
|
|
|
*mouse_x = -1;
|
|
|
|
*mouse_y = -1;
|
|
|
|
|
|
|
|
/* First, get the actual mouse event. */
|
|
|
|
if (getmouse(&mevent) == ERR)
|
2007-05-20 23:41:56 +00:00
|
|
|
return -1;
|
2003-11-28 19:47:42 +00:00
|
|
|
|
2007-05-20 23:41:56 +00:00
|
|
|
/* Save the screen coordinates where the mouse event took place. */
|
|
|
|
*mouse_x = mevent.x;
|
|
|
|
*mouse_y = mevent.y;
|
2007-05-15 18:04:25 +00:00
|
|
|
|
2007-12-08 04:21:15 +00:00
|
|
|
in_bottomwin = wenclose(bottomwin, *mouse_y, *mouse_x);
|
|
|
|
|
2007-06-28 18:31:13 +00:00
|
|
|
/* Handle releases/clicks of the first mouse button. */
|
2007-05-29 17:01:12 +00:00
|
|
|
if (mevent.bstate & (BUTTON1_RELEASED | BUTTON1_CLICKED)) {
|
2007-05-15 18:04:25 +00:00
|
|
|
/* If we're allowing shortcuts, the current shortcut list is
|
|
|
|
* being displayed on the last two lines of the screen, and the
|
2007-05-29 17:01:12 +00:00
|
|
|
* first mouse button was released on/clicked inside it, we need
|
|
|
|
* to figure out which shortcut was released on/clicked and put
|
|
|
|
* back the equivalent keystroke(s) for it. */
|
2007-12-08 04:21:15 +00:00
|
|
|
if (allow_shortcuts && !ISSET(NO_HELP) && in_bottomwin) {
|
2007-05-22 17:20:28 +00:00
|
|
|
int i;
|
|
|
|
/* The width of all the shortcuts, except for the last
|
|
|
|
* two, in the shortcut list in bottomwin. */
|
|
|
|
int j;
|
2014-05-09 11:44:17 +00:00
|
|
|
/* The calculated index number of the clicked item. */
|
2007-05-15 18:04:25 +00:00
|
|
|
size_t currslen;
|
|
|
|
/* The number of shortcuts in the current shortcut
|
|
|
|
* list. */
|
|
|
|
|
2007-12-08 04:21:15 +00:00
|
|
|
/* Translate the mouse event coordinates so that they're
|
|
|
|
* relative to bottomwin. */
|
|
|
|
wmouse_trafo(bottomwin, mouse_y, mouse_x, FALSE);
|
|
|
|
|
|
|
|
/* Handle releases/clicks of the first mouse button on the
|
|
|
|
* statusbar elsewhere. */
|
|
|
|
if (*mouse_y == 0) {
|
|
|
|
/* Restore the untranslated mouse event coordinates, so
|
|
|
|
* that they're relative to the entire screen again. */
|
|
|
|
*mouse_x = mevent.x;
|
|
|
|
*mouse_y = mevent.y;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2007-05-22 17:20:28 +00:00
|
|
|
|
2007-05-15 18:04:25 +00:00
|
|
|
/* Get the shortcut lists' length. */
|
2008-03-05 07:34:01 +00:00
|
|
|
if (currmenu == MMAIN)
|
2004-08-26 01:43:16 +00:00
|
|
|
currslen = MAIN_VISIBLE;
|
2007-05-15 18:04:25 +00:00
|
|
|
else {
|
2008-03-05 07:34:01 +00:00
|
|
|
currslen = length_of_list(currmenu);
|
2004-08-26 01:43:16 +00:00
|
|
|
|
2007-05-15 18:04:25 +00:00
|
|
|
/* We don't show any more shortcuts than the main list
|
|
|
|
* does. */
|
|
|
|
if (currslen > MAIN_VISIBLE)
|
|
|
|
currslen = MAIN_VISIBLE;
|
|
|
|
}
|
2006-04-18 16:13:35 +00:00
|
|
|
|
2007-05-15 18:04:25 +00:00
|
|
|
/* Calculate the width of all of the shortcuts in the list
|
|
|
|
* except for the last two, which are longer by (COLS % i)
|
|
|
|
* columns so as to not waste space. */
|
|
|
|
if (currslen < 2)
|
|
|
|
i = COLS / (MAIN_VISIBLE / 2);
|
|
|
|
else
|
|
|
|
i = COLS / ((currslen / 2) + (currslen % 2));
|
|
|
|
|
2014-05-09 11:44:17 +00:00
|
|
|
/* Calculate the one-based index in the shortcut list. */
|
|
|
|
j = (*mouse_x / i) * 2 + *mouse_y;
|
2007-05-15 18:04:25 +00:00
|
|
|
|
2014-05-09 11:44:17 +00:00
|
|
|
/* Adjust the index if we hit the last two wider ones. */
|
|
|
|
if ((j > currslen) && (*mouse_x % i < COLS % i))
|
2007-05-15 18:04:25 +00:00
|
|
|
j -= 2;
|
2014-04-16 08:24:32 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
fprintf(stderr, "Calculated %i as index in shortcut list, currmenu = %x.\n", j, currmenu);
|
|
|
|
#endif
|
2007-05-29 17:01:12 +00:00
|
|
|
/* Ignore releases/clicks of the first mouse button beyond
|
|
|
|
* the last shortcut. */
|
2014-05-09 11:44:17 +00:00
|
|
|
if (j > currslen)
|
2007-05-20 23:41:56 +00:00
|
|
|
return 2;
|
2007-05-15 18:04:25 +00:00
|
|
|
|
2014-04-16 08:24:32 +00:00
|
|
|
/* Go through the list of functions to determine which
|
|
|
|
* shortcut in the current menu we released/clicked on. */
|
2014-05-09 11:44:17 +00:00
|
|
|
for (f = allfuncs; f != NULL; f = f->next) {
|
2014-06-27 20:01:27 +00:00
|
|
|
if ((f->menus & currmenu) == 0)
|
2014-05-09 11:44:17 +00:00
|
|
|
continue;
|
2008-08-30 21:00:00 +00:00
|
|
|
#ifndef DISABLE_HELP
|
2014-05-09 11:44:17 +00:00
|
|
|
if (!f->help || strlen(f->help) == 0)
|
|
|
|
continue;
|
2008-08-30 21:00:00 +00:00
|
|
|
#endif
|
2014-05-09 11:44:17 +00:00
|
|
|
if (first_sc_for(currmenu, f->scfunc) == NULL)
|
2014-06-27 20:01:27 +00:00
|
|
|
continue;
|
2014-05-09 11:44:17 +00:00
|
|
|
/* Tick off an actually shown shortcut. */
|
|
|
|
j -= 1;
|
2014-04-16 08:24:32 +00:00
|
|
|
if (j == 0)
|
|
|
|
break;
|
2008-03-11 04:52:57 +00:00
|
|
|
}
|
2014-04-16 08:24:32 +00:00
|
|
|
#ifdef DEBUG
|
2014-04-21 13:07:18 +00:00
|
|
|
fprintf(stderr, "Stopped on func %ld present in menus %x\n", (long)f->scfunc, f->menus);
|
2014-04-16 08:24:32 +00:00
|
|
|
#endif
|
2008-03-11 04:52:57 +00:00
|
|
|
|
2014-04-16 08:24:32 +00:00
|
|
|
/* And put the corresponding key into the keyboard buffer. */
|
2008-03-05 07:34:01 +00:00
|
|
|
if (f != NULL) {
|
2014-06-27 20:01:27 +00:00
|
|
|
const sc *s = first_sc_for(currmenu, f->scfunc);
|
2014-06-11 19:24:38 +00:00
|
|
|
unget_kbinput(s->seq, s->type == META, s->type == FKEY);
|
2007-05-15 18:04:25 +00:00
|
|
|
}
|
2014-06-11 18:04:36 +00:00
|
|
|
return 1;
|
2007-05-15 18:04:25 +00:00
|
|
|
} else
|
2007-05-29 17:01:12 +00:00
|
|
|
/* Handle releases/clicks of the first mouse button that
|
|
|
|
* aren't on the current shortcut list elsewhere. */
|
2007-05-20 23:41:56 +00:00
|
|
|
return 0;
|
2003-11-28 19:47:42 +00:00
|
|
|
}
|
2007-05-15 18:04:25 +00:00
|
|
|
#if NCURSES_MOUSE_VERSION >= 2
|
|
|
|
/* Handle presses of the fourth mouse button (upward rolls of the
|
2007-05-20 23:41:56 +00:00
|
|
|
* mouse wheel) and presses of the fifth mouse button (downward
|
|
|
|
* rolls of the mouse wheel) . */
|
|
|
|
else if (mevent.bstate & (BUTTON4_PRESSED | BUTTON5_PRESSED)) {
|
2007-12-08 16:59:13 +00:00
|
|
|
bool in_edit = wenclose(edit, *mouse_y, *mouse_x);
|
2007-05-20 23:41:56 +00:00
|
|
|
|
2007-12-08 04:21:15 +00:00
|
|
|
if (in_bottomwin)
|
|
|
|
/* Translate the mouse event coordinates so that they're
|
|
|
|
* relative to bottomwin. */
|
|
|
|
wmouse_trafo(bottomwin, mouse_y, mouse_x, FALSE);
|
2007-05-22 17:20:28 +00:00
|
|
|
|
2007-12-08 04:21:15 +00:00
|
|
|
if (in_edit || (in_bottomwin && *mouse_y == 0)) {
|
2007-12-08 16:59:13 +00:00
|
|
|
int i;
|
|
|
|
|
2007-05-20 23:41:56 +00:00
|
|
|
/* One upward roll of the mouse wheel is equivalent to
|
|
|
|
* moving up three lines, and one downward roll of the mouse
|
|
|
|
* wheel is equivalent to moving down three lines. */
|
|
|
|
for (i = 0; i < 3; i++)
|
|
|
|
unget_kbinput((mevent.bstate & BUTTON4_PRESSED) ?
|
2014-06-10 19:12:14 +00:00
|
|
|
sc_seq_or(do_up_void, 0) : sc_seq_or(do_down_void, 0),
|
2014-02-22 19:36:35 +00:00
|
|
|
FALSE, FALSE);
|
2007-05-20 23:41:56 +00:00
|
|
|
|
|
|
|
return 1;
|
|
|
|
} else
|
|
|
|
/* Ignore presses of the fourth mouse button and presses of
|
|
|
|
* the fifth mouse buttons that aren't on the edit window or
|
|
|
|
* the statusbar. */
|
|
|
|
return 2;
|
2007-05-15 18:04:25 +00:00
|
|
|
}
|
|
|
|
#endif
|
2007-06-28 16:38:00 +00:00
|
|
|
|
|
|
|
/* Ignore all other mouse events. */
|
|
|
|
return 2;
|
2003-11-28 19:47:42 +00:00
|
|
|
}
|
2004-08-25 15:39:10 +00:00
|
|
|
#endif /* !DISABLE_MOUSE */
|
|
|
|
|
2014-04-14 09:22:29 +00:00
|
|
|
/* Return the shortcut that corresponds to the values of kbinput (the
|
|
|
|
* key itself) and meta_key (whether the key is a meta sequence). The
|
|
|
|
* returned shortcut will be the first in the list that corresponds to
|
|
|
|
* the given sequence. */
|
2014-07-01 10:41:10 +00:00
|
|
|
const sc *get_shortcut(int *kbinput)
|
2004-08-25 15:39:10 +00:00
|
|
|
{
|
2008-03-05 07:34:01 +00:00
|
|
|
sc *s;
|
2004-08-25 15:39:10 +00:00
|
|
|
|
2004-11-27 06:43:06 +00:00
|
|
|
#ifdef DEBUG
|
2014-06-30 18:04:33 +00:00
|
|
|
fprintf(stderr, "get_shortcut(): kbinput = %d, meta_key = %s -- ", *kbinput, meta_key ? "TRUE" : "FALSE");
|
2004-11-27 06:43:06 +00:00
|
|
|
#endif
|
|
|
|
|
2008-03-05 07:34:01 +00:00
|
|
|
for (s = sclist; s != NULL; s = s->next) {
|
2015-07-15 20:13:05 +00:00
|
|
|
if ((s->menus & currmenu) && *kbinput == s->seq
|
2014-06-30 18:04:33 +00:00
|
|
|
&& meta_key == (s->type == META)) {
|
2008-03-05 07:34:01 +00:00
|
|
|
#ifdef DEBUG
|
2014-04-14 09:22:29 +00:00
|
|
|
fprintf (stderr, "matched seq \"%s\", and btw meta was %d (menu is %x from %x)\n",
|
2015-07-15 20:13:05 +00:00
|
|
|
s->keystr, meta_key, currmenu, s->menus);
|
2008-03-05 07:34:01 +00:00
|
|
|
#endif
|
2005-01-08 06:16:19 +00:00
|
|
|
return s;
|
2004-08-25 15:39:10 +00:00
|
|
|
}
|
|
|
|
}
|
2008-03-05 07:34:01 +00:00
|
|
|
#ifdef DEBUG
|
2014-06-30 18:04:33 +00:00
|
|
|
fprintf (stderr, "matched nothing, btw meta was %d\n", meta_key);
|
2008-03-05 07:34:01 +00:00
|
|
|
#endif
|
2004-08-25 15:39:10 +00:00
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2005-07-10 02:37:38 +00:00
|
|
|
/* Move to (x, y) in win, and display a line of n spaces with the
|
|
|
|
* current attributes. */
|
|
|
|
void blank_line(WINDOW *win, int y, int x, int n)
|
|
|
|
{
|
|
|
|
wmove(win, y, x);
|
2007-04-19 03:15:04 +00:00
|
|
|
|
2005-07-10 02:37:38 +00:00
|
|
|
for (; n > 0; n--)
|
|
|
|
waddch(win, ' ');
|
|
|
|
}
|
|
|
|
|
2005-12-08 07:09:08 +00:00
|
|
|
/* Blank the first line of the top portion of the window. */
|
2004-05-18 01:20:36 +00:00
|
|
|
void blank_titlebar(void)
|
2000-06-06 05:53:49 +00:00
|
|
|
{
|
2005-07-10 02:37:38 +00:00
|
|
|
blank_line(topwin, 0, 0, COLS);
|
2002-09-06 20:35:28 +00:00
|
|
|
}
|
|
|
|
|
2005-12-08 07:09:08 +00:00
|
|
|
/* If the MORE_SPACE flag isn't set, blank the second line of the top
|
|
|
|
* portion of the window. */
|
2005-01-17 05:06:55 +00:00
|
|
|
void blank_topbar(void)
|
|
|
|
{
|
|
|
|
if (!ISSET(MORE_SPACE))
|
2005-07-10 02:37:38 +00:00
|
|
|
blank_line(topwin, 1, 0, COLS);
|
2005-01-17 05:06:55 +00:00
|
|
|
}
|
|
|
|
|
2006-07-28 17:06:27 +00:00
|
|
|
/* Blank all the lines of the middle portion of the window, i.e. the
|
2005-12-08 07:09:08 +00:00
|
|
|
* edit window. */
|
2000-06-06 05:53:49 +00:00
|
|
|
void blank_edit(void)
|
|
|
|
{
|
2004-07-28 20:46:25 +00:00
|
|
|
int i;
|
2007-04-19 03:15:04 +00:00
|
|
|
|
2003-09-29 05:15:24 +00:00
|
|
|
for (i = 0; i < editwinrows; i++)
|
2005-07-10 02:37:38 +00:00
|
|
|
blank_line(edit, i, 0, COLS);
|
2000-06-06 05:53:49 +00:00
|
|
|
}
|
|
|
|
|
2005-12-08 07:09:08 +00:00
|
|
|
/* Blank the first line of the bottom portion of the window. */
|
2000-06-06 05:53:49 +00:00
|
|
|
void blank_statusbar(void)
|
|
|
|
{
|
2005-07-10 02:37:38 +00:00
|
|
|
blank_line(bottomwin, 0, 0, COLS);
|
2000-06-06 05:53:49 +00:00
|
|
|
}
|
|
|
|
|
2005-12-08 07:09:08 +00:00
|
|
|
/* If the NO_HELP flag isn't set, blank the last two lines of the bottom
|
|
|
|
* portion of the window. */
|
2005-03-17 17:56:48 +00:00
|
|
|
void blank_bottombars(void)
|
|
|
|
{
|
|
|
|
if (!ISSET(NO_HELP)) {
|
2005-07-10 02:37:38 +00:00
|
|
|
blank_line(bottomwin, 1, 0, COLS);
|
|
|
|
blank_line(bottomwin, 2, 0, COLS);
|
2005-03-17 17:56:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-12-08 07:09:08 +00:00
|
|
|
/* Check if the number of keystrokes needed to blank the statusbar has
|
|
|
|
* been pressed. If so, blank the statusbar, unless constant cursor
|
|
|
|
* position display is on. */
|
2004-09-30 22:07:21 +00:00
|
|
|
void check_statusblank(void)
|
2000-06-06 05:53:49 +00:00
|
|
|
{
|
2006-05-27 18:06:11 +00:00
|
|
|
if (statusblank > 0) {
|
2004-09-30 22:07:21 +00:00
|
|
|
statusblank--;
|
2005-06-17 21:52:59 +00:00
|
|
|
|
2006-05-27 18:06:11 +00:00
|
|
|
if (statusblank == 0 && !ISSET(CONST_UPDATE)) {
|
|
|
|
blank_statusbar();
|
|
|
|
wnoutrefresh(bottomwin);
|
|
|
|
reset_cursor();
|
|
|
|
wnoutrefresh(edit);
|
|
|
|
}
|
2000-06-06 05:53:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-09-16 01:16:49 +00:00
|
|
|
/* Convert buf into a string that can be displayed on screen. The
|
|
|
|
* caller wants to display buf starting with column start_col, and
|
|
|
|
* extending for at most len columns. start_col is zero-based. len is
|
|
|
|
* one-based, so len == 0 means you get "" returned. The returned
|
2004-12-23 17:43:27 +00:00
|
|
|
* string is dynamically allocated, and should be freed. If dollars is
|
|
|
|
* TRUE, the caller might put "$" at the beginning or end of the line if
|
|
|
|
* it's too long. */
|
|
|
|
char *display_string(const char *buf, size_t start_col, size_t len, bool
|
|
|
|
dollars)
|
2003-09-16 01:16:49 +00:00
|
|
|
{
|
|
|
|
size_t start_index;
|
2004-12-24 15:45:36 +00:00
|
|
|
/* Index in buf of the first character shown. */
|
2003-09-16 01:16:49 +00:00
|
|
|
size_t column;
|
2004-12-24 15:45:36 +00:00
|
|
|
/* Screen column that start_index corresponds to. */
|
2003-09-16 01:16:49 +00:00
|
|
|
size_t alloc_len;
|
|
|
|
/* The length of memory allocated for converted. */
|
|
|
|
char *converted;
|
|
|
|
/* The string we return. */
|
|
|
|
size_t index;
|
|
|
|
/* Current position in converted. */
|
2006-02-03 03:51:51 +00:00
|
|
|
char *buf_mb;
|
2005-01-12 03:25:57 +00:00
|
|
|
int buf_mb_len;
|
|
|
|
|
2005-01-05 06:09:34 +00:00
|
|
|
/* If dollars is TRUE, make room for the "$" at the end of the
|
|
|
|
* line. */
|
|
|
|
if (dollars && len > 0 && strlenpt(buf) > start_col + len)
|
|
|
|
len--;
|
|
|
|
|
2003-09-16 01:16:49 +00:00
|
|
|
if (len == 0)
|
|
|
|
return mallocstrcpy(NULL, "");
|
|
|
|
|
2006-02-03 03:51:51 +00:00
|
|
|
buf_mb = charalloc(mb_cur_max());
|
|
|
|
|
2003-09-16 01:16:49 +00:00
|
|
|
start_index = actual_x(buf, start_col);
|
|
|
|
column = strnlenpt(buf, start_index);
|
2004-12-23 17:43:27 +00:00
|
|
|
|
2003-09-16 01:16:49 +00:00
|
|
|
assert(column <= start_col);
|
2004-12-23 17:43:27 +00:00
|
|
|
|
2006-02-03 03:58:49 +00:00
|
|
|
/* Make sure there's enough room for the initial character, whether
|
|
|
|
* it's a multibyte control character, a non-control multibyte
|
|
|
|
* character, a tab character, or a null terminator. Rationale:
|
|
|
|
*
|
|
|
|
* multibyte control character followed by a null terminator:
|
|
|
|
* 1 byte ('^') + mb_cur_max() bytes + 1 byte ('\0')
|
|
|
|
* multibyte non-control character followed by a null terminator:
|
|
|
|
* mb_cur_max() bytes + 1 byte ('\0')
|
|
|
|
* tab character followed by a null terminator:
|
|
|
|
* mb_cur_max() bytes + (tabsize - 1) bytes + 1 byte ('\0')
|
|
|
|
*
|
|
|
|
* Since tabsize has a minimum value of 1, it can substitute for 1
|
|
|
|
* byte above. */
|
|
|
|
alloc_len = (mb_cur_max() + tabsize + 1) * MAX_BUF_SIZE;
|
|
|
|
converted = charalloc(alloc_len);
|
2005-01-05 16:59:49 +00:00
|
|
|
|
2003-09-16 01:16:49 +00:00
|
|
|
index = 0;
|
|
|
|
|
2006-07-05 05:31:21 +00:00
|
|
|
if (buf[start_index] != '\0' && buf[start_index] != '\t' &&
|
|
|
|
(column < start_col || (dollars && column > 0))) {
|
2004-12-23 17:43:27 +00:00
|
|
|
/* We don't display all of buf[start_index] since it starts to
|
|
|
|
* the left of the screen. */
|
2005-07-26 06:13:45 +00:00
|
|
|
buf_mb_len = parse_mbchar(buf + start_index, buf_mb, NULL);
|
2004-12-23 17:43:27 +00:00
|
|
|
|
2005-01-12 03:25:57 +00:00
|
|
|
if (is_cntrl_mbchar(buf_mb)) {
|
2004-12-24 17:52:17 +00:00
|
|
|
if (column < start_col) {
|
2005-01-12 03:25:57 +00:00
|
|
|
char *ctrl_buf_mb = charalloc(mb_cur_max());
|
|
|
|
int ctrl_buf_mb_len, i;
|
2004-12-23 17:43:27 +00:00
|
|
|
|
2005-01-12 03:25:57 +00:00
|
|
|
ctrl_buf_mb = control_mbrep(buf_mb, ctrl_buf_mb,
|
|
|
|
&ctrl_buf_mb_len);
|
2004-12-27 23:11:59 +00:00
|
|
|
|
2005-01-12 03:25:57 +00:00
|
|
|
for (i = 0; i < ctrl_buf_mb_len; i++)
|
|
|
|
converted[index++] = ctrl_buf_mb[i];
|
2004-12-23 17:43:27 +00:00
|
|
|
|
2005-01-12 03:25:57 +00:00
|
|
|
start_col += mbwidth(ctrl_buf_mb);
|
2004-12-27 23:35:25 +00:00
|
|
|
|
2005-01-12 03:25:57 +00:00
|
|
|
free(ctrl_buf_mb);
|
2005-01-03 06:56:38 +00:00
|
|
|
|
2005-01-12 03:25:57 +00:00
|
|
|
start_index += buf_mb_len;
|
2004-12-23 17:43:27 +00:00
|
|
|
}
|
2005-01-03 06:56:38 +00:00
|
|
|
}
|
2005-07-17 02:40:07 +00:00
|
|
|
#ifdef ENABLE_UTF8
|
2006-05-19 17:50:01 +00:00
|
|
|
else if (using_utf8() && mbwidth(buf_mb) == 2) {
|
|
|
|
if (column >= start_col) {
|
|
|
|
converted[index++] = ' ';
|
|
|
|
start_col++;
|
|
|
|
}
|
|
|
|
|
2005-01-05 06:09:34 +00:00
|
|
|
converted[index++] = ' ';
|
2004-12-27 23:35:25 +00:00
|
|
|
start_col++;
|
2005-01-12 03:25:57 +00:00
|
|
|
|
|
|
|
start_index += buf_mb_len;
|
2004-12-23 17:43:27 +00:00
|
|
|
}
|
2005-01-03 06:56:38 +00:00
|
|
|
#endif
|
2004-12-23 17:43:27 +00:00
|
|
|
}
|
|
|
|
|
2006-02-03 03:58:49 +00:00
|
|
|
while (buf[start_index] != '\0') {
|
2005-07-26 06:13:45 +00:00
|
|
|
buf_mb_len = parse_mbchar(buf + start_index, buf_mb, NULL);
|
2004-12-23 17:43:27 +00:00
|
|
|
|
2006-02-03 03:58:49 +00:00
|
|
|
/* Make sure there's enough room for the next character, whether
|
|
|
|
* it's a multibyte control character, a non-control multibyte
|
|
|
|
* character, a tab character, or a null terminator. */
|
|
|
|
if (index + mb_cur_max() + tabsize + 1 >= alloc_len - 1) {
|
|
|
|
alloc_len += (mb_cur_max() + tabsize + 1) * MAX_BUF_SIZE;
|
|
|
|
converted = charealloc(converted, alloc_len);
|
|
|
|
}
|
|
|
|
|
2005-07-06 19:12:41 +00:00
|
|
|
/* If buf contains a tab character, interpret it. */
|
2005-01-12 03:25:57 +00:00
|
|
|
if (*buf_mb == '\t') {
|
2014-04-13 20:50:20 +00:00
|
|
|
#if !defined(NANO_TINY) && !defined(DISABLE_NANORC)
|
2005-03-10 22:52:21 +00:00
|
|
|
if (ISSET(WHITESPACE_DISPLAY)) {
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < whitespace_len[0]; i++)
|
|
|
|
converted[index++] = whitespace[i];
|
|
|
|
} else
|
2004-05-29 16:25:30 +00:00
|
|
|
#endif
|
2007-04-19 03:15:04 +00:00
|
|
|
converted[index++] = ' ';
|
2004-12-23 17:43:27 +00:00
|
|
|
start_col++;
|
2004-12-27 23:21:34 +00:00
|
|
|
while (start_col % tabsize != 0) {
|
2003-09-16 01:16:49 +00:00
|
|
|
converted[index++] = ' ';
|
2004-12-23 17:43:27 +00:00
|
|
|
start_col++;
|
|
|
|
}
|
2015-04-18 20:07:31 +00:00
|
|
|
/* If buf contains a control character, interpret it. */
|
2005-01-12 03:25:57 +00:00
|
|
|
} else if (is_cntrl_mbchar(buf_mb)) {
|
2005-07-18 03:23:37 +00:00
|
|
|
char *ctrl_buf_mb = charalloc(mb_cur_max());
|
|
|
|
int ctrl_buf_mb_len, i;
|
2004-12-23 17:43:27 +00:00
|
|
|
|
2003-09-16 01:16:49 +00:00
|
|
|
converted[index++] = '^';
|
2004-12-23 17:43:27 +00:00
|
|
|
start_col++;
|
|
|
|
|
2005-07-18 03:23:37 +00:00
|
|
|
ctrl_buf_mb = control_mbrep(buf_mb, ctrl_buf_mb,
|
|
|
|
&ctrl_buf_mb_len);
|
2004-12-23 17:43:27 +00:00
|
|
|
|
2005-07-18 03:23:37 +00:00
|
|
|
for (i = 0; i < ctrl_buf_mb_len; i++)
|
|
|
|
converted[index++] = ctrl_buf_mb[i];
|
2004-12-23 17:43:27 +00:00
|
|
|
|
2005-07-18 03:23:37 +00:00
|
|
|
start_col += mbwidth(ctrl_buf_mb);
|
2004-12-23 17:43:27 +00:00
|
|
|
|
2005-07-18 03:23:37 +00:00
|
|
|
free(ctrl_buf_mb);
|
2005-07-06 19:12:41 +00:00
|
|
|
/* If buf contains a space character, interpret it. */
|
2005-01-12 03:25:57 +00:00
|
|
|
} else if (*buf_mb == ' ') {
|
2014-04-13 20:50:20 +00:00
|
|
|
#if !defined(NANO_TINY) && !defined(DISABLE_NANORC)
|
2005-03-10 22:52:21 +00:00
|
|
|
if (ISSET(WHITESPACE_DISPLAY)) {
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = whitespace_len[0]; i < whitespace_len[0] +
|
|
|
|
whitespace_len[1]; i++)
|
|
|
|
converted[index++] = whitespace[i];
|
|
|
|
} else
|
2004-05-29 16:25:30 +00:00
|
|
|
#endif
|
2007-04-19 03:15:04 +00:00
|
|
|
converted[index++] = ' ';
|
2004-12-23 17:43:27 +00:00
|
|
|
start_col++;
|
2015-04-18 20:07:31 +00:00
|
|
|
/* If buf contains a non-control character, interpret it. If buf
|
|
|
|
* contains an invalid multibyte sequence, display it as such. */
|
2004-12-23 17:43:27 +00:00
|
|
|
} else {
|
2005-07-26 06:13:45 +00:00
|
|
|
char *nctrl_buf_mb = charalloc(mb_cur_max());
|
|
|
|
int nctrl_buf_mb_len, i;
|
2004-12-23 17:43:27 +00:00
|
|
|
|
2015-04-18 20:07:31 +00:00
|
|
|
/* Make sure an invalid sequence-starter byte is properly
|
|
|
|
* terminated, so that it doesn't pick up lingering bytes
|
|
|
|
* of any previous content. */
|
|
|
|
null_at(&buf_mb, buf_mb_len);
|
|
|
|
|
2005-07-26 06:13:45 +00:00
|
|
|
nctrl_buf_mb = mbrep(buf_mb, nctrl_buf_mb,
|
|
|
|
&nctrl_buf_mb_len);
|
2005-01-12 03:25:57 +00:00
|
|
|
|
2005-07-26 06:13:45 +00:00
|
|
|
for (i = 0; i < nctrl_buf_mb_len; i++)
|
|
|
|
converted[index++] = nctrl_buf_mb[i];
|
|
|
|
|
|
|
|
start_col += mbwidth(nctrl_buf_mb);
|
|
|
|
|
|
|
|
free(nctrl_buf_mb);
|
2004-12-23 17:43:27 +00:00
|
|
|
}
|
|
|
|
|
2005-01-12 03:25:57 +00:00
|
|
|
start_index += buf_mb_len;
|
2003-09-16 01:16:49 +00:00
|
|
|
}
|
|
|
|
|
2005-06-13 14:00:22 +00:00
|
|
|
free(buf_mb);
|
|
|
|
|
2006-02-03 03:58:49 +00:00
|
|
|
assert(alloc_len >= index + 1);
|
|
|
|
|
2006-10-29 21:14:53 +00:00
|
|
|
/* Null-terminate converted. */
|
2006-02-03 03:58:49 +00:00
|
|
|
converted[index] = '\0';
|
2005-01-05 19:05:04 +00:00
|
|
|
|
|
|
|
/* Make sure converted takes up no more than len columns. */
|
|
|
|
index = actual_x(converted, len);
|
2004-12-23 17:43:27 +00:00
|
|
|
null_at(&converted, index);
|
2005-01-05 19:05:04 +00:00
|
|
|
|
2004-12-23 17:43:27 +00:00
|
|
|
return converted;
|
2003-09-16 01:16:49 +00:00
|
|
|
}
|
|
|
|
|
2006-07-09 00:52:16 +00:00
|
|
|
/* If path is NULL, we're in normal editing mode, so display the current
|
|
|
|
* version of nano, the current filename, and whether the current file
|
|
|
|
* has been modified on the titlebar. If path isn't NULL, we're in the
|
|
|
|
* file browser, and path contains the directory to start the file
|
|
|
|
* browser in, so display the current version of nano and the contents
|
|
|
|
* of path on the titlebar. */
|
2003-02-13 22:25:01 +00:00
|
|
|
void titlebar(const char *path)
|
2000-06-06 05:53:49 +00:00
|
|
|
{
|
2005-07-10 23:45:23 +00:00
|
|
|
int space = COLS;
|
2004-05-23 21:11:14 +00:00
|
|
|
/* The space we have available for display. */
|
2006-03-30 01:18:29 +00:00
|
|
|
size_t verlen = strlenpt(PACKAGE_STRING) + 1;
|
2005-07-10 23:45:23 +00:00
|
|
|
/* The length of the version message in columns, plus one for
|
|
|
|
* padding. */
|
2004-05-23 21:11:14 +00:00
|
|
|
const char *prefix;
|
2005-07-10 02:37:38 +00:00
|
|
|
/* "DIR:", "File:", or "New Buffer". Goes before filename. */
|
2004-05-23 21:11:14 +00:00
|
|
|
size_t prefixlen;
|
2005-07-10 23:45:23 +00:00
|
|
|
/* The length of the prefix in columns, plus one for padding. */
|
2004-05-23 21:11:14 +00:00
|
|
|
const char *state;
|
2005-07-10 02:37:38 +00:00
|
|
|
/* "Modified", "View", or "". Shows the state of this
|
|
|
|
* buffer. */
|
2004-05-23 21:11:14 +00:00
|
|
|
size_t statelen = 0;
|
2005-07-10 02:37:38 +00:00
|
|
|
/* The length of the state in columns, or the length of
|
2006-07-09 00:52:16 +00:00
|
|
|
* "Modified" if the state is blank and we're not in the file
|
|
|
|
* browser. */
|
2004-05-23 21:11:14 +00:00
|
|
|
char *exppath = NULL;
|
2006-07-04 03:47:36 +00:00
|
|
|
/* The filename, expanded for display. */
|
2004-12-05 05:42:46 +00:00
|
|
|
bool newfie = FALSE;
|
2004-05-23 21:11:14 +00:00
|
|
|
/* Do we say "New Buffer"? */
|
2004-12-05 05:42:46 +00:00
|
|
|
bool dots = FALSE;
|
2004-05-23 21:11:14 +00:00
|
|
|
/* Do we put an ellipsis before the path? */
|
|
|
|
|
2005-07-08 20:09:16 +00:00
|
|
|
assert(path != NULL || openfile->filename != NULL);
|
2000-06-06 05:53:49 +00:00
|
|
|
|
2014-05-10 19:15:04 +00:00
|
|
|
if (interface_color_pair[TITLE_BAR].bright)
|
|
|
|
wattron(topwin, A_BOLD);
|
|
|
|
wattron(topwin, interface_color_pair[TITLE_BAR].pairnum);
|
2006-07-02 18:29:49 +00:00
|
|
|
|
2004-05-18 01:20:36 +00:00
|
|
|
blank_titlebar();
|
2000-06-06 05:53:49 +00:00
|
|
|
|
2005-07-10 23:45:23 +00:00
|
|
|
/* space has to be at least 4: two spaces before the version message,
|
|
|
|
* at least one character of the version message, and one space
|
|
|
|
* after the version message. */
|
|
|
|
if (space < 4)
|
2004-05-23 21:11:14 +00:00
|
|
|
space = 0;
|
|
|
|
else {
|
2005-07-10 23:45:23 +00:00
|
|
|
/* Limit verlen to 1/3 the length of the screen in columns,
|
|
|
|
* minus three columns for spaces. */
|
|
|
|
if (verlen > (COLS / 3) - 3)
|
|
|
|
verlen = (COLS / 3) - 3;
|
2004-05-23 21:11:14 +00:00
|
|
|
}
|
2000-06-06 05:53:49 +00:00
|
|
|
|
2005-07-10 23:45:23 +00:00
|
|
|
if (space >= 4) {
|
2005-07-11 07:12:33 +00:00
|
|
|
/* Add a space after the version message, and account for both
|
|
|
|
* it and the two spaces before it. */
|
2006-03-30 01:18:29 +00:00
|
|
|
mvwaddnstr(topwin, 0, 2, PACKAGE_STRING,
|
|
|
|
actual_x(PACKAGE_STRING, verlen));
|
2005-07-10 23:45:23 +00:00
|
|
|
verlen += 3;
|
|
|
|
|
|
|
|
/* Account for the full length of the version message. */
|
|
|
|
space -= verlen;
|
2004-05-23 21:11:14 +00:00
|
|
|
}
|
2000-06-06 05:53:49 +00:00
|
|
|
|
2005-07-10 02:37:38 +00:00
|
|
|
#ifndef DISABLE_BROWSER
|
|
|
|
/* Don't display the state if we're in the file browser. */
|
|
|
|
if (path != NULL)
|
|
|
|
state = "";
|
|
|
|
else
|
|
|
|
#endif
|
|
|
|
state = openfile->modified ? _("Modified") : ISSET(VIEW_MODE) ?
|
|
|
|
_("View") : "";
|
|
|
|
|
2007-07-01 21:33:17 +00:00
|
|
|
statelen = strlenpt((*state == '\0' && path == NULL) ?
|
2006-07-09 00:50:23 +00:00
|
|
|
_("Modified") : state);
|
2005-03-25 05:00:32 +00:00
|
|
|
|
2005-07-10 23:45:23 +00:00
|
|
|
/* If possible, add a space before state. */
|
|
|
|
if (space > 0 && statelen < space)
|
2004-05-23 21:11:14 +00:00
|
|
|
statelen++;
|
2005-07-10 23:45:23 +00:00
|
|
|
else
|
2004-05-23 21:11:14 +00:00
|
|
|
goto the_end;
|
|
|
|
|
|
|
|
#ifndef DISABLE_BROWSER
|
2005-07-10 02:37:38 +00:00
|
|
|
/* path should be a directory if we're in the file browser. */
|
2004-05-23 21:11:14 +00:00
|
|
|
if (path != NULL)
|
|
|
|
prefix = _("DIR:");
|
|
|
|
else
|
|
|
|
#endif
|
2005-07-08 20:09:16 +00:00
|
|
|
if (openfile->filename[0] == '\0') {
|
2004-05-23 21:11:14 +00:00
|
|
|
prefix = _("New Buffer");
|
2004-12-05 05:42:46 +00:00
|
|
|
newfie = TRUE;
|
2004-05-23 21:11:14 +00:00
|
|
|
} else
|
|
|
|
prefix = _("File:");
|
2005-03-24 22:28:25 +00:00
|
|
|
|
2005-07-10 23:45:23 +00:00
|
|
|
prefixlen = strnlenpt(prefix, space - statelen) + 1;
|
2005-03-25 05:00:32 +00:00
|
|
|
|
2005-07-10 23:45:23 +00:00
|
|
|
/* If newfie is FALSE, add a space after prefix. */
|
2004-12-05 05:42:46 +00:00
|
|
|
if (!newfie && prefixlen + statelen < space)
|
2004-05-23 21:11:14 +00:00
|
|
|
prefixlen++;
|
|
|
|
|
2006-07-09 00:52:16 +00:00
|
|
|
/* If we're not in the file browser, set path to the current
|
2005-07-10 02:37:38 +00:00
|
|
|
* filename. */
|
2004-05-23 21:11:14 +00:00
|
|
|
if (path == NULL)
|
2005-07-08 20:09:16 +00:00
|
|
|
path = openfile->filename;
|
2005-07-10 02:37:38 +00:00
|
|
|
|
2005-07-10 23:45:23 +00:00
|
|
|
/* Account for the full lengths of the prefix and the state. */
|
2004-12-05 05:42:46 +00:00
|
|
|
if (space >= prefixlen + statelen)
|
|
|
|
space -= prefixlen + statelen;
|
|
|
|
else
|
|
|
|
space = 0;
|
2005-07-10 23:45:23 +00:00
|
|
|
/* space is now the room we have for the filename. */
|
2005-03-25 05:00:32 +00:00
|
|
|
|
2004-12-05 05:42:46 +00:00
|
|
|
if (!newfie) {
|
2005-07-10 23:45:23 +00:00
|
|
|
size_t lenpt = strlenpt(path), start_col;
|
2004-05-23 21:11:14 +00:00
|
|
|
|
2006-11-25 22:27:22 +00:00
|
|
|
/* Don't set dots to TRUE if we have fewer than eight columns
|
|
|
|
* (i.e. one column for padding, plus seven columns for a
|
|
|
|
* filename). */
|
2006-07-13 02:10:27 +00:00
|
|
|
dots = (space >= 8 && lenpt >= space);
|
2004-12-23 17:43:27 +00:00
|
|
|
|
|
|
|
if (dots) {
|
|
|
|
start_col = lenpt - space + 3;
|
|
|
|
space -= 3;
|
|
|
|
} else
|
|
|
|
start_col = 0;
|
|
|
|
|
|
|
|
exppath = display_string(path, start_col, space, FALSE);
|
2004-05-23 21:11:14 +00:00
|
|
|
}
|
|
|
|
|
2006-07-02 18:29:49 +00:00
|
|
|
/* If dots is TRUE, we will display something like "File:
|
|
|
|
* ...ename". */
|
|
|
|
if (dots) {
|
|
|
|
mvwaddnstr(topwin, 0, verlen - 1, prefix, actual_x(prefix,
|
|
|
|
prefixlen));
|
|
|
|
if (space <= -3 || newfie)
|
|
|
|
goto the_end;
|
|
|
|
waddch(topwin, ' ');
|
|
|
|
waddnstr(topwin, "...", space + 3);
|
|
|
|
if (space <= 0)
|
|
|
|
goto the_end;
|
|
|
|
waddstr(topwin, exppath);
|
|
|
|
} else {
|
2004-12-23 17:43:27 +00:00
|
|
|
size_t exppathlen = newfie ? 0 : strlenpt(exppath);
|
|
|
|
/* The length of the expanded filename. */
|
|
|
|
|
2004-05-23 21:11:14 +00:00
|
|
|
/* There is room for the whole filename, so we center it. */
|
2005-07-10 23:45:23 +00:00
|
|
|
mvwaddnstr(topwin, 0, verlen + ((space - exppathlen) / 3),
|
|
|
|
prefix, actual_x(prefix, prefixlen));
|
2004-12-05 05:42:46 +00:00
|
|
|
if (!newfie) {
|
2004-05-23 21:11:14 +00:00
|
|
|
waddch(topwin, ' ');
|
|
|
|
waddstr(topwin, exppath);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
the_end:
|
|
|
|
free(exppath);
|
|
|
|
|
2005-07-10 02:37:38 +00:00
|
|
|
if (state[0] != '\0') {
|
2005-10-26 23:14:59 +00:00
|
|
|
if (statelen >= COLS - 1)
|
2005-07-10 02:37:38 +00:00
|
|
|
mvwaddnstr(topwin, 0, 0, state, actual_x(state, COLS));
|
|
|
|
else {
|
2005-07-10 23:57:32 +00:00
|
|
|
assert(COLS - statelen - 1 >= 0);
|
2005-03-24 22:28:25 +00:00
|
|
|
|
2005-07-10 02:37:38 +00:00
|
|
|
mvwaddnstr(topwin, 0, COLS - statelen - 1, state,
|
2005-03-25 05:00:32 +00:00
|
|
|
actual_x(state, statelen));
|
2005-07-10 02:37:38 +00:00
|
|
|
}
|
2004-05-23 21:11:14 +00:00
|
|
|
}
|
2001-04-30 11:28:46 +00:00
|
|
|
|
2014-05-10 19:15:04 +00:00
|
|
|
wattroff(topwin, A_BOLD);
|
|
|
|
wattroff(topwin, interface_color_pair[TITLE_BAR].pairnum);
|
2001-04-30 11:28:46 +00:00
|
|
|
|
2004-05-23 21:11:14 +00:00
|
|
|
wnoutrefresh(topwin);
|
2000-06-06 05:53:49 +00:00
|
|
|
reset_cursor();
|
2005-07-26 14:42:57 +00:00
|
|
|
wnoutrefresh(edit);
|
2000-06-06 05:53:49 +00:00
|
|
|
}
|
|
|
|
|
2005-12-08 07:09:08 +00:00
|
|
|
/* Mark the current file as modified if it isn't already, and then
|
|
|
|
* update the titlebar to display the file's new status. */
|
2004-05-18 01:20:36 +00:00
|
|
|
void set_modified(void)
|
|
|
|
{
|
2005-07-08 20:09:16 +00:00
|
|
|
if (!openfile->modified) {
|
|
|
|
openfile->modified = TRUE;
|
2004-05-18 01:20:36 +00:00
|
|
|
titlebar(NULL);
|
2013-01-03 03:07:27 +00:00
|
|
|
#ifndef NANO_TINY
|
2013-01-03 03:36:20 +00:00
|
|
|
if (ISSET(LOCKING)) {
|
2014-06-09 14:33:00 +00:00
|
|
|
if (openfile->filename[0] == '\0')
|
2014-01-26 04:09:04 +00:00
|
|
|
return;
|
|
|
|
else if (openfile->lock_filename == NULL) {
|
2014-06-27 20:01:27 +00:00
|
|
|
/* TRANSLATORS: Try to keep this at most 76 characters. */
|
|
|
|
statusbar(_("Warning: Modifying a file which is not locked, check directory permission?"));
|
2013-01-03 03:36:20 +00:00
|
|
|
} else {
|
|
|
|
write_lockfile(openfile->lock_filename,
|
2014-06-27 20:01:27 +00:00
|
|
|
get_full_path(openfile->filename), TRUE);
|
|
|
|
}
|
2013-01-03 03:36:20 +00:00
|
|
|
}
|
2013-01-03 03:07:27 +00:00
|
|
|
#endif
|
2004-05-18 01:20:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-06-28 19:49:15 +00:00
|
|
|
/* Display a message on the statusbar, and set disable_cursorpos to
|
|
|
|
* TRUE, so that the message won't be immediately overwritten if
|
|
|
|
* constant cursor position display is on. */
|
2004-05-18 01:20:36 +00:00
|
|
|
void statusbar(const char *msg, ...)
|
|
|
|
{
|
|
|
|
va_list ap;
|
2005-10-27 03:35:42 +00:00
|
|
|
char *bar, *foo;
|
2014-05-04 08:25:09 +00:00
|
|
|
size_t start_x;
|
2014-04-13 20:50:20 +00:00
|
|
|
#if !defined(NANO_TINY) && !defined(DISABLE_NANORC)
|
2005-10-27 03:35:42 +00:00
|
|
|
bool old_whitespace;
|
|
|
|
#endif
|
2004-05-18 01:20:36 +00:00
|
|
|
|
|
|
|
va_start(ap, msg);
|
|
|
|
|
|
|
|
/* Curses mode is turned off. If we use wmove() now, it will muck
|
|
|
|
* up the terminal settings. So we just use vfprintf(). */
|
2006-06-03 17:31:52 +00:00
|
|
|
if (isendwin()) {
|
2004-05-18 01:20:36 +00:00
|
|
|
vfprintf(stderr, msg, ap);
|
|
|
|
va_end(ap);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
blank_statusbar();
|
|
|
|
|
2014-04-13 20:50:20 +00:00
|
|
|
#if !defined(NANO_TINY) && !defined(DISABLE_NANORC)
|
2005-10-27 03:35:42 +00:00
|
|
|
old_whitespace = ISSET(WHITESPACE_DISPLAY);
|
|
|
|
UNSET(WHITESPACE_DISPLAY);
|
2004-05-29 16:25:30 +00:00
|
|
|
#endif
|
2005-10-27 03:35:42 +00:00
|
|
|
bar = charalloc(mb_cur_max() * (COLS - 3));
|
|
|
|
vsnprintf(bar, mb_cur_max() * (COLS - 3), msg, ap);
|
|
|
|
va_end(ap);
|
|
|
|
foo = display_string(bar, 0, COLS - 4, FALSE);
|
2014-05-04 08:25:09 +00:00
|
|
|
free(bar);
|
2014-04-13 20:50:20 +00:00
|
|
|
#if !defined(NANO_TINY) && !defined(DISABLE_NANORC)
|
2005-10-27 03:35:42 +00:00
|
|
|
if (old_whitespace)
|
|
|
|
SET(WHITESPACE_DISPLAY);
|
2004-05-29 16:25:30 +00:00
|
|
|
#endif
|
2014-05-04 08:25:09 +00:00
|
|
|
start_x = (COLS - strlenpt(foo) - 4) / 2;
|
2004-05-18 01:20:36 +00:00
|
|
|
|
2005-10-27 03:35:42 +00:00
|
|
|
wmove(bottomwin, 0, start_x);
|
2014-05-10 19:15:04 +00:00
|
|
|
if (interface_color_pair[STATUS_BAR].bright)
|
|
|
|
wattron(bottomwin, A_BOLD);
|
|
|
|
wattron(bottomwin, interface_color_pair[STATUS_BAR].pairnum);
|
2005-10-27 03:35:42 +00:00
|
|
|
waddstr(bottomwin, "[ ");
|
|
|
|
waddstr(bottomwin, foo);
|
|
|
|
free(foo);
|
|
|
|
waddstr(bottomwin, " ]");
|
2014-05-10 19:15:04 +00:00
|
|
|
wattroff(bottomwin, A_BOLD);
|
|
|
|
wattroff(bottomwin, interface_color_pair[STATUS_BAR].pairnum);
|
2005-10-27 03:35:42 +00:00
|
|
|
wnoutrefresh(bottomwin);
|
|
|
|
reset_cursor();
|
|
|
|
wnoutrefresh(edit);
|
|
|
|
/* Leave the cursor at its position in the edit window, not in
|
|
|
|
* the statusbar. */
|
2004-05-18 01:20:36 +00:00
|
|
|
|
2005-06-17 18:27:00 +00:00
|
|
|
disable_cursorpos = TRUE;
|
2005-06-17 22:33:15 +00:00
|
|
|
|
|
|
|
/* If we're doing quick statusbar blanking, and constant cursor
|
|
|
|
* position display is off, blank the statusbar after only one
|
2006-05-21 21:23:21 +00:00
|
|
|
* keystroke. Otherwise, blank it after twenty-six keystrokes, as
|
|
|
|
* Pico does. */
|
2005-06-17 19:06:25 +00:00
|
|
|
statusblank =
|
2005-11-15 03:17:35 +00:00
|
|
|
#ifndef NANO_TINY
|
2005-06-17 21:52:59 +00:00
|
|
|
ISSET(QUICK_BLANK) && !ISSET(CONST_UPDATE) ? 1 :
|
2005-06-17 19:06:25 +00:00
|
|
|
#endif
|
2006-05-21 21:23:21 +00:00
|
|
|
26;
|
2004-05-18 01:20:36 +00:00
|
|
|
}
|
|
|
|
|
2005-12-08 07:09:08 +00:00
|
|
|
/* Display the shortcut list in s on the last two rows of the bottom
|
|
|
|
* portion of the window. */
|
2008-03-05 07:34:01 +00:00
|
|
|
void bottombars(int menu)
|
2000-06-06 05:53:49 +00:00
|
|
|
{
|
2004-05-23 21:11:14 +00:00
|
|
|
size_t i, colwidth, slen;
|
2008-03-05 07:34:01 +00:00
|
|
|
subnfunc *f;
|
|
|
|
const sc *s;
|
2002-02-15 19:17:02 +00:00
|
|
|
|
2015-04-07 14:16:07 +00:00
|
|
|
/* Set the global variable to the given menu. */
|
|
|
|
currmenu = menu;
|
|
|
|
|
2000-06-06 05:53:49 +00:00
|
|
|
if (ISSET(NO_HELP))
|
|
|
|
return;
|
|
|
|
|
2008-03-05 07:34:01 +00:00
|
|
|
if (menu == MMAIN) {
|
2002-05-12 19:52:15 +00:00
|
|
|
slen = MAIN_VISIBLE;
|
2005-05-26 05:17:13 +00:00
|
|
|
|
2008-03-05 07:34:01 +00:00
|
|
|
assert(slen <= length_of_list(menu));
|
2004-05-13 17:28:03 +00:00
|
|
|
} else {
|
2008-03-05 07:34:01 +00:00
|
|
|
slen = length_of_list(menu);
|
2002-05-12 19:52:15 +00:00
|
|
|
|
2004-05-23 21:11:14 +00:00
|
|
|
/* Don't show any more shortcuts than the main list does. */
|
2004-05-13 17:28:03 +00:00
|
|
|
if (slen > MAIN_VISIBLE)
|
|
|
|
slen = MAIN_VISIBLE;
|
|
|
|
}
|
|
|
|
|
2006-04-18 16:13:35 +00:00
|
|
|
/* There will be this many characters per column, except for the
|
|
|
|
* last two, which will be longer by (COLS % colwidth) columns so as
|
|
|
|
* to not waste space. We need at least three columns to display
|
|
|
|
* anything properly. */
|
2004-05-23 21:11:14 +00:00
|
|
|
colwidth = COLS / ((slen / 2) + (slen % 2));
|
2000-06-06 05:53:49 +00:00
|
|
|
|
2004-05-18 01:20:36 +00:00
|
|
|
blank_bottombars();
|
2001-06-14 02:54:22 +00:00
|
|
|
|
2008-03-05 07:34:01 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
fprintf(stderr, "In bottombars, and slen == \"%d\"\n", (int) slen);
|
|
|
|
#endif
|
2005-05-02 21:48:34 +00:00
|
|
|
|
2008-03-05 07:34:01 +00:00
|
|
|
for (f = allfuncs, i = 0; i < slen && f != NULL; f = f->next) {
|
2005-05-02 21:48:34 +00:00
|
|
|
|
2008-03-05 07:34:01 +00:00
|
|
|
#ifdef DEBUG
|
2014-06-27 20:01:27 +00:00
|
|
|
fprintf(stderr, "Checking menu items....");
|
2008-03-05 07:34:01 +00:00
|
|
|
#endif
|
2014-06-27 20:01:27 +00:00
|
|
|
if ((f->menus & menu) == 0)
|
2008-03-05 07:34:01 +00:00
|
|
|
continue;
|
2004-10-25 15:00:38 +00:00
|
|
|
|
2008-03-05 07:34:01 +00:00
|
|
|
#ifdef DEBUG
|
2014-06-27 20:01:27 +00:00
|
|
|
fprintf(stderr, "found one! f->menus = %x, desc = \"%s\"\n", f->menus, f->desc);
|
2008-03-05 07:34:01 +00:00
|
|
|
#endif
|
2014-06-27 20:01:27 +00:00
|
|
|
s = first_sc_for(menu, f->scfunc);
|
|
|
|
if (s == NULL) {
|
2008-03-05 07:34:01 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
fprintf(stderr, "Whoops, guess not, no shortcut key found for func!\n");
|
|
|
|
#endif
|
2014-06-27 20:01:27 +00:00
|
|
|
continue;
|
|
|
|
}
|
2004-10-25 15:00:38 +00:00
|
|
|
wmove(bottomwin, 1 + i % 2, (i / 2) * colwidth);
|
2008-03-05 07:34:01 +00:00
|
|
|
#ifdef DEBUG
|
2014-06-27 20:01:27 +00:00
|
|
|
fprintf(stderr, "Calling onekey with keystr \"%s\" and desc \"%s\"\n", s->keystr, f->desc);
|
2008-03-05 07:34:01 +00:00
|
|
|
#endif
|
2008-03-18 03:06:27 +00:00
|
|
|
onekey(s->keystr, _(f->desc), colwidth + (COLS % colwidth));
|
2014-06-27 20:01:27 +00:00
|
|
|
i++;
|
2000-06-06 05:53:49 +00:00
|
|
|
}
|
2001-04-30 11:28:46 +00:00
|
|
|
|
2004-05-23 21:11:14 +00:00
|
|
|
wnoutrefresh(bottomwin);
|
|
|
|
reset_cursor();
|
2005-07-26 14:42:57 +00:00
|
|
|
wnoutrefresh(edit);
|
2000-06-06 05:53:49 +00:00
|
|
|
}
|
|
|
|
|
2004-05-23 21:11:14 +00:00
|
|
|
/* Write a shortcut key to the help area at the bottom of the window.
|
|
|
|
* keystroke is e.g. "^G" and desc is e.g. "Get Help". We are careful
|
|
|
|
* to write at most len characters, even if len is very small and
|
|
|
|
* keystroke and desc are long. Note that waddnstr(,,(size_t)-1) adds
|
|
|
|
* the whole string! We do not bother padding the entry with blanks. */
|
|
|
|
void onekey(const char *keystroke, const char *desc, size_t len)
|
2000-06-06 05:53:49 +00:00
|
|
|
{
|
2004-12-24 00:43:41 +00:00
|
|
|
size_t keystroke_len = strlenpt(keystroke) + 1;
|
|
|
|
|
2005-01-07 22:37:01 +00:00
|
|
|
assert(keystroke != NULL && desc != NULL);
|
|
|
|
|
2014-05-10 19:15:04 +00:00
|
|
|
if (interface_color_pair[KEY_COMBO].bright)
|
|
|
|
wattron(bottomwin, A_BOLD);
|
|
|
|
wattron(bottomwin, interface_color_pair[KEY_COMBO].pairnum);
|
2004-12-24 00:43:41 +00:00
|
|
|
waddnstr(bottomwin, keystroke, actual_x(keystroke, len));
|
2014-05-10 19:15:04 +00:00
|
|
|
wattroff(bottomwin, A_BOLD);
|
|
|
|
wattroff(bottomwin, interface_color_pair[KEY_COMBO].pairnum);
|
2004-12-24 00:43:41 +00:00
|
|
|
|
|
|
|
if (len > keystroke_len)
|
|
|
|
len -= keystroke_len;
|
|
|
|
else
|
|
|
|
len = 0;
|
|
|
|
|
2002-09-06 20:35:28 +00:00
|
|
|
if (len > 0) {
|
|
|
|
waddch(bottomwin, ' ');
|
2014-05-10 19:15:04 +00:00
|
|
|
if (interface_color_pair[FUNCTION_TAG].bright)
|
|
|
|
wattron(bottomwin, A_BOLD);
|
|
|
|
wattron(bottomwin, interface_color_pair[FUNCTION_TAG].pairnum);
|
2004-12-24 00:43:41 +00:00
|
|
|
waddnstr(bottomwin, desc, actual_x(desc, len));
|
2014-05-10 19:15:04 +00:00
|
|
|
wattroff(bottomwin, A_BOLD);
|
|
|
|
wattroff(bottomwin, interface_color_pair[FUNCTION_TAG].pairnum);
|
2000-06-06 05:53:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-11-01 17:45:31 +00:00
|
|
|
/* Reset current_y, based on the position of current, and put the cursor
|
|
|
|
* in the edit window at (current_y, current_x). */
|
2002-08-21 16:10:37 +00:00
|
|
|
void reset_cursor(void)
|
|
|
|
{
|
2009-08-17 07:52:10 +00:00
|
|
|
size_t xpt;
|
2004-09-05 21:40:31 +00:00
|
|
|
/* If we haven't opened any files yet, put the cursor in the top
|
|
|
|
* left corner of the edit window and get out. */
|
2005-07-08 20:59:24 +00:00
|
|
|
if (openfile == NULL) {
|
2004-09-05 21:40:31 +00:00
|
|
|
wmove(edit, 0, 0);
|
2002-08-21 16:10:37 +00:00
|
|
|
return;
|
2004-09-05 21:40:31 +00:00
|
|
|
}
|
2002-08-21 16:10:37 +00:00
|
|
|
|
2009-08-17 07:52:10 +00:00
|
|
|
xpt = xplustabs();
|
2006-05-26 03:02:50 +00:00
|
|
|
|
2014-06-09 20:26:54 +00:00
|
|
|
#ifndef NANO_TINY
|
2009-08-17 07:52:10 +00:00
|
|
|
if (ISSET(SOFTWRAP)) {
|
|
|
|
filestruct *tmp;
|
2009-11-11 06:00:33 +00:00
|
|
|
openfile->current_y = 0;
|
|
|
|
|
2009-08-30 03:50:16 +00:00
|
|
|
for (tmp = openfile->edittop; tmp && tmp != openfile->current; tmp = tmp->next)
|
2014-06-09 20:41:15 +00:00
|
|
|
openfile->current_y += (strlenpt(tmp->data) / COLS) + 1;
|
2009-08-17 07:52:10 +00:00
|
|
|
|
2009-11-11 06:00:33 +00:00
|
|
|
openfile->current_y += xplustabs() / COLS;
|
2009-08-17 07:52:10 +00:00
|
|
|
if (openfile->current_y < editwinrows)
|
2009-11-11 06:00:33 +00:00
|
|
|
wmove(edit, openfile->current_y, xpt % COLS);
|
2014-06-09 20:26:54 +00:00
|
|
|
} else
|
|
|
|
#endif
|
|
|
|
{
|
2009-08-17 07:52:10 +00:00
|
|
|
openfile->current_y = openfile->current->lineno -
|
|
|
|
openfile->edittop->lineno;
|
|
|
|
|
|
|
|
if (openfile->current_y < editwinrows)
|
|
|
|
wmove(edit, openfile->current_y, xpt - get_page_start(xpt));
|
|
|
|
}
|
2002-08-21 16:10:37 +00:00
|
|
|
}
|
2002-07-19 01:08:59 +00:00
|
|
|
|
2005-10-27 20:10:45 +00:00
|
|
|
/* edit_draw() takes care of the job of actually painting a line into
|
|
|
|
* the edit window. fileptr is the line to be painted, at row line of
|
|
|
|
* the window. converted is the actual string to be written to the
|
|
|
|
* window, with tabs and control characters replaced by strings of
|
|
|
|
* regular characters. start is the column number of the first
|
|
|
|
* character of this page. That is, the first character of converted
|
|
|
|
* corresponds to character number actual_x(fileptr->data, start) of the
|
|
|
|
* line. */
|
2009-01-25 07:25:17 +00:00
|
|
|
void edit_draw(filestruct *fileptr, const char *converted, int
|
2005-10-27 20:10:45 +00:00
|
|
|
line, size_t start)
|
2000-06-06 05:53:49 +00:00
|
|
|
{
|
2014-04-04 11:59:03 +00:00
|
|
|
#if !defined(NANO_TINY) || !defined(DISABLE_COLOR)
|
2003-09-16 01:16:49 +00:00
|
|
|
size_t startpos = actual_x(fileptr->data, start);
|
|
|
|
/* The position in fileptr->data of the leftmost character
|
|
|
|
* that displays at least partially on the window. */
|
|
|
|
size_t endpos = actual_x(fileptr->data, start + COLS - 1) + 1;
|
|
|
|
/* The position in fileptr->data of the first character that is
|
|
|
|
* completely off the window to the right.
|
|
|
|
*
|
|
|
|
* Note that endpos might be beyond the null terminator of the
|
|
|
|
* string. */
|
2001-12-02 04:55:44 +00:00
|
|
|
#endif
|
|
|
|
|
2005-07-13 20:18:46 +00:00
|
|
|
assert(openfile != NULL && fileptr != NULL && converted != NULL);
|
2005-01-03 22:23:00 +00:00
|
|
|
assert(strlenpt(converted) <= COLS);
|
2003-09-16 01:16:49 +00:00
|
|
|
|
2014-05-19 20:44:24 +00:00
|
|
|
/* First simply paint the line -- then we'll add colors or the
|
|
|
|
* marking highlight on just the pieces that need it. */
|
|
|
|
mvwaddstr(edit, line, 0, converted);
|
2014-06-04 16:02:51 +00:00
|
|
|
|
2014-05-28 01:35:51 +00:00
|
|
|
#ifndef USE_SLANG
|
2014-06-04 16:02:51 +00:00
|
|
|
/* Tell ncurses to really redraw the line without trying to optimize
|
|
|
|
* for what it thinks is already there, because it gets it wrong in
|
|
|
|
* the case of a wide character in column zero. See bug #31743. */
|
2014-05-23 20:24:31 +00:00
|
|
|
wredrawln(edit, line, 1);
|
2014-05-28 01:35:51 +00:00
|
|
|
#endif
|
2001-12-02 04:55:44 +00:00
|
|
|
|
2014-04-04 11:59:03 +00:00
|
|
|
#ifndef DISABLE_COLOR
|
2005-07-13 20:18:46 +00:00
|
|
|
/* If color syntaxes are available and turned on, we need to display
|
|
|
|
* them. */
|
|
|
|
if (openfile->colorstrings != NULL && !ISSET(NO_COLOR_SYNTAX)) {
|
|
|
|
const colortype *tmpcolor = openfile->colorstrings;
|
2002-09-27 14:21:59 +00:00
|
|
|
|
2014-06-04 16:02:51 +00:00
|
|
|
/* Set up multi-line color data for this line if it's not yet
|
|
|
|
* calculated. */
|
|
|
|
if (fileptr->multidata == NULL && openfile->syntax
|
2009-01-25 07:25:17 +00:00
|
|
|
&& openfile->syntax->nmultis > 0) {
|
2014-03-17 21:36:37 +00:00
|
|
|
int i;
|
2014-06-04 16:02:51 +00:00
|
|
|
fileptr->multidata = (short *)nmalloc(openfile->syntax->nmultis * sizeof(short));
|
|
|
|
for (i = 0; i < openfile->syntax->nmultis; i++)
|
|
|
|
/* Assume this applies until we know otherwise. */
|
|
|
|
fileptr->multidata[i] = -1;
|
2009-01-25 07:25:17 +00:00
|
|
|
}
|
2002-09-27 14:21:59 +00:00
|
|
|
for (; tmpcolor != NULL; tmpcolor = tmpcolor->next) {
|
|
|
|
int x_start;
|
|
|
|
/* Starting column for mvwaddnstr. Zero-based. */
|
2015-06-14 18:06:36 +00:00
|
|
|
int paintlen = 0;
|
2006-08-02 18:41:55 +00:00
|
|
|
/* Number of chars to paint on this line. There are
|
|
|
|
* COLS characters on a whole line. */
|
2005-01-04 02:55:45 +00:00
|
|
|
size_t index;
|
2005-01-03 22:23:00 +00:00
|
|
|
/* Index in converted where we paint. */
|
2005-06-26 22:59:54 +00:00
|
|
|
regmatch_t startmatch;
|
|
|
|
/* Match position for start_regex. */
|
|
|
|
regmatch_t endmatch;
|
|
|
|
/* Match position for end_regex. */
|
2002-09-27 14:21:59 +00:00
|
|
|
|
|
|
|
if (tmpcolor->bright)
|
|
|
|
wattron(edit, A_BOLD);
|
|
|
|
wattron(edit, COLOR_PAIR(tmpcolor->pairnum));
|
2005-12-08 07:24:54 +00:00
|
|
|
/* Two notes about regexec(). A return value of zero means
|
|
|
|
* that there is a match. Also, rm_eo is the first
|
|
|
|
* non-matching character after the match. */
|
2002-09-27 14:21:59 +00:00
|
|
|
|
2013-03-17 22:09:38 +00:00
|
|
|
/* First case, tmpcolor is a single-line expression. */
|
2002-01-19 16:52:34 +00:00
|
|
|
if (tmpcolor->end == NULL) {
|
2002-09-27 14:21:59 +00:00
|
|
|
size_t k = 0;
|
|
|
|
|
|
|
|
/* We increment k by rm_eo, to move past the end of the
|
2003-09-16 01:16:49 +00:00
|
|
|
* last match. Even though two matches may overlap, we
|
2006-05-26 11:58:37 +00:00
|
|
|
* want to ignore them, so that we can highlight e.g. C
|
|
|
|
* strings correctly. */
|
2003-09-16 01:16:49 +00:00
|
|
|
while (k < endpos) {
|
|
|
|
/* Note the fifth parameter to regexec(). It says
|
|
|
|
* not to match the beginning-of-line character
|
2006-05-26 11:58:37 +00:00
|
|
|
* unless k is zero. If regexec() returns
|
|
|
|
* REG_NOMATCH, there are no more matches in the
|
|
|
|
* line. */
|
2005-07-13 20:18:46 +00:00
|
|
|
if (regexec(tmpcolor->start, &fileptr->data[k], 1,
|
2005-07-29 21:41:04 +00:00
|
|
|
&startmatch, (k == 0) ? 0 : REG_NOTBOL) ==
|
|
|
|
REG_NOMATCH)
|
2002-01-19 16:52:34 +00:00
|
|
|
break;
|
2005-03-10 20:55:11 +00:00
|
|
|
/* Translate the match to the beginning of the
|
|
|
|
* line. */
|
2002-09-27 14:21:59 +00:00
|
|
|
startmatch.rm_so += k;
|
|
|
|
startmatch.rm_eo += k;
|
2006-06-21 20:51:36 +00:00
|
|
|
|
|
|
|
/* Skip over a zero-length regex match. */
|
|
|
|
if (startmatch.rm_so == startmatch.rm_eo)
|
2002-10-17 02:19:31 +00:00
|
|
|
startmatch.rm_eo++;
|
2006-06-21 20:51:36 +00:00
|
|
|
else if (startmatch.rm_so < endpos &&
|
2005-03-10 20:55:11 +00:00
|
|
|
startmatch.rm_eo > startpos) {
|
2006-05-08 16:25:12 +00:00
|
|
|
x_start = (startmatch.rm_so <= startpos) ? 0 :
|
|
|
|
strnlenpt(fileptr->data,
|
2004-04-29 06:30:36 +00:00
|
|
|
startmatch.rm_so) - start;
|
2002-09-27 14:21:59 +00:00
|
|
|
|
2005-01-03 22:23:00 +00:00
|
|
|
index = actual_x(converted, x_start);
|
|
|
|
|
|
|
|
paintlen = actual_x(converted + index,
|
2005-01-12 18:23:09 +00:00
|
|
|
strnlenpt(fileptr->data,
|
|
|
|
startmatch.rm_eo) - start - x_start);
|
2005-01-03 22:23:00 +00:00
|
|
|
|
|
|
|
assert(0 <= x_start && 0 <= paintlen);
|
|
|
|
|
2013-03-17 22:09:38 +00:00
|
|
|
mvwaddnstr(edit, line, x_start, converted +
|
2005-10-27 20:10:45 +00:00
|
|
|
index, paintlen);
|
2003-09-16 01:16:49 +00:00
|
|
|
}
|
2013-03-17 22:09:38 +00:00
|
|
|
k = startmatch.rm_eo;
|
2002-01-19 01:59:37 +00:00
|
|
|
}
|
2009-02-07 14:48:30 +00:00
|
|
|
} else if (fileptr->multidata != NULL && fileptr->multidata[tmpcolor->id] != CNONE) {
|
2005-06-26 22:59:54 +00:00
|
|
|
/* This is a multi-line regex. There are two steps.
|
2002-09-27 14:21:59 +00:00
|
|
|
* First, we have to see if the beginning of the line is
|
|
|
|
* colored by a start on an earlier line, and an end on
|
|
|
|
* this line or later.
|
|
|
|
*
|
|
|
|
* We find the first line before fileptr matching the
|
|
|
|
* start. If every match on that line is followed by an
|
2005-01-24 21:51:07 +00:00
|
|
|
* end, then go to step two. Otherwise, find the next
|
|
|
|
* line after start_line matching the end. If that line
|
|
|
|
* is not before fileptr, then paint the beginning of
|
|
|
|
* this line. */
|
2002-09-27 14:21:59 +00:00
|
|
|
const filestruct *start_line = fileptr->prev;
|
2005-01-24 21:51:07 +00:00
|
|
|
/* The first line before fileptr matching start. */
|
2002-09-27 14:21:59 +00:00
|
|
|
regoff_t start_col;
|
2005-01-24 21:51:07 +00:00
|
|
|
/* Where it starts in that line. */
|
2002-09-27 14:21:59 +00:00
|
|
|
const filestruct *end_line;
|
2009-02-03 05:05:58 +00:00
|
|
|
short md = fileptr->multidata[tmpcolor->id];
|
|
|
|
|
|
|
|
if (md == -1)
|
2014-06-04 16:02:51 +00:00
|
|
|
/* Assume this until we know otherwise. */
|
|
|
|
fileptr->multidata[tmpcolor->id] = CNONE;
|
2009-02-03 05:05:58 +00:00
|
|
|
else if (md == CNONE)
|
2014-05-17 20:25:42 +00:00
|
|
|
goto end_of_loop;
|
2009-02-03 05:05:58 +00:00
|
|
|
else if (md == CWHOLELINE) {
|
|
|
|
mvwaddnstr(edit, line, 0, converted, -1);
|
2014-05-17 20:25:42 +00:00
|
|
|
goto end_of_loop;
|
2009-02-07 07:09:31 +00:00
|
|
|
} else if (md == CBEGINBEFORE) {
|
|
|
|
regexec(tmpcolor->end, fileptr->data, 1, &endmatch, 0);
|
|
|
|
paintlen = actual_x(converted, strnlenpt(fileptr->data,
|
|
|
|
endmatch.rm_eo) - start);
|
|
|
|
mvwaddnstr(edit, line, 0, converted, paintlen);
|
2014-05-17 20:25:42 +00:00
|
|
|
goto end_of_loop;
|
2009-02-03 05:05:58 +00:00
|
|
|
}
|
2009-01-25 07:25:17 +00:00
|
|
|
|
2005-07-13 20:18:46 +00:00
|
|
|
while (start_line != NULL && regexec(tmpcolor->start,
|
2005-07-29 21:41:04 +00:00
|
|
|
start_line->data, 1, &startmatch, 0) ==
|
|
|
|
REG_NOMATCH) {
|
2002-09-27 14:21:59 +00:00
|
|
|
/* If there is an end on this line, there is no need
|
|
|
|
* to look for starts on earlier lines. */
|
2004-04-29 06:30:36 +00:00
|
|
|
if (regexec(tmpcolor->end, start_line->data, 0,
|
|
|
|
NULL, 0) == 0)
|
2002-09-27 14:21:59 +00:00
|
|
|
goto step_two;
|
|
|
|
start_line = start_line->prev;
|
|
|
|
}
|
2006-06-21 20:51:36 +00:00
|
|
|
|
2015-06-14 17:56:44 +00:00
|
|
|
/* If the found start has been qualified as an end earlier,
|
|
|
|
* believe it and skip to the next step. */
|
2015-06-23 18:06:30 +00:00
|
|
|
if (start_line != NULL && start_line->multidata != NULL &&
|
2015-07-18 07:34:27 +00:00
|
|
|
(start_line->multidata[tmpcolor->id] == CBEGINBEFORE ||
|
|
|
|
start_line->multidata[tmpcolor->id] == CSTARTENDHERE))
|
2015-06-14 17:56:44 +00:00
|
|
|
goto step_two;
|
|
|
|
|
2006-06-21 20:51:36 +00:00
|
|
|
/* Skip over a zero-length regex match. */
|
|
|
|
if (startmatch.rm_so == startmatch.rm_eo)
|
2006-05-08 15:57:04 +00:00
|
|
|
startmatch.rm_eo++;
|
2006-06-21 20:51:36 +00:00
|
|
|
else {
|
2006-05-08 15:57:04 +00:00
|
|
|
/* No start found, so skip to the next step. */
|
|
|
|
if (start_line == NULL)
|
2002-09-27 14:21:59 +00:00
|
|
|
goto step_two;
|
2006-05-08 15:57:04 +00:00
|
|
|
/* Now start_line is the first line before fileptr
|
|
|
|
* containing a start match. Is there a start on
|
|
|
|
* this line not followed by an end on this line? */
|
|
|
|
start_col = 0;
|
|
|
|
while (TRUE) {
|
|
|
|
start_col += startmatch.rm_so;
|
|
|
|
startmatch.rm_eo -= startmatch.rm_so;
|
|
|
|
if (regexec(tmpcolor->end, start_line->data +
|
|
|
|
start_col + startmatch.rm_eo, 0, NULL,
|
|
|
|
(start_col + startmatch.rm_eo == 0) ?
|
|
|
|
0 : REG_NOTBOL) == REG_NOMATCH)
|
|
|
|
/* No end found after this start. */
|
|
|
|
break;
|
|
|
|
start_col++;
|
|
|
|
if (regexec(tmpcolor->start, start_line->data +
|
|
|
|
start_col, 1, &startmatch,
|
|
|
|
REG_NOTBOL) == REG_NOMATCH)
|
|
|
|
/* No later start on this line. */
|
|
|
|
goto step_two;
|
|
|
|
}
|
|
|
|
/* Indeed, there is a start not followed on this
|
|
|
|
* line by an end. */
|
|
|
|
|
|
|
|
/* We have already checked that there is no end
|
|
|
|
* before fileptr and after the start. Is there an
|
|
|
|
* end after the start at all? We don't paint
|
|
|
|
* unterminated starts. */
|
|
|
|
end_line = fileptr;
|
|
|
|
while (end_line != NULL && regexec(tmpcolor->end,
|
2005-07-29 21:41:04 +00:00
|
|
|
end_line->data, 1, &endmatch, 0) == REG_NOMATCH)
|
2006-05-08 15:57:04 +00:00
|
|
|
end_line = end_line->next;
|
2002-09-27 14:21:59 +00:00
|
|
|
|
2006-05-08 15:57:04 +00:00
|
|
|
/* No end found, or it is too early. */
|
|
|
|
if (end_line == NULL || (end_line == fileptr &&
|
2005-01-04 02:55:45 +00:00
|
|
|
endmatch.rm_eo <= startpos))
|
2006-05-08 15:57:04 +00:00
|
|
|
goto step_two;
|
2002-09-27 14:21:59 +00:00
|
|
|
|
2006-08-02 18:38:45 +00:00
|
|
|
/* Now paint the start of fileptr. If the start of
|
|
|
|
* fileptr is on a different line from the end,
|
|
|
|
* paintlen is -1, meaning that everything on the
|
|
|
|
* line gets painted. Otherwise, paintlen is the
|
|
|
|
* expanded location of the end of the match minus
|
|
|
|
* the expanded location of the beginning of the
|
|
|
|
* page. */
|
2009-02-03 05:05:58 +00:00
|
|
|
if (end_line != fileptr) {
|
2006-11-21 17:05:04 +00:00
|
|
|
paintlen = -1;
|
2009-02-03 05:05:58 +00:00
|
|
|
fileptr->multidata[tmpcolor->id] = CWHOLELINE;
|
2015-06-14 15:58:57 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
fprintf(stderr, " Marking for id %i line %i as CWHOLELINE\n", tmpcolor->id, line);
|
|
|
|
#endif
|
2009-02-03 05:05:58 +00:00
|
|
|
} else {
|
2006-11-21 17:05:04 +00:00
|
|
|
paintlen = actual_x(converted,
|
|
|
|
strnlenpt(fileptr->data,
|
|
|
|
endmatch.rm_eo) - start);
|
2009-02-03 05:05:58 +00:00
|
|
|
fileptr->multidata[tmpcolor->id] = CBEGINBEFORE;
|
2015-06-14 15:58:57 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
fprintf(stderr, " Marking for id %i line %i as CBEGINBEFORE\n", tmpcolor->id, line);
|
|
|
|
#endif
|
2009-02-03 05:05:58 +00:00
|
|
|
}
|
2006-05-08 15:57:04 +00:00
|
|
|
mvwaddnstr(edit, line, 0, converted, paintlen);
|
2015-06-14 18:06:36 +00:00
|
|
|
/* If the whole line has been painted, don't bother
|
|
|
|
* looking for any more starts. */
|
|
|
|
if (paintlen < 0)
|
|
|
|
goto end_of_loop;
|
2006-05-08 15:57:04 +00:00
|
|
|
step_two:
|
2015-07-18 07:34:27 +00:00
|
|
|
/* Second step: look for starts on this line, but start
|
|
|
|
* looking only after an end match, if there is one. */
|
|
|
|
start_col = (paintlen == 0) ? 0 : endmatch.rm_eo;
|
2006-05-08 15:57:04 +00:00
|
|
|
|
|
|
|
while (start_col < endpos) {
|
|
|
|
if (regexec(tmpcolor->start, fileptr->data +
|
|
|
|
start_col, 1, &startmatch, (start_col ==
|
|
|
|
0) ? 0 : REG_NOTBOL) == REG_NOMATCH ||
|
|
|
|
start_col + startmatch.rm_so >= endpos)
|
|
|
|
/* No more starts on this line. */
|
|
|
|
break;
|
|
|
|
/* Translate the match to be relative to the
|
2003-09-16 01:16:49 +00:00
|
|
|
* beginning of the line. */
|
2006-05-08 15:57:04 +00:00
|
|
|
startmatch.rm_so += start_col;
|
|
|
|
startmatch.rm_eo += start_col;
|
|
|
|
|
|
|
|
x_start = (startmatch.rm_so <= startpos) ? 0 :
|
2005-01-12 18:23:09 +00:00
|
|
|
strnlenpt(fileptr->data,
|
2006-05-08 15:57:04 +00:00
|
|
|
startmatch.rm_so) - start;
|
2005-01-03 22:23:00 +00:00
|
|
|
|
2006-05-08 15:57:04 +00:00
|
|
|
index = actual_x(converted, x_start);
|
2002-09-27 14:21:59 +00:00
|
|
|
|
2006-05-08 15:57:04 +00:00
|
|
|
if (regexec(tmpcolor->end, fileptr->data +
|
|
|
|
startmatch.rm_eo, 1, &endmatch,
|
|
|
|
(startmatch.rm_eo == 0) ? 0 :
|
|
|
|
REG_NOTBOL) == 0) {
|
|
|
|
/* Translate the end match to be relative to
|
|
|
|
* the beginning of the line. */
|
|
|
|
endmatch.rm_so += startmatch.rm_eo;
|
|
|
|
endmatch.rm_eo += startmatch.rm_eo;
|
|
|
|
/* There is an end on this line. But does
|
|
|
|
* it appear on this page, and is the match
|
|
|
|
* more than zero characters long? */
|
|
|
|
if (endmatch.rm_eo > startpos &&
|
|
|
|
endmatch.rm_eo > startmatch.rm_so) {
|
|
|
|
paintlen = actual_x(converted + index,
|
|
|
|
strnlenpt(fileptr->data,
|
|
|
|
endmatch.rm_eo) - start -
|
|
|
|
x_start);
|
2005-01-24 21:51:07 +00:00
|
|
|
|
2006-05-08 15:57:04 +00:00
|
|
|
assert(0 <= x_start && x_start < COLS);
|
|
|
|
|
|
|
|
mvwaddnstr(edit, line, x_start,
|
|
|
|
converted + index, paintlen);
|
2015-06-14 15:58:57 +00:00
|
|
|
if (paintlen > 0) {
|
2009-02-03 05:05:58 +00:00
|
|
|
fileptr->multidata[tmpcolor->id] = CSTARTENDHERE;
|
2015-06-14 15:58:57 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
fprintf(stderr, " Marking for id %i line %i as CSTARTENDHERE\n", tmpcolor->id, line);
|
|
|
|
#endif
|
|
|
|
}
|
2006-05-08 15:57:04 +00:00
|
|
|
}
|
2015-07-18 07:34:27 +00:00
|
|
|
start_col = endmatch.rm_eo;
|
2006-05-08 15:57:04 +00:00
|
|
|
} else {
|
|
|
|
/* There is no end on this line. But we
|
|
|
|
* haven't yet looked for one on later
|
|
|
|
* lines. */
|
|
|
|
end_line = fileptr->next;
|
|
|
|
|
|
|
|
while (end_line != NULL &&
|
2005-01-24 21:51:07 +00:00
|
|
|
regexec(tmpcolor->end, end_line->data,
|
|
|
|
0, NULL, 0) == REG_NOMATCH)
|
2006-05-08 15:57:04 +00:00
|
|
|
end_line = end_line->next;
|
2005-01-03 22:23:00 +00:00
|
|
|
|
2006-05-08 15:57:04 +00:00
|
|
|
if (end_line != NULL) {
|
|
|
|
assert(0 <= x_start && x_start < COLS);
|
2005-01-03 22:23:00 +00:00
|
|
|
|
2006-05-08 15:57:04 +00:00
|
|
|
mvwaddnstr(edit, line, x_start,
|
|
|
|
converted + index, -1);
|
|
|
|
/* We painted to the end of the line, so
|
|
|
|
* don't bother checking any more
|
|
|
|
* starts. */
|
2015-06-14 15:58:57 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
fprintf(stderr, " Marking for id %i line %i as CENDAFTER\n", tmpcolor->id, line);
|
|
|
|
#endif
|
2009-02-03 05:05:58 +00:00
|
|
|
fileptr->multidata[tmpcolor->id] = CENDAFTER;
|
2006-05-08 15:57:04 +00:00
|
|
|
break;
|
|
|
|
}
|
2015-07-18 07:34:27 +00:00
|
|
|
start_col = startmatch.rm_so + 1;
|
2002-01-19 16:52:34 +00:00
|
|
|
}
|
|
|
|
}
|
2005-03-10 20:55:11 +00:00
|
|
|
}
|
|
|
|
}
|
2014-05-17 20:25:42 +00:00
|
|
|
end_of_loop:
|
2002-09-27 14:21:59 +00:00
|
|
|
wattroff(edit, A_BOLD);
|
|
|
|
wattroff(edit, COLOR_PAIR(tmpcolor->pairnum));
|
2005-03-10 20:55:11 +00:00
|
|
|
}
|
2002-09-27 14:21:59 +00:00
|
|
|
}
|
2014-04-04 11:59:03 +00:00
|
|
|
#endif /* !DISABLE_COLOR */
|
2001-12-02 04:55:44 +00:00
|
|
|
|
2005-11-15 03:17:35 +00:00
|
|
|
#ifndef NANO_TINY
|
2005-07-13 20:18:46 +00:00
|
|
|
/* If the mark is on, we need to display it. */
|
2005-07-08 20:09:16 +00:00
|
|
|
if (openfile->mark_set && (fileptr->lineno <=
|
2005-07-12 17:40:16 +00:00
|
|
|
openfile->mark_begin->lineno || fileptr->lineno <=
|
2005-07-08 20:09:16 +00:00
|
|
|
openfile->current->lineno) && (fileptr->lineno >=
|
2005-07-12 17:40:16 +00:00
|
|
|
openfile->mark_begin->lineno || fileptr->lineno >=
|
2005-07-08 20:09:16 +00:00
|
|
|
openfile->current->lineno)) {
|
2002-09-27 14:21:59 +00:00
|
|
|
/* fileptr is at least partially selected. */
|
2003-09-16 01:16:49 +00:00
|
|
|
const filestruct *top;
|
2005-07-12 17:40:16 +00:00
|
|
|
/* Either current or mark_begin, whichever is first. */
|
2003-09-16 01:16:49 +00:00
|
|
|
size_t top_x;
|
2005-07-12 17:40:16 +00:00
|
|
|
/* current_x or mark_begin_x, corresponding to top. */
|
2003-09-16 01:16:49 +00:00
|
|
|
const filestruct *bot;
|
|
|
|
size_t bot_x;
|
2002-09-27 14:21:59 +00:00
|
|
|
int x_start;
|
2005-07-12 17:40:16 +00:00
|
|
|
/* Starting column for mvwaddnstr(). Zero-based. */
|
2002-09-27 14:21:59 +00:00
|
|
|
int paintlen;
|
2006-08-02 19:13:31 +00:00
|
|
|
/* Number of characters to paint on this line. There are
|
|
|
|
* COLS characters on a whole line. */
|
2005-01-04 02:55:45 +00:00
|
|
|
size_t index;
|
2005-01-03 22:23:00 +00:00
|
|
|
/* Index in converted where we paint. */
|
2002-09-27 14:21:59 +00:00
|
|
|
|
2004-11-05 23:03:03 +00:00
|
|
|
mark_order(&top, &top_x, &bot, &bot_x, NULL);
|
2003-09-16 01:16:49 +00:00
|
|
|
|
|
|
|
if (top->lineno < fileptr->lineno || top_x < startpos)
|
|
|
|
top_x = startpos;
|
|
|
|
if (bot->lineno > fileptr->lineno || bot_x > endpos)
|
|
|
|
bot_x = endpos;
|
2002-07-19 01:08:59 +00:00
|
|
|
|
2003-10-03 04:20:28 +00:00
|
|
|
/* The selected bit of fileptr is on this page. */
|
2003-09-16 01:16:49 +00:00
|
|
|
if (top_x < endpos && bot_x > startpos) {
|
|
|
|
assert(startpos <= top_x);
|
2003-10-03 04:20:28 +00:00
|
|
|
|
|
|
|
/* x_start is the expanded location of the beginning of the
|
|
|
|
* mark minus the beginning of the page. */
|
|
|
|
x_start = strnlenpt(fileptr->data, top_x) - start;
|
2003-09-16 01:16:49 +00:00
|
|
|
|
2006-08-02 18:38:45 +00:00
|
|
|
/* If the end of the mark is off the page, paintlen is -1,
|
|
|
|
* meaning that everything on the line gets painted.
|
|
|
|
* Otherwise, paintlen is the expanded location of the end
|
|
|
|
* of the mark minus the expanded location of the beginning
|
|
|
|
* of the mark. */
|
2006-11-21 17:05:04 +00:00
|
|
|
if (bot_x >= endpos)
|
|
|
|
paintlen = -1;
|
|
|
|
else
|
|
|
|
paintlen = strnlenpt(fileptr->data, bot_x) - (x_start +
|
|
|
|
start);
|
2003-10-03 04:20:28 +00:00
|
|
|
|
|
|
|
/* If x_start is before the beginning of the page, shift
|
|
|
|
* paintlen x_start characters to compensate, and put
|
|
|
|
* x_start at the beginning of the page. */
|
|
|
|
if (x_start < 0) {
|
|
|
|
paintlen += x_start;
|
|
|
|
x_start = 0;
|
|
|
|
}
|
2003-09-16 01:16:49 +00:00
|
|
|
|
|
|
|
assert(x_start >= 0 && x_start <= strlen(converted));
|
|
|
|
|
2005-01-03 22:23:00 +00:00
|
|
|
index = actual_x(converted, x_start);
|
2005-01-24 21:51:07 +00:00
|
|
|
|
2005-01-03 22:23:00 +00:00
|
|
|
if (paintlen > 0)
|
|
|
|
paintlen = actual_x(converted + index, paintlen);
|
|
|
|
|
2014-05-04 08:53:06 +00:00
|
|
|
wattron(edit, hilite_attribute);
|
2005-10-27 20:10:45 +00:00
|
|
|
mvwaddnstr(edit, line, x_start, converted + index,
|
2005-01-03 22:56:38 +00:00
|
|
|
paintlen);
|
2014-05-04 08:53:06 +00:00
|
|
|
wattroff(edit, hilite_attribute);
|
2000-06-06 05:53:49 +00:00
|
|
|
}
|
2001-11-29 02:42:27 +00:00
|
|
|
}
|
2005-11-15 03:17:35 +00:00
|
|
|
#endif /* !NANO_TINY */
|
2000-06-06 05:53:49 +00:00
|
|
|
}
|
|
|
|
|
2004-12-08 23:24:31 +00:00
|
|
|
/* Just update one line in the edit buffer. This is basically a wrapper
|
2005-11-07 06:20:02 +00:00
|
|
|
* for edit_draw(). The line will be displayed starting with
|
2009-08-17 07:52:10 +00:00
|
|
|
* fileptr->data[index]. Likely arguments are current_x or zero.
|
2014-04-08 12:35:18 +00:00
|
|
|
* Returns: Number of additional lines consumed (needed for SOFTWRAP). */
|
2009-08-17 07:52:10 +00:00
|
|
|
int update_line(filestruct *fileptr, size_t index)
|
2000-06-06 05:53:49 +00:00
|
|
|
{
|
2009-08-17 07:52:10 +00:00
|
|
|
int line = 0;
|
2004-12-08 23:24:31 +00:00
|
|
|
/* The line in the edit window that we want to update. */
|
2014-04-15 11:25:29 +00:00
|
|
|
int extralinesused = 0;
|
2002-09-27 14:21:59 +00:00
|
|
|
char *converted;
|
|
|
|
/* fileptr->data converted to have tabs and control characters
|
|
|
|
* expanded. */
|
|
|
|
size_t page_start;
|
2000-06-06 05:53:49 +00:00
|
|
|
|
2003-09-16 01:16:49 +00:00
|
|
|
assert(fileptr != NULL);
|
2000-06-18 00:11:03 +00:00
|
|
|
|
2014-06-09 20:26:54 +00:00
|
|
|
#ifndef NANO_TINY
|
2009-08-17 07:52:10 +00:00
|
|
|
if (ISSET(SOFTWRAP)) {
|
2014-06-09 20:26:54 +00:00
|
|
|
filestruct *tmp;
|
|
|
|
|
2014-06-09 20:41:15 +00:00
|
|
|
for (tmp = openfile->edittop; tmp && tmp != fileptr; tmp = tmp->next)
|
|
|
|
line += (strlenpt(tmp->data) / COLS) + 1;
|
2009-08-17 07:52:10 +00:00
|
|
|
} else
|
2014-06-09 20:26:54 +00:00
|
|
|
#endif
|
2009-08-17 07:52:10 +00:00
|
|
|
line = fileptr->lineno - openfile->edittop->lineno;
|
|
|
|
|
2002-09-27 14:21:59 +00:00
|
|
|
if (line < 0 || line >= editwinrows)
|
2009-09-15 04:51:09 +00:00
|
|
|
return 1;
|
2000-06-16 04:25:30 +00:00
|
|
|
|
2004-12-08 23:24:31 +00:00
|
|
|
/* First, blank out the line. */
|
2005-07-10 02:37:38 +00:00
|
|
|
blank_line(edit, line, 0, COLS);
|
2002-09-27 14:21:59 +00:00
|
|
|
|
2003-09-16 01:16:49 +00:00
|
|
|
/* Next, convert variables that index the line to their equivalent
|
|
|
|
* positions in the expanded line. */
|
2014-06-09 20:26:54 +00:00
|
|
|
#ifndef NANO_TINY
|
2009-08-17 07:52:10 +00:00
|
|
|
if (ISSET(SOFTWRAP))
|
|
|
|
index = 0;
|
|
|
|
else
|
2014-06-09 20:26:54 +00:00
|
|
|
#endif
|
2009-08-17 07:52:10 +00:00
|
|
|
index = strnlenpt(fileptr->data, index);
|
2003-09-16 01:16:49 +00:00
|
|
|
page_start = get_page_start(index);
|
2003-01-05 20:41:21 +00:00
|
|
|
|
2004-12-08 23:24:31 +00:00
|
|
|
/* Expand the line, replacing tabs with spaces, and control
|
|
|
|
* characters with their displayed forms. */
|
2014-06-09 20:26:54 +00:00
|
|
|
#ifdef NANO_TINY
|
|
|
|
converted = display_string(fileptr->data, page_start, COLS, TRUE);
|
|
|
|
#else
|
2009-11-11 06:00:33 +00:00
|
|
|
converted = display_string(fileptr->data, page_start, COLS, !ISSET(SOFTWRAP));
|
|
|
|
#ifdef DEBUG
|
|
|
|
if (ISSET(SOFTWRAP) && strlen(converted) >= COLS - 2)
|
2014-06-09 14:23:53 +00:00
|
|
|
fprintf(stderr, "update_line(): converted(1) line = %s\n", converted);
|
2009-11-11 06:00:33 +00:00
|
|
|
#endif
|
2014-06-09 20:26:54 +00:00
|
|
|
#endif /* !NANO_TINY */
|
2009-11-11 06:00:33 +00:00
|
|
|
|
2004-12-08 23:24:31 +00:00
|
|
|
/* Paint the line. */
|
2005-10-27 20:10:45 +00:00
|
|
|
edit_draw(fileptr, converted, line, page_start);
|
2002-09-27 14:21:59 +00:00
|
|
|
free(converted);
|
2000-06-06 05:53:49 +00:00
|
|
|
|
2014-06-09 20:26:54 +00:00
|
|
|
#ifndef NANO_TINY
|
2009-08-17 07:52:10 +00:00
|
|
|
if (!ISSET(SOFTWRAP)) {
|
2014-06-09 20:26:54 +00:00
|
|
|
#endif
|
2009-08-17 07:52:10 +00:00
|
|
|
if (page_start > 0)
|
|
|
|
mvwaddch(edit, line, 0, '$');
|
|
|
|
if (strlenpt(fileptr->data) > page_start + COLS)
|
|
|
|
mvwaddch(edit, line, COLS - 1, '$');
|
2014-06-09 20:26:54 +00:00
|
|
|
#ifndef NANO_TINY
|
2009-08-17 07:52:10 +00:00
|
|
|
} else {
|
2014-06-10 19:07:47 +00:00
|
|
|
size_t full_length = strlenpt(fileptr->data);
|
2009-11-11 06:00:33 +00:00
|
|
|
for (index += COLS; index <= full_length && line < editwinrows; index += COLS) {
|
2009-08-17 07:52:10 +00:00
|
|
|
line++;
|
|
|
|
#ifdef DEBUG
|
2014-06-10 19:07:47 +00:00
|
|
|
fprintf(stderr, "update_line(): softwrap code, moving to %d index %lu\n", line, (unsigned long)index);
|
2009-08-17 07:52:10 +00:00
|
|
|
#endif
|
2014-05-13 20:14:01 +00:00
|
|
|
blank_line(edit, line, 0, COLS);
|
2009-08-17 07:52:10 +00:00
|
|
|
|
|
|
|
/* Expand the line, replacing tabs with spaces, and control
|
2014-05-13 20:14:01 +00:00
|
|
|
* characters with their displayed forms. */
|
2009-11-11 06:00:33 +00:00
|
|
|
converted = display_string(fileptr->data, index, COLS, !ISSET(SOFTWRAP));
|
|
|
|
#ifdef DEBUG
|
|
|
|
if (ISSET(SOFTWRAP) && strlen(converted) >= COLS - 2)
|
|
|
|
fprintf(stderr, "update_line(): converted(2) line = %s\n", converted);
|
|
|
|
#endif
|
2009-08-17 07:52:10 +00:00
|
|
|
|
|
|
|
/* Paint the line. */
|
|
|
|
edit_draw(fileptr, converted, line, index);
|
2014-05-13 20:14:01 +00:00
|
|
|
free(converted);
|
2009-08-17 07:52:10 +00:00
|
|
|
extralinesused++;
|
|
|
|
}
|
|
|
|
}
|
2014-06-09 20:26:54 +00:00
|
|
|
#endif /* !NANO_TINY */
|
2009-08-17 07:52:10 +00:00
|
|
|
return extralinesused;
|
2000-06-06 05:53:49 +00:00
|
|
|
}
|
|
|
|
|
2015-04-20 08:16:41 +00:00
|
|
|
/* Return TRUE if we need an update after moving the cursor, and
|
|
|
|
* FALSE otherwise. We need an update if the mark is on, or if
|
|
|
|
* pww_save and placewewant are on different pages. */
|
|
|
|
bool need_screen_update(size_t pww_save)
|
2004-05-28 20:44:09 +00:00
|
|
|
{
|
|
|
|
return
|
2005-11-15 03:17:35 +00:00
|
|
|
#ifndef NANO_TINY
|
2005-07-08 20:09:16 +00:00
|
|
|
openfile->mark_set ||
|
2004-05-28 20:44:09 +00:00
|
|
|
#endif
|
2006-08-26 16:50:51 +00:00
|
|
|
get_page_start(pww_save) !=
|
2005-07-08 20:09:16 +00:00
|
|
|
get_page_start(openfile->placewewant);
|
2004-05-28 20:44:09 +00:00
|
|
|
}
|
|
|
|
|
2009-11-13 13:48:56 +00:00
|
|
|
/* When edittop changes, try and figure out how many lines
|
2014-04-08 12:35:18 +00:00
|
|
|
* we really have to work with (i.e. set maxrows). */
|
2009-11-13 13:48:56 +00:00
|
|
|
void compute_maxrows(void)
|
|
|
|
{
|
|
|
|
int n;
|
|
|
|
filestruct *foo = openfile->edittop;
|
|
|
|
|
2009-11-16 04:28:40 +00:00
|
|
|
if (!ISSET(SOFTWRAP)) {
|
|
|
|
maxrows = editwinrows;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-11-13 13:48:56 +00:00
|
|
|
maxrows = 0;
|
|
|
|
for (n = 0; n < editwinrows && foo; n++) {
|
2014-04-08 12:35:18 +00:00
|
|
|
maxrows++;
|
2009-11-24 17:15:53 +00:00
|
|
|
n += strlenpt(foo->data) / COLS;
|
2009-11-13 13:48:56 +00:00
|
|
|
foo = foo->next;
|
|
|
|
}
|
|
|
|
|
2009-11-16 04:28:40 +00:00
|
|
|
if (n < editwinrows)
|
|
|
|
maxrows += editwinrows - n;
|
|
|
|
|
2009-11-13 13:48:56 +00:00
|
|
|
#ifdef DEBUG
|
2014-06-09 15:08:59 +00:00
|
|
|
fprintf(stderr, "compute_maxrows(): maxrows = %d\n", maxrows);
|
2009-11-13 13:48:56 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2004-05-28 20:44:09 +00:00
|
|
|
/* Scroll the edit window in the given direction and the given number
|
|
|
|
* of lines, and draw new lines on the blank lines left after the
|
2014-06-23 18:20:12 +00:00
|
|
|
* scrolling. direction is the direction to scroll, either UPWARD or
|
|
|
|
* DOWNWARD, and nlines is the number of lines to scroll. We change
|
2006-07-19 00:14:52 +00:00
|
|
|
* edittop, and assume that current and current_x are up to date. We
|
|
|
|
* also assume that scrollok(edit) is FALSE. */
|
2005-08-01 21:05:29 +00:00
|
|
|
void edit_scroll(scroll_dir direction, ssize_t nlines)
|
2004-05-28 20:44:09 +00:00
|
|
|
{
|
2014-03-17 13:15:50 +00:00
|
|
|
ssize_t i;
|
2009-01-25 07:25:17 +00:00
|
|
|
filestruct *foo;
|
2015-04-20 08:16:41 +00:00
|
|
|
bool do_redraw = need_screen_update(0);
|
2004-05-28 20:44:09 +00:00
|
|
|
|
2005-07-22 23:17:19 +00:00
|
|
|
/* Don't bother scrolling less than one line. */
|
|
|
|
if (nlines < 1)
|
2004-05-28 20:44:09 +00:00
|
|
|
return;
|
|
|
|
|
2005-07-22 23:17:19 +00:00
|
|
|
/* Part 1: nlines is the number of lines we're going to scroll the
|
|
|
|
* text of the edit window. */
|
|
|
|
|
2004-05-28 20:44:09 +00:00
|
|
|
/* Move the top line of the edit window up or down (depending on the
|
2005-07-16 22:50:30 +00:00
|
|
|
* value of direction) nlines lines, or as many lines as we can if
|
|
|
|
* there are fewer than nlines lines available. */
|
2004-05-28 20:44:09 +00:00
|
|
|
for (i = nlines; i > 0; i--) {
|
2014-06-23 18:20:12 +00:00
|
|
|
if (direction == UPWARD) {
|
2005-11-10 04:27:30 +00:00
|
|
|
if (openfile->edittop == openfile->fileage)
|
2004-05-28 20:44:09 +00:00
|
|
|
break;
|
2005-07-08 20:09:16 +00:00
|
|
|
openfile->edittop = openfile->edittop->prev;
|
2004-05-28 20:44:09 +00:00
|
|
|
} else {
|
2005-11-10 04:27:30 +00:00
|
|
|
if (openfile->edittop == openfile->filebot)
|
2004-05-28 20:44:09 +00:00
|
|
|
break;
|
2005-07-08 20:09:16 +00:00
|
|
|
openfile->edittop = openfile->edittop->next;
|
2004-05-28 20:44:09 +00:00
|
|
|
}
|
2014-06-09 20:26:54 +00:00
|
|
|
|
|
|
|
#ifndef NANO_TINY
|
2014-04-15 11:25:29 +00:00
|
|
|
/* Don't over-scroll on long lines. */
|
2014-06-23 18:20:12 +00:00
|
|
|
if (ISSET(SOFTWRAP) && direction == UPWARD) {
|
2010-01-13 03:21:19 +00:00
|
|
|
ssize_t len = strlenpt(openfile->edittop->data) / COLS;
|
2014-05-16 11:03:04 +00:00
|
|
|
i -= len;
|
2010-01-13 03:21:19 +00:00
|
|
|
if (len > 0)
|
|
|
|
do_redraw = TRUE;
|
|
|
|
}
|
2014-06-09 20:26:54 +00:00
|
|
|
#endif
|
2004-05-28 20:44:09 +00:00
|
|
|
}
|
|
|
|
|
2005-08-01 21:53:54 +00:00
|
|
|
/* Limit nlines to the number of lines we could scroll. */
|
2005-07-23 21:06:22 +00:00
|
|
|
nlines -= i;
|
2005-08-01 21:17:38 +00:00
|
|
|
|
2005-08-01 21:53:54 +00:00
|
|
|
/* Don't bother scrolling zero lines or more than the number of
|
|
|
|
* lines in the edit window minus one; in both cases, get out, and
|
2007-09-16 16:53:20 +00:00
|
|
|
* call edit_refresh() beforehand if we need to. */
|
2009-08-30 03:50:16 +00:00
|
|
|
if (nlines == 0 || do_redraw || nlines >= editwinrows) {
|
2007-09-16 16:53:20 +00:00
|
|
|
if (do_redraw || nlines >= editwinrows)
|
2010-01-13 03:21:19 +00:00
|
|
|
edit_refresh_needed = TRUE;
|
2005-08-01 21:17:38 +00:00
|
|
|
return;
|
|
|
|
}
|
2005-07-22 23:17:19 +00:00
|
|
|
|
|
|
|
/* Scroll the text of the edit window up or down nlines lines,
|
|
|
|
* depending on the value of direction. */
|
2005-07-22 22:56:03 +00:00
|
|
|
scrollok(edit, TRUE);
|
2014-06-23 18:20:12 +00:00
|
|
|
wscrl(edit, (direction == UPWARD) ? -nlines : nlines);
|
2005-07-22 22:56:03 +00:00
|
|
|
scrollok(edit, FALSE);
|
|
|
|
|
2005-07-22 23:17:19 +00:00
|
|
|
/* Part 2: nlines is the number of lines in the scrolled region of
|
|
|
|
* the edit window that we need to draw. */
|
|
|
|
|
2005-08-16 03:03:15 +00:00
|
|
|
/* If the top or bottom line of the file is now visible in the edit
|
|
|
|
* window, we need to draw the entire edit window. */
|
2014-06-23 18:20:12 +00:00
|
|
|
if ((direction == UPWARD && openfile->edittop ==
|
|
|
|
openfile->fileage) || (direction == DOWNWARD &&
|
2006-07-19 00:14:52 +00:00
|
|
|
openfile->edittop->lineno + editwinrows - 1 >=
|
|
|
|
openfile->filebot->lineno))
|
2005-07-23 21:06:22 +00:00
|
|
|
nlines = editwinrows;
|
2005-07-17 02:19:47 +00:00
|
|
|
|
2006-01-10 07:51:49 +00:00
|
|
|
/* If the scrolled region contains only one line, and the line
|
|
|
|
* before it is visible in the edit window, we need to draw it too.
|
|
|
|
* If the scrolled region contains more than one line, and the lines
|
|
|
|
* before and after the scrolled region are visible in the edit
|
|
|
|
* window, we need to draw them too. */
|
|
|
|
nlines += (nlines == 1) ? 1 : 2;
|
2005-08-01 21:53:54 +00:00
|
|
|
|
2005-07-17 22:51:44 +00:00
|
|
|
if (nlines > editwinrows)
|
|
|
|
nlines = editwinrows;
|
2005-07-16 22:50:30 +00:00
|
|
|
|
|
|
|
/* If we scrolled up, we're on the line before the scrolled
|
|
|
|
* region. */
|
2005-07-08 20:09:16 +00:00
|
|
|
foo = openfile->edittop;
|
2005-07-14 20:37:01 +00:00
|
|
|
|
2005-07-16 22:50:30 +00:00
|
|
|
/* If we scrolled down, move down to the line before the scrolled
|
|
|
|
* region. */
|
2014-06-23 18:20:12 +00:00
|
|
|
if (direction == DOWNWARD) {
|
2005-07-16 22:50:30 +00:00
|
|
|
for (i = editwinrows - nlines; i > 0 && foo != NULL; i--)
|
2004-05-28 20:44:09 +00:00
|
|
|
foo = foo->next;
|
|
|
|
}
|
|
|
|
|
2005-07-23 20:39:41 +00:00
|
|
|
/* Draw new lines on any blank lines before or inside the scrolled
|
|
|
|
* region. If we scrolled down and we're on the top line, or if we
|
|
|
|
* scrolled up and we're on the bottom line, the line won't be
|
|
|
|
* blank, so we don't need to draw it unless the mark is on or we're
|
|
|
|
* not on the first page. */
|
|
|
|
for (i = nlines; i > 0 && foo != NULL; i--) {
|
2014-06-23 18:20:12 +00:00
|
|
|
if ((i == nlines && direction == DOWNWARD) || (i == 1 &&
|
|
|
|
direction == UPWARD)) {
|
2005-07-23 20:39:41 +00:00
|
|
|
if (do_redraw)
|
|
|
|
update_line(foo, (foo == openfile->current) ?
|
|
|
|
openfile->current_x : 0);
|
|
|
|
} else
|
|
|
|
update_line(foo, (foo == openfile->current) ?
|
2005-07-16 22:50:30 +00:00
|
|
|
openfile->current_x : 0);
|
2005-07-14 18:01:08 +00:00
|
|
|
foo = foo->next;
|
2004-05-28 20:44:09 +00:00
|
|
|
}
|
2014-02-26 11:38:30 +00:00
|
|
|
compute_maxrows();
|
2004-05-28 20:44:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Update any lines between old_current and current that need to be
|
2005-07-26 14:26:47 +00:00
|
|
|
* updated. Use this if we've moved without changing any text. */
|
2009-01-25 07:25:17 +00:00
|
|
|
void edit_redraw(filestruct *old_current, size_t pww_save)
|
2004-05-28 20:44:09 +00:00
|
|
|
{
|
2009-01-25 07:25:17 +00:00
|
|
|
filestruct *foo = NULL;
|
2015-04-20 08:16:41 +00:00
|
|
|
bool do_redraw = need_screen_update(0) || need_screen_update(pww_save);
|
2004-05-28 20:44:09 +00:00
|
|
|
|
2005-08-01 21:05:29 +00:00
|
|
|
/* If either old_current or current is offscreen, scroll the edit
|
|
|
|
* window until it's onscreen and get out. */
|
2005-07-08 20:09:16 +00:00
|
|
|
if (old_current->lineno < openfile->edittop->lineno ||
|
|
|
|
old_current->lineno >= openfile->edittop->lineno +
|
2009-11-13 13:48:56 +00:00
|
|
|
maxrows || openfile->current->lineno <
|
2005-07-08 20:09:16 +00:00
|
|
|
openfile->edittop->lineno || openfile->current->lineno >=
|
2009-11-13 13:48:56 +00:00
|
|
|
openfile->edittop->lineno + maxrows) {
|
2010-01-13 03:21:19 +00:00
|
|
|
#ifdef DEBUG
|
2014-06-09 15:08:59 +00:00
|
|
|
fprintf(stderr, "edit_redraw(): line %ld was offscreen, oldcurrent = %ld edittop = %ld",
|
|
|
|
(long)openfile->current->lineno, (long)old_current->lineno, (long)openfile->edittop->lineno);
|
2010-01-13 03:21:19 +00:00
|
|
|
#endif
|
2005-08-01 21:05:29 +00:00
|
|
|
|
2006-05-26 03:04:24 +00:00
|
|
|
#ifndef NANO_TINY
|
|
|
|
/* If the mark is on, update all the lines between old_current
|
2006-05-26 03:46:03 +00:00
|
|
|
* and either the old first line or old last line (depending on
|
|
|
|
* whether we've scrolled up or down) of the edit window. */
|
2006-05-26 03:04:24 +00:00
|
|
|
if (openfile->mark_set) {
|
2006-05-26 03:46:03 +00:00
|
|
|
ssize_t old_lineno;
|
2013-01-03 04:23:10 +00:00
|
|
|
filestruct *old_edittop = openfile->edittop;
|
2006-05-26 03:46:03 +00:00
|
|
|
|
|
|
|
if (old_edittop->lineno < openfile->edittop->lineno)
|
|
|
|
old_lineno = old_edittop->lineno;
|
|
|
|
else
|
2009-11-13 13:48:56 +00:00
|
|
|
old_lineno = (old_edittop->lineno + maxrows <=
|
2006-05-26 03:46:03 +00:00
|
|
|
openfile->filebot->lineno) ?
|
|
|
|
old_edittop->lineno + editwinrows :
|
|
|
|
openfile->filebot->lineno;
|
2006-05-26 03:04:24 +00:00
|
|
|
|
|
|
|
foo = old_current;
|
|
|
|
|
2006-05-26 03:46:03 +00:00
|
|
|
while (foo->lineno != old_lineno) {
|
2006-05-26 03:04:24 +00:00
|
|
|
update_line(foo, 0);
|
|
|
|
|
2006-05-26 03:46:03 +00:00
|
|
|
foo = (foo->lineno > old_lineno) ? foo->prev :
|
2006-05-26 03:04:24 +00:00
|
|
|
foo->next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif /* !NANO_TINY */
|
|
|
|
|
2015-03-22 13:23:42 +00:00
|
|
|
/* Make sure the current line is on the screen. */
|
2015-03-28 17:01:46 +00:00
|
|
|
edit_update((ISSET(SMOOTH_SCROLL) && !focusing) ? NONE : CENTER);
|
2005-08-01 21:05:29 +00:00
|
|
|
|
2006-07-06 18:29:37 +00:00
|
|
|
/* Update old_current if we're not on the same page as
|
|
|
|
* before. */
|
2006-01-10 07:51:49 +00:00
|
|
|
if (do_redraw)
|
|
|
|
update_line(old_current, 0);
|
|
|
|
|
2006-05-26 03:04:24 +00:00
|
|
|
#ifndef NANO_TINY
|
2006-05-26 03:46:03 +00:00
|
|
|
/* If the mark is on, update all the lines between the old first
|
|
|
|
* line or old last line of the edit window (depending on
|
|
|
|
* whether we've scrolled up or down) and current. */
|
2006-05-26 03:04:24 +00:00
|
|
|
if (openfile->mark_set) {
|
2006-05-26 03:46:03 +00:00
|
|
|
while (foo->lineno != openfile->current->lineno) {
|
2006-05-26 03:04:24 +00:00
|
|
|
update_line(foo, 0);
|
|
|
|
|
2006-05-26 03:46:03 +00:00
|
|
|
foo = (foo->lineno > openfile->current->lineno) ?
|
2006-05-26 03:04:24 +00:00
|
|
|
foo->prev : foo->next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif /* !NANO_TINY */
|
|
|
|
|
2004-05-28 20:44:09 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2006-07-06 18:29:37 +00:00
|
|
|
/* Update old_current and current if we're not on the same page as
|
|
|
|
* before. If the mark is on, update all the lines between
|
|
|
|
* old_current and current too. */
|
2004-05-28 20:44:09 +00:00
|
|
|
foo = old_current;
|
2005-07-14 18:01:08 +00:00
|
|
|
|
2005-07-08 20:09:16 +00:00
|
|
|
while (foo != openfile->current) {
|
2005-07-23 20:39:41 +00:00
|
|
|
if (do_redraw)
|
2004-05-28 20:44:09 +00:00
|
|
|
update_line(foo, 0);
|
2005-07-16 02:12:18 +00:00
|
|
|
|
2005-11-15 03:17:35 +00:00
|
|
|
#ifndef NANO_TINY
|
2005-07-08 20:09:16 +00:00
|
|
|
if (!openfile->mark_set)
|
2004-05-28 20:44:09 +00:00
|
|
|
#endif
|
|
|
|
break;
|
2005-07-16 02:12:18 +00:00
|
|
|
|
2005-11-15 03:17:35 +00:00
|
|
|
#ifndef NANO_TINY
|
2005-07-16 02:12:18 +00:00
|
|
|
foo = (foo->lineno > openfile->current->lineno) ? foo->prev :
|
|
|
|
foo->next;
|
2005-07-08 20:09:16 +00:00
|
|
|
#endif
|
2004-05-28 20:44:09 +00:00
|
|
|
}
|
2005-07-14 18:01:08 +00:00
|
|
|
|
2005-07-23 20:39:41 +00:00
|
|
|
if (do_redraw)
|
2005-07-08 20:09:16 +00:00
|
|
|
update_line(openfile->current, openfile->current_x);
|
2004-05-28 20:44:09 +00:00
|
|
|
}
|
|
|
|
|
2005-07-26 14:26:47 +00:00
|
|
|
/* Refresh the screen without changing the position of lines. Use this
|
|
|
|
* if we've moved and changed text. */
|
2000-06-06 05:53:49 +00:00
|
|
|
void edit_refresh(void)
|
|
|
|
{
|
2009-01-25 07:25:17 +00:00
|
|
|
filestruct *foo;
|
2005-07-16 23:36:10 +00:00
|
|
|
int nlines;
|
2005-07-16 22:47:12 +00:00
|
|
|
|
2014-04-15 11:25:29 +00:00
|
|
|
/* Figure out what maxrows should really be. */
|
2009-11-16 04:28:40 +00:00
|
|
|
compute_maxrows();
|
2009-11-13 13:48:56 +00:00
|
|
|
|
2005-07-08 20:09:16 +00:00
|
|
|
if (openfile->current->lineno < openfile->edittop->lineno ||
|
|
|
|
openfile->current->lineno >= openfile->edittop->lineno +
|
2009-11-16 04:28:40 +00:00
|
|
|
maxrows) {
|
|
|
|
#ifdef DEBUG
|
2014-06-09 15:08:59 +00:00
|
|
|
fprintf(stderr, "edit_refresh(): line = %ld, edittop %ld + maxrows %d\n",
|
|
|
|
(long)openfile->current->lineno, (long)openfile->edittop->lineno, maxrows);
|
2009-11-16 04:28:40 +00:00
|
|
|
#endif
|
|
|
|
|
2015-03-22 13:23:42 +00:00
|
|
|
/* Make sure the current line is on the screen. */
|
2015-03-28 17:11:28 +00:00
|
|
|
edit_update(ISSET(SMOOTH_SCROLL) ? NONE : CENTER);
|
2009-11-16 04:28:40 +00:00
|
|
|
}
|
2000-06-06 05:53:49 +00:00
|
|
|
|
2005-07-16 23:36:10 +00:00
|
|
|
foo = openfile->edittop;
|
|
|
|
|
2004-02-24 20:41:39 +00:00
|
|
|
#ifdef DEBUG
|
2005-07-16 22:47:12 +00:00
|
|
|
fprintf(stderr, "edit_refresh(): edittop->lineno = %ld\n", (long)openfile->edittop->lineno);
|
2004-02-24 20:41:39 +00:00
|
|
|
#endif
|
2001-10-22 03:15:31 +00:00
|
|
|
|
2005-07-16 23:36:10 +00:00
|
|
|
for (nlines = 0; nlines < editwinrows && foo != NULL; nlines++) {
|
2009-08-17 07:52:10 +00:00
|
|
|
nlines += update_line(foo, (foo == openfile->current) ?
|
2005-07-08 20:09:16 +00:00
|
|
|
openfile->current_x : 0);
|
2005-07-16 22:47:12 +00:00
|
|
|
foo = foo->next;
|
|
|
|
}
|
|
|
|
|
2005-07-16 23:36:10 +00:00
|
|
|
for (; nlines < editwinrows; nlines++)
|
2005-07-16 22:47:12 +00:00
|
|
|
blank_line(edit, nlines, 0, COLS);
|
|
|
|
|
|
|
|
reset_cursor();
|
2005-07-26 14:42:57 +00:00
|
|
|
wnoutrefresh(edit);
|
2000-06-06 05:53:49 +00:00
|
|
|
}
|
|
|
|
|
2005-07-16 22:47:12 +00:00
|
|
|
/* Move edittop to put it in range of current, keeping current in the
|
|
|
|
* same place. location determines how we move it: if it's CENTER, we
|
|
|
|
* center current, and if it's NONE, we put current current_y lines
|
|
|
|
* below edittop. */
|
2005-08-01 18:27:10 +00:00
|
|
|
void edit_update(update_type location)
|
2000-06-06 05:53:49 +00:00
|
|
|
{
|
2005-07-08 20:09:16 +00:00
|
|
|
filestruct *foo = openfile->current;
|
2005-07-16 22:47:12 +00:00
|
|
|
int goal;
|
|
|
|
|
|
|
|
/* If location is CENTER, we move edittop up (editwinrows / 2)
|
|
|
|
* lines. This puts current at the center of the screen. If
|
|
|
|
* location is NONE, we move edittop up current_y lines if current_y
|
|
|
|
* is in range of the screen, 0 lines if current_y is less than 0,
|
|
|
|
* or (editwinrows - 1) lines if current_y is greater than
|
|
|
|
* (editwinrows - 1). This puts current at the same place on the
|
|
|
|
* screen as before, or at the top or bottom of the screen if
|
|
|
|
* edittop is beyond either. */
|
|
|
|
if (location == CENTER)
|
2010-01-04 19:00:55 +00:00
|
|
|
goal = editwinrows / 2;
|
2005-07-16 22:47:12 +00:00
|
|
|
else {
|
|
|
|
goal = openfile->current_y;
|
2004-08-26 18:07:58 +00:00
|
|
|
|
2005-07-16 22:47:12 +00:00
|
|
|
/* Limit goal to (editwinrows - 1) lines maximum. */
|
2010-01-04 19:00:55 +00:00
|
|
|
if (goal > editwinrows - 1)
|
|
|
|
goal = editwinrows - 1;
|
2002-07-19 01:08:59 +00:00
|
|
|
}
|
2004-08-27 17:02:05 +00:00
|
|
|
|
2009-09-13 04:50:44 +00:00
|
|
|
for (; goal > 0 && foo->prev != NULL; goal--) {
|
2005-07-16 22:47:12 +00:00
|
|
|
foo = foo->prev;
|
2014-06-09 20:26:54 +00:00
|
|
|
#ifndef NANO_TINY
|
2010-01-13 03:21:19 +00:00
|
|
|
if (ISSET(SOFTWRAP) && foo)
|
|
|
|
goal -= strlenpt(foo->data) / COLS;
|
2014-06-09 20:26:54 +00:00
|
|
|
#endif
|
2009-09-13 04:50:44 +00:00
|
|
|
}
|
2005-07-08 20:09:16 +00:00
|
|
|
openfile->edittop = foo;
|
2010-01-13 03:21:19 +00:00
|
|
|
#ifdef DEBUG
|
2014-06-10 19:07:47 +00:00
|
|
|
fprintf(stderr, "edit_update(): setting edittop to lineno %ld\n", (long)openfile->edittop->lineno);
|
2010-01-13 03:21:19 +00:00
|
|
|
#endif
|
2009-11-16 04:28:40 +00:00
|
|
|
compute_maxrows();
|
2010-01-13 03:21:19 +00:00
|
|
|
edit_refresh_needed = TRUE;
|
2000-06-06 05:53:49 +00:00
|
|
|
}
|
|
|
|
|
2005-12-08 07:09:08 +00:00
|
|
|
/* Unconditionally redraw the entire screen. */
|
2005-06-18 15:49:17 +00:00
|
|
|
void total_redraw(void)
|
2002-09-06 20:35:28 +00:00
|
|
|
{
|
2007-12-18 15:55:48 +00:00
|
|
|
#ifdef USE_SLANG
|
|
|
|
/* Slang curses emulation brain damage, part 4: Slang doesn't define
|
|
|
|
* curscr. */
|
|
|
|
SLsmg_touch_screen();
|
|
|
|
SLsmg_refresh();
|
|
|
|
#else
|
2005-07-10 02:37:38 +00:00
|
|
|
wrefresh(curscr);
|
2007-12-18 15:55:48 +00:00
|
|
|
#endif
|
2005-03-17 17:56:48 +00:00
|
|
|
}
|
|
|
|
|
2005-12-08 07:09:08 +00:00
|
|
|
/* Unconditionally redraw the entire screen, and then refresh it using
|
|
|
|
* the current file. */
|
2005-03-17 17:56:48 +00:00
|
|
|
void total_refresh(void)
|
|
|
|
{
|
2005-06-18 15:49:17 +00:00
|
|
|
total_redraw();
|
2002-09-06 20:35:28 +00:00
|
|
|
titlebar(NULL);
|
2004-12-04 17:41:52 +00:00
|
|
|
edit_refresh();
|
2008-03-05 07:34:01 +00:00
|
|
|
bottombars(currmenu);
|
2002-09-06 20:35:28 +00:00
|
|
|
}
|
|
|
|
|
2005-12-08 07:09:08 +00:00
|
|
|
/* Display the main shortcut list on the last two rows of the bottom
|
|
|
|
* portion of the window. */
|
2002-09-06 20:35:28 +00:00
|
|
|
void display_main_list(void)
|
|
|
|
{
|
2014-04-04 11:59:03 +00:00
|
|
|
#ifndef DISABLE_COLOR
|
2015-01-03 07:24:17 +00:00
|
|
|
if (openfile->syntax
|
|
|
|
&& (openfile->syntax->formatter || openfile->syntax->linter))
|
|
|
|
set_lint_or_format_shortcuts();
|
2014-02-24 10:18:15 +00:00
|
|
|
else
|
|
|
|
set_spell_shortcuts();
|
|
|
|
#endif
|
|
|
|
|
2008-03-05 07:34:01 +00:00
|
|
|
bottombars(MMAIN);
|
2002-09-06 20:35:28 +00:00
|
|
|
}
|
|
|
|
|
2005-06-28 20:04:14 +00:00
|
|
|
/* If constant is TRUE, we display the current cursor position only if
|
|
|
|
* disable_cursorpos is FALSE. Otherwise, we display it
|
|
|
|
* unconditionally and set disable_cursorpos to FALSE. If constant is
|
|
|
|
* TRUE and disable_cursorpos is TRUE, we also set disable_cursorpos to
|
|
|
|
* FALSE, so that we leave the current statusbar alone this time, and
|
|
|
|
* display the current cursor position next time. */
|
2004-08-25 15:39:10 +00:00
|
|
|
void do_cursorpos(bool constant)
|
2000-06-06 05:53:49 +00:00
|
|
|
{
|
2005-08-01 02:18:05 +00:00
|
|
|
filestruct *f;
|
2005-07-31 20:15:01 +00:00
|
|
|
char c;
|
2005-07-31 20:20:37 +00:00
|
|
|
size_t i, cur_xpt = xplustabs() + 1;
|
2005-07-08 20:09:16 +00:00
|
|
|
size_t cur_lenpt = strlenpt(openfile->current->data) + 1;
|
2005-06-28 20:04:14 +00:00
|
|
|
int linepct, colpct, charpct;
|
2000-06-06 05:53:49 +00:00
|
|
|
|
2005-07-31 18:51:51 +00:00
|
|
|
assert(openfile->fileage != NULL && openfile->current != NULL);
|
2001-11-29 03:43:08 +00:00
|
|
|
|
2005-08-01 02:18:05 +00:00
|
|
|
f = openfile->current->next;
|
2005-07-31 20:15:01 +00:00
|
|
|
c = openfile->current->data[openfile->current_x];
|
2005-08-01 02:18:05 +00:00
|
|
|
|
|
|
|
openfile->current->next = NULL;
|
2005-07-31 20:15:01 +00:00
|
|
|
openfile->current->data[openfile->current_x] = '\0';
|
2005-08-01 02:18:05 +00:00
|
|
|
|
|
|
|
i = get_totsize(openfile->fileage, openfile->current);
|
|
|
|
|
2005-07-31 20:15:01 +00:00
|
|
|
openfile->current->data[openfile->current_x] = c;
|
2005-08-01 02:18:05 +00:00
|
|
|
openfile->current->next = f;
|
2002-01-25 21:59:02 +00:00
|
|
|
|
2005-06-17 18:27:00 +00:00
|
|
|
if (constant && disable_cursorpos) {
|
|
|
|
disable_cursorpos = FALSE;
|
2004-07-02 14:31:03 +00:00
|
|
|
return;
|
2003-01-28 01:16:47 +00:00
|
|
|
}
|
2000-06-06 05:53:49 +00:00
|
|
|
|
2007-04-19 03:15:04 +00:00
|
|
|
/* Display the current cursor position on the statusbar, and set
|
2005-06-28 20:04:14 +00:00
|
|
|
* disable_cursorpos to FALSE. */
|
2015-07-10 17:25:51 +00:00
|
|
|
linepct = 100 * openfile->current->lineno / openfile->filebot->lineno;
|
2005-06-28 20:04:14 +00:00
|
|
|
colpct = 100 * cur_xpt / cur_lenpt;
|
2015-07-10 17:25:51 +00:00
|
|
|
charpct = (openfile->totsize == 0) ? 0 : 100 * i / openfile->totsize;
|
2005-06-28 20:04:14 +00:00
|
|
|
|
|
|
|
statusbar(
|
2005-07-25 21:23:11 +00:00
|
|
|
_("line %ld/%ld (%d%%), col %lu/%lu (%d%%), char %lu/%lu (%d%%)"),
|
2005-07-08 20:09:16 +00:00
|
|
|
(long)openfile->current->lineno,
|
2005-07-25 21:23:11 +00:00
|
|
|
(long)openfile->filebot->lineno, linepct,
|
2005-06-28 20:04:14 +00:00
|
|
|
(unsigned long)cur_xpt, (unsigned long)cur_lenpt, colpct,
|
2005-07-08 20:09:16 +00:00
|
|
|
(unsigned long)i, (unsigned long)openfile->totsize, charpct);
|
2001-11-29 03:43:08 +00:00
|
|
|
|
2005-06-28 20:04:14 +00:00
|
|
|
disable_cursorpos = FALSE;
|
2000-06-06 05:53:49 +00:00
|
|
|
}
|
|
|
|
|
2005-12-08 07:09:08 +00:00
|
|
|
/* Unconditionally display the current cursor position. */
|
2004-07-02 14:31:03 +00:00
|
|
|
void do_cursorpos_void(void)
|
2001-11-29 03:43:08 +00:00
|
|
|
{
|
2004-07-02 14:31:03 +00:00
|
|
|
do_cursorpos(FALSE);
|
2001-11-29 03:43:08 +00:00
|
|
|
}
|
|
|
|
|
2009-01-24 22:40:41 +00:00
|
|
|
void enable_nodelay(void)
|
|
|
|
{
|
2014-06-20 10:48:26 +00:00
|
|
|
nodelay_mode = TRUE;
|
|
|
|
nodelay(edit, TRUE);
|
2009-01-24 22:40:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void disable_nodelay(void)
|
|
|
|
{
|
2014-06-20 10:48:26 +00:00
|
|
|
nodelay_mode = FALSE;
|
|
|
|
nodelay(edit, FALSE);
|
2009-01-24 22:40:41 +00:00
|
|
|
}
|
|
|
|
|
2003-09-16 01:16:49 +00:00
|
|
|
/* Highlight the current word being replaced or spell checked. We
|
|
|
|
* expect word to have tabs and control characters expanded. */
|
2005-06-30 03:55:55 +00:00
|
|
|
void do_replace_highlight(bool highlight, const char *word)
|
2000-12-05 11:36:41 +00:00
|
|
|
{
|
2005-06-30 03:53:28 +00:00
|
|
|
size_t y = xplustabs(), word_len = strlenpt(word);
|
2002-07-19 01:08:59 +00:00
|
|
|
|
2003-09-16 01:16:49 +00:00
|
|
|
y = get_page_start(y) + COLS - y;
|
2005-01-05 05:08:14 +00:00
|
|
|
/* Now y is the number of columns that we can display on this
|
2003-09-16 01:16:49 +00:00
|
|
|
* line. */
|
2000-12-05 11:36:41 +00:00
|
|
|
|
2005-01-05 05:08:14 +00:00
|
|
|
assert(y > 0);
|
|
|
|
|
|
|
|
if (word_len > y)
|
|
|
|
y--;
|
|
|
|
|
2000-12-05 11:36:41 +00:00
|
|
|
reset_cursor();
|
2007-12-04 16:38:47 +00:00
|
|
|
wnoutrefresh(edit);
|
2002-01-19 01:59:37 +00:00
|
|
|
|
2005-06-30 03:55:55 +00:00
|
|
|
if (highlight)
|
2014-05-04 08:53:06 +00:00
|
|
|
wattron(edit, hilite_attribute);
|
2000-12-05 11:36:41 +00:00
|
|
|
|
2006-11-10 20:13:38 +00:00
|
|
|
/* This is so we can show zero-length matches. */
|
2003-12-24 08:17:54 +00:00
|
|
|
if (word_len == 0)
|
2005-06-13 02:22:44 +00:00
|
|
|
waddch(edit, ' ');
|
2003-12-24 08:17:54 +00:00
|
|
|
else
|
2005-01-05 05:08:14 +00:00
|
|
|
waddnstr(edit, word, actual_x(word, y));
|
2003-09-16 01:16:49 +00:00
|
|
|
|
|
|
|
if (word_len > y)
|
|
|
|
waddch(edit, '$');
|
2000-12-05 11:36:41 +00:00
|
|
|
|
2005-06-30 03:55:55 +00:00
|
|
|
if (highlight)
|
2014-05-04 08:53:06 +00:00
|
|
|
wattroff(edit, hilite_attribute);
|
2000-12-05 11:36:41 +00:00
|
|
|
}
|
|
|
|
|
2014-04-03 20:57:44 +00:00
|
|
|
#ifndef DISABLE_EXTRA
|
2015-02-01 09:19:58 +00:00
|
|
|
#define CREDIT_LEN 54
|
|
|
|
#define XLCREDIT_LEN 9
|
2002-07-21 15:44:13 +00:00
|
|
|
|
2005-08-16 03:02:46 +00:00
|
|
|
/* Easter egg: Display credits. Assume nodelay(edit) and scrollok(edit)
|
|
|
|
* are FALSE. */
|
2000-11-24 20:45:14 +00:00
|
|
|
void do_credits(void)
|
|
|
|
{
|
2005-08-14 19:25:16 +00:00
|
|
|
bool old_more_space = ISSET(MORE_SPACE);
|
|
|
|
bool old_no_help = ISSET(NO_HELP);
|
2005-06-07 03:20:35 +00:00
|
|
|
int kbinput = ERR, crpos = 0, xlpos = 0;
|
2004-05-18 01:20:36 +00:00
|
|
|
const char *credits[CREDIT_LEN] = {
|
|
|
|
NULL, /* "The nano text editor" */
|
|
|
|
NULL, /* "version" */
|
2002-01-19 01:59:37 +00:00
|
|
|
VERSION,
|
|
|
|
"",
|
2004-05-18 01:20:36 +00:00
|
|
|
NULL, /* "Brought to you by:" */
|
2002-01-19 01:59:37 +00:00
|
|
|
"Chris Allegretta",
|
|
|
|
"Jordi Mallach",
|
|
|
|
"Adam Rogoyski",
|
|
|
|
"Rob Siemborski",
|
|
|
|
"Rocco Corsi",
|
2002-02-15 19:17:02 +00:00
|
|
|
"David Lawrence Ramsey",
|
2002-11-04 16:05:42 +00:00
|
|
|
"David Benbennick",
|
2014-12-28 22:27:56 +00:00
|
|
|
"Mark Majeres",
|
2005-08-29 18:29:02 +00:00
|
|
|
"Mike Frysinger",
|
2014-02-24 15:15:51 +00:00
|
|
|
"Benno Schulenberg",
|
2002-01-19 01:59:37 +00:00
|
|
|
"Ken Tyler",
|
|
|
|
"Sven Guckes",
|
|
|
|
"Bill Soudan",
|
|
|
|
"Christian Weisgerber",
|
|
|
|
"Erik Andersen",
|
|
|
|
"Big Gaute",
|
|
|
|
"Joshua Jensen",
|
|
|
|
"Ryan Krebs",
|
|
|
|
"Albert Chin",
|
|
|
|
"",
|
2004-05-18 01:20:36 +00:00
|
|
|
NULL, /* "Special thanks to:" */
|
2014-02-24 15:15:51 +00:00
|
|
|
"Monique, Brielle & Joseph",
|
2002-01-19 01:59:37 +00:00
|
|
|
"Plattsburgh State University",
|
|
|
|
"Benet Laboratories",
|
|
|
|
"Amy Allegretta",
|
|
|
|
"Linda Young",
|
|
|
|
"Jeremy Robichaud",
|
|
|
|
"Richard Kolb II",
|
2004-05-18 01:20:36 +00:00
|
|
|
NULL, /* "The Free Software Foundation" */
|
2002-01-19 01:59:37 +00:00
|
|
|
"Linus Torvalds",
|
2015-02-01 09:19:58 +00:00
|
|
|
NULL, /* "the many translators and the TP" */
|
2004-05-18 01:20:36 +00:00
|
|
|
NULL, /* "For ncurses:" */
|
2002-03-16 01:03:41 +00:00
|
|
|
"Thomas Dickey",
|
|
|
|
"Pavel Curtis",
|
|
|
|
"Zeyd Ben-Halim",
|
|
|
|
"Eric S. Raymond",
|
2004-05-18 01:20:36 +00:00
|
|
|
NULL, /* "and anyone else we forgot..." */
|
|
|
|
NULL, /* "Thank you for using nano!" */
|
|
|
|
"",
|
|
|
|
"",
|
|
|
|
"",
|
|
|
|
"",
|
2015-02-01 09:32:02 +00:00
|
|
|
"(C) 1999 - 2015",
|
2007-10-11 05:01:32 +00:00
|
|
|
"Free Software Foundation, Inc.",
|
2004-05-18 01:20:36 +00:00
|
|
|
"",
|
|
|
|
"",
|
|
|
|
"",
|
|
|
|
"",
|
2002-11-04 16:05:42 +00:00
|
|
|
"http://www.nano-editor.org/"
|
2000-11-24 20:45:14 +00:00
|
|
|
};
|
|
|
|
|
2004-05-18 01:20:36 +00:00
|
|
|
const char *xlcredits[XLCREDIT_LEN] = {
|
2004-07-12 03:10:30 +00:00
|
|
|
N_("The nano text editor"),
|
|
|
|
N_("version"),
|
|
|
|
N_("Brought to you by:"),
|
|
|
|
N_("Special thanks to:"),
|
|
|
|
N_("The Free Software Foundation"),
|
2015-02-01 09:19:58 +00:00
|
|
|
N_("the many translators and the TP"),
|
2004-07-12 03:10:30 +00:00
|
|
|
N_("For ncurses:"),
|
|
|
|
N_("and anyone else we forgot..."),
|
|
|
|
N_("Thank you for using nano!")
|
2004-05-18 01:20:36 +00:00
|
|
|
};
|
2002-07-21 15:44:13 +00:00
|
|
|
|
2005-08-14 19:25:16 +00:00
|
|
|
if (!old_more_space || !old_no_help) {
|
|
|
|
SET(MORE_SPACE);
|
|
|
|
SET(NO_HELP);
|
|
|
|
window_init();
|
|
|
|
}
|
|
|
|
|
2000-11-24 20:45:14 +00:00
|
|
|
curs_set(0);
|
|
|
|
nodelay(edit, TRUE);
|
2005-08-14 19:25:16 +00:00
|
|
|
|
2004-05-18 01:20:36 +00:00
|
|
|
blank_titlebar();
|
2005-01-17 05:06:55 +00:00
|
|
|
blank_topbar();
|
2000-11-25 18:21:37 +00:00
|
|
|
blank_edit();
|
2004-05-18 01:20:36 +00:00
|
|
|
blank_statusbar();
|
|
|
|
blank_bottombars();
|
2005-08-14 21:17:37 +00:00
|
|
|
|
2004-05-18 01:20:36 +00:00
|
|
|
wrefresh(topwin);
|
2000-11-25 18:21:37 +00:00
|
|
|
wrefresh(edit);
|
2000-11-24 20:45:14 +00:00
|
|
|
wrefresh(bottomwin);
|
2005-08-14 21:17:37 +00:00
|
|
|
napms(700);
|
2000-11-24 20:45:14 +00:00
|
|
|
|
2004-05-18 01:20:36 +00:00
|
|
|
for (crpos = 0; crpos < CREDIT_LEN + editwinrows / 2; crpos++) {
|
2005-06-07 03:20:35 +00:00
|
|
|
if ((kbinput = wgetch(edit)) != ERR)
|
2004-05-18 01:20:36 +00:00
|
|
|
break;
|
2005-03-15 06:34:09 +00:00
|
|
|
|
2004-05-18 01:20:36 +00:00
|
|
|
if (crpos < CREDIT_LEN) {
|
2005-06-28 07:26:11 +00:00
|
|
|
const char *what;
|
2004-05-18 01:20:36 +00:00
|
|
|
size_t start_x;
|
|
|
|
|
2005-03-15 06:58:02 +00:00
|
|
|
if (credits[crpos] == NULL) {
|
2004-05-18 01:20:36 +00:00
|
|
|
assert(0 <= xlpos && xlpos < XLCREDIT_LEN);
|
2005-03-15 06:58:02 +00:00
|
|
|
|
2005-06-28 07:26:11 +00:00
|
|
|
what = _(xlcredits[xlpos]);
|
2004-05-18 01:20:36 +00:00
|
|
|
xlpos++;
|
2005-03-15 06:58:02 +00:00
|
|
|
} else
|
2005-06-28 07:26:11 +00:00
|
|
|
what = credits[crpos];
|
2005-03-15 06:58:02 +00:00
|
|
|
|
2004-12-23 17:43:27 +00:00
|
|
|
start_x = COLS / 2 - strlenpt(what) / 2 - 1;
|
2005-03-15 06:58:02 +00:00
|
|
|
mvwaddstr(edit, editwinrows - 1 - (editwinrows % 2),
|
|
|
|
start_x, what);
|
2000-11-24 20:45:14 +00:00
|
|
|
}
|
2005-03-15 06:34:09 +00:00
|
|
|
|
2005-08-14 21:17:37 +00:00
|
|
|
wrefresh(edit);
|
|
|
|
|
|
|
|
if ((kbinput = wgetch(edit)) != ERR)
|
|
|
|
break;
|
2004-05-18 01:20:36 +00:00
|
|
|
napms(700);
|
2005-08-14 21:17:37 +00:00
|
|
|
|
2005-08-14 19:25:16 +00:00
|
|
|
scrollok(edit, TRUE);
|
2005-08-14 21:17:37 +00:00
|
|
|
wscrl(edit, 1);
|
2005-08-14 19:25:16 +00:00
|
|
|
scrollok(edit, FALSE);
|
2004-05-18 01:20:36 +00:00
|
|
|
wrefresh(edit);
|
2005-08-14 21:17:37 +00:00
|
|
|
|
2005-06-07 03:20:35 +00:00
|
|
|
if ((kbinput = wgetch(edit)) != ERR)
|
2000-11-24 20:45:14 +00:00
|
|
|
break;
|
2004-05-18 01:20:36 +00:00
|
|
|
napms(700);
|
2005-08-14 21:17:37 +00:00
|
|
|
|
2005-08-14 19:25:16 +00:00
|
|
|
scrollok(edit, TRUE);
|
2005-08-14 21:17:37 +00:00
|
|
|
wscrl(edit, 1);
|
2005-08-14 19:25:16 +00:00
|
|
|
scrollok(edit, FALSE);
|
2004-05-18 01:20:36 +00:00
|
|
|
wrefresh(edit);
|
2000-11-24 20:45:14 +00:00
|
|
|
}
|
|
|
|
|
2005-06-07 03:20:35 +00:00
|
|
|
if (kbinput != ERR)
|
|
|
|
ungetch(kbinput);
|
|
|
|
|
2005-08-14 19:25:16 +00:00
|
|
|
if (!old_more_space || !old_no_help) {
|
|
|
|
UNSET(MORE_SPACE);
|
|
|
|
UNSET(NO_HELP);
|
|
|
|
window_init();
|
|
|
|
}
|
|
|
|
|
2005-06-07 03:20:35 +00:00
|
|
|
curs_set(1);
|
2000-11-24 20:45:14 +00:00
|
|
|
nodelay(edit, FALSE);
|
2005-08-14 19:25:16 +00:00
|
|
|
|
2000-11-24 20:45:14 +00:00
|
|
|
total_refresh();
|
2002-01-19 01:59:37 +00:00
|
|
|
}
|
2014-04-03 20:57:44 +00:00
|
|
|
#endif /* !DISABLE_EXTRA */
|