2000-06-06 05:53:49 +00:00
|
|
|
/**************************************************************************
|
2016-08-29 15:10:49 +00:00
|
|
|
* winio.c -- This file is part of GNU nano. *
|
2000-06-06 05:53:49 +00:00
|
|
|
* *
|
2021-01-11 13:21:03 +00:00
|
|
|
* Copyright (C) 1999-2011, 2013-2021 Free Software Foundation, Inc. *
|
2021-09-24 09:01:41 +00:00
|
|
|
* Copyright (C) 2014-2021 Benno Schulenberg *
|
2016-08-29 13:14:18 +00:00
|
|
|
* *
|
2016-08-29 15:10:49 +00:00
|
|
|
* GNU nano is free software: you can redistribute it and/or modify *
|
|
|
|
* it under the terms of the GNU General Public License as published *
|
|
|
|
* by the Free Software Foundation, either version 3 of the License, *
|
|
|
|
* or (at your option) any later version. *
|
2000-06-06 05:53:49 +00:00
|
|
|
* *
|
2016-08-29 15:10:49 +00:00
|
|
|
* GNU nano 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 *
|
2016-08-29 15:10:49 +00:00
|
|
|
* along with this program. If not, see http://www.gnu.org/licenses/. *
|
2000-06-06 05:53:49 +00:00
|
|
|
* *
|
|
|
|
**************************************************************************/
|
|
|
|
|
2020-06-20 10:09:31 +00:00
|
|
|
#include "prototypes.h"
|
2016-05-20 10:59:57 +00:00
|
|
|
#include "revision.h"
|
2002-09-13 18:14:04 +00:00
|
|
|
|
2017-08-06 11:32:44 +00:00
|
|
|
#include <ctype.h>
|
2016-09-08 19:00:51 +00:00
|
|
|
#ifdef __linux__
|
2016-07-29 07:15:07 +00:00
|
|
|
#include <sys/ioctl.h>
|
2016-08-11 10:37:11 +00:00
|
|
|
#endif
|
2000-06-06 05:53:49 +00:00
|
|
|
#include <string.h>
|
2019-06-11 10:29:32 +00:00
|
|
|
#ifdef ENABLE_UTF8
|
|
|
|
#include <wchar.h>
|
|
|
|
#endif
|
2000-06-06 05:53:49 +00:00
|
|
|
|
2016-05-20 10:59:57 +00:00
|
|
|
#ifdef REVISION
|
2020-05-29 16:45:14 +00:00
|
|
|
#define BRANDING REVISION
|
2016-05-20 10:59:57 +00:00
|
|
|
#else
|
2020-05-29 16:45:14 +00:00
|
|
|
#define BRANDING PACKAGE_STRING
|
2016-05-20 10:59:57 +00:00
|
|
|
#endif
|
|
|
|
|
2020-11-26 13:25:16 +00:00
|
|
|
/* When having an older ncurses, then most likely libvte is older too. */
|
|
|
|
#if defined(NCURSES_VERSION_PATCH) && (NCURSES_VERSION_PATCH < 20200212)
|
|
|
|
#define USING_OLDER_LIBVTE yes
|
|
|
|
#endif
|
|
|
|
|
2005-01-12 03:25:57 +00:00
|
|
|
static int *key_buffer = NULL;
|
2018-01-10 18:25:23 +00:00
|
|
|
/* A buffer for the keystrokes that haven't been handled yet. */
|
2004-12-04 17:41:52 +00:00
|
|
|
static size_t key_buffer_len = 0;
|
2017-12-29 18:27:33 +00:00
|
|
|
/* The length of the keystroke buffer. */
|
2018-01-11 11:47:42 +00:00
|
|
|
static int digit_count = 0;
|
2018-01-11 09:14:04 +00:00
|
|
|
/* How many digits of a three-digit character code we've eaten. */
|
2020-01-27 12:36:28 +00:00
|
|
|
static bool reveal_cursor = FALSE;
|
|
|
|
/* Whether the cursor should be shown when waiting for input. */
|
2020-08-08 05:40:33 +00:00
|
|
|
static bool linger_after_escape = FALSE;
|
|
|
|
/* Whether to give ncurses some time to get the next code. */
|
2005-06-25 20:56:36 +00:00
|
|
|
static int statusblank = 0;
|
2020-01-16 15:16:31 +00:00
|
|
|
/* The number of keystrokes left before we blank the status bar. */
|
2021-04-07 09:11:05 +00:00
|
|
|
size_t from_x = 0;
|
|
|
|
/* From where in the relevant line the current row is drawn. */
|
|
|
|
size_t till_x = 0;
|
|
|
|
/* Until where in the relevant line the current row is drawn. */
|
2020-01-26 19:01:34 +00:00
|
|
|
static bool has_more = FALSE;
|
|
|
|
/* Whether the current line has more text after the displayed part. */
|
2020-01-27 12:36:28 +00:00
|
|
|
static bool is_shorter = TRUE;
|
|
|
|
/* Whether a row's text is narrower than the screen's width. */
|
2017-10-09 22:03:51 +00:00
|
|
|
#ifndef NANO_TINY
|
2020-01-27 14:36:37 +00:00
|
|
|
static size_t sequel_column = 0;
|
|
|
|
/* The starting column of the next chunk when softwrapping. */
|
2017-10-09 22:03:51 +00:00
|
|
|
static bool recording = FALSE;
|
2017-12-29 18:27:33 +00:00
|
|
|
/* Whether we are in the process of recording a macro. */
|
2017-10-09 22:03:51 +00:00
|
|
|
static int *macro_buffer = NULL;
|
2017-12-29 18:27:33 +00:00
|
|
|
/* A buffer where the recorded key codes are stored. */
|
2017-10-09 22:03:51 +00:00
|
|
|
static size_t macro_length = 0;
|
2017-12-29 18:27:33 +00:00
|
|
|
/* The current length of the macro. */
|
2017-10-09 22:03:51 +00:00
|
|
|
|
|
|
|
/* Add the given code to the macro buffer. */
|
|
|
|
void add_to_macrobuffer(int code)
|
|
|
|
{
|
2017-12-29 18:27:33 +00:00
|
|
|
macro_length++;
|
2020-08-30 02:57:45 +00:00
|
|
|
macro_buffer = nrealloc(macro_buffer, macro_length * sizeof(int));
|
2017-12-29 18:27:33 +00:00
|
|
|
macro_buffer[macro_length - 1] = code;
|
2017-10-09 22:03:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Remove the last key code plus any trailing Esc codes from macro buffer. */
|
|
|
|
void snip_last_keystroke(void)
|
|
|
|
{
|
|
|
|
macro_length--;
|
2017-12-29 18:27:33 +00:00
|
|
|
while (macro_length > 0 && macro_buffer[macro_length - 1] == '\x1b')
|
|
|
|
macro_length--;
|
2017-10-09 22:03:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Start or stop the recording of keystrokes. */
|
|
|
|
void record_macro(void)
|
|
|
|
{
|
2017-12-29 18:27:33 +00:00
|
|
|
recording = !recording;
|
2017-10-09 22:03:51 +00:00
|
|
|
|
2017-12-29 18:27:33 +00:00
|
|
|
if (recording) {
|
|
|
|
macro_length = 0;
|
2020-12-08 16:09:07 +00:00
|
|
|
statusline(REMARK, _("Recording a macro..."));
|
2017-12-29 18:27:33 +00:00
|
|
|
} else {
|
|
|
|
snip_last_keystroke();
|
2020-12-08 16:09:07 +00:00
|
|
|
statusline(REMARK, _("Stopped recording"));
|
2017-12-29 18:27:33 +00:00
|
|
|
}
|
2020-09-19 17:50:45 +00:00
|
|
|
|
|
|
|
if (ISSET(STATEFLAGS))
|
|
|
|
titlebar(NULL);
|
2017-10-09 22:03:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Copy the stored sequence of codes into the regular key buffer,
|
|
|
|
* so they will be "executed" again. */
|
|
|
|
void run_macro(void)
|
|
|
|
{
|
2017-12-29 18:27:33 +00:00
|
|
|
if (recording) {
|
2020-12-08 16:09:07 +00:00
|
|
|
statusline(AHEM, _("Cannot run macro while recording"));
|
2017-12-29 18:27:33 +00:00
|
|
|
snip_last_keystroke();
|
|
|
|
return;
|
|
|
|
}
|
2017-10-09 22:03:51 +00:00
|
|
|
|
2017-12-29 18:27:33 +00:00
|
|
|
if (macro_length == 0) {
|
2020-12-08 16:09:07 +00:00
|
|
|
statusline(REMARK, _("Macro is empty"));
|
2017-12-29 18:27:33 +00:00
|
|
|
return;
|
|
|
|
}
|
2017-10-09 22:03:51 +00:00
|
|
|
|
2020-08-30 02:57:45 +00:00
|
|
|
key_buffer = nrealloc(key_buffer, macro_length * sizeof(int));
|
2017-12-29 18:27:33 +00:00
|
|
|
key_buffer_len = macro_length;
|
2017-10-09 22:03:51 +00:00
|
|
|
|
2020-01-28 09:20:17 +00:00
|
|
|
for (size_t i = 0; i < macro_length; i++)
|
2017-12-29 18:27:33 +00:00
|
|
|
key_buffer[i] = macro_buffer[i];
|
2020-01-23 11:32:28 +00:00
|
|
|
|
|
|
|
mute_modifiers = TRUE;
|
2017-10-09 22:03:51 +00:00
|
|
|
}
|
|
|
|
#endif /* !NANO_TINY */
|
2000-06-06 23:04:06 +00:00
|
|
|
|
2004-05-01 01:21:38 +00:00
|
|
|
/* Control character compatibility:
|
|
|
|
*
|
2016-07-22 13:57:20 +00:00
|
|
|
* - Ctrl-H is Backspace under ASCII, ANSI, VT100, and VT220.
|
|
|
|
* - Ctrl-I is Tab under ASCII, ANSI, VT100, VT220, and VT320.
|
|
|
|
* - Ctrl-M is Enter under ASCII, ANSI, VT100, VT220, and VT320.
|
|
|
|
* - Ctrl-Q is XON under ASCII, ANSI, VT100, VT220, and VT320.
|
|
|
|
* - Ctrl-S is XOFF under ASCII, ANSI, VT100, VT220, and VT320.
|
2018-12-30 17:00:28 +00:00
|
|
|
* - Ctrl-? is Delete under ASCII, ANSI, VT100, and VT220,
|
2016-08-01 10:56:05 +00:00
|
|
|
* but is Backspace under VT320.
|
2004-05-01 01:21:38 +00:00
|
|
|
*
|
2019-12-29 13:13:27 +00:00
|
|
|
* Note: the VT220 and VT320 also generate Esc [ 3 ~ for Delete. By default,
|
|
|
|
* xterm assumes it's running on a VT320 and generates Ctrl-? for Backspace
|
|
|
|
* and Esc [ 3 ~ for Delete. This causes problems for VT100-derived terminals
|
|
|
|
* such as the FreeBSD console, which expect Ctrl-H for Backspace and Ctrl-?
|
|
|
|
* for Delete, and on which ncurses translates the VT320 sequences to KEY_DC
|
|
|
|
* and [nothing]. We work around this conflict via the REBIND_DELETE flag:
|
|
|
|
* if it's set, we assume VT100 compatibility, and VT320 otherwise.
|
2004-05-01 01:21:38 +00:00
|
|
|
*
|
|
|
|
* Escape sequence compatibility:
|
|
|
|
*
|
|
|
|
* We support escape sequences for ANSI, VT100, VT220, VT320, the Linux
|
2019-12-26 13:32:44 +00:00
|
|
|
* console, the FreeBSD console, the Mach console, xterm, and Terminal,
|
|
|
|
* and some for Konsole, rxvt, Eterm, and iTerm2. Among these sequences,
|
|
|
|
* there are several conflicts and omissions:
|
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
|
2019-12-29 13:13:27 +00:00
|
|
|
* 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
|
2006-07-31 23:29:22 +00:00
|
|
|
* omitted. (Same as above.) */
|
2004-04-23 18:02:37 +00:00
|
|
|
|
2017-12-26 21:09:00 +00:00
|
|
|
/* Read in a sequence of keystrokes from the given window and save them
|
|
|
|
* in the keystroke buffer. */
|
2018-01-10 16:40:07 +00:00
|
|
|
void read_keys_from(WINDOW *win)
|
2004-08-25 16:37:06 +00:00
|
|
|
{
|
2017-12-29 18:27:33 +00:00
|
|
|
int input = ERR;
|
|
|
|
size_t errcount = 0;
|
2020-12-04 10:50:23 +00:00
|
|
|
#ifndef NANO_TINY
|
|
|
|
bool timed = FALSE;
|
|
|
|
#endif
|
2004-12-04 17:41:52 +00:00
|
|
|
|
2021-05-10 10:17:35 +00:00
|
|
|
/* On a one-row terminal, overwrite an unimportant message. */
|
|
|
|
if (LINES == 1 && currmenu == MMAIN && lastmessage == HUSH)
|
|
|
|
edit_refresh();
|
|
|
|
|
2017-12-29 18:27:33 +00:00
|
|
|
/* Before reading the first keycode, display any pending screen updates. */
|
|
|
|
doupdate();
|
2005-07-26 14:42:57 +00:00
|
|
|
|
2021-05-10 10:17:35 +00:00
|
|
|
if (reveal_cursor && !hide_cursor && (LINES > 1 || lastmessage <= HUSH))
|
2017-12-29 18:27:33 +00:00
|
|
|
curs_set(1);
|
2017-09-18 18:34:57 +00:00
|
|
|
|
2020-12-04 10:50:23 +00:00
|
|
|
#ifndef NANO_TINY
|
2021-05-31 08:40:46 +00:00
|
|
|
if (currmenu == MMAIN && (spotlighted || ((ISSET(MINIBAR) || LINES == 1) &&
|
|
|
|
lastmessage > HUSH &&
|
|
|
|
lastmessage != INFO && lastmessage < ALERT))) {
|
2020-12-04 10:50:23 +00:00
|
|
|
timed = TRUE;
|
2021-02-07 11:09:38 +00:00
|
|
|
halfdelay(ISSET(QUICK_BLANK) ? 8 : 15);
|
2020-12-19 19:09:56 +00:00
|
|
|
disable_kb_interrupt();
|
2020-12-04 10:50:23 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2020-08-20 07:17:48 +00:00
|
|
|
/* Read in the first keycode, waiting for it to arrive. */
|
2017-12-29 18:27:33 +00:00
|
|
|
while (input == ERR) {
|
|
|
|
input = wgetch(win);
|
2016-05-17 20:12:28 +00:00
|
|
|
|
2016-05-18 09:14:17 +00:00
|
|
|
#ifndef NANO_TINY
|
2017-12-29 18:27:33 +00:00
|
|
|
if (the_window_resized) {
|
|
|
|
regenerate_screen();
|
|
|
|
input = KEY_WINCH;
|
|
|
|
}
|
2020-12-04 10:50:23 +00:00
|
|
|
|
|
|
|
if (timed) {
|
|
|
|
timed = FALSE;
|
|
|
|
raw();
|
|
|
|
|
|
|
|
if (input == ERR) {
|
2021-05-31 08:40:46 +00:00
|
|
|
if (spotlighted || LINES == 1) {
|
2021-05-12 14:00:11 +00:00
|
|
|
lastmessage = VACUUM;
|
2021-05-31 08:40:46 +00:00
|
|
|
spotlighted = FALSE;
|
2021-06-11 14:44:31 +00:00
|
|
|
update_line(openfile->current, openfile->current_x);
|
|
|
|
wnoutrefresh(edit);
|
2021-05-10 15:03:17 +00:00
|
|
|
curs_set(1);
|
2021-05-31 08:40:46 +00:00
|
|
|
}
|
|
|
|
if (ISSET(MINIBAR) && LINES > 1)
|
2021-05-10 15:03:17 +00:00
|
|
|
minibar();
|
2020-12-08 16:09:07 +00:00
|
|
|
as_an_at = TRUE;
|
2020-12-04 10:50:23 +00:00
|
|
|
place_the_cursor();
|
|
|
|
doupdate();
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
2016-05-18 09:14:17 +00:00
|
|
|
#endif
|
2021-06-29 11:20:16 +00:00
|
|
|
/* When we've failed to get a keycode millions of times in a row,
|
2017-12-29 18:27:33 +00:00
|
|
|
* assume our input source is gone and die gracefully. We could
|
|
|
|
* check if errno is set to EIO ("Input/output error") and die in
|
|
|
|
* that case, but it's not always set properly. Argh. */
|
2021-06-29 11:20:16 +00:00
|
|
|
if (input == ERR && ++errcount == 12345678)
|
2018-10-19 00:21:44 +00:00
|
|
|
die(_("Too many errors from stdin\n"));
|
2017-12-29 18:27:33 +00:00
|
|
|
}
|
2004-02-16 20:32:40 +00:00
|
|
|
|
2017-12-29 18:27:33 +00:00
|
|
|
curs_set(0);
|
2017-10-04 19:37:35 +00:00
|
|
|
|
2017-12-29 18:27:33 +00:00
|
|
|
/* Initiate the keystroke buffer, and save the keycode in it. */
|
2020-08-30 02:57:45 +00:00
|
|
|
key_buffer = nrealloc(key_buffer, sizeof(int));
|
2017-12-29 18:27:33 +00:00
|
|
|
key_buffer[0] = input;
|
2018-01-10 18:25:23 +00:00
|
|
|
key_buffer_len = 1;
|
2003-08-17 02:48:43 +00:00
|
|
|
|
2015-05-28 13:02:29 +00:00
|
|
|
#ifndef NANO_TINY
|
2021-05-31 08:40:46 +00:00
|
|
|
/* Cancel the highlighting of a search match, if there still is one. */
|
|
|
|
refresh_needed |= spotlighted;
|
|
|
|
spotlighted = FALSE;
|
|
|
|
|
2017-12-29 18:27:33 +00:00
|
|
|
/* If we got a SIGWINCH, get out as the win argument is no longer valid. */
|
|
|
|
if (input == KEY_WINCH)
|
|
|
|
return;
|
2015-05-28 13:02:29 +00:00
|
|
|
#endif
|
|
|
|
|
2020-08-20 07:17:48 +00:00
|
|
|
/* Read in any remaining key codes using non-blocking input. */
|
2017-12-29 18:27:33 +00:00
|
|
|
nodelay(win, TRUE);
|
2004-12-04 17:41:52 +00:00
|
|
|
|
2020-08-15 14:07:30 +00:00
|
|
|
/* After an ESC, when ncurses does not translate escape sequences,
|
|
|
|
* give the keyboard some time to bring the next code to ncurses. */
|
2020-08-15 12:03:34 +00:00
|
|
|
if (input == ESC_CODE && (linger_after_escape || ISSET(RAW_SEQUENCES)))
|
2020-08-08 05:40:33 +00:00
|
|
|
napms(20);
|
|
|
|
|
2017-12-29 18:27:33 +00:00
|
|
|
while (TRUE) {
|
2017-10-09 22:03:51 +00:00
|
|
|
#ifndef NANO_TINY
|
2017-12-29 18:27:33 +00:00
|
|
|
if (recording)
|
|
|
|
add_to_macrobuffer(input);
|
2017-10-09 22:03:51 +00:00
|
|
|
#endif
|
2017-12-29 18:27:33 +00:00
|
|
|
input = wgetch(win);
|
2004-12-12 19:04:56 +00:00
|
|
|
|
2017-12-29 18:27:33 +00:00
|
|
|
/* If there aren't any more characters, stop reading. */
|
|
|
|
if (input == ERR)
|
|
|
|
break;
|
2004-12-04 17:41:52 +00:00
|
|
|
|
2017-12-29 18:27:33 +00:00
|
|
|
/* Extend the keystroke buffer, and save the keycode at its end. */
|
|
|
|
key_buffer_len++;
|
2020-08-30 02:57:45 +00:00
|
|
|
key_buffer = nrealloc(key_buffer, key_buffer_len * sizeof(int));
|
2017-12-29 18:27:33 +00:00
|
|
|
key_buffer[key_buffer_len - 1] = input;
|
|
|
|
}
|
2004-12-04 17:41:52 +00:00
|
|
|
|
2020-08-20 07:17:48 +00:00
|
|
|
/* Restore blocking-input mode. */
|
|
|
|
nodelay(win, FALSE);
|
2005-03-16 14:39:42 +00:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
2017-12-29 18:27:33 +00:00
|
|
|
fprintf(stderr, "\nSequence of hex codes:");
|
|
|
|
for (size_t 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
|
|
|
{
|
2017-12-29 18:27:33 +00:00
|
|
|
return key_buffer_len;
|
2004-12-04 17:41:52 +00:00
|
|
|
}
|
|
|
|
|
2018-01-15 19:09:03 +00:00
|
|
|
/* Add the given keycode to the front of the keystroke buffer. */
|
2018-01-27 10:29:11 +00:00
|
|
|
void put_back(int keycode)
|
2004-12-04 17:41:52 +00:00
|
|
|
{
|
2018-01-15 18:54:12 +00:00
|
|
|
/* If the keystroke buffer is at maximum capacity, don't add anything. */
|
|
|
|
if (key_buffer_len + 1 < key_buffer_len)
|
|
|
|
return;
|
2004-12-04 17:41:52 +00:00
|
|
|
|
2018-01-15 18:54:12 +00:00
|
|
|
/* Extend the keystroke buffer to make room for the extra keycode. */
|
2020-08-30 02:57:45 +00:00
|
|
|
key_buffer = nrealloc(key_buffer, ++key_buffer_len * sizeof(int));
|
2004-12-04 17:41:52 +00:00
|
|
|
|
2018-01-15 19:09:03 +00:00
|
|
|
/* If the keystroke buffer wasn't empty before, move all the
|
|
|
|
* existing content one step further away. */
|
2018-01-15 18:54:12 +00:00
|
|
|
if (key_buffer_len > 1)
|
|
|
|
memmove(key_buffer + 1, key_buffer, (key_buffer_len - 1) * sizeof(int));
|
2004-12-04 17:41:52 +00:00
|
|
|
|
2018-01-15 19:09:03 +00:00
|
|
|
*key_buffer = keycode;
|
2004-12-04 17:41:52 +00:00
|
|
|
}
|
|
|
|
|
2018-02-27 12:34:32 +00:00
|
|
|
#ifdef ENABLE_NANORC
|
|
|
|
/* Insert the given string into the keyboard buffer. */
|
|
|
|
void implant(const char *string)
|
|
|
|
{
|
|
|
|
for (int i = strlen(string); i > 0; i--)
|
2018-09-23 09:44:47 +00:00
|
|
|
put_back((unsigned char)string[i - 1]);
|
2020-01-23 11:32:28 +00:00
|
|
|
|
|
|
|
mute_modifiers = TRUE;
|
2018-02-27 12:34:32 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2020-08-10 05:53:41 +00:00
|
|
|
/* Try to read one code from the keystroke buffer. If the buffer is empty and
|
|
|
|
* win isn't NULL, try to get more codes from the keyboard. Return the first
|
|
|
|
* code, or ERR if the keystroke buffer is still empty. */
|
2020-08-10 05:39:29 +00:00
|
|
|
int get_input(WINDOW *win)
|
2004-12-04 17:41:52 +00:00
|
|
|
{
|
2020-08-10 05:39:29 +00:00
|
|
|
int input;
|
2017-12-29 18:27:33 +00:00
|
|
|
|
|
|
|
if (key_buffer_len == 0 && win != NULL)
|
2018-01-10 16:40:07 +00:00
|
|
|
read_keys_from(win);
|
2017-12-29 18:27:33 +00:00
|
|
|
|
|
|
|
if (key_buffer_len == 0)
|
2020-08-10 05:39:29 +00:00
|
|
|
return ERR;
|
2017-12-29 18:27:33 +00:00
|
|
|
|
2020-08-10 05:39:29 +00:00
|
|
|
/* Take the first code from the head of the keystroke buffer. */
|
|
|
|
input = key_buffer[0];
|
2017-12-29 18:27:33 +00:00
|
|
|
|
2020-08-10 05:39:29 +00:00
|
|
|
/* If the buffer contains more codes, move them to the front. */
|
|
|
|
if (--key_buffer_len > 0)
|
|
|
|
memmove(key_buffer, key_buffer + 1, key_buffer_len * sizeof(int));
|
2004-12-04 17:41:52 +00:00
|
|
|
|
2017-12-29 18:27:33 +00:00
|
|
|
return input;
|
2003-08-17 02:48:43 +00:00
|
|
|
}
|
|
|
|
|
2020-01-26 15:02:40 +00:00
|
|
|
/* Return the arrow-key code that corresponds to the given letter.
|
|
|
|
* (This mapping is common to a handful of escape sequences.) */
|
|
|
|
int arrow_from_ABCD(int letter)
|
2003-08-17 02:48:43 +00:00
|
|
|
{
|
2020-01-26 15:02:40 +00:00
|
|
|
if (letter < 'C')
|
|
|
|
return (letter == 'A' ? KEY_UP : KEY_DOWN);
|
|
|
|
else
|
|
|
|
return (letter == 'D' ? KEY_LEFT : KEY_RIGHT);
|
|
|
|
}
|
2017-12-29 18:27:33 +00:00
|
|
|
|
2020-08-08 17:30:47 +00:00
|
|
|
/* Translate a sequence that began with "Esc O" to its corresponding key code. */
|
|
|
|
int convert_SS3_sequence(const int *seq, size_t length, int *consumed)
|
2020-01-26 15:02:40 +00:00
|
|
|
{
|
2020-08-08 17:44:54 +00:00
|
|
|
switch (seq[0]) {
|
|
|
|
case '1':
|
|
|
|
if (length > 3 && seq[1] == ';') {
|
|
|
|
*consumed = 4;
|
2020-10-01 12:01:36 +00:00
|
|
|
#ifndef NANO_TINY
|
2020-08-08 17:44:54 +00:00
|
|
|
switch (seq[2]) {
|
|
|
|
case '2':
|
2020-08-08 18:00:15 +00:00
|
|
|
if ('A' <= seq[3] && seq[3] <= 'D') {
|
|
|
|
/* Esc O 1 ; 2 A == Shift-Up on old Terminal. */
|
|
|
|
/* Esc O 1 ; 2 B == Shift-Down on old Terminal. */
|
|
|
|
/* Esc O 1 ; 2 C == Shift-Right on old Terminal. */
|
|
|
|
/* Esc O 1 ; 2 D == Shift-Left on old Terminal. */
|
|
|
|
shift_held = TRUE;
|
|
|
|
return arrow_from_ABCD(seq[3]);
|
2020-08-08 17:44:54 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case '5':
|
|
|
|
switch (seq[3]) {
|
2020-08-08 18:00:15 +00:00
|
|
|
case 'A': /* Esc O 1 ; 5 A == Ctrl-Up on old Terminal. */
|
2020-08-08 17:44:54 +00:00
|
|
|
return CONTROL_UP;
|
2020-08-08 18:00:15 +00:00
|
|
|
case 'B': /* Esc O 1 ; 5 B == Ctrl-Down on old Terminal. */
|
2020-08-08 17:44:54 +00:00
|
|
|
return CONTROL_DOWN;
|
2020-08-08 18:00:15 +00:00
|
|
|
case 'C': /* Esc O 1 ; 5 C == Ctrl-Right on old Terminal. */
|
2020-08-08 17:44:54 +00:00
|
|
|
return CONTROL_RIGHT;
|
2020-08-08 18:00:15 +00:00
|
|
|
case 'D': /* Esc O 1 ; 5 D == Ctrl-Left on old Terminal. */
|
2020-08-08 17:44:54 +00:00
|
|
|
return CONTROL_LEFT;
|
|
|
|
}
|
|
|
|
break;
|
2020-07-19 09:46:05 +00:00
|
|
|
}
|
2020-10-01 12:01:36 +00:00
|
|
|
#endif
|
2020-08-08 17:44:54 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case '2': /* Shift */
|
|
|
|
case '3': /* Alt */
|
|
|
|
case '4': /* Shift+Alt */
|
|
|
|
case '5': /* Ctrl */
|
|
|
|
case '6': /* Shift+Ctrl */
|
|
|
|
case '7': /* Alt+Ctrl */
|
|
|
|
case '8': /* Shift+Alt+Ctrl */
|
|
|
|
if (length > 1) {
|
|
|
|
*consumed = 2;
|
|
|
|
/* Do not accept multiple modifiers. */
|
|
|
|
if (seq[0] == '4' || seq[0] > '5')
|
|
|
|
return FOREIGN_SEQUENCE;
|
2020-07-19 09:46:05 +00:00
|
|
|
#ifndef NANO_TINY
|
2020-08-08 17:44:54 +00:00
|
|
|
switch (seq[1]) {
|
|
|
|
case 'A': /* Esc O 5 A == Ctrl-Up on Haiku. */
|
|
|
|
return CONTROL_UP;
|
|
|
|
case 'B': /* Esc O 5 B == Ctrl-Down on Haiku. */
|
|
|
|
return CONTROL_DOWN;
|
|
|
|
case 'C': /* Esc O 5 C == Ctrl-Right on Haiku. */
|
|
|
|
return CONTROL_RIGHT;
|
|
|
|
case 'D': /* Esc O 5 D == Ctrl-Left on Haiku. */
|
|
|
|
return CONTROL_LEFT;
|
2017-12-29 18:27:33 +00:00
|
|
|
}
|
2020-08-08 17:44:54 +00:00
|
|
|
#endif
|
|
|
|
/* Translate Shift+digit on the keypad to the digit
|
|
|
|
* (Esc O 2 p == Shift-0, ...), modifier+operator to
|
|
|
|
* the operator, and modifier+Enter to CR. */
|
|
|
|
return (seq[1] - 0x40);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'A': /* Esc O A == Up on VT100/VT320. */
|
|
|
|
case 'B': /* Esc O B == Down on VT100/VT320. */
|
|
|
|
case 'C': /* Esc O C == Right on VT100/VT320. */
|
|
|
|
case 'D': /* Esc O D == Left on VT100/VT320. */
|
|
|
|
return arrow_from_ABCD(seq[0]);
|
2020-10-01 12:01:36 +00:00
|
|
|
#ifndef NANO_TINY
|
2020-08-08 17:44:54 +00:00
|
|
|
case 'F': /* Esc O F == End on old xterm. */
|
|
|
|
return KEY_END;
|
|
|
|
case 'H': /* Esc O H == Home on old xterm. */
|
|
|
|
return KEY_HOME;
|
|
|
|
case 'M': /* Esc O M == Enter on numeric keypad
|
|
|
|
* with NumLock off on VT100/VT220/VT320. */
|
|
|
|
return KEY_ENTER;
|
2020-10-01 12:01:36 +00:00
|
|
|
#endif
|
2020-09-30 17:37:34 +00:00
|
|
|
case 'P': /* Esc O P == F1 on VT100/VT220/VT320/xterm/Mach console. */
|
|
|
|
case 'Q': /* Esc O Q == F2 on VT100/VT220/VT320/xterm/Mach console. */
|
|
|
|
case 'R': /* Esc O R == F3 on VT100/VT220/VT320/xterm/Mach console. */
|
|
|
|
case 'S': /* Esc O S == F4 on VT100/VT220/VT320/xterm/Mach console. */
|
2020-10-01 12:01:36 +00:00
|
|
|
return KEY_F(seq[0] - 'O');
|
|
|
|
#ifndef NANO_TINY
|
2020-08-08 17:44:54 +00:00
|
|
|
case 'T': /* Esc O T == F5 on Mach console. */
|
|
|
|
case 'U': /* Esc O U == F6 on Mach console. */
|
|
|
|
case 'V': /* Esc O V == F7 on Mach console. */
|
|
|
|
case 'W': /* Esc O W == F8 on Mach console. */
|
|
|
|
case 'X': /* Esc O X == F9 on Mach console. */
|
|
|
|
case 'Y': /* Esc O Y == F10 on Mach console. */
|
|
|
|
return KEY_F(seq[0] - 'O');
|
|
|
|
case 'a': /* Esc O a == Ctrl-Up on rxvt/Eterm. */
|
|
|
|
return CONTROL_UP;
|
|
|
|
case 'b': /* Esc O b == Ctrl-Down on rxvt/Eterm. */
|
|
|
|
return CONTROL_DOWN;
|
|
|
|
case 'c': /* Esc O c == Ctrl-Right on rxvt/Eterm. */
|
|
|
|
return CONTROL_RIGHT;
|
|
|
|
case 'd': /* Esc O d == Ctrl-Left on rxvt/Eterm. */
|
|
|
|
return CONTROL_LEFT;
|
|
|
|
case 'j': /* Esc O j == '*' on numeric keypad with
|
|
|
|
* NumLock off on xterm/rxvt/Eterm. */
|
|
|
|
return '*';
|
|
|
|
case 'k': /* Esc O k == '+' on the same. */
|
|
|
|
return '+';
|
|
|
|
case 'l': /* Esc O l == ',' on VT100/VT220/VT320. */
|
|
|
|
return ',';
|
|
|
|
case 'm': /* Esc O m == '-' on numeric keypad with
|
|
|
|
* NumLock off on VTnnn/xterm/rxvt/Eterm. */
|
|
|
|
return '-';
|
|
|
|
case 'n': /* Esc O n == Delete (.) on numeric keypad
|
|
|
|
* with NumLock off on rxvt/Eterm. */
|
|
|
|
return KEY_DC;
|
|
|
|
case 'o': /* Esc O o == '/' on numeric keypad with
|
|
|
|
* NumLock off on VTnnn/xterm/rxvt/Eterm. */
|
|
|
|
return '/';
|
|
|
|
case 'p': /* Esc O p == Insert (0) on numeric keypad
|
|
|
|
* with NumLock off on rxvt/Eterm. */
|
|
|
|
return KEY_IC;
|
|
|
|
case 'q': /* Esc O q == End (1) on the same. */
|
|
|
|
return KEY_END;
|
|
|
|
case 'r': /* Esc O r == Down (2) on the same. */
|
|
|
|
return KEY_DOWN;
|
|
|
|
case 's': /* Esc O s == PageDown (3) on the same. */
|
|
|
|
return KEY_NPAGE;
|
|
|
|
case 't': /* Esc O t == Left (4) on the same. */
|
|
|
|
return KEY_LEFT;
|
|
|
|
case 'v': /* Esc O v == Right (6) on the same. */
|
|
|
|
return KEY_RIGHT;
|
|
|
|
case 'w': /* Esc O w == Home (7) on the same. */
|
|
|
|
return KEY_HOME;
|
|
|
|
case 'x': /* Esc O x == Up (8) on the same. */
|
|
|
|
return KEY_UP;
|
|
|
|
case 'y': /* Esc O y == PageUp (9) on the same. */
|
|
|
|
return KEY_PPAGE;
|
2020-09-30 17:57:23 +00:00
|
|
|
#endif
|
2020-08-08 17:44:54 +00:00
|
|
|
}
|
2020-08-08 17:30:47 +00:00
|
|
|
|
|
|
|
return FOREIGN_SEQUENCE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Translate a sequence that began with "Esc [" to its corresponding key code. */
|
|
|
|
int convert_CSI_sequence(const int *seq, size_t length, int *consumed)
|
|
|
|
{
|
2020-08-08 17:44:54 +00:00
|
|
|
if (seq[0] < '9')
|
|
|
|
*consumed = 2;
|
|
|
|
switch (seq[0]) {
|
|
|
|
case '1':
|
|
|
|
if (length > 1 && seq[1] == '~')
|
|
|
|
/* Esc [ 1 ~ == Home on VT320/Linux console. */
|
|
|
|
return KEY_HOME;
|
|
|
|
else if (length > 2 && seq[2] == '~') {
|
|
|
|
*consumed = 3;
|
|
|
|
switch (seq[1]) {
|
2020-09-30 17:57:23 +00:00
|
|
|
#ifndef NANO_TINY
|
2020-08-08 17:44:54 +00:00
|
|
|
case '1': /* Esc [ 1 1 ~ == F1 on rxvt/Eterm. */
|
|
|
|
case '2': /* Esc [ 1 2 ~ == F2 on rxvt/Eterm. */
|
|
|
|
case '3': /* Esc [ 1 3 ~ == F3 on rxvt/Eterm. */
|
|
|
|
case '4': /* Esc [ 1 4 ~ == F4 on rxvt/Eterm. */
|
2020-10-01 12:01:36 +00:00
|
|
|
#endif
|
2020-08-08 17:44:54 +00:00
|
|
|
case '5': /* Esc [ 1 5 ~ == F5 on xterm/rxvt/Eterm. */
|
|
|
|
return KEY_F(seq[1] - '0');
|
|
|
|
case '7': /* Esc [ 1 7 ~ == F6 on VT220/VT320/
|
|
|
|
* Linux console/xterm/rxvt/Eterm. */
|
|
|
|
case '8': /* Esc [ 1 8 ~ == F7 on the same. */
|
|
|
|
case '9': /* Esc [ 1 9 ~ == F8 on the same. */
|
|
|
|
return KEY_F(seq[1] - '1');
|
|
|
|
}
|
2020-10-01 12:01:36 +00:00
|
|
|
} else if (length > 3 && seq[1] == ';') {
|
2020-08-08 17:44:54 +00:00
|
|
|
*consumed = 4;
|
2020-10-01 12:01:36 +00:00
|
|
|
#ifndef NANO_TINY
|
2020-08-08 17:44:54 +00:00
|
|
|
switch (seq[2]) {
|
|
|
|
case '2':
|
|
|
|
switch (seq[3]) {
|
|
|
|
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. */
|
|
|
|
shift_held = TRUE;
|
|
|
|
return arrow_from_ABCD(seq[3]);
|
|
|
|
case 'F': /* Esc [ 1 ; 2 F == Shift-End on xterm. */
|
|
|
|
return SHIFT_END;
|
|
|
|
case 'H': /* Esc [ 1 ; 2 H == Shift-Home on xterm. */
|
|
|
|
return SHIFT_HOME;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case '9': /* To accommodate iTerm2 in "xterm mode". */
|
|
|
|
case '3':
|
|
|
|
switch (seq[3]) {
|
|
|
|
case 'A': /* Esc [ 1 ; 3 A == Alt-Up on xterm. */
|
|
|
|
return ALT_UP;
|
|
|
|
case 'B': /* Esc [ 1 ; 3 B == Alt-Down on xterm. */
|
|
|
|
return ALT_DOWN;
|
|
|
|
case 'C': /* Esc [ 1 ; 3 C == Alt-Right on xterm. */
|
|
|
|
return ALT_RIGHT;
|
|
|
|
case 'D': /* Esc [ 1 ; 3 D == Alt-Left on xterm. */
|
|
|
|
return ALT_LEFT;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case '4':
|
|
|
|
/* When the arrow keys are held together with Shift+Meta,
|
|
|
|
* act as if they are Home/End/PgUp/PgDown with Shift. */
|
|
|
|
switch (seq[3]) {
|
|
|
|
case 'A': /* Esc [ 1 ; 4 A == Shift-Alt-Up on xterm. */
|
|
|
|
return SHIFT_PAGEUP;
|
|
|
|
case 'B': /* Esc [ 1 ; 4 B == Shift-Alt-Down on xterm. */
|
|
|
|
return SHIFT_PAGEDOWN;
|
|
|
|
case 'C': /* Esc [ 1 ; 4 C == Shift-Alt-Right on xterm. */
|
|
|
|
return SHIFT_END;
|
|
|
|
case 'D': /* Esc [ 1 ; 4 D == Shift-Alt-Left on xterm. */
|
|
|
|
return SHIFT_HOME;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case '5':
|
|
|
|
switch (seq[3]) {
|
|
|
|
case 'A': /* Esc [ 1 ; 5 A == Ctrl-Up on xterm. */
|
|
|
|
return CONTROL_UP;
|
|
|
|
case 'B': /* Esc [ 1 ; 5 B == Ctrl-Down on xterm. */
|
|
|
|
return CONTROL_DOWN;
|
|
|
|
case 'C': /* Esc [ 1 ; 5 C == Ctrl-Right on xterm. */
|
|
|
|
return CONTROL_RIGHT;
|
|
|
|
case 'D': /* Esc [ 1 ; 5 D == Ctrl-Left on xterm. */
|
|
|
|
return CONTROL_LEFT;
|
|
|
|
case 'F': /* Esc [ 1 ; 5 F == Ctrl-End on xterm. */
|
|
|
|
return CONTROL_END;
|
|
|
|
case 'H': /* Esc [ 1 ; 5 H == Ctrl-Home on xterm. */
|
|
|
|
return CONTROL_HOME;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case '6':
|
|
|
|
switch (seq[3]) {
|
|
|
|
case 'A': /* Esc [ 1 ; 6 A == Shift-Ctrl-Up on xterm. */
|
|
|
|
return shiftcontrolup;
|
|
|
|
case 'B': /* Esc [ 1 ; 6 B == Shift-Ctrl-Down on xterm. */
|
|
|
|
return shiftcontroldown;
|
|
|
|
case 'C': /* Esc [ 1 ; 6 C == Shift-Ctrl-Right on xterm. */
|
|
|
|
return shiftcontrolright;
|
|
|
|
case 'D': /* Esc [ 1 ; 6 D == Shift-Ctrl-Left on xterm. */
|
|
|
|
return shiftcontrolleft;
|
|
|
|
case 'F': /* Esc [ 1 ; 6 F == Shift-Ctrl-End on xterm. */
|
|
|
|
return shiftcontrolend;
|
|
|
|
case 'H': /* Esc [ 1 ; 6 H == Shift-Ctrl-Home on xterm. */
|
|
|
|
return shiftcontrolhome;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2020-10-01 12:01:36 +00:00
|
|
|
#endif /* !NANO-TINY */
|
2020-08-08 17:44:54 +00:00
|
|
|
} else if (length > 4 && seq[2] == ';' && seq[4] == '~')
|
|
|
|
/* Esc [ 1 n ; 2 ~ == F17...F20 on some terminals. */
|
|
|
|
*consumed = 5;
|
|
|
|
break;
|
|
|
|
case '2':
|
|
|
|
if (length > 2 && seq[2] == '~') {
|
|
|
|
*consumed = 3;
|
|
|
|
switch (seq[1]) {
|
|
|
|
case '0': /* Esc [ 2 0 ~ == F9 on VT220/VT320/
|
|
|
|
* Linux console/xterm/rxvt/Eterm. */
|
|
|
|
return KEY_F(9);
|
|
|
|
case '1': /* Esc [ 2 1 ~ == F10 on the same. */
|
|
|
|
return KEY_F(10);
|
|
|
|
case '3': /* Esc [ 2 3 ~ == F11 on the same. */
|
|
|
|
return KEY_F(11);
|
|
|
|
case '4': /* Esc [ 2 4 ~ == F12 on the same. */
|
|
|
|
return KEY_F(12);
|
|
|
|
}
|
|
|
|
} else if (length > 1 && seq[1] == '~')
|
|
|
|
/* Esc [ 2 ~ == Insert on VT220/VT320/
|
|
|
|
* Linux console/xterm/Terminal. */
|
|
|
|
return KEY_IC;
|
|
|
|
else if (length > 3 && seq[1] == ';' && seq[3] == '~') {
|
|
|
|
/* Esc [ 2 ; x ~ == modified Insert on xterm. */
|
|
|
|
*consumed = 4;
|
2018-12-04 01:45:18 +00:00
|
|
|
#ifndef NANO_TINY
|
2020-08-08 17:44:54 +00:00
|
|
|
if (seq[2] == '3')
|
|
|
|
return ALT_INSERT;
|
2018-12-04 01:45:18 +00:00
|
|
|
#endif
|
2020-08-08 17:44:54 +00:00
|
|
|
}
|
|
|
|
else if (length > 4 && seq[2] == ';' && seq[4] == '~')
|
|
|
|
/* Esc [ 2 n ; 2 ~ == F21...F24 on some terminals. */
|
|
|
|
*consumed = 5;
|
2020-01-26 15:02:40 +00:00
|
|
|
#ifndef NANO_TINY
|
2020-08-08 17:44:54 +00:00
|
|
|
else if (length > 3 && seq[1] == '0' && seq[3] == '~') {
|
|
|
|
/* Esc [ 2 0 0 ~ == start of a bracketed paste,
|
|
|
|
* Esc [ 2 0 1 ~ == end of a bracketed paste. */
|
|
|
|
*consumed = 4;
|
|
|
|
if (seq[2] == '0') {
|
|
|
|
bracketed_paste = TRUE;
|
|
|
|
return BRACKETED_PASTE_MARKER;
|
|
|
|
} else if (seq[2] == '1') {
|
|
|
|
bracketed_paste = FALSE;
|
|
|
|
return BRACKETED_PASTE_MARKER;
|
2020-07-19 09:46:05 +00:00
|
|
|
}
|
2020-08-08 17:44:54 +00:00
|
|
|
}
|
2016-07-10 18:01:23 +00:00
|
|
|
#endif
|
2020-08-08 17:44:54 +00:00
|
|
|
break;
|
|
|
|
case '3': /* Esc [ 3 ~ == Delete on VT220/VT320/
|
|
|
|
* Linux console/xterm/Terminal. */
|
|
|
|
if (length > 1 && seq[1] == '~')
|
|
|
|
return KEY_DC;
|
|
|
|
if (length > 3 && seq[1] == ';' && seq[3] == '~') {
|
|
|
|
*consumed = 4;
|
2020-01-26 15:02:40 +00:00
|
|
|
#ifndef NANO_TINY
|
2020-08-08 17:44:54 +00:00
|
|
|
if (seq[2] == '2')
|
|
|
|
/* Esc [ 3 ; 2 ~ == Shift-Delete on xterm/Terminal. */
|
2020-07-19 09:46:05 +00:00
|
|
|
return SHIFT_DELETE;
|
2020-08-08 17:44:54 +00:00
|
|
|
if (seq[2] == '3')
|
|
|
|
/* Esc [ 3 ; 3 ~ == Alt-Delete on xterm/rxvt/Eterm/Terminal. */
|
|
|
|
return ALT_DELETE;
|
|
|
|
if (seq[2] == '5')
|
|
|
|
/* Esc [ 3 ; 5 ~ == Ctrl-Delete on xterm. */
|
2020-07-19 09:46:05 +00:00
|
|
|
return CONTROL_DELETE;
|
2020-08-08 17:44:54 +00:00
|
|
|
if (seq[2] == '6')
|
|
|
|
/* Esc [ 3 ; 6 ~ == Ctrl-Shift-Delete on xterm. */
|
2020-07-19 09:46:05 +00:00
|
|
|
return controlshiftdelete;
|
2018-01-25 11:54:43 +00:00
|
|
|
#endif
|
2020-08-08 17:44:54 +00:00
|
|
|
}
|
2016-04-24 09:28:28 +00:00
|
|
|
#ifndef NANO_TINY
|
2020-08-08 17:44:54 +00:00
|
|
|
if (length > 1 && seq[1] == '$')
|
|
|
|
/* Esc [ 3 $ == Shift-Delete on urxvt. */
|
|
|
|
return SHIFT_DELETE;
|
|
|
|
if (length > 1 && seq[1] == '^')
|
|
|
|
/* Esc [ 3 ^ == Ctrl-Delete on urxvt. */
|
|
|
|
return CONTROL_DELETE;
|
|
|
|
if (length > 1 && seq[1] == '@')
|
|
|
|
/* Esc [ 3 @ == Ctrl-Shift-Delete on urxvt. */
|
|
|
|
return controlshiftdelete;
|
|
|
|
if (length > 2 && seq[2] == '~')
|
|
|
|
/* Esc [ 3 n ~ == F17...F20 on some terminals. */
|
|
|
|
*consumed = 3;
|
2016-12-01 15:51:40 +00:00
|
|
|
#endif
|
2020-08-08 17:44:54 +00:00
|
|
|
break;
|
|
|
|
case '4': /* Esc [ 4 ~ == End on VT220/VT320/
|
|
|
|
* Linux console/xterm. */
|
|
|
|
if (length > 1 && seq[1] == '~')
|
|
|
|
return KEY_END;
|
|
|
|
break;
|
|
|
|
case '5': /* Esc [ 5 ~ == PageUp on VT220/VT320/
|
|
|
|
* Linux console/xterm/Eterm/urxvt/Terminal */
|
|
|
|
if (length > 1 && seq[1] == '~')
|
|
|
|
return KEY_PPAGE;
|
|
|
|
else if (length > 3 && seq[1] == ';' && seq[3] == '~') {
|
|
|
|
*consumed = 4;
|
2020-01-26 15:02:40 +00:00
|
|
|
#ifndef NANO_TINY
|
2020-08-08 17:44:54 +00:00
|
|
|
if (seq[2] == '2')
|
|
|
|
return shiftaltup;
|
|
|
|
if (seq[2] == '3')
|
|
|
|
return ALT_PAGEUP;
|
2016-04-24 09:28:28 +00:00
|
|
|
#endif
|
2020-08-08 17:44:54 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case '6': /* Esc [ 6 ~ == PageDown on VT220/VT320/
|
|
|
|
* Linux console/xterm/Eterm/urxvt/Terminal */
|
|
|
|
if (length > 1 && seq[1] == '~')
|
|
|
|
return KEY_NPAGE;
|
|
|
|
else if (length > 3 && seq[1] == ';' && seq[3] == '~') {
|
|
|
|
*consumed = 4;
|
2016-04-24 09:28:28 +00:00
|
|
|
#ifndef NANO_TINY
|
2020-08-08 17:44:54 +00:00
|
|
|
if (seq[2] == '2')
|
|
|
|
return shiftaltdown;
|
|
|
|
if (seq[2] == '3')
|
|
|
|
return ALT_PAGEDOWN;
|
2016-12-01 15:51:40 +00:00
|
|
|
#endif
|
2020-08-08 17:44:54 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case '7': /* Esc [ 7 ~ == Home on Eterm/rxvt;
|
|
|
|
* Esc [ 7 $ == Shift-Home on Eterm/rxvt;
|
|
|
|
* Esc [ 7 ^ == Control-Home on Eterm/rxvt;
|
|
|
|
* Esc [ 7 @ == Shift-Control-Home on same. */
|
|
|
|
if (length > 1 && seq[1] == '~')
|
|
|
|
return KEY_HOME;
|
|
|
|
else if (length > 1 && seq[1] == '$')
|
|
|
|
return SHIFT_HOME;
|
|
|
|
else if (length > 1 && seq[1] == '^')
|
|
|
|
return CONTROL_HOME;
|
2020-01-26 15:02:40 +00:00
|
|
|
#ifndef NANO_TINY
|
2020-08-08 17:44:54 +00:00
|
|
|
else if (length > 1 && seq[1] == '@')
|
|
|
|
return shiftcontrolhome;
|
2016-04-24 09:28:28 +00:00
|
|
|
#endif
|
2020-08-08 17:44:54 +00:00
|
|
|
break;
|
|
|
|
case '8': /* Esc [ 8 ~ == End on Eterm/rxvt;
|
|
|
|
* Esc [ 8 $ == Shift-End on Eterm/rxvt;
|
|
|
|
* Esc [ 8 ^ == Control-End on Eterm/rxvt;
|
|
|
|
* Esc [ 8 @ == Shift-Control-End on same. */
|
|
|
|
if (length > 1 && seq[1] == '~')
|
2020-07-19 09:46:05 +00:00
|
|
|
return KEY_END;
|
2020-08-08 17:44:54 +00:00
|
|
|
else if (length > 1 && seq[1] == '$')
|
|
|
|
return SHIFT_END;
|
|
|
|
else if (length > 1 && seq[1] == '^')
|
|
|
|
return CONTROL_END;
|
|
|
|
#ifndef NANO_TINY
|
|
|
|
else if (length > 1 && seq[1] == '@')
|
|
|
|
return shiftcontrolend;
|
|
|
|
#endif
|
|
|
|
break;
|
|
|
|
case '9': /* Esc [ 9 == Delete on Mach console. */
|
|
|
|
return KEY_DC;
|
|
|
|
case '@': /* Esc [ @ == Insert on Mach console. */
|
|
|
|
return KEY_IC;
|
|
|
|
case 'A': /* Esc [ A == Up on ANSI/VT220/Linux console/
|
|
|
|
* FreeBSD console/Mach console/xterm/Eterm/
|
|
|
|
* urxvt/Gnome and Xfce Terminal. */
|
|
|
|
case 'B': /* Esc [ B == Down on the same. */
|
|
|
|
case 'C': /* Esc [ C == Right on the same. */
|
|
|
|
case 'D': /* Esc [ D == Left on the same. */
|
|
|
|
return arrow_from_ABCD(seq[0]);
|
|
|
|
case 'F': /* Esc [ F == End on FreeBSD console/Eterm. */
|
|
|
|
return KEY_END;
|
|
|
|
case 'G': /* Esc [ G == PageDown on FreeBSD console. */
|
|
|
|
return KEY_NPAGE;
|
|
|
|
case 'H': /* Esc [ H == Home on ANSI/VT220/FreeBSD
|
|
|
|
* console/Mach console/Eterm. */
|
|
|
|
return KEY_HOME;
|
|
|
|
case 'I': /* Esc [ I == PageUp on FreeBSD console. */
|
|
|
|
return KEY_PPAGE;
|
|
|
|
case 'L': /* Esc [ L == Insert on ANSI/FreeBSD console. */
|
|
|
|
return KEY_IC;
|
2020-09-30 17:57:23 +00:00
|
|
|
#ifndef NANO_TINY
|
2020-08-08 17:44:54 +00:00
|
|
|
case 'M': /* Esc [ M == F1 on FreeBSD console. */
|
|
|
|
case 'N': /* Esc [ N == F2 on FreeBSD console. */
|
2020-09-30 17:51:29 +00:00
|
|
|
case 'O': /* Esc [ O == F3 on FreeBSD console. */
|
2020-08-08 17:44:54 +00:00
|
|
|
case 'P': /* Esc [ P == F4 on FreeBSD console. */
|
|
|
|
case 'Q': /* Esc [ Q == F5 on FreeBSD console. */
|
|
|
|
case 'R': /* Esc [ R == F6 on FreeBSD console. */
|
|
|
|
case 'S': /* Esc [ S == F7 on FreeBSD console. */
|
|
|
|
case 'T': /* Esc [ T == F8 on FreeBSD console. */
|
2020-09-30 17:51:29 +00:00
|
|
|
return KEY_F(seq[0] - 'L');
|
2020-09-30 17:57:23 +00:00
|
|
|
#endif
|
2020-08-08 17:44:54 +00:00
|
|
|
case 'U': /* Esc [ U == PageDown on Mach console. */
|
|
|
|
return KEY_NPAGE;
|
|
|
|
case 'V': /* Esc [ V == PageUp on Mach console. */
|
|
|
|
return KEY_PPAGE;
|
2020-09-30 17:57:23 +00:00
|
|
|
#ifndef NANO_TINY
|
2020-08-08 17:44:54 +00:00
|
|
|
case 'W': /* Esc [ W == F11 on FreeBSD console. */
|
|
|
|
return KEY_F(11);
|
|
|
|
case 'X': /* Esc [ X == F12 on FreeBSD console. */
|
|
|
|
return KEY_F(12);
|
2020-09-30 17:57:23 +00:00
|
|
|
#endif
|
2020-08-08 17:44:54 +00:00
|
|
|
case 'Y': /* Esc [ Y == End on Mach console. */
|
|
|
|
return KEY_END;
|
|
|
|
case 'Z': /* Esc [ Z == Shift-Tab on ANSI/Linux console/
|
|
|
|
* FreeBSD console/xterm/rxvt/Terminal. */
|
|
|
|
return SHIFT_TAB;
|
2020-09-30 17:57:23 +00:00
|
|
|
#ifndef NANO_TINY
|
2020-08-08 17:44:54 +00:00
|
|
|
case 'a': /* Esc [ a == Shift-Up on rxvt/Eterm. */
|
|
|
|
case 'b': /* Esc [ b == Shift-Down on rxvt/Eterm. */
|
|
|
|
case 'c': /* Esc [ c == Shift-Right on rxvt/Eterm. */
|
|
|
|
case 'd': /* Esc [ d == Shift-Left on rxvt/Eterm. */
|
|
|
|
shift_held = TRUE;
|
|
|
|
return arrow_from_ABCD(seq[0] - 0x20);
|
2020-09-30 17:57:23 +00:00
|
|
|
#endif
|
2020-08-08 17:44:54 +00:00
|
|
|
case '[':
|
|
|
|
if (length > 1) {
|
|
|
|
*consumed = 2;
|
|
|
|
if ('@' < seq[1] && seq[1] < 'F')
|
|
|
|
/* Esc [ [ A == F1 on Linux console. */
|
|
|
|
/* Esc [ [ B == F2 on Linux console. */
|
|
|
|
/* Esc [ [ C == F3 on Linux console. */
|
|
|
|
/* Esc [ [ D == F4 on Linux console. */
|
|
|
|
/* Esc [ [ E == F5 on Linux console. */
|
|
|
|
return KEY_F(seq[1] - '@');
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2020-01-26 15:02:40 +00:00
|
|
|
|
2020-06-03 14:45:15 +00:00
|
|
|
return FOREIGN_SEQUENCE;
|
2020-01-26 15:02:40 +00:00
|
|
|
}
|
|
|
|
|
2020-08-09 13:29:40 +00:00
|
|
|
/* Interpret an escape sequence that has the given post-ESC starter byte
|
|
|
|
* and with the rest of the sequence still in the keystroke buffer. */
|
2020-08-08 17:30:47 +00:00
|
|
|
int parse_escape_sequence(int starter)
|
2020-01-26 15:02:40 +00:00
|
|
|
{
|
2020-08-08 17:30:47 +00:00
|
|
|
int consumed = 1;
|
|
|
|
int keycode = 0;
|
2020-01-26 15:02:40 +00:00
|
|
|
|
2020-08-08 17:30:47 +00:00
|
|
|
if (starter == 'O')
|
2020-08-09 13:29:40 +00:00
|
|
|
keycode = convert_SS3_sequence(key_buffer, key_buffer_len, &consumed);
|
2020-08-08 17:30:47 +00:00
|
|
|
else if (starter == '[')
|
2020-08-09 13:29:40 +00:00
|
|
|
keycode = convert_CSI_sequence(key_buffer, key_buffer_len, &consumed);
|
2020-08-08 18:00:15 +00:00
|
|
|
#ifndef NANO_TINY
|
2020-08-08 17:30:47 +00:00
|
|
|
else
|
|
|
|
die("Bad sequence starter -- please report a bug\n");
|
2020-08-08 18:00:15 +00:00
|
|
|
#endif
|
2020-01-26 15:02:40 +00:00
|
|
|
|
2020-08-09 13:25:22 +00:00
|
|
|
/* Remove the consumed sequence bytes from the keystroke buffer. */
|
|
|
|
key_buffer_len -= consumed;
|
|
|
|
memmove(key_buffer, key_buffer + consumed, key_buffer_len * sizeof(int));
|
2020-01-26 15:02:40 +00:00
|
|
|
|
2020-06-03 16:38:11 +00:00
|
|
|
return keycode;
|
2020-01-26 15:02:40 +00:00
|
|
|
}
|
|
|
|
|
2020-07-20 15:04:48 +00:00
|
|
|
#define PROCEED -44
|
|
|
|
|
2020-07-20 15:15:06 +00:00
|
|
|
/* For each consecutive call, gather the given digit into a three-digit
|
|
|
|
* decimal byte code (from 000 to 255). Return the assembled code when
|
|
|
|
* it is complete, but until then return PROCEED when the given digit is
|
|
|
|
* valid, and the given digit itself otherwise. */
|
2020-07-20 16:25:19 +00:00
|
|
|
int assemble_byte_code(int keycode)
|
2020-07-20 15:04:48 +00:00
|
|
|
{
|
|
|
|
static int byte = 0;
|
|
|
|
|
2020-07-22 09:07:20 +00:00
|
|
|
digit_count++;
|
|
|
|
|
|
|
|
/* The first digit is either 0, 1, or 2 (checked before the call). */
|
|
|
|
if (digit_count == 1) {
|
2020-07-20 16:25:19 +00:00
|
|
|
byte = (keycode - '0') * 100;
|
|
|
|
return PROCEED;
|
2020-07-22 09:07:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* The second digit may be at most 5 if the first was 2. */
|
2020-11-30 12:27:09 +00:00
|
|
|
if (digit_count == 2) {
|
2020-07-20 16:25:19 +00:00
|
|
|
if (byte < 200 || keycode <= '5') {
|
|
|
|
byte += (keycode - '0') * 10;
|
|
|
|
return PROCEED;
|
|
|
|
} else
|
|
|
|
return keycode;
|
2020-07-20 15:04:48 +00:00
|
|
|
}
|
2020-07-20 16:41:06 +00:00
|
|
|
|
|
|
|
/* The third digit may be at most 5 if the first two were 2 and 5. */
|
|
|
|
if (byte < 250 || keycode <= '5')
|
|
|
|
return (byte + keycode - '0');
|
|
|
|
else
|
|
|
|
return keycode;
|
2020-07-20 15:04:48 +00:00
|
|
|
}
|
|
|
|
|
2020-07-11 17:43:37 +00:00
|
|
|
/* Translate a normal ASCII character into its corresponding control code.
|
|
|
|
* The following groups of control keystrokes are equivalent:
|
|
|
|
* Ctrl-2 == Ctrl-@ == Ctrl-` == Ctrl-Space
|
|
|
|
* Ctrl-3 == Ctrl-[ == <Esc>
|
|
|
|
* Ctrl-4 == Ctrl-\ == Ctrl-|
|
|
|
|
* Ctrl-5 == Ctrl-]
|
|
|
|
* Ctrl-6 == Ctrl-^ == Ctrl-~
|
|
|
|
* Ctrl-7 == Ctrl-/ == Ctrl-_
|
|
|
|
* Ctrl-8 == Ctrl-? */
|
|
|
|
int convert_to_control(int kbinput)
|
|
|
|
{
|
|
|
|
if ('@' <= kbinput && kbinput <= '_')
|
|
|
|
return kbinput - '@';
|
|
|
|
if ('`' <= kbinput && kbinput <= '~')
|
|
|
|
return kbinput - '`';
|
|
|
|
if ('3' <= kbinput && kbinput <= '7')
|
|
|
|
return kbinput - 24;
|
|
|
|
if (kbinput == '?' || kbinput == '8')
|
|
|
|
return DEL_CODE;
|
|
|
|
if (kbinput == ' ' || kbinput == '2')
|
|
|
|
return 0;
|
|
|
|
if (kbinput == '/')
|
|
|
|
return 31;
|
|
|
|
|
|
|
|
return kbinput;
|
|
|
|
}
|
|
|
|
|
2020-07-20 09:47:10 +00:00
|
|
|
/* Extract one keystroke from the input stream. Translate escape sequences
|
|
|
|
* and possibly keypad codes into their corresponding values. Set meta_key
|
|
|
|
* to TRUE when appropriate. Supported keypad keystrokes are: the arrow keys,
|
|
|
|
* Insert, Delete, Home, End, PageUp, PageDown, Enter, and Backspace (many of
|
|
|
|
* them also when modified with Shift, Ctrl, Alt, Shift+Ctrl, or Shift+Alt),
|
|
|
|
* the function keys (F1-F12), and the numeric keypad with NumLock off. */
|
2020-01-26 15:02:40 +00:00
|
|
|
int parse_kbinput(WINDOW *win)
|
|
|
|
{
|
2020-12-04 15:35:28 +00:00
|
|
|
static bool first_escape_was_alone = FALSE;
|
2020-12-04 15:57:17 +00:00
|
|
|
static bool last_escape_was_alone = FALSE;
|
2020-01-26 15:02:40 +00:00
|
|
|
static int escapes = 0;
|
2020-08-10 05:39:29 +00:00
|
|
|
int keycode;
|
2020-01-26 15:02:40 +00:00
|
|
|
|
|
|
|
meta_key = FALSE;
|
|
|
|
shift_held = FALSE;
|
|
|
|
|
2020-08-10 05:39:29 +00:00
|
|
|
/* Get one code from the input stream. */
|
|
|
|
keycode = get_input(win);
|
2020-01-26 15:02:40 +00:00
|
|
|
|
|
|
|
if (keycode == ERR)
|
|
|
|
return ERR;
|
|
|
|
|
2020-12-04 16:03:10 +00:00
|
|
|
/* For an Esc, remember whether the last two arrived by themselves.
|
|
|
|
* Then increment the counter, rolling around on three escapes. */
|
2020-01-26 15:02:40 +00:00
|
|
|
if (keycode == ESC_CODE) {
|
2020-12-04 15:57:17 +00:00
|
|
|
first_escape_was_alone = last_escape_was_alone;
|
|
|
|
last_escape_was_alone = (key_buffer_len == 0);
|
2020-07-24 11:38:44 +00:00
|
|
|
if (digit_count > 0) {
|
2020-07-20 09:05:39 +00:00
|
|
|
digit_count = 0;
|
2020-01-26 15:02:40 +00:00
|
|
|
escapes = 1;
|
2020-07-24 11:38:44 +00:00
|
|
|
} else if (++escapes > 2)
|
2020-12-04 15:57:17 +00:00
|
|
|
escapes = (last_escape_was_alone ? 0 : 1);
|
2020-01-26 15:02:40 +00:00
|
|
|
return ERR;
|
|
|
|
}
|
|
|
|
|
2020-08-05 07:24:29 +00:00
|
|
|
if (escapes == 0) {
|
2020-08-05 07:37:22 +00:00
|
|
|
/* Most key codes in byte range cannot be special keys. */
|
2020-09-07 14:50:17 +00:00
|
|
|
if (keycode < 0xFF && keycode != '\t' && keycode != DEL_CODE)
|
2020-08-05 07:37:22 +00:00
|
|
|
return keycode;
|
2020-08-05 07:24:29 +00:00
|
|
|
} else if (escapes == 1) {
|
2020-08-05 08:09:49 +00:00
|
|
|
escapes = 0;
|
2020-08-07 16:46:55 +00:00
|
|
|
/* Codes out of ASCII printable range cannot form an escape sequence. */
|
|
|
|
if (keycode < 0x20 || 0x7E < keycode) {
|
|
|
|
if (keycode == '\t')
|
|
|
|
return SHIFT_TAB;
|
2020-07-06 08:54:50 +00:00
|
|
|
#ifndef NANO_TINY
|
2020-08-07 16:50:26 +00:00
|
|
|
else if (keycode == KEY_BACKSPACE || keycode == '\b' ||
|
|
|
|
keycode == DEL_CODE)
|
2020-08-05 08:09:49 +00:00
|
|
|
return CONTROL_SHIFT_DELETE;
|
2020-08-15 11:44:25 +00:00
|
|
|
#endif
|
|
|
|
#ifdef ENABLE_UTF8
|
|
|
|
else if (0xC0 <= keycode && keycode <= 0xFF && using_utf8()) {
|
|
|
|
while (key_buffer_len > 0 && 0x80 <= *key_buffer && *key_buffer <= 0xBF)
|
|
|
|
get_input(NULL);
|
|
|
|
return FOREIGN_SEQUENCE;
|
|
|
|
}
|
2020-07-06 08:54:50 +00:00
|
|
|
#endif
|
2020-12-04 15:57:17 +00:00
|
|
|
else if (keycode < 0x20 && !last_escape_was_alone)
|
2020-08-07 16:46:55 +00:00
|
|
|
meta_key = TRUE;
|
|
|
|
} else if (key_buffer_len == 0 || *key_buffer == ESC_CODE ||
|
2020-08-05 08:09:49 +00:00
|
|
|
(keycode != 'O' && keycode != '[')) {
|
2020-08-05 08:34:28 +00:00
|
|
|
if (!shifted_metas)
|
|
|
|
keycode = tolower(keycode);
|
2020-08-07 16:46:55 +00:00
|
|
|
meta_key = TRUE;
|
2020-08-05 08:09:49 +00:00
|
|
|
} else
|
2020-08-05 08:34:28 +00:00
|
|
|
keycode = parse_escape_sequence(keycode);
|
2020-08-05 07:24:29 +00:00
|
|
|
} else {
|
2020-08-05 08:09:49 +00:00
|
|
|
escapes = 0;
|
|
|
|
if (keycode == '[' && key_buffer_len > 0 &&
|
|
|
|
(('A' <= *key_buffer && *key_buffer <= 'D') ||
|
|
|
|
('a' <= *key_buffer && *key_buffer <= 'd'))) {
|
|
|
|
/* An iTerm2/Eterm/rxvt double-escape sequence: Esc Esc [ X
|
|
|
|
* for Option+arrow, or Esc Esc [ x for Shift+Alt+arrow. */
|
2020-08-10 05:53:41 +00:00
|
|
|
switch (get_input(NULL)) {
|
2020-08-05 08:09:49 +00:00
|
|
|
case 'A': return KEY_HOME;
|
|
|
|
case 'B': return KEY_END;
|
|
|
|
case 'C': return CONTROL_RIGHT;
|
|
|
|
case 'D': return CONTROL_LEFT;
|
2020-07-24 14:43:05 +00:00
|
|
|
#ifndef NANO_TINY
|
2020-08-05 09:03:35 +00:00
|
|
|
case 'a': shift_held = TRUE; return KEY_PPAGE;
|
|
|
|
case 'b': shift_held = TRUE; return KEY_NPAGE;
|
|
|
|
case 'c': shift_held = TRUE; return KEY_HOME;
|
|
|
|
case 'd': shift_held = TRUE; return KEY_END;
|
2020-07-24 14:43:05 +00:00
|
|
|
#endif
|
2020-08-05 08:09:49 +00:00
|
|
|
}
|
|
|
|
} else if (key_buffer_len > 0 && *key_buffer != ESC_CODE &&
|
|
|
|
(keycode == '[' || keycode == 'O')) {
|
2020-08-05 08:34:28 +00:00
|
|
|
keycode = parse_escape_sequence(keycode);
|
2020-08-05 08:09:49 +00:00
|
|
|
meta_key = TRUE;
|
|
|
|
} else if ('0' <= keycode && (keycode <= '2' ||
|
|
|
|
(keycode <= '9' && digit_count > 0))) {
|
2020-08-05 07:37:22 +00:00
|
|
|
/* Two escapes followed by one digit: byte sequence mode. */
|
2020-08-05 08:09:49 +00:00
|
|
|
int byte = assemble_byte_code(keycode);
|
|
|
|
|
2020-08-05 07:37:22 +00:00
|
|
|
/* If the decimal byte value is not yet complete, return nothing. */
|
2020-08-05 08:09:49 +00:00
|
|
|
if (byte == PROCEED) {
|
|
|
|
escapes = 2;
|
|
|
|
return ERR;
|
|
|
|
}
|
2020-07-20 17:08:08 +00:00
|
|
|
#ifdef ENABLE_UTF8
|
2020-08-05 08:09:49 +00:00
|
|
|
else if (byte > 0x7F && using_utf8()) {
|
2020-08-05 07:37:22 +00:00
|
|
|
/* Convert the code to the corresponding Unicode, and
|
|
|
|
* put the second byte back into the keyboard buffer. */
|
2020-08-05 08:09:49 +00:00
|
|
|
if (byte < 0xC0) {
|
|
|
|
put_back((unsigned char)byte);
|
|
|
|
return 0xC2;
|
|
|
|
} else {
|
|
|
|
put_back((unsigned char)(byte - 0x40));
|
|
|
|
return 0xC3;
|
2020-07-24 15:12:31 +00:00
|
|
|
}
|
2020-08-05 08:09:49 +00:00
|
|
|
}
|
2020-07-20 17:08:08 +00:00
|
|
|
#endif
|
2020-08-05 08:09:49 +00:00
|
|
|
else if (byte == '\t' || byte == DEL_CODE)
|
2020-08-05 08:34:28 +00:00
|
|
|
keycode = byte;
|
2020-08-05 08:09:49 +00:00
|
|
|
else
|
|
|
|
return byte;
|
2020-08-05 09:03:35 +00:00
|
|
|
} else if (digit_count == 0) {
|
2020-12-04 16:03:10 +00:00
|
|
|
/* If the first escape arrived alone but not the second, then it
|
|
|
|
* is a Meta keystroke; otherwise, it is an "Esc Esc control". */
|
2020-12-04 15:57:17 +00:00
|
|
|
if (first_escape_was_alone && !last_escape_was_alone) {
|
2020-08-05 09:03:35 +00:00
|
|
|
if (!shifted_metas)
|
|
|
|
keycode = tolower(keycode);
|
|
|
|
meta_key = TRUE;
|
|
|
|
} else
|
|
|
|
keycode = convert_to_control(keycode);
|
|
|
|
}
|
2020-01-26 15:02:40 +00:00
|
|
|
}
|
|
|
|
|
2020-08-05 08:34:28 +00:00
|
|
|
if (keycode == controlleft)
|
2020-01-26 15:02:40 +00:00
|
|
|
return CONTROL_LEFT;
|
2020-08-05 08:34:28 +00:00
|
|
|
else if (keycode == controlright)
|
2020-01-26 15:02:40 +00:00
|
|
|
return CONTROL_RIGHT;
|
2020-08-05 08:34:28 +00:00
|
|
|
else if (keycode == controlup)
|
2020-01-26 15:02:40 +00:00
|
|
|
return CONTROL_UP;
|
2020-08-05 08:34:28 +00:00
|
|
|
else if (keycode == controldown)
|
2020-01-26 15:02:40 +00:00
|
|
|
return CONTROL_DOWN;
|
2020-08-05 08:34:28 +00:00
|
|
|
else if (keycode == controlhome)
|
2020-01-26 15:02:40 +00:00
|
|
|
return CONTROL_HOME;
|
2020-08-05 08:34:28 +00:00
|
|
|
else if (keycode == controlend)
|
2020-01-26 15:02:40 +00:00
|
|
|
return CONTROL_END;
|
|
|
|
#ifndef NANO_TINY
|
2020-08-05 08:34:28 +00:00
|
|
|
else if (keycode == controldelete)
|
2020-01-26 15:02:40 +00:00
|
|
|
return CONTROL_DELETE;
|
2020-08-05 08:34:28 +00:00
|
|
|
else if (keycode == controlshiftdelete)
|
2020-01-26 15:02:40 +00:00
|
|
|
return CONTROL_SHIFT_DELETE;
|
2020-08-05 08:34:28 +00:00
|
|
|
else if (keycode == shiftup) {
|
2020-01-26 15:02:40 +00:00
|
|
|
shift_held = TRUE;
|
|
|
|
return KEY_UP;
|
2020-08-05 08:34:28 +00:00
|
|
|
} else if (keycode == shiftdown) {
|
2020-01-26 15:02:40 +00:00
|
|
|
shift_held = TRUE;
|
|
|
|
return KEY_DOWN;
|
2020-08-05 08:34:28 +00:00
|
|
|
} else if (keycode == shiftcontrolleft) {
|
2020-01-26 15:02:40 +00:00
|
|
|
shift_held = TRUE;
|
|
|
|
return CONTROL_LEFT;
|
2020-08-05 08:34:28 +00:00
|
|
|
} else if (keycode == shiftcontrolright) {
|
2020-01-26 15:02:40 +00:00
|
|
|
shift_held = TRUE;
|
|
|
|
return CONTROL_RIGHT;
|
2020-08-05 08:34:28 +00:00
|
|
|
} else if (keycode == shiftcontrolup) {
|
2020-01-26 15:02:40 +00:00
|
|
|
shift_held = TRUE;
|
|
|
|
return CONTROL_UP;
|
2020-08-05 08:34:28 +00:00
|
|
|
} else if (keycode == shiftcontroldown) {
|
2020-01-26 15:02:40 +00:00
|
|
|
shift_held = TRUE;
|
|
|
|
return CONTROL_DOWN;
|
2020-08-05 08:34:28 +00:00
|
|
|
} else if (keycode == shiftcontrolhome) {
|
2020-01-26 15:02:40 +00:00
|
|
|
shift_held = TRUE;
|
|
|
|
return CONTROL_HOME;
|
2020-08-05 08:34:28 +00:00
|
|
|
} else if (keycode == shiftcontrolend) {
|
2020-01-26 15:02:40 +00:00
|
|
|
shift_held = TRUE;
|
|
|
|
return CONTROL_END;
|
2020-08-05 08:34:28 +00:00
|
|
|
} else if (keycode == altleft)
|
2020-01-26 15:02:40 +00:00
|
|
|
return ALT_LEFT;
|
2020-08-05 08:34:28 +00:00
|
|
|
else if (keycode == altright)
|
2020-01-26 15:02:40 +00:00
|
|
|
return ALT_RIGHT;
|
2020-08-05 08:34:28 +00:00
|
|
|
else if (keycode == altup)
|
2020-01-26 15:02:40 +00:00
|
|
|
return ALT_UP;
|
2020-08-05 08:34:28 +00:00
|
|
|
else if (keycode == altdown)
|
2020-01-26 15:02:40 +00:00
|
|
|
return ALT_DOWN;
|
2020-08-05 08:34:28 +00:00
|
|
|
else if (keycode == altpageup)
|
2018-12-04 01:45:18 +00:00
|
|
|
return ALT_PAGEUP;
|
2020-08-05 08:34:28 +00:00
|
|
|
else if (keycode == altpagedown)
|
2018-12-04 01:45:18 +00:00
|
|
|
return ALT_PAGEDOWN;
|
2020-08-05 08:34:28 +00:00
|
|
|
else if (keycode == altinsert)
|
2018-12-04 01:45:18 +00:00
|
|
|
return ALT_INSERT;
|
2020-08-05 08:34:28 +00:00
|
|
|
else if (keycode == altdelete)
|
2020-01-26 15:02:40 +00:00
|
|
|
return ALT_DELETE;
|
2020-08-05 08:34:28 +00:00
|
|
|
else if (keycode == shiftaltleft) {
|
2020-01-26 15:02:40 +00:00
|
|
|
shift_held = TRUE;
|
|
|
|
return KEY_HOME;
|
2020-08-05 08:34:28 +00:00
|
|
|
} else if (keycode == shiftaltright) {
|
2020-01-26 15:02:40 +00:00
|
|
|
shift_held = TRUE;
|
|
|
|
return KEY_END;
|
2020-08-05 08:34:28 +00:00
|
|
|
} else if (keycode == shiftaltup) {
|
2020-01-26 15:02:40 +00:00
|
|
|
shift_held = TRUE;
|
|
|
|
return KEY_PPAGE;
|
2020-08-05 08:34:28 +00:00
|
|
|
} else if (keycode == shiftaltdown) {
|
2020-01-26 15:02:40 +00:00
|
|
|
shift_held = TRUE;
|
|
|
|
return KEY_NPAGE;
|
|
|
|
}
|
2019-12-30 10:55:41 +00:00
|
|
|
#endif
|
2020-01-26 15:02:40 +00:00
|
|
|
|
|
|
|
#ifdef __linux__
|
|
|
|
/* When not running under X, check for the bare arrow keys whether
|
|
|
|
* Shift/Ctrl/Alt are being held together with them. */
|
|
|
|
unsigned char modifiers = 6;
|
|
|
|
|
|
|
|
/* Modifiers are: Alt (8), Ctrl (4), Shift (1). */
|
|
|
|
if (on_a_vt && !mute_modifiers && ioctl(0, TIOCLINUX, &modifiers) >= 0) {
|
|
|
|
#ifndef NANO_TINY
|
|
|
|
/* Is Shift being held? */
|
|
|
|
if (modifiers & 0x01) {
|
2020-08-05 08:34:28 +00:00
|
|
|
if (keycode == '\t')
|
2020-01-26 15:02:40 +00:00
|
|
|
return SHIFT_TAB;
|
2020-08-05 08:34:28 +00:00
|
|
|
if (keycode == KEY_DC && modifiers == 0x01)
|
2020-07-22 18:32:38 +00:00
|
|
|
return SHIFT_DELETE;
|
2020-08-05 08:34:28 +00:00
|
|
|
if (keycode == KEY_DC && modifiers == 0x05)
|
2020-07-22 18:32:38 +00:00
|
|
|
return CONTROL_SHIFT_DELETE;
|
2020-01-26 15:02:40 +00:00
|
|
|
if (!meta_key)
|
|
|
|
shift_held = TRUE;
|
|
|
|
}
|
|
|
|
/* Is Alt being held? */
|
|
|
|
if (modifiers == 0x08) {
|
2020-08-05 08:34:28 +00:00
|
|
|
switch (keycode) {
|
2020-07-22 08:51:20 +00:00
|
|
|
case KEY_UP: return ALT_UP;
|
|
|
|
case KEY_DOWN: return ALT_DOWN;
|
|
|
|
case KEY_PPAGE: return ALT_PAGEUP;
|
|
|
|
case KEY_NPAGE: return ALT_PAGEDOWN;
|
|
|
|
case KEY_DC: return ALT_DELETE;
|
|
|
|
case KEY_IC: return ALT_INSERT;
|
|
|
|
}
|
2020-01-26 15:02:40 +00:00
|
|
|
}
|
2018-01-23 11:12:41 +00:00
|
|
|
#endif
|
2020-01-26 15:02:40 +00:00
|
|
|
/* Is Ctrl being held? */
|
|
|
|
if (modifiers & 0x04) {
|
2020-08-05 08:34:28 +00:00
|
|
|
switch (keycode) {
|
2020-07-22 08:51:20 +00:00
|
|
|
case KEY_UP: return CONTROL_UP;
|
|
|
|
case KEY_DOWN: return CONTROL_DOWN;
|
|
|
|
case KEY_LEFT: return CONTROL_LEFT;
|
|
|
|
case KEY_RIGHT: return CONTROL_RIGHT;
|
|
|
|
case KEY_HOME: return CONTROL_HOME;
|
|
|
|
case KEY_END: return CONTROL_END;
|
|
|
|
case KEY_DC: return CONTROL_DELETE;
|
|
|
|
}
|
2020-01-26 15:02:40 +00:00
|
|
|
}
|
2016-04-24 09:28:28 +00:00
|
|
|
#ifndef NANO_TINY
|
2020-01-26 15:02:40 +00:00
|
|
|
/* Are both Shift and Alt being held? */
|
|
|
|
if ((modifiers & 0x09) == 0x09) {
|
2020-08-05 08:34:28 +00:00
|
|
|
switch (keycode) {
|
2020-07-22 08:51:20 +00:00
|
|
|
case KEY_UP: return KEY_PPAGE;
|
|
|
|
case KEY_DOWN: return KEY_NPAGE;
|
|
|
|
case KEY_LEFT: return KEY_HOME;
|
|
|
|
case KEY_RIGHT: return KEY_END;
|
|
|
|
}
|
2020-01-26 15:02:40 +00:00
|
|
|
}
|
2017-12-29 18:27:33 +00:00
|
|
|
#endif
|
2020-01-26 15:02:40 +00:00
|
|
|
}
|
|
|
|
#endif /* __linux__ */
|
|
|
|
|
2016-04-24 09:28:28 +00:00
|
|
|
#ifndef NANO_TINY
|
2020-01-26 15:02:40 +00:00
|
|
|
/* When <Tab> is pressed while the mark is on, do an indent. */
|
2020-08-05 08:34:28 +00:00
|
|
|
if (keycode == '\t' && openfile->mark && currmenu == MMAIN &&
|
2020-01-26 15:02:40 +00:00
|
|
|
!bracketed_paste && openfile->mark != openfile->current)
|
|
|
|
return INDENT_KEY;
|
2016-04-24 09:28:28 +00:00
|
|
|
#endif
|
2020-01-26 15:02:40 +00:00
|
|
|
|
2020-08-05 08:34:28 +00:00
|
|
|
switch (keycode) {
|
2020-01-26 15:02:40 +00:00
|
|
|
case KEY_SLEFT:
|
|
|
|
shift_held = TRUE;
|
|
|
|
return KEY_LEFT;
|
|
|
|
case KEY_SRIGHT:
|
|
|
|
shift_held = TRUE;
|
|
|
|
return KEY_RIGHT;
|
|
|
|
#ifdef KEY_SR
|
2020-12-05 11:34:17 +00:00
|
|
|
#ifdef KEY_SUP /* Ncurses doesn't know Shift+Up. */
|
2020-01-26 15:02:40 +00:00
|
|
|
case KEY_SUP:
|
2020-01-03 11:34:15 +00:00
|
|
|
#endif
|
2020-01-26 15:02:40 +00:00
|
|
|
case KEY_SR: /* Scroll backward, on Xfce4-terminal. */
|
|
|
|
shift_held = TRUE;
|
|
|
|
return KEY_UP;
|
2020-01-22 11:55:32 +00:00
|
|
|
#endif
|
2020-01-26 15:02:40 +00:00
|
|
|
#ifdef KEY_SF
|
2020-12-05 11:34:17 +00:00
|
|
|
#ifdef KEY_SDOWN /* Ncurses doesn't know Shift+Down. */
|
2020-01-26 15:02:40 +00:00
|
|
|
case KEY_SDOWN:
|
|
|
|
#endif
|
|
|
|
case KEY_SF: /* Scroll forward, on Xfce4-terminal. */
|
|
|
|
shift_held = TRUE;
|
|
|
|
return KEY_DOWN;
|
|
|
|
#endif
|
2020-12-05 11:34:17 +00:00
|
|
|
#ifdef KEY_SHOME /* HP-UX 10-11 doesn't know Shift+Home. */
|
2020-01-26 15:02:40 +00:00
|
|
|
case KEY_SHOME:
|
|
|
|
#endif
|
|
|
|
case SHIFT_HOME:
|
|
|
|
shift_held = TRUE;
|
|
|
|
case KEY_A1: /* Home (7) on keypad with NumLock off. */
|
|
|
|
return KEY_HOME;
|
2020-12-05 11:34:17 +00:00
|
|
|
#ifdef KEY_SEND /* HP-UX 10-11 doesn't know Shift+End. */
|
2020-01-26 15:02:40 +00:00
|
|
|
case KEY_SEND:
|
|
|
|
#endif
|
|
|
|
case SHIFT_END:
|
|
|
|
shift_held = TRUE;
|
|
|
|
case KEY_C1: /* End (1) on keypad with NumLock off. */
|
|
|
|
return KEY_END;
|
|
|
|
#ifdef KEY_EOL
|
|
|
|
case KEY_EOL: /* Ctrl+End on rxvt-unicode. */
|
|
|
|
return CONTROL_END;
|
2018-11-07 20:04:20 +00:00
|
|
|
#endif
|
|
|
|
#ifndef NANO_TINY
|
2020-01-26 15:02:40 +00:00
|
|
|
#ifdef KEY_SPREVIOUS
|
|
|
|
case KEY_SPREVIOUS:
|
2018-10-05 17:09:17 +00:00
|
|
|
#endif
|
2020-01-26 15:02:40 +00:00
|
|
|
case SHIFT_PAGEUP: /* Fake key, from Shift+Alt+Up. */
|
|
|
|
shift_held = TRUE;
|
2018-01-23 18:32:13 +00:00
|
|
|
#endif
|
2020-01-26 15:02:40 +00:00
|
|
|
case KEY_A3: /* PageUp (9) on keypad with NumLock off. */
|
|
|
|
return KEY_PPAGE;
|
2018-07-17 16:20:52 +00:00
|
|
|
#ifndef NANO_TINY
|
2020-01-26 15:02:40 +00:00
|
|
|
#ifdef KEY_SNEXT
|
|
|
|
case KEY_SNEXT:
|
2018-01-23 18:32:13 +00:00
|
|
|
#endif
|
2020-01-26 15:02:40 +00:00
|
|
|
case SHIFT_PAGEDOWN: /* Fake key, from Shift+Alt+Down. */
|
|
|
|
shift_held = TRUE;
|
2017-12-29 18:27:33 +00:00
|
|
|
#endif
|
2020-01-26 15:02:40 +00:00
|
|
|
case KEY_C3: /* PageDown (3) on keypad with NumLock off. */
|
|
|
|
return KEY_NPAGE;
|
|
|
|
/* When requested, swap meanings of keycodes for <Bsp> and <Del>. */
|
|
|
|
case DEL_CODE:
|
|
|
|
case KEY_BACKSPACE:
|
|
|
|
return (ISSET(REBIND_DELETE) ? KEY_DC : KEY_BACKSPACE);
|
|
|
|
case KEY_DC:
|
|
|
|
return (ISSET(REBIND_DELETE) ? KEY_BACKSPACE : KEY_DC);
|
|
|
|
case KEY_SDC:
|
|
|
|
return SHIFT_DELETE;
|
|
|
|
case KEY_SCANCEL:
|
2020-06-27 08:03:07 +00:00
|
|
|
return KEY_CANCEL;
|
2020-01-26 15:02:40 +00:00
|
|
|
case KEY_SSUSPEND:
|
2020-06-27 08:03:07 +00:00
|
|
|
return KEY_SUSPEND;
|
2020-01-26 15:02:40 +00:00
|
|
|
case KEY_BTAB:
|
|
|
|
return SHIFT_TAB;
|
2020-12-05 11:34:17 +00:00
|
|
|
|
2020-01-26 15:02:40 +00:00
|
|
|
case KEY_SBEG:
|
|
|
|
case KEY_BEG:
|
|
|
|
case KEY_B2: /* Center (5) on keypad with NumLock off. */
|
|
|
|
#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:
|
|
|
|
#endif
|
2020-12-05 11:34:17 +00:00
|
|
|
#ifdef KEY_RESIZE /* SunOS 5.7-5.9 doesn't know KEY_RESIZE. */
|
2020-01-26 15:02:40 +00:00
|
|
|
case KEY_RESIZE:
|
|
|
|
#endif
|
|
|
|
case KEY_FLUSH:
|
|
|
|
return ERR; /* Ignore this keystroke. */
|
2006-07-23 17:54:35 +00:00
|
|
|
}
|
|
|
|
|
2020-08-05 08:34:28 +00:00
|
|
|
return keycode;
|
2006-05-25 22:10:27 +00:00
|
|
|
}
|
|
|
|
|
2020-01-26 14:41:09 +00:00
|
|
|
/* Read in a single keystroke, ignoring any that are invalid. */
|
|
|
|
int get_kbinput(WINDOW *win, bool showcursor)
|
|
|
|
{
|
|
|
|
int kbinput = ERR;
|
|
|
|
|
|
|
|
reveal_cursor = showcursor;
|
|
|
|
|
|
|
|
/* Extract one keystroke from the input stream. */
|
|
|
|
while (kbinput == ERR)
|
|
|
|
kbinput = parse_kbinput(win);
|
|
|
|
|
|
|
|
/* If we read from the edit window, blank the status bar if needed. */
|
|
|
|
if (win == edit)
|
|
|
|
check_statusblank();
|
|
|
|
|
|
|
|
return kbinput;
|
|
|
|
}
|
|
|
|
|
2006-05-27 17:39:19 +00:00
|
|
|
#ifdef ENABLE_UTF8
|
2020-08-10 07:24:22 +00:00
|
|
|
#define INVALID_DIGIT -77
|
|
|
|
|
2020-07-23 07:56:38 +00:00
|
|
|
/* If the given symbol is a valid hexadecimal digit, multiply it by factor
|
|
|
|
* and add the result to the given unicode, and return PROCEED to signify
|
|
|
|
* okay. When not a hexadecimal digit, return the symbol itself. */
|
|
|
|
long add_unicode_digit(int symbol, long factor, long *unicode)
|
2006-05-28 17:30:28 +00:00
|
|
|
{
|
2020-07-23 07:56:38 +00:00
|
|
|
if ('0' <= symbol && symbol <= '9')
|
|
|
|
*unicode += (symbol - '0') * factor;
|
|
|
|
else if ('a' <= tolower(symbol) && tolower(symbol) <= 'f')
|
|
|
|
*unicode += (tolower(symbol) - 'a' + 10) * factor;
|
2017-12-29 18:27:33 +00:00
|
|
|
else
|
2020-08-10 07:24:22 +00:00
|
|
|
return INVALID_DIGIT;
|
2006-05-28 17:30:28 +00:00
|
|
|
|
2020-07-11 16:58:12 +00:00
|
|
|
return PROCEED;
|
2006-05-28 17:30:28 +00:00
|
|
|
}
|
|
|
|
|
2020-07-23 07:56:38 +00:00
|
|
|
/* For each consecutive call, gather the given symbol into a six-digit Unicode
|
2020-07-11 16:23:12 +00:00
|
|
|
* (from 000000 to 10FFFF, case-insensitive). When it is complete, return the
|
2020-07-23 07:56:38 +00:00
|
|
|
* assembled Unicode; until then, return PROCEED when the symbol is valid. */
|
|
|
|
long assemble_unicode(int symbol)
|
2005-01-03 19:56:56 +00:00
|
|
|
{
|
2020-07-23 07:44:14 +00:00
|
|
|
static long unicode = 0;
|
|
|
|
static int digits = 0;
|
2020-07-11 16:58:12 +00:00
|
|
|
long retval = PROCEED;
|
2017-12-29 18:27:33 +00:00
|
|
|
|
2020-07-23 07:44:14 +00:00
|
|
|
switch (++digits) {
|
2017-12-29 18:27:33 +00:00
|
|
|
case 1:
|
2020-07-23 07:56:38 +00:00
|
|
|
unicode = (symbol - '0') * 0x100000;
|
2017-12-29 18:27:33 +00:00
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
/* The second digit must be zero if the first was one, but
|
|
|
|
* may be any hexadecimal value if the first was zero. */
|
2020-07-23 07:56:38 +00:00
|
|
|
if (symbol == '0' || unicode == 0)
|
|
|
|
retval = add_unicode_digit(symbol, 0x10000, &unicode);
|
2017-12-29 18:27:33 +00:00
|
|
|
else
|
2020-08-10 07:24:22 +00:00
|
|
|
retval = INVALID_DIGIT;
|
2017-12-29 18:27:33 +00:00
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
/* Later digits may be any hexadecimal value. */
|
2020-07-23 07:56:38 +00:00
|
|
|
retval = add_unicode_digit(symbol, 0x1000, &unicode);
|
2017-12-29 18:27:33 +00:00
|
|
|
break;
|
|
|
|
case 4:
|
2020-07-23 07:56:38 +00:00
|
|
|
retval = add_unicode_digit(symbol, 0x100, &unicode);
|
2017-12-29 18:27:33 +00:00
|
|
|
break;
|
|
|
|
case 5:
|
2020-07-23 07:56:38 +00:00
|
|
|
retval = add_unicode_digit(symbol, 0x10, &unicode);
|
2017-12-29 18:27:33 +00:00
|
|
|
break;
|
|
|
|
case 6:
|
2020-07-23 07:56:38 +00:00
|
|
|
retval = add_unicode_digit(symbol, 0x1, &unicode);
|
2017-12-29 18:27:33 +00:00
|
|
|
/* If also the sixth digit was a valid hexadecimal value, then
|
|
|
|
* the Unicode sequence is complete, so return it. */
|
2020-07-11 16:58:12 +00:00
|
|
|
if (retval == PROCEED)
|
2020-07-23 07:44:14 +00:00
|
|
|
retval = unicode;
|
2017-12-29 18:27:33 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Show feedback only when editing, not when at a prompt. */
|
2020-07-11 16:58:12 +00:00
|
|
|
if (retval == PROCEED && currmenu == MMAIN) {
|
2017-12-29 18:27:33 +00:00
|
|
|
char partial[7] = "......";
|
|
|
|
|
|
|
|
/* Construct the partial result, right-padding it with dots. */
|
2020-07-23 07:44:14 +00:00
|
|
|
snprintf(partial, digits + 1, "%06lX", unicode);
|
|
|
|
partial[digits] = '.';
|
2017-12-29 18:27:33 +00:00
|
|
|
|
|
|
|
/* TRANSLATORS: This is shown while a six-digit hexadecimal
|
|
|
|
* Unicode character code (%s) is being typed in. */
|
2020-12-08 16:09:07 +00:00
|
|
|
statusline(INFO, _("Unicode Input: %s"), partial);
|
2017-12-29 18:27:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* If we have an end result, reset the Unicode digit counter. */
|
2020-07-11 16:58:12 +00:00
|
|
|
if (retval != PROCEED)
|
2020-07-23 07:44:14 +00:00
|
|
|
digits = 0;
|
2017-12-29 18:27:33 +00:00
|
|
|
|
|
|
|
return retval;
|
2004-12-04 17:41:52 +00:00
|
|
|
}
|
2006-05-27 17:39:19 +00:00
|
|
|
#endif /* ENABLE_UTF8 */
|
2006-05-27 15:52:26 +00:00
|
|
|
|
2016-11-18 13:14:36 +00:00
|
|
|
/* Read in one control character (or an iTerm/Eterm/rxvt double Escape),
|
|
|
|
* or convert a series of six digits into a Unicode codepoint. Return
|
|
|
|
* in count either 1 (for a control character or the first byte of a
|
|
|
|
* multibyte sequence), or 2 (for an iTerm/Eterm/rxvt double Escape). */
|
2016-07-16 17:44:24 +00:00
|
|
|
int *parse_verbatim_kbinput(WINDOW *win, size_t *count)
|
2004-05-28 17:23:33 +00:00
|
|
|
{
|
2020-08-10 05:39:29 +00:00
|
|
|
int keycode, *yield;
|
2004-05-28 17:23:33 +00:00
|
|
|
|
2017-12-29 18:27:33 +00:00
|
|
|
reveal_cursor = TRUE;
|
2017-09-20 20:20:18 +00:00
|
|
|
|
2017-12-29 18:27:33 +00:00
|
|
|
/* Read in the first code. */
|
2020-08-10 05:39:29 +00:00
|
|
|
keycode = get_input(win);
|
2004-12-04 17:41:52 +00:00
|
|
|
|
2016-07-25 15:28:54 +00:00
|
|
|
#ifndef NANO_TINY
|
2017-12-29 18:27:33 +00:00
|
|
|
/* When the window was resized, abort and return nothing. */
|
2020-08-10 05:39:29 +00:00
|
|
|
if (keycode == KEY_WINCH) {
|
2020-08-10 09:42:09 +00:00
|
|
|
*count = 999;
|
2017-12-29 18:27:33 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
2016-07-25 15:28:54 +00:00
|
|
|
#endif
|
2016-07-16 20:11:14 +00:00
|
|
|
|
2020-08-10 05:39:29 +00:00
|
|
|
/* Reserve ample space for the possible result. */
|
2020-08-30 02:57:45 +00:00
|
|
|
yield = nmalloc(6 * sizeof(int));
|
2017-02-28 13:45:02 +00:00
|
|
|
|
2006-05-27 17:39:19 +00:00
|
|
|
#ifdef ENABLE_UTF8
|
2020-08-10 05:53:41 +00:00
|
|
|
/* If the first code is a valid Unicode starter digit (0 or 1),
|
|
|
|
* commence Unicode input. Otherwise, put the code back. */
|
|
|
|
if (using_utf8() && (keycode == '0' || keycode == '1')) {
|
2020-08-10 05:55:00 +00:00
|
|
|
long unicode = assemble_unicode(keycode);
|
2021-04-07 15:08:05 +00:00
|
|
|
char multibyte[MB_CUR_MAX];
|
2017-12-29 18:27:33 +00:00
|
|
|
|
2020-08-10 05:55:00 +00:00
|
|
|
reveal_cursor = FALSE;
|
2017-12-29 18:27:33 +00:00
|
|
|
|
2020-08-10 05:55:00 +00:00
|
|
|
while (unicode == PROCEED) {
|
|
|
|
keycode = get_input(win);
|
|
|
|
unicode = assemble_unicode(keycode);
|
|
|
|
}
|
2004-12-04 17:41:52 +00:00
|
|
|
|
2020-08-11 17:58:04 +00:00
|
|
|
#ifndef NANO_TINY
|
2020-08-10 09:42:09 +00:00
|
|
|
if (keycode == KEY_WINCH) {
|
|
|
|
*count = 999;
|
|
|
|
free(yield);
|
|
|
|
return NULL;
|
|
|
|
}
|
2020-08-11 17:58:04 +00:00
|
|
|
#endif
|
2020-08-10 07:24:22 +00:00
|
|
|
/* For an invalid digit, discard its possible continuation bytes. */
|
2020-08-10 14:08:17 +00:00
|
|
|
if (unicode == INVALID_DIGIT) {
|
|
|
|
if (keycode == ESC_CODE) {
|
2020-08-10 07:24:22 +00:00
|
|
|
get_input(NULL);
|
2020-08-10 14:08:17 +00:00
|
|
|
while (key_buffer_len > 0 && 0x1F < *key_buffer && *key_buffer < 0x40)
|
|
|
|
get_input(NULL);
|
|
|
|
if (key_buffer_len > 0 && 0x3F < *key_buffer && *key_buffer < 0x7F)
|
|
|
|
get_input(NULL);
|
|
|
|
} else if (0xC0 <= keycode && keycode <= 0xFF)
|
|
|
|
while (key_buffer_len > 0 && 0x7F < *key_buffer && *key_buffer < 0xC0)
|
|
|
|
get_input(NULL);
|
|
|
|
}
|
2020-08-10 07:24:22 +00:00
|
|
|
|
2020-08-10 05:55:00 +00:00
|
|
|
/* Convert the Unicode value to a multibyte sequence. */
|
2021-04-07 15:08:05 +00:00
|
|
|
*count = wctomb(multibyte, unicode);
|
|
|
|
|
|
|
|
if (*count > MAXCHARLEN)
|
|
|
|
*count = 0;
|
2006-05-27 17:39:19 +00:00
|
|
|
|
2020-08-10 05:55:00 +00:00
|
|
|
/* Change the multibyte character into a series of integers. */
|
|
|
|
for (size_t i = 0; i < *count; i++)
|
|
|
|
yield[i] = (int)multibyte[i];
|
2017-02-28 13:45:02 +00:00
|
|
|
|
2020-08-10 05:55:00 +00:00
|
|
|
return yield;
|
2020-08-10 05:39:29 +00:00
|
|
|
}
|
2006-05-28 17:09:49 +00:00
|
|
|
#endif /* ENABLE_UTF8 */
|
2004-12-04 17:41:52 +00:00
|
|
|
|
2020-08-10 05:39:29 +00:00
|
|
|
yield[0] = keycode;
|
2006-12-02 17:22:21 +00:00
|
|
|
|
2020-08-07 13:52:35 +00:00
|
|
|
/* In case of an escape, take also a second code, as it might be another
|
|
|
|
* escape (on iTerm2/rxvt) or a control code (for M-Bsp and M-Enter). */
|
2020-08-10 05:39:29 +00:00
|
|
|
if (keycode == ESC_CODE && key_buffer_len > 0) {
|
|
|
|
yield[1] = get_input(NULL);
|
2017-12-29 18:27:33 +00:00
|
|
|
*count = 2;
|
2020-08-10 05:39:29 +00:00
|
|
|
}
|
2016-07-16 17:44:24 +00:00
|
|
|
|
2020-08-10 05:39:29 +00:00
|
|
|
return yield;
|
2004-05-28 17:23:33 +00:00
|
|
|
}
|
|
|
|
|
2020-02-12 15:06:57 +00:00
|
|
|
/* Read in one control code, one character byte, or the leading escapes of
|
|
|
|
* an escape sequence, and return the resulting number of bytes in count. */
|
2020-02-12 16:16:27 +00:00
|
|
|
char *get_verbatim_kbinput(WINDOW *win, size_t *count)
|
2020-02-12 15:06:57 +00:00
|
|
|
{
|
2020-08-30 02:57:45 +00:00
|
|
|
char *bytes = nmalloc(MAXCHARLEN + 2);
|
2020-02-12 15:06:57 +00:00
|
|
|
int *input;
|
|
|
|
|
|
|
|
/* Turn off flow control characters if necessary so that we can type
|
|
|
|
* them in verbatim, and turn the keypad off if necessary so that we
|
|
|
|
* don't get extended keypad values. */
|
|
|
|
if (ISSET(PRESERVE))
|
|
|
|
disable_flow_control();
|
|
|
|
if (!ISSET(RAW_SEQUENCES))
|
|
|
|
keypad(win, FALSE);
|
2020-12-05 10:57:08 +00:00
|
|
|
|
2020-07-08 14:14:08 +00:00
|
|
|
#ifndef NANO_TINY
|
|
|
|
/* Turn bracketed-paste mode off. */
|
2020-07-22 07:07:14 +00:00
|
|
|
printf("\x1B[?2004l");
|
2020-07-08 14:14:08 +00:00
|
|
|
fflush(stdout);
|
|
|
|
#endif
|
|
|
|
|
2020-08-15 14:07:30 +00:00
|
|
|
linger_after_escape = TRUE;
|
|
|
|
|
2020-02-12 15:06:57 +00:00
|
|
|
/* Read in a single byte or two escapes. */
|
|
|
|
input = parse_verbatim_kbinput(win, count);
|
|
|
|
|
2020-02-13 12:46:31 +00:00
|
|
|
/* If the byte is invalid in the current mode, discard it;
|
|
|
|
* if it is an incomplete Unicode sequence, stuff it back. */
|
|
|
|
if (input != NULL) {
|
2020-08-10 09:55:56 +00:00
|
|
|
if (*input >= 0x80 && *count == 1) {
|
2020-02-13 12:46:31 +00:00
|
|
|
put_back(*input);
|
2020-08-10 09:48:31 +00:00
|
|
|
*count = 999;
|
2020-08-10 09:55:56 +00:00
|
|
|
} else if ((*input == '\n' && as_an_at) || (*input == '\0' && !as_an_at))
|
|
|
|
*count = 0;
|
2020-02-13 12:15:46 +00:00
|
|
|
}
|
|
|
|
|
2020-08-15 14:07:30 +00:00
|
|
|
linger_after_escape = FALSE;
|
|
|
|
|
2020-07-08 14:14:08 +00:00
|
|
|
#ifndef NANO_TINY
|
|
|
|
/* Turn bracketed-paste mode back on. */
|
2020-07-22 07:07:14 +00:00
|
|
|
printf("\x1B[?2004h");
|
2020-07-08 14:14:08 +00:00
|
|
|
fflush(stdout);
|
|
|
|
#endif
|
|
|
|
|
2020-02-12 15:06:57 +00:00
|
|
|
/* Turn flow control characters back on if necessary and turn the
|
|
|
|
* keypad back on if necessary now that we're done. */
|
|
|
|
if (ISSET(PRESERVE))
|
|
|
|
enable_flow_control();
|
2020-12-05 10:57:08 +00:00
|
|
|
|
2020-02-12 15:06:57 +00:00
|
|
|
/* Use the global window pointers, because a resize may have freed
|
|
|
|
* the data that the win parameter points to. */
|
|
|
|
if (!ISSET(RAW_SEQUENCES)) {
|
|
|
|
keypad(edit, TRUE);
|
|
|
|
keypad(bottomwin, TRUE);
|
|
|
|
}
|
|
|
|
|
2020-08-10 09:42:09 +00:00
|
|
|
if (*count < 999) {
|
|
|
|
for (size_t i = 0; i < *count; i++)
|
|
|
|
bytes[i] = (char)input[i];
|
|
|
|
bytes[*count] = '\0';
|
|
|
|
}
|
2020-02-12 16:16:27 +00:00
|
|
|
|
|
|
|
free(input);
|
|
|
|
|
|
|
|
return bytes;
|
2020-02-12 15:06:57 +00:00
|
|
|
}
|
|
|
|
|
2017-05-01 18:45:07 +00:00
|
|
|
#ifdef ENABLE_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
|
2018-01-27 19:15:54 +00:00
|
|
|
* keystroke associated with that shortcut. If ncurses supports them,
|
|
|
|
* we also handle presses of the fourth mouse button (upward rolls of
|
|
|
|
* the mouse wheel) by putting back keystrokes to move up, and presses
|
|
|
|
* of the fifth mouse button (downward rolls of the mouse wheel) by
|
|
|
|
* putting back keystrokes to move down. We also store the coordinates
|
|
|
|
* of a mouse event that needs further handling in mouse_x and mouse_y.
|
|
|
|
* Return -1 on error, 0 if the mouse event needs to be handled, 1 if it's
|
|
|
|
* been handled by putting back keystrokes, or 2 if it's been ignored. */
|
2018-01-27 19:00:14 +00:00
|
|
|
int get_mouseinput(int *mouse_y, int *mouse_x, bool allow_shortcuts)
|
2003-11-28 19:47:42 +00:00
|
|
|
{
|
2020-12-22 11:20:42 +00:00
|
|
|
bool in_editwin, in_bottomwin;
|
2020-12-22 18:23:40 +00:00
|
|
|
MEVENT event;
|
2017-12-29 18:27:33 +00:00
|
|
|
|
|
|
|
/* First, get the actual mouse event. */
|
2020-12-22 18:23:40 +00:00
|
|
|
if (getmouse(&event) == ERR)
|
2017-12-29 18:27:33 +00:00
|
|
|
return -1;
|
|
|
|
|
2020-12-22 18:23:40 +00:00
|
|
|
in_editwin = wenclose(edit, event.y, event.x);
|
|
|
|
in_bottomwin = wenclose(bottomwin, event.y, event.x);
|
2020-12-22 11:20:42 +00:00
|
|
|
|
2017-12-29 18:27:33 +00:00
|
|
|
/* Save the screen coordinates where the mouse event took place. */
|
2020-12-22 18:23:40 +00:00
|
|
|
*mouse_x = event.x - (in_editwin ? margin : 0);
|
|
|
|
*mouse_y = event.y;
|
2017-12-29 18:27:33 +00:00
|
|
|
|
|
|
|
/* Handle releases/clicks of the first mouse button. */
|
2020-12-22 18:23:40 +00:00
|
|
|
if (event.bstate & (BUTTON1_RELEASED | BUTTON1_CLICKED)) {
|
2018-01-27 19:15:54 +00:00
|
|
|
/* If we're allowing shortcuts, and the current shortcut list is
|
2017-12-29 18:27:33 +00:00
|
|
|
* being displayed on the last two lines of the screen, and the
|
|
|
|
* 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. */
|
|
|
|
if (allow_shortcuts && !ISSET(NO_HELP) && in_bottomwin) {
|
2018-12-30 19:18:29 +00:00
|
|
|
int width;
|
2018-12-30 20:27:04 +00:00
|
|
|
/* The width of each shortcut item, except the last two. */
|
2018-12-30 19:18:29 +00:00
|
|
|
int index;
|
2018-12-30 20:27:04 +00:00
|
|
|
/* The calculated index of the clicked item. */
|
2017-12-29 18:27:33 +00:00
|
|
|
size_t number;
|
2018-12-30 20:27:04 +00:00
|
|
|
/* The number of shortcut items that get displayed. */
|
2017-12-29 18:27:33 +00:00
|
|
|
|
2018-12-30 20:27:04 +00:00
|
|
|
/* Translate the coordinates to become relative to bottomwin. */
|
2017-12-29 18:27:33 +00:00
|
|
|
wmouse_trafo(bottomwin, mouse_y, mouse_x, FALSE);
|
|
|
|
|
2018-12-30 20:27:04 +00:00
|
|
|
/* Clicks on the status bar are handled elsewhere, so
|
|
|
|
* restore the untranslated mouse-event coordinates. */
|
2017-12-29 18:27:33 +00:00
|
|
|
if (*mouse_y == 0) {
|
2020-12-22 18:23:40 +00:00
|
|
|
*mouse_x = event.x;
|
|
|
|
*mouse_y = event.y;
|
2017-12-29 18:27:33 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2004-08-26 01:43:16 +00:00
|
|
|
|
2019-09-27 16:49:39 +00:00
|
|
|
/* Determine how many shortcuts are being shown. */
|
2019-09-27 17:07:25 +00:00
|
|
|
number = shown_entries_for(currmenu);
|
2017-12-29 18:27:33 +00:00
|
|
|
|
2019-10-01 10:29:02 +00:00
|
|
|
/* Calculate the clickable width of each menu item. */
|
|
|
|
if (number < 5)
|
|
|
|
width = COLS / 2;
|
2017-12-29 18:27:33 +00:00
|
|
|
else
|
2019-10-01 10:29:02 +00:00
|
|
|
width = COLS / ((number + 1) / 2);
|
2017-12-29 18:27:33 +00:00
|
|
|
|
|
|
|
/* Calculate the one-based index in the shortcut list. */
|
2018-12-30 19:18:29 +00:00
|
|
|
index = (*mouse_x / width) * 2 + *mouse_y;
|
2017-12-29 18:27:33 +00:00
|
|
|
|
|
|
|
/* Adjust the index if we hit the last two wider ones. */
|
2018-12-30 19:18:29 +00:00
|
|
|
if ((index > number) && (*mouse_x % width < COLS % width))
|
|
|
|
index -= 2;
|
2017-12-29 18:27:33 +00:00
|
|
|
|
2018-12-30 20:27:04 +00:00
|
|
|
/* Ignore clicks beyond the last shortcut. */
|
2018-12-30 19:18:29 +00:00
|
|
|
if (index > number)
|
2017-12-29 18:27:33 +00:00
|
|
|
return 2;
|
|
|
|
|
2020-01-17 18:11:06 +00:00
|
|
|
/* Search through the list of functions to determine which
|
|
|
|
* shortcut in the current menu the user clicked on; then
|
|
|
|
* put the corresponding keystroke into the keyboard buffer. */
|
|
|
|
for (funcstruct *f = allfuncs; f != NULL; f = f->next) {
|
2017-12-29 18:27:33 +00:00
|
|
|
if ((f->menus & currmenu) == 0)
|
|
|
|
continue;
|
2018-02-24 18:31:11 +00:00
|
|
|
if (first_sc_for(currmenu, f->func) == NULL)
|
2017-12-29 18:27:33 +00:00
|
|
|
continue;
|
2020-01-17 18:11:06 +00:00
|
|
|
if (--index == 0) {
|
|
|
|
const keystruct *shortcut = first_sc_for(currmenu, f->func);
|
|
|
|
|
|
|
|
put_back(shortcut->keycode);
|
2020-01-22 12:22:27 +00:00
|
|
|
if (0x20 <= shortcut->keycode && shortcut->keycode <= 0x7E)
|
2020-01-17 18:11:06 +00:00
|
|
|
put_back(ESC_CODE);
|
2017-12-29 18:27:33 +00:00
|
|
|
break;
|
2020-01-17 18:11:06 +00:00
|
|
|
}
|
2017-12-29 18:27:33 +00:00
|
|
|
}
|
2006-04-18 16:13:35 +00:00
|
|
|
|
2017-12-29 18:27:33 +00:00
|
|
|
return 1;
|
|
|
|
} else
|
2018-12-30 20:27:04 +00:00
|
|
|
/* Clicks outside of bottomwin are handled elsewhere. */
|
2017-12-29 18:27:33 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2007-05-15 18:04:25 +00:00
|
|
|
#if NCURSES_MOUSE_VERSION >= 2
|
2017-12-29 18:27:33 +00:00
|
|
|
/* Handle presses of the fourth mouse button (upward rolls of the
|
|
|
|
* mouse wheel) and presses of the fifth mouse button (downward
|
|
|
|
* rolls of the mouse wheel) . */
|
2020-12-22 18:23:40 +00:00
|
|
|
else if (event.bstate & (BUTTON4_PRESSED | BUTTON5_PRESSED)) {
|
2017-12-29 18:27:33 +00:00
|
|
|
bool in_edit = wenclose(edit, *mouse_y, *mouse_x);
|
|
|
|
|
|
|
|
if (in_bottomwin)
|
2018-12-30 20:27:04 +00:00
|
|
|
/* Translate the coordinates to become relative to bottomwin. */
|
2017-12-29 18:27:33 +00:00
|
|
|
wmouse_trafo(bottomwin, mouse_y, mouse_x, FALSE);
|
|
|
|
|
|
|
|
if (in_edit || (in_bottomwin && *mouse_y == 0)) {
|
2020-12-22 18:23:40 +00:00
|
|
|
int keycode = (event.bstate & BUTTON4_PRESSED) ? KEY_UP : KEY_DOWN;
|
2020-01-17 17:51:30 +00:00
|
|
|
|
2017-12-29 18:27:33 +00:00
|
|
|
/* One roll of the mouse wheel should move three lines. */
|
2020-01-17 17:51:30 +00:00
|
|
|
for (int count = 3; count > 0; count--)
|
|
|
|
put_back(keycode);
|
|
|
|
|
2017-12-29 18:27:33 +00:00
|
|
|
return 1;
|
|
|
|
} else
|
2018-12-30 17:00:28 +00:00
|
|
|
/* Ignore presses of the fourth and fifth mouse buttons
|
|
|
|
* that aren't on the edit window or the status bar. */
|
2017-12-29 18:27:33 +00:00
|
|
|
return 2;
|
|
|
|
}
|
2007-05-15 18:04:25 +00:00
|
|
|
#endif
|
2017-12-29 18:27:33 +00:00
|
|
|
/* Ignore all other mouse events. */
|
|
|
|
return 2;
|
2003-11-28 19:47:42 +00:00
|
|
|
}
|
2017-05-01 18:45:07 +00:00
|
|
|
#endif /* ENABLE_MOUSE */
|
2004-08-25 15:39:10 +00:00
|
|
|
|
2019-06-25 09:03:51 +00:00
|
|
|
/* Move (in the given window) to the given row and wipe it clean. */
|
|
|
|
void blank_row(WINDOW *window, int row)
|
2005-07-10 02:37:38 +00:00
|
|
|
{
|
2019-06-25 09:03:51 +00:00
|
|
|
wmove(window, row, 0);
|
|
|
|
wclrtoeol(window);
|
2005-07-10 02:37:38 +00:00
|
|
|
}
|
|
|
|
|
2019-06-25 09:34:04 +00:00
|
|
|
/* Blank the first line of the top portion of the screen. */
|
2004-05-18 01:20:36 +00:00
|
|
|
void blank_titlebar(void)
|
2000-06-06 05:53:49 +00:00
|
|
|
{
|
2019-06-25 06:28:10 +00:00
|
|
|
mvwprintw(topwin, 0, 0, "%*s", COLS, " ");
|
2002-09-06 20:35:28 +00:00
|
|
|
}
|
|
|
|
|
2019-06-25 09:34:04 +00:00
|
|
|
/* Blank all lines of the middle portion of the screen (the edit window). */
|
2000-06-06 05:53:49 +00:00
|
|
|
void blank_edit(void)
|
|
|
|
{
|
2019-06-25 09:34:04 +00:00
|
|
|
for (int row = 0; row < editwinrows; row++)
|
2019-06-25 09:03:51 +00:00
|
|
|
blank_row(edit, row);
|
2000-06-06 05:53:49 +00:00
|
|
|
}
|
|
|
|
|
2019-06-25 09:34:04 +00:00
|
|
|
/* Blank the first line of the bottom portion of the screen. */
|
2000-06-06 05:53:49 +00:00
|
|
|
void blank_statusbar(void)
|
|
|
|
{
|
2019-06-25 09:03:51 +00:00
|
|
|
blank_row(bottomwin, 0);
|
2000-06-06 05:53:49 +00:00
|
|
|
}
|
|
|
|
|
2017-12-29 16:34:03 +00:00
|
|
|
/* Wipe the status bar clean and include this in the next screen update. */
|
|
|
|
void wipe_statusbar(void)
|
|
|
|
{
|
2019-06-25 09:03:51 +00:00
|
|
|
blank_row(bottomwin, 0);
|
2017-12-29 18:27:33 +00:00
|
|
|
wnoutrefresh(bottomwin);
|
2021-05-25 12:37:31 +00:00
|
|
|
lastmessage = VACUUM;
|
2017-12-29 16:34:03 +00:00
|
|
|
}
|
|
|
|
|
2019-06-25 09:34:04 +00:00
|
|
|
/* Blank out the two help lines (when they are present). */
|
2005-03-17 17:56:48 +00:00
|
|
|
void blank_bottombars(void)
|
|
|
|
{
|
2017-12-29 18:27:33 +00:00
|
|
|
if (!ISSET(NO_HELP) && LINES > 4) {
|
2019-06-25 09:03:51 +00:00
|
|
|
blank_row(bottomwin, 1);
|
|
|
|
blank_row(bottomwin, 2);
|
2017-12-29 18:27:33 +00:00
|
|
|
}
|
2005-03-17 17:56:48 +00:00
|
|
|
}
|
|
|
|
|
2020-01-16 15:16:31 +00:00
|
|
|
/* Check if the number of keystrokes needed to blank the status bar has
|
|
|
|
* been pressed. If so, blank the status bar, unless constant cursor
|
2016-05-15 09:36:51 +00:00
|
|
|
* position display is on and we are in the editing screen. */
|
2004-09-30 22:07:21 +00:00
|
|
|
void check_statusblank(void)
|
2000-06-06 05:53:49 +00:00
|
|
|
{
|
2017-12-29 18:27:33 +00:00
|
|
|
if (statusblank == 0)
|
|
|
|
return;
|
2016-05-15 09:36:51 +00:00
|
|
|
|
2017-12-29 18:27:33 +00:00
|
|
|
statusblank--;
|
2016-05-15 09:36:51 +00:00
|
|
|
|
2017-12-29 18:27:33 +00:00
|
|
|
/* When editing and 'constantshow' is active, skip the blanking. */
|
2021-05-09 17:11:49 +00:00
|
|
|
if (currmenu == MMAIN && ISSET(CONSTANT_SHOW) && LINES > 1)
|
2017-12-29 18:27:33 +00:00
|
|
|
return;
|
2016-05-15 09:36:51 +00:00
|
|
|
|
2017-12-29 18:27:33 +00:00
|
|
|
if (statusblank == 0)
|
|
|
|
wipe_statusbar();
|
2016-08-15 17:44:49 +00:00
|
|
|
|
2017-12-29 18:27:33 +00:00
|
|
|
/* If the subwindows overlap, make sure to show the edit window now. */
|
|
|
|
if (LINES == 1)
|
|
|
|
edit_refresh();
|
2000-06-06 05:53:49 +00:00
|
|
|
}
|
|
|
|
|
2020-09-17 17:30:18 +00:00
|
|
|
/* Ensure that the status bar will be wiped upon the next keystroke. */
|
|
|
|
void set_blankdelay_to_one(void)
|
|
|
|
{
|
|
|
|
statusblank = 1;
|
|
|
|
}
|
|
|
|
|
2021-04-06 14:27:46 +00:00
|
|
|
/* Convert text into a string that can be displayed on screen. The caller
|
|
|
|
* wants to display text starting with the given column, and extending for
|
2017-04-28 12:05:07 +00:00
|
|
|
* at most span columns. column is zero-based, and span is one-based, so
|
|
|
|
* span == 0 means you get "" returned. The returned string is dynamically
|
|
|
|
* allocated, and should be freed. If isdata is TRUE, the caller might put
|
2019-02-27 20:37:53 +00:00
|
|
|
* "<" at the beginning or ">" at the end of the line if it's too long. If
|
|
|
|
* isprompt is TRUE, the caller might put ">" at the end of the line if it's
|
|
|
|
* too long. */
|
2021-04-06 14:27:46 +00:00
|
|
|
char *display_string(const char *text, size_t column, size_t span,
|
2019-02-27 20:37:53 +00:00
|
|
|
bool isdata, bool isprompt)
|
2003-09-16 01:16:49 +00:00
|
|
|
{
|
2021-04-07 09:11:05 +00:00
|
|
|
const char *origin = text;
|
|
|
|
/* The beginning of the text, to later determine the covered part. */
|
2021-04-08 10:19:34 +00:00
|
|
|
size_t start_x = actual_x(text, column);
|
2017-12-29 18:27:33 +00:00
|
|
|
/* The index of the first character that the caller wishes to show. */
|
2021-04-08 10:19:34 +00:00
|
|
|
size_t start_col = wideness(text, start_x);
|
2017-12-29 18:27:33 +00:00
|
|
|
/* The actual column where that first character starts. */
|
2021-04-08 09:44:48 +00:00
|
|
|
size_t stowaways = 20;
|
|
|
|
/* The number of zero-width characters for which to reserve space. */
|
|
|
|
size_t allocsize = (COLS + stowaways) * MAXCHARLEN + 1;
|
|
|
|
/* The amount of memory to reserve for the displayable string. */
|
|
|
|
char *converted = nmalloc(allocsize);
|
|
|
|
/* The displayable string we will return. */
|
2017-12-29 18:27:33 +00:00
|
|
|
size_t index = 0;
|
|
|
|
/* Current position in converted. */
|
|
|
|
size_t beyond = column + span;
|
|
|
|
/* The column number just beyond the last shown character. */
|
2005-01-12 03:25:57 +00:00
|
|
|
|
2021-04-08 10:19:34 +00:00
|
|
|
text += start_x;
|
2017-12-29 18:27:33 +00:00
|
|
|
|
2019-04-12 17:15:48 +00:00
|
|
|
#ifndef NANO_TINY
|
|
|
|
if (span > HIGHEST_POSITIVE) {
|
|
|
|
statusline(ALERT, "Span has underflowed -- please report a bug");
|
|
|
|
converted[0] = '\0';
|
|
|
|
return converted;
|
|
|
|
}
|
|
|
|
#endif
|
2017-12-29 18:27:33 +00:00
|
|
|
/* If the first character starts before the left edge, or would be
|
2019-02-11 20:11:22 +00:00
|
|
|
* overwritten by a "<" token, then show placeholders instead. */
|
2021-04-05 14:10:44 +00:00
|
|
|
if ((start_col < column || (start_col > 0 && isdata && !ISSET(SOFTWRAP))) &&
|
2021-04-06 14:27:46 +00:00
|
|
|
*text != '\0' && *text != '\t') {
|
|
|
|
if (is_cntrl_char(text)) {
|
2017-12-29 18:27:33 +00:00
|
|
|
if (start_col < column) {
|
2021-04-06 14:27:46 +00:00
|
|
|
converted[index++] = control_mbrep(text, isdata);
|
2017-12-29 18:27:33 +00:00
|
|
|
column++;
|
2021-04-06 14:27:46 +00:00
|
|
|
text += char_length(text);
|
2017-12-29 18:27:33 +00:00
|
|
|
}
|
|
|
|
}
|
2005-07-17 02:40:07 +00:00
|
|
|
#ifdef ENABLE_UTF8
|
2021-04-09 14:24:22 +00:00
|
|
|
else if (is_doublewidth(text)) {
|
2017-12-29 18:27:33 +00:00
|
|
|
if (start_col == column) {
|
|
|
|
converted[index++] = ' ';
|
|
|
|
column++;
|
|
|
|
}
|
2006-05-19 17:50:01 +00:00
|
|
|
|
2019-02-11 19:44:30 +00:00
|
|
|
/* Display the right half of a two-column character as ']'. */
|
|
|
|
converted[index++] = ']';
|
2017-12-29 18:27:33 +00:00
|
|
|
column++;
|
2021-04-06 14:27:46 +00:00
|
|
|
text += char_length(text);
|
2017-12-29 18:27:33 +00:00
|
|
|
}
|
2005-01-03 06:56:38 +00:00
|
|
|
#endif
|
2017-12-29 18:27:33 +00:00
|
|
|
}
|
2004-12-23 17:43:27 +00:00
|
|
|
|
2019-06-11 14:51:41 +00:00
|
|
|
#ifdef ENABLE_UTF8
|
|
|
|
#define ISO8859_CHAR FALSE
|
2021-04-09 14:24:22 +00:00
|
|
|
#define ZEROWIDTH_CHAR (is_zerowidth(text))
|
2019-06-11 14:51:41 +00:00
|
|
|
#else
|
2021-04-06 14:27:46 +00:00
|
|
|
#define ISO8859_CHAR ((unsigned char)*text > 0x9F)
|
2019-10-03 08:25:58 +00:00
|
|
|
#define ZEROWIDTH_CHAR FALSE
|
2019-06-11 14:51:41 +00:00
|
|
|
#endif
|
|
|
|
|
2021-04-06 14:27:46 +00:00
|
|
|
while (*text != '\0' && (column < beyond || ZEROWIDTH_CHAR)) {
|
2019-06-11 09:21:29 +00:00
|
|
|
/* A plain printable ASCII character is one byte, one column. */
|
2021-04-06 14:27:46 +00:00
|
|
|
if (((signed char)*text > 0x20 && *text != DEL_CODE) || ISO8859_CHAR) {
|
|
|
|
converted[index++] = *(text++);
|
2019-06-11 09:21:29 +00:00
|
|
|
column++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2019-06-10 18:03:27 +00:00
|
|
|
/* Show a space as a visible character, or as a space. */
|
2021-04-06 14:27:46 +00:00
|
|
|
if (*text == ' ') {
|
2016-05-30 08:41:11 +00:00
|
|
|
#ifndef NANO_TINY
|
2017-12-29 18:27:33 +00:00
|
|
|
if (ISSET(WHITESPACE_DISPLAY)) {
|
2019-06-10 18:03:27 +00:00
|
|
|
for (int i = whitelen[0]; i < whitelen[0] + whitelen[1];)
|
2017-12-29 18:27:33 +00:00
|
|
|
converted[index++] = whitespace[i++];
|
|
|
|
} else
|
|
|
|
#endif
|
|
|
|
converted[index++] = ' ';
|
|
|
|
column++;
|
2021-04-06 14:27:46 +00:00
|
|
|
text++;
|
2017-12-29 18:27:33 +00:00
|
|
|
continue;
|
2019-06-10 18:03:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Show a tab as a visible character plus spaces, or as just spaces. */
|
2021-04-06 14:27:46 +00:00
|
|
|
if (*text == '\t') {
|
2015-08-09 16:05:50 +00:00
|
|
|
#ifndef NANO_TINY
|
2017-12-29 18:27:33 +00:00
|
|
|
if (ISSET(WHITESPACE_DISPLAY) && (index > 0 || !isdata ||
|
|
|
|
!ISSET(SOFTWRAP) || column % tabsize == 0 ||
|
|
|
|
column == start_col)) {
|
2019-06-10 18:03:27 +00:00
|
|
|
for (int i = 0; i < whitelen[0];)
|
2017-12-29 18:27:33 +00:00
|
|
|
converted[index++] = whitespace[i++];
|
|
|
|
} else
|
|
|
|
#endif
|
|
|
|
converted[index++] = ' ';
|
|
|
|
column++;
|
|
|
|
/* Fill the tab up with the required number of spaces. */
|
|
|
|
while (column % tabsize != 0 && column < beyond) {
|
|
|
|
converted[index++] = ' ';
|
|
|
|
column++;
|
|
|
|
}
|
2021-04-06 14:27:46 +00:00
|
|
|
text++;
|
2017-12-29 18:27:33 +00:00
|
|
|
continue;
|
|
|
|
}
|
2016-06-06 10:48:26 +00:00
|
|
|
|
2019-06-10 18:03:27 +00:00
|
|
|
/* Represent a control character with a leading caret. */
|
2021-04-06 14:27:46 +00:00
|
|
|
if (is_cntrl_char(text)) {
|
2017-12-29 18:27:33 +00:00
|
|
|
converted[index++] = '^';
|
2021-04-06 14:27:46 +00:00
|
|
|
converted[index++] = control_mbrep(text, isdata);
|
|
|
|
text += char_length(text);
|
2019-06-10 18:03:27 +00:00
|
|
|
column += 2;
|
2017-12-29 18:27:33 +00:00
|
|
|
continue;
|
|
|
|
}
|
2016-06-05 19:18:32 +00:00
|
|
|
|
2019-06-10 17:27:42 +00:00
|
|
|
#ifdef ENABLE_UTF8
|
2019-06-11 12:24:30 +00:00
|
|
|
int charlength, charwidth;
|
2019-06-10 17:27:42 +00:00
|
|
|
wchar_t wc;
|
|
|
|
|
2019-06-10 18:03:27 +00:00
|
|
|
/* Convert a multibyte character to a single code. */
|
2021-04-06 14:27:46 +00:00
|
|
|
charlength = mbtowide(&wc, text);
|
2019-06-10 17:27:42 +00:00
|
|
|
|
2019-06-10 18:03:27 +00:00
|
|
|
/* Represent an invalid character with the Replacement Character. */
|
2021-03-25 16:28:51 +00:00
|
|
|
if (charlength < 0) {
|
2019-06-10 17:27:42 +00:00
|
|
|
converted[index++] = '\xEF';
|
|
|
|
converted[index++] = '\xBF';
|
|
|
|
converted[index++] = '\xBD';
|
2021-04-06 14:27:46 +00:00
|
|
|
text++;
|
2019-06-10 18:03:27 +00:00
|
|
|
column++;
|
2017-12-29 18:27:33 +00:00
|
|
|
continue;
|
|
|
|
}
|
2004-12-23 17:43:27 +00:00
|
|
|
|
2020-01-15 16:28:14 +00:00
|
|
|
/* Determine whether the character takes zero, one, or two columns. */
|
|
|
|
charwidth = wcwidth(wc);
|
|
|
|
|
2021-04-08 09:44:48 +00:00
|
|
|
/* Watch the number of zero-widths, to keep ample memory reserved. */
|
|
|
|
if (charwidth == 0 && --stowaways == 0) {
|
|
|
|
stowaways = 40;
|
|
|
|
allocsize += stowaways * MAXCHARLEN;
|
|
|
|
converted = nrealloc(converted, allocsize);
|
|
|
|
}
|
|
|
|
|
2020-01-15 16:28:14 +00:00
|
|
|
#ifdef __linux__
|
|
|
|
/* On a Linux console, skip zero-width characters, as it would show
|
|
|
|
* them WITH a width, thus messing up the display. See bug #52954. */
|
|
|
|
if (on_a_vt && charwidth == 0) {
|
2021-04-06 14:27:46 +00:00
|
|
|
text += charlength;
|
2020-01-15 16:28:14 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
#endif
|
2019-06-10 17:27:42 +00:00
|
|
|
/* For any valid character, just copy its bytes. */
|
|
|
|
for (; charlength > 0; charlength--)
|
2021-04-06 14:27:46 +00:00
|
|
|
converted[index++] = *(text++);
|
2019-06-10 17:27:42 +00:00
|
|
|
|
|
|
|
/* If the codepoint is unassigned, assume a width of one. */
|
|
|
|
column += (charwidth < 0 ? 1 : charwidth);
|
|
|
|
#endif /* ENABLE_UTF8 */
|
2017-12-29 18:27:33 +00:00
|
|
|
}
|
2003-09-16 01:16:49 +00:00
|
|
|
|
2019-02-11 20:11:22 +00:00
|
|
|
/* If there is more text than can be shown, make room for the ">". */
|
2021-04-06 14:27:46 +00:00
|
|
|
if (column > beyond || (*text != '\0' && (isprompt ||
|
2019-10-03 09:20:48 +00:00
|
|
|
(isdata && !ISSET(SOFTWRAP))))) {
|
2019-10-03 08:25:58 +00:00
|
|
|
#ifdef ENABLE_UTF8
|
2019-02-22 13:09:17 +00:00
|
|
|
do {
|
2019-06-09 17:37:56 +00:00
|
|
|
index = step_left(converted, index);
|
2021-04-09 14:24:22 +00:00
|
|
|
} while (is_zerowidth(converted + index));
|
2017-03-08 13:32:36 +00:00
|
|
|
|
2019-02-11 19:44:30 +00:00
|
|
|
/* Display the left half of a two-column character as '['. */
|
2021-04-09 14:24:22 +00:00
|
|
|
if (is_doublewidth(converted + index))
|
2019-02-11 19:44:30 +00:00
|
|
|
converted[index++] = '[';
|
2019-10-03 08:25:58 +00:00
|
|
|
#else
|
|
|
|
index--;
|
2017-04-02 21:47:52 +00:00
|
|
|
#endif
|
2020-01-26 19:01:34 +00:00
|
|
|
has_more = TRUE;
|
|
|
|
} else
|
|
|
|
has_more = FALSE;
|
2017-04-02 21:47:52 +00:00
|
|
|
|
2019-06-28 18:07:42 +00:00
|
|
|
is_shorter = (column < beyond);
|
|
|
|
|
2017-12-29 18:27:33 +00:00
|
|
|
/* Null-terminate the converted string. */
|
|
|
|
converted[index] = '\0';
|
2005-01-05 19:05:04 +00:00
|
|
|
|
2021-04-07 09:11:05 +00:00
|
|
|
/* Remember what part of the original text is covered by converted. */
|
2021-04-08 10:19:34 +00:00
|
|
|
from_x = start_x;
|
2021-04-07 09:11:05 +00:00
|
|
|
till_x = text - origin;
|
|
|
|
|
2017-12-29 18:27:33 +00:00
|
|
|
return converted;
|
2003-09-16 01:16:49 +00:00
|
|
|
}
|
|
|
|
|
2018-03-23 09:53:06 +00:00
|
|
|
#ifdef ENABLE_MULTIBUFFER
|
2017-09-01 16:47:19 +00:00
|
|
|
/* Determine the sequence number of the given buffer in the circular list. */
|
|
|
|
int buffer_number(openfilestruct *buffer)
|
|
|
|
{
|
2017-12-29 18:27:33 +00:00
|
|
|
int count = 1;
|
2017-09-01 16:47:19 +00:00
|
|
|
|
2019-04-22 17:45:42 +00:00
|
|
|
while (buffer != startfile) {
|
2017-12-29 18:27:33 +00:00
|
|
|
buffer = buffer->prev;
|
|
|
|
count++;
|
|
|
|
}
|
2017-09-01 16:47:19 +00:00
|
|
|
|
2017-12-29 18:27:33 +00:00
|
|
|
return count;
|
2017-09-01 16:47:19 +00:00
|
|
|
}
|
2018-03-23 09:53:06 +00:00
|
|
|
#endif
|
2017-09-01 16:47:19 +00:00
|
|
|
|
2020-10-15 17:54:05 +00:00
|
|
|
#ifndef NANO_TINY
|
|
|
|
/* Show the state of auto-indenting, the mark, hard-wrapping, macro recording,
|
|
|
|
* and soft-wrapping by showing corresponding letters in the given window. */
|
|
|
|
void show_states_at(WINDOW *window)
|
|
|
|
{
|
|
|
|
waddstr(window, ISSET(AUTOINDENT) ? "I" : " ");
|
|
|
|
waddstr(window, openfile->mark ? "M" : " ");
|
|
|
|
waddstr(window, ISSET(BREAK_LONG_LINES) ? "L" : " ");
|
|
|
|
waddstr(window, recording ? "R" : " ");
|
|
|
|
waddstr(window, ISSET(SOFTWRAP) ? "S" : " ");
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
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
|
2020-01-16 15:16:31 +00:00
|
|
|
* has been modified on the title bar. If path isn't NULL, we're either
|
2017-04-22 16:27:01 +00:00
|
|
|
* in the file browser or the help viewer, so show either the current
|
|
|
|
* directory or the title of help text, that is: whatever is in path. */
|
2003-02-13 22:25:01 +00:00
|
|
|
void titlebar(const char *path)
|
2000-06-06 05:53:49 +00:00
|
|
|
{
|
2017-12-29 18:27:33 +00:00
|
|
|
size_t verlen, prefixlen, pathlen, statelen;
|
2020-01-16 15:16:31 +00:00
|
|
|
/* The width of the different title-bar elements, in columns. */
|
2017-12-29 18:27:33 +00:00
|
|
|
size_t pluglen = 0;
|
|
|
|
/* The width that "Modified" would take up. */
|
|
|
|
size_t offset = 0;
|
2020-01-16 15:16:31 +00:00
|
|
|
/* The position at which the center part of the title bar starts. */
|
2017-12-29 18:27:33 +00:00
|
|
|
const char *upperleft = "";
|
|
|
|
/* What is shown in the top left corner. */
|
|
|
|
const char *prefix = "";
|
|
|
|
/* What is shown before the path -- "DIR:" or nothing. */
|
|
|
|
const char *state = "";
|
|
|
|
/* The state of the current buffer -- "Modified", "View", or "". */
|
|
|
|
char *caption;
|
|
|
|
/* The presentable form of the pathname. */
|
2020-08-17 11:36:03 +00:00
|
|
|
char *ranking = NULL;
|
|
|
|
/* The buffer sequence number plus the total buffer count. */
|
2017-12-29 18:27:33 +00:00
|
|
|
|
2020-01-16 15:16:31 +00:00
|
|
|
/* If the screen is too small, there is no title bar. */
|
2017-12-29 18:27:33 +00:00
|
|
|
if (topwin == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
wattron(topwin, interface_color_pair[TITLE_BAR]);
|
|
|
|
|
|
|
|
blank_titlebar();
|
|
|
|
as_an_at = FALSE;
|
|
|
|
|
|
|
|
/* Do as Pico: if there is not enough width available for all items,
|
|
|
|
* first sacrifice the version string, then eat up the side spaces,
|
|
|
|
* then sacrifice the prefix, and only then start dottifying. */
|
|
|
|
|
|
|
|
/* Figure out the path, prefix and state strings. */
|
2018-10-17 18:17:03 +00:00
|
|
|
#ifdef ENABLE_COLOR
|
|
|
|
if (currmenu == MLINTER) {
|
2018-12-03 11:20:06 +00:00
|
|
|
/* TRANSLATORS: The next five are "labels" in the title bar. */
|
2018-10-17 18:17:03 +00:00
|
|
|
prefix = _("Linting --");
|
|
|
|
path = openfile->filename;
|
|
|
|
} else
|
|
|
|
#endif
|
2017-05-08 17:08:23 +00:00
|
|
|
#ifdef ENABLE_BROWSER
|
2017-12-29 18:27:33 +00:00
|
|
|
if (!inhelp && path != NULL)
|
|
|
|
prefix = _("DIR:");
|
2017-09-12 19:47:17 +00:00
|
|
|
else
|
2017-12-29 18:27:33 +00:00
|
|
|
#endif
|
|
|
|
if (!inhelp) {
|
2018-03-23 09:53:06 +00:00
|
|
|
#ifdef ENABLE_MULTIBUFFER
|
2017-12-29 18:27:33 +00:00
|
|
|
/* If there are/were multiple buffers, show which out of how many. */
|
|
|
|
if (more_than_one) {
|
2020-08-30 02:57:45 +00:00
|
|
|
ranking = nmalloc(24);
|
2020-08-17 11:36:03 +00:00
|
|
|
sprintf(ranking, "[%i/%i]", buffer_number(openfile),
|
2019-04-22 17:45:42 +00:00
|
|
|
buffer_number(startfile->prev));
|
2020-08-17 11:36:03 +00:00
|
|
|
upperleft = ranking;
|
2017-12-29 18:27:33 +00:00
|
|
|
} else
|
2018-03-23 09:53:06 +00:00
|
|
|
#endif
|
2017-12-29 18:27:33 +00:00
|
|
|
upperleft = BRANDING;
|
|
|
|
|
|
|
|
if (openfile->filename[0] == '\0')
|
|
|
|
path = _("New Buffer");
|
|
|
|
else
|
|
|
|
path = openfile->filename;
|
|
|
|
|
2020-09-23 07:21:15 +00:00
|
|
|
if (ISSET(VIEW_MODE))
|
|
|
|
state = _("View");
|
|
|
|
#ifndef NANO_TINY
|
|
|
|
else if (ISSET(STATEFLAGS))
|
2020-09-19 17:50:45 +00:00
|
|
|
state = "+.xxxxx";
|
2020-09-23 07:21:15 +00:00
|
|
|
#endif
|
|
|
|
else if (openfile->modified)
|
2017-12-29 18:27:33 +00:00
|
|
|
state = _("Modified");
|
2018-12-03 11:20:06 +00:00
|
|
|
else if (ISSET(RESTRICTED))
|
|
|
|
state = _("Restricted");
|
2019-10-28 09:28:52 +00:00
|
|
|
else
|
|
|
|
pluglen = breadth(_("Modified")) + 1;
|
2004-05-23 21:11:14 +00:00
|
|
|
}
|
|
|
|
|
2017-12-29 18:27:33 +00:00
|
|
|
/* Determine the widths of the four elements, including their padding. */
|
2019-04-24 06:49:18 +00:00
|
|
|
verlen = breadth(upperleft) + 3;
|
|
|
|
prefixlen = breadth(prefix);
|
2017-12-29 18:27:33 +00:00
|
|
|
if (prefixlen > 0)
|
|
|
|
prefixlen++;
|
2019-04-24 06:49:18 +00:00
|
|
|
pathlen = breadth(path);
|
|
|
|
statelen = breadth(state) + 2;
|
2019-10-28 09:28:52 +00:00
|
|
|
if (statelen > 2)
|
2017-12-29 18:27:33 +00:00
|
|
|
pathlen++;
|
|
|
|
|
|
|
|
/* Only print the version message when there is room for it. */
|
|
|
|
if (verlen + prefixlen + pathlen + pluglen + statelen <= COLS)
|
|
|
|
mvwaddstr(topwin, 0, 2, upperleft);
|
|
|
|
else {
|
|
|
|
verlen = 2;
|
|
|
|
/* If things don't fit yet, give up the placeholder. */
|
|
|
|
if (verlen + prefixlen + pathlen + pluglen + statelen > COLS)
|
|
|
|
pluglen = 0;
|
|
|
|
/* If things still don't fit, give up the side spaces. */
|
|
|
|
if (verlen + prefixlen + pathlen + pluglen + statelen > COLS) {
|
|
|
|
verlen = 0;
|
|
|
|
statelen -= 2;
|
|
|
|
}
|
|
|
|
}
|
2017-09-01 16:47:19 +00:00
|
|
|
|
2020-08-17 11:36:03 +00:00
|
|
|
free(ranking);
|
2005-03-24 22:28:25 +00:00
|
|
|
|
2017-12-29 18:27:33 +00:00
|
|
|
/* If we have side spaces left, center the path name. */
|
|
|
|
if (verlen > 0)
|
|
|
|
offset = verlen + (COLS - (verlen + pluglen + statelen) -
|
|
|
|
(prefixlen + pathlen)) / 2;
|
|
|
|
|
|
|
|
/* Only print the prefix when there is room for it. */
|
|
|
|
if (verlen + prefixlen + pathlen + pluglen + statelen <= COLS) {
|
|
|
|
mvwaddstr(topwin, 0, offset, prefix);
|
|
|
|
if (prefixlen > 0)
|
|
|
|
waddstr(topwin, " ");
|
|
|
|
} else
|
|
|
|
wmove(topwin, 0, offset);
|
|
|
|
|
|
|
|
/* Print the full path if there's room; otherwise, dottify it. */
|
|
|
|
if (pathlen + pluglen + statelen <= COLS) {
|
2019-02-27 20:37:53 +00:00
|
|
|
caption = display_string(path, 0, pathlen, FALSE, FALSE);
|
2017-12-29 18:27:33 +00:00
|
|
|
waddstr(topwin, caption);
|
|
|
|
free(caption);
|
|
|
|
} else if (5 + statelen <= COLS) {
|
|
|
|
waddstr(topwin, "...");
|
|
|
|
caption = display_string(path, 3 + pathlen - COLS + statelen,
|
2019-02-27 20:37:53 +00:00
|
|
|
COLS - statelen, FALSE, FALSE);
|
2017-12-29 18:27:33 +00:00
|
|
|
waddstr(topwin, caption);
|
|
|
|
free(caption);
|
|
|
|
}
|
|
|
|
|
2020-09-23 07:21:15 +00:00
|
|
|
#ifndef NANO_TINY
|
2020-09-19 17:50:45 +00:00
|
|
|
/* When requested, show on the title bar the state of three options and
|
|
|
|
* the state of the mark and whether a macro is being recorded. */
|
2020-12-21 13:54:49 +00:00
|
|
|
if (*state && ISSET(STATEFLAGS) && !ISSET(VIEW_MODE)) {
|
2020-09-24 14:24:34 +00:00
|
|
|
if (openfile->modified && COLS > 1)
|
|
|
|
waddstr(topwin, " *");
|
2020-09-19 17:50:45 +00:00
|
|
|
if (statelen < COLS) {
|
|
|
|
wmove(topwin, 0, COLS + 2 - statelen);
|
2020-10-15 17:54:05 +00:00
|
|
|
show_states_at(topwin);
|
2020-09-19 17:50:45 +00:00
|
|
|
}
|
2020-09-23 07:21:15 +00:00
|
|
|
} else
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
/* If there's room, right-align the state word; otherwise, clip it. */
|
|
|
|
if (statelen > 0 && statelen <= COLS)
|
|
|
|
mvwaddstr(topwin, 0, COLS - statelen, state);
|
|
|
|
else if (statelen > 0)
|
|
|
|
mvwaddnstr(topwin, 0, 0, state, actual_x(state, COLS));
|
2020-09-19 17:50:45 +00:00
|
|
|
}
|
2017-12-29 18:27:33 +00:00
|
|
|
|
|
|
|
wattroff(topwin, interface_color_pair[TITLE_BAR]);
|
|
|
|
|
|
|
|
wrefresh(topwin);
|
2000-06-06 05:53:49 +00:00
|
|
|
}
|
|
|
|
|
2020-08-15 15:32:31 +00:00
|
|
|
#ifndef NANO_TINY
|
|
|
|
/* Draw a bar at the bottom with some minimal state information. */
|
|
|
|
void minibar(void)
|
|
|
|
{
|
2020-11-09 12:39:36 +00:00
|
|
|
char *thename = NULL, *number_of_lines = NULL, *ranking = NULL;
|
2020-12-29 14:11:04 +00:00
|
|
|
char *location = nmalloc(44);
|
|
|
|
char *hexadecimal = nmalloc(9);
|
2021-01-06 14:27:14 +00:00
|
|
|
char *successor = NULL;
|
2020-12-29 12:21:07 +00:00
|
|
|
size_t namewidth, placewidth;
|
2020-12-29 19:02:03 +00:00
|
|
|
size_t tallywidth = 0;
|
2020-12-29 12:21:07 +00:00
|
|
|
size_t padding = 2;
|
2021-01-08 11:05:55 +00:00
|
|
|
#ifdef ENABLE_UTF8
|
2020-08-15 15:32:31 +00:00
|
|
|
wchar_t widecode;
|
2021-01-08 11:05:55 +00:00
|
|
|
#endif
|
2020-08-15 15:32:31 +00:00
|
|
|
|
|
|
|
/* Draw a colored bar over the full width of the screen. */
|
2021-06-07 10:10:23 +00:00
|
|
|
wattron(bottomwin, interface_color_pair[MINI_INFOBAR]);
|
2020-08-15 15:32:31 +00:00
|
|
|
mvwprintw(bottomwin, 0, 0, "%*s", COLS, " ");
|
|
|
|
|
|
|
|
if (openfile->filename[0] != '\0') {
|
|
|
|
as_an_at = FALSE;
|
2021-04-07 10:12:06 +00:00
|
|
|
thename = display_string(openfile->filename, 0, COLS, FALSE, FALSE);
|
2020-08-15 15:32:31 +00:00
|
|
|
} else
|
|
|
|
thename = copy_of(_("(nameless)"));
|
2020-12-29 12:21:07 +00:00
|
|
|
|
2021-01-07 15:17:17 +00:00
|
|
|
sprintf(location, "%zi,%zi", openfile->current->lineno, xplustabs() + 1);
|
2020-12-29 12:21:07 +00:00
|
|
|
placewidth = strlen(location);
|
|
|
|
namewidth = breadth(thename);
|
|
|
|
|
2020-12-30 18:01:35 +00:00
|
|
|
/* If the file name is relatively long, drop the side spaces. */
|
|
|
|
if (namewidth + 19 > COLS)
|
2020-12-29 12:21:07 +00:00
|
|
|
padding = 0;
|
|
|
|
|
2021-04-07 10:28:48 +00:00
|
|
|
/* Display the name of the current file (dottifying it if it doesn't fit),
|
|
|
|
* plus a star when the file has been modified. */
|
2020-12-29 12:21:07 +00:00
|
|
|
if (COLS > 4) {
|
|
|
|
if (namewidth > COLS - 2) {
|
2021-10-12 10:44:23 +00:00
|
|
|
char *shortname = display_string(thename, namewidth - COLS + 5,
|
|
|
|
COLS - 5, FALSE, FALSE);
|
2020-12-29 12:21:07 +00:00
|
|
|
mvwaddstr(bottomwin, 0, 0, "...");
|
2021-10-12 10:44:23 +00:00
|
|
|
waddstr(bottomwin, shortname);
|
|
|
|
free(shortname);
|
2020-12-29 12:21:07 +00:00
|
|
|
} else
|
|
|
|
mvwaddstr(bottomwin, 0, padding, thename);
|
|
|
|
|
2020-12-29 14:11:04 +00:00
|
|
|
waddstr(bottomwin, openfile->modified ? " *" : " ");
|
2020-12-29 12:21:07 +00:00
|
|
|
}
|
2020-08-15 15:32:31 +00:00
|
|
|
|
2021-04-07 10:28:48 +00:00
|
|
|
/* Right after reading or writing a file, display its number of lines;
|
2021-06-17 08:52:44 +00:00
|
|
|
* otherwise, when there are multiple buffers, display an [x/n] counter. */
|
2020-12-29 12:21:07 +00:00
|
|
|
if (report_size && COLS > 35) {
|
2020-11-09 12:39:36 +00:00
|
|
|
size_t count = openfile->filebot->lineno - (openfile->filebot->data[0] == '\0');
|
|
|
|
|
|
|
|
number_of_lines = nmalloc(44);
|
|
|
|
sprintf(number_of_lines, P_(" (%zu line)", " (%zu lines)", count), count);
|
2020-12-29 19:02:03 +00:00
|
|
|
tallywidth = breadth(number_of_lines);
|
2020-12-30 15:14:38 +00:00
|
|
|
if (namewidth + tallywidth + 11 < COLS)
|
2020-12-29 14:11:04 +00:00
|
|
|
waddstr(bottomwin, number_of_lines);
|
2020-12-29 19:02:03 +00:00
|
|
|
else
|
|
|
|
tallywidth = 0;
|
2020-11-09 12:39:36 +00:00
|
|
|
report_size = FALSE;
|
|
|
|
}
|
2020-08-16 09:24:13 +00:00
|
|
|
#ifdef ENABLE_MULTIBUFFER
|
2020-12-29 12:21:07 +00:00
|
|
|
else if (openfile->next != openfile && COLS > 35) {
|
2020-08-16 09:24:13 +00:00
|
|
|
ranking = nmalloc(24);
|
|
|
|
sprintf(ranking, " [%i/%i]", buffer_number(openfile), buffer_number(startfile->prev));
|
2020-12-30 15:07:29 +00:00
|
|
|
if (namewidth + placewidth + breadth(ranking) + 32 < COLS)
|
2020-12-29 14:11:04 +00:00
|
|
|
waddstr(bottomwin, ranking);
|
2020-08-16 09:24:13 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2020-08-15 15:32:31 +00:00
|
|
|
/* Display the line/column position of the cursor. */
|
2021-01-31 18:20:38 +00:00
|
|
|
if (ISSET(CONSTANT_SHOW) && namewidth + tallywidth + placewidth + 32 < COLS)
|
2020-12-29 12:21:07 +00:00
|
|
|
mvwaddstr(bottomwin, 0, COLS - 27 - placewidth, location);
|
2020-08-15 15:32:31 +00:00
|
|
|
|
2021-04-07 10:28:48 +00:00
|
|
|
/* Display the hexadecimal code of the character under the cursor,
|
2021-06-17 08:52:44 +00:00
|
|
|
* plus the codes of up to two succeeding zero-width characters. */
|
2021-01-31 18:20:38 +00:00
|
|
|
if (ISSET(CONSTANT_SHOW) && namewidth + tallywidth + 28 < COLS) {
|
2021-01-06 09:05:35 +00:00
|
|
|
char *this_position = openfile->current->data + openfile->current_x;
|
2020-12-29 14:11:04 +00:00
|
|
|
|
2021-01-06 09:05:35 +00:00
|
|
|
if (*this_position == '\0')
|
2021-01-07 09:33:04 +00:00
|
|
|
sprintf(hexadecimal, openfile->current->next ?
|
2021-01-08 11:05:55 +00:00
|
|
|
#ifdef ENABLE_UTF8
|
|
|
|
using_utf8() ? "U+000A" :
|
|
|
|
#endif
|
|
|
|
" 0x0A" : " ----");
|
2021-01-06 09:05:35 +00:00
|
|
|
else if (*this_position == '\n')
|
2021-01-06 14:02:15 +00:00
|
|
|
sprintf(hexadecimal, " 0x00");
|
|
|
|
#ifdef ENABLE_UTF8
|
2021-01-07 09:33:04 +00:00
|
|
|
else if ((unsigned char)*this_position < 0x80 && using_utf8())
|
|
|
|
sprintf(hexadecimal, "U+%04X", (unsigned char)*this_position);
|
2021-03-25 16:28:51 +00:00
|
|
|
else if (using_utf8() && mbtowide(&widecode, this_position) > 0)
|
2021-01-07 15:17:17 +00:00
|
|
|
sprintf(hexadecimal, "U+%04X", (int)widecode);
|
2021-01-06 14:02:15 +00:00
|
|
|
#endif
|
2020-12-29 14:11:04 +00:00
|
|
|
else
|
2021-01-06 14:02:15 +00:00
|
|
|
sprintf(hexadecimal, " 0x%02X", (unsigned char)*this_position);
|
2020-12-29 14:11:04 +00:00
|
|
|
|
|
|
|
mvwaddstr(bottomwin, 0, COLS - 23, hexadecimal);
|
2021-01-06 14:27:14 +00:00
|
|
|
|
|
|
|
#ifdef ENABLE_UTF8
|
|
|
|
successor = this_position + char_length(this_position);
|
|
|
|
|
2021-01-07 18:17:22 +00:00
|
|
|
if (*this_position && *successor && is_zerowidth(successor) &&
|
2021-03-25 16:28:51 +00:00
|
|
|
mbtowide(&widecode, successor) > 0) {
|
2021-01-06 14:27:14 +00:00
|
|
|
sprintf(hexadecimal, "|%04X", (int)widecode);
|
|
|
|
waddstr(bottomwin, hexadecimal);
|
2021-01-07 18:17:22 +00:00
|
|
|
|
|
|
|
successor += char_length(successor);
|
|
|
|
|
2021-03-25 16:28:51 +00:00
|
|
|
if (is_zerowidth(successor) && mbtowide(&widecode, successor) > 0) {
|
2021-01-07 18:17:22 +00:00
|
|
|
sprintf(hexadecimal, "|%04X", (int)widecode);
|
|
|
|
waddstr(bottomwin, hexadecimal);
|
|
|
|
}
|
2021-01-06 14:27:14 +00:00
|
|
|
} else
|
|
|
|
successor = NULL;
|
|
|
|
#endif
|
2020-12-29 12:21:07 +00:00
|
|
|
}
|
2020-08-15 15:32:31 +00:00
|
|
|
|
|
|
|
/* Display the state of three flags, and the state of macro and mark. */
|
2021-02-01 16:19:28 +00:00
|
|
|
if (ISSET(STATEFLAGS) && !successor && namewidth + tallywidth + 14 + 2 * padding < COLS) {
|
2020-12-30 18:01:35 +00:00
|
|
|
wmove(bottomwin, 0, COLS - 11 - padding);
|
2020-12-29 14:11:04 +00:00
|
|
|
show_states_at(bottomwin);
|
2020-12-29 12:21:07 +00:00
|
|
|
}
|
2020-08-15 15:32:31 +00:00
|
|
|
|
2020-12-20 15:19:49 +00:00
|
|
|
/* Display how many percent the current line is into the file. */
|
2020-12-30 15:07:29 +00:00
|
|
|
if (namewidth + 6 < COLS) {
|
2021-01-07 15:17:17 +00:00
|
|
|
sprintf(location, "%3zi%%", 100 * openfile->current->lineno / openfile->filebot->lineno);
|
2020-12-29 14:11:04 +00:00
|
|
|
mvwaddstr(bottomwin, 0, COLS - 4 - padding, location);
|
2020-12-29 12:21:07 +00:00
|
|
|
}
|
2020-12-20 15:19:49 +00:00
|
|
|
|
2021-06-07 10:10:23 +00:00
|
|
|
wattroff(bottomwin, interface_color_pair[MINI_INFOBAR]);
|
2020-08-15 15:32:31 +00:00
|
|
|
wrefresh(bottomwin);
|
|
|
|
|
2020-11-09 12:39:36 +00:00
|
|
|
free(number_of_lines);
|
2020-08-15 15:32:31 +00:00
|
|
|
free(hexadecimal);
|
|
|
|
free(location);
|
|
|
|
free(thename);
|
2020-08-16 09:24:13 +00:00
|
|
|
free(ranking);
|
2020-08-15 15:32:31 +00:00
|
|
|
}
|
|
|
|
#endif /* NANO_TINY */
|
|
|
|
|
2020-07-03 07:32:25 +00:00
|
|
|
/* Display the given message on the status bar, but only if its importance
|
|
|
|
* is higher than that of a message that is already there. */
|
2016-05-19 18:43:08 +00:00
|
|
|
void statusline(message_type importance, const char *msg, ...)
|
2004-05-18 01:20:36 +00:00
|
|
|
{
|
2017-12-29 18:27:33 +00:00
|
|
|
va_list ap;
|
2018-02-20 08:50:54 +00:00
|
|
|
int colorpair;
|
2017-12-29 18:27:33 +00:00
|
|
|
char *compound, *message;
|
2019-10-12 12:17:30 +00:00
|
|
|
static size_t start_col = 0;
|
2017-12-29 18:27:33 +00:00
|
|
|
bool bracketed;
|
2015-08-09 16:05:50 +00:00
|
|
|
#ifndef NANO_TINY
|
2017-12-29 18:27:33 +00:00
|
|
|
bool old_whitespace = ISSET(WHITESPACE_DISPLAY);
|
2015-08-09 16:05:50 +00:00
|
|
|
|
2017-12-29 18:27:33 +00:00
|
|
|
UNSET(WHITESPACE_DISPLAY);
|
2005-10-27 03:35:42 +00:00
|
|
|
#endif
|
2004-05-18 01:20:36 +00:00
|
|
|
|
2018-07-14 19:15:23 +00:00
|
|
|
/* Ignore a message with an importance that is lower than the last one. */
|
2020-12-08 16:09:07 +00:00
|
|
|
if (importance < lastmessage && lastmessage > NOTICE)
|
2018-07-14 19:15:23 +00:00
|
|
|
return;
|
|
|
|
|
2021-03-13 10:25:21 +00:00
|
|
|
/* Construct the message out of all the arguments. */
|
|
|
|
compound = nmalloc(MAXCHARLEN * COLS + 1);
|
|
|
|
va_start(ap, msg);
|
|
|
|
vsnprintf(compound, MAXCHARLEN * COLS + 1, msg, ap);
|
|
|
|
va_end(ap);
|
|
|
|
|
2021-07-14 08:16:31 +00:00
|
|
|
/* When not in curses mode, write the message to standard error. */
|
|
|
|
if (isendwin()) {
|
|
|
|
fprintf(stderr, "\n%s\n", compound);
|
|
|
|
free(compound);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-04-10 09:57:06 +00:00
|
|
|
#if !defined(NANO_TINY) && defined(ENABLE_MULTIBUFFER)
|
2021-03-23 15:12:48 +00:00
|
|
|
if (!we_are_running && importance == ALERT && openfile && !openfile->fmt &&
|
2021-03-13 11:08:47 +00:00
|
|
|
!openfile->errormessage && openfile->next != openfile)
|
|
|
|
openfile->errormessage = copy_of(compound);
|
|
|
|
#endif
|
|
|
|
|
2021-07-14 08:08:32 +00:00
|
|
|
/* On a one-row terminal, ensure that any changes in the edit window are
|
|
|
|
* written out first, to prevent them from overwriting the message. */
|
|
|
|
if (LINES == 1 && importance < INFO)
|
|
|
|
wnoutrefresh(edit);
|
|
|
|
|
2019-10-12 12:17:30 +00:00
|
|
|
/* If there are multiple alert messages, add trailing dots to the first. */
|
|
|
|
if (lastmessage == ALERT) {
|
|
|
|
if (start_col > 4) {
|
|
|
|
wmove(bottomwin, 0, COLS + 2 - start_col);
|
|
|
|
wattron(bottomwin, interface_color_pair[ERROR_MESSAGE]);
|
|
|
|
waddstr(bottomwin, "...");
|
|
|
|
wattroff(bottomwin, interface_color_pair[ERROR_MESSAGE]);
|
|
|
|
wnoutrefresh(bottomwin);
|
|
|
|
start_col = 0;
|
|
|
|
napms(100);
|
|
|
|
beep();
|
|
|
|
}
|
2021-03-13 10:25:21 +00:00
|
|
|
free(compound);
|
2019-10-12 12:17:30 +00:00
|
|
|
return;
|
|
|
|
}
|
2017-12-29 18:27:33 +00:00
|
|
|
|
2020-12-08 16:09:07 +00:00
|
|
|
if (importance > NOTICE) {
|
|
|
|
if (importance == ALERT)
|
|
|
|
beep();
|
2018-02-20 08:50:54 +00:00
|
|
|
colorpair = interface_color_pair[ERROR_MESSAGE];
|
2018-10-17 18:30:25 +00:00
|
|
|
} else if (importance == NOTICE)
|
|
|
|
colorpair = interface_color_pair[SELECTED_TEXT];
|
|
|
|
else
|
2018-02-20 08:50:54 +00:00
|
|
|
colorpair = interface_color_pair[STATUS_BAR];
|
2017-12-29 18:27:33 +00:00
|
|
|
|
|
|
|
lastmessage = importance;
|
|
|
|
|
|
|
|
blank_statusbar();
|
|
|
|
|
2019-02-27 20:37:53 +00:00
|
|
|
message = display_string(compound, 0, COLS, FALSE, FALSE);
|
2017-12-29 18:27:33 +00:00
|
|
|
free(compound);
|
2017-06-29 19:33:29 +00:00
|
|
|
|
2019-04-24 06:49:18 +00:00
|
|
|
start_col = (COLS - breadth(message)) / 2;
|
2017-12-29 18:27:33 +00:00
|
|
|
bracketed = (start_col > 1);
|
2004-05-18 01:20:36 +00:00
|
|
|
|
2017-12-29 18:27:33 +00:00
|
|
|
wmove(bottomwin, 0, (bracketed ? start_col - 2 : start_col));
|
2018-02-20 08:50:54 +00:00
|
|
|
wattron(bottomwin, colorpair);
|
2017-12-29 18:27:33 +00:00
|
|
|
if (bracketed)
|
|
|
|
waddstr(bottomwin, "[ ");
|
|
|
|
waddstr(bottomwin, message);
|
|
|
|
if (bracketed)
|
|
|
|
waddstr(bottomwin, " ]");
|
2018-02-20 08:50:54 +00:00
|
|
|
wattroff(bottomwin, colorpair);
|
2017-12-29 18:27:33 +00:00
|
|
|
|
2020-11-27 13:15:42 +00:00
|
|
|
#ifdef USING_OLDER_LIBVTE
|
2017-12-29 18:27:33 +00:00
|
|
|
/* Defeat a VTE/Konsole bug, where the cursor can go off-limits. */
|
|
|
|
if (ISSET(CONSTANT_SHOW) && ISSET(NO_HELP))
|
|
|
|
wmove(bottomwin, 0, 0);
|
2020-11-27 13:15:42 +00:00
|
|
|
#endif
|
2017-12-29 18:27:33 +00:00
|
|
|
|
|
|
|
/* Push the message to the screen straightaway. */
|
|
|
|
wrefresh(bottomwin);
|
2021-03-13 10:25:21 +00:00
|
|
|
free(message);
|
2017-12-29 18:27:33 +00:00
|
|
|
|
2005-11-15 03:17:35 +00:00
|
|
|
#ifndef NANO_TINY
|
2017-12-29 18:27:33 +00:00
|
|
|
if (old_whitespace)
|
|
|
|
SET(WHITESPACE_DISPLAY);
|
2017-04-19 11:44:00 +00:00
|
|
|
#endif
|
2016-08-22 08:50:51 +00:00
|
|
|
|
2021-01-11 15:18:35 +00:00
|
|
|
/* When requested, wipe the status bar after just one keystroke. */
|
|
|
|
statusblank = (ISSET(QUICK_BLANK) ? 1 : 20);
|
2004-05-18 01:20:36 +00:00
|
|
|
}
|
|
|
|
|
2020-01-16 15:16:31 +00:00
|
|
|
/* Display a normal message on the status bar, quietly. */
|
2019-10-13 14:21:31 +00:00
|
|
|
void statusbar(const char *msg)
|
|
|
|
{
|
|
|
|
statusline(HUSH, msg);
|
|
|
|
}
|
|
|
|
|
2020-01-16 15:16:31 +00:00
|
|
|
/* Warn the user on the status bar and pause for a moment, so that the
|
2019-10-13 14:21:31 +00:00
|
|
|
* message can be noticed and read. */
|
2020-05-28 14:59:50 +00:00
|
|
|
void warn_and_briefly_pause(const char *msg)
|
2019-10-13 14:21:31 +00:00
|
|
|
{
|
2020-01-14 09:49:12 +00:00
|
|
|
blank_bottombars();
|
2019-10-13 14:21:31 +00:00
|
|
|
statusline(ALERT, msg);
|
2020-07-04 07:34:54 +00:00
|
|
|
lastmessage = VACUUM;
|
2020-01-14 09:49:12 +00:00
|
|
|
napms(1500);
|
2019-10-13 14:21:31 +00:00
|
|
|
}
|
|
|
|
|
2020-03-16 09:17:15 +00:00
|
|
|
/* Write a key's representation plus a minute description of its function
|
|
|
|
* to the screen. For example, the key could be "^C" and its tag "Cancel".
|
|
|
|
* Key plus tag may occupy at most width columns. */
|
|
|
|
void post_one_key(const char *keystroke, const char *tag, int width)
|
|
|
|
{
|
|
|
|
wattron(bottomwin, interface_color_pair[KEY_COMBO]);
|
|
|
|
waddnstr(bottomwin, keystroke, actual_x(keystroke, width));
|
|
|
|
wattroff(bottomwin, interface_color_pair[KEY_COMBO]);
|
|
|
|
|
2020-03-25 15:49:46 +00:00
|
|
|
/* If the remaining space is too small, skip the description. */
|
2020-03-16 09:17:15 +00:00
|
|
|
width -= breadth(keystroke);
|
|
|
|
if (width < 2)
|
|
|
|
return;
|
|
|
|
|
|
|
|
waddch(bottomwin, ' ');
|
|
|
|
wattron(bottomwin, interface_color_pair[FUNCTION_TAG]);
|
|
|
|
waddnstr(bottomwin, tag, actual_x(tag, width - 1));
|
|
|
|
wattroff(bottomwin, interface_color_pair[FUNCTION_TAG]);
|
|
|
|
}
|
|
|
|
|
2015-12-04 21:11:10 +00:00
|
|
|
/* Display the shortcut list corresponding to menu 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
|
|
|
{
|
2020-03-16 09:15:01 +00:00
|
|
|
size_t index, number, itemwidth;
|
2019-04-03 15:34:05 +00:00
|
|
|
const keystruct *s;
|
2020-03-16 09:15:01 +00:00
|
|
|
funcstruct *f;
|
2002-02-15 19:17:02 +00:00
|
|
|
|
2017-12-29 18:27:33 +00:00
|
|
|
/* Set the global variable to the given menu. */
|
|
|
|
currmenu = menu;
|
2015-04-07 14:16:07 +00:00
|
|
|
|
2017-12-29 18:27:33 +00:00
|
|
|
if (ISSET(NO_HELP) || LINES < 5)
|
|
|
|
return;
|
2000-06-06 05:53:49 +00:00
|
|
|
|
2019-09-27 16:49:39 +00:00
|
|
|
/* Determine how many shortcuts must be shown. */
|
2019-09-27 17:07:25 +00:00
|
|
|
number = shown_entries_for(menu);
|
2002-05-12 19:52:15 +00:00
|
|
|
|
2017-12-29 18:27:33 +00:00
|
|
|
/* Compute the width of each keyname-plus-explanation pair. */
|
2019-10-01 13:03:40 +00:00
|
|
|
itemwidth = COLS / ((number + 1) / 2);
|
2000-06-06 05:53:49 +00:00
|
|
|
|
2017-12-29 18:27:33 +00:00
|
|
|
/* If there is no room, don't print anything. */
|
|
|
|
if (itemwidth == 0)
|
|
|
|
return;
|
2016-08-15 10:55:03 +00:00
|
|
|
|
2017-12-29 18:27:33 +00:00
|
|
|
blank_bottombars();
|
2001-06-14 02:54:22 +00:00
|
|
|
|
2017-12-29 18:27:33 +00:00
|
|
|
/* Display the first number of shortcuts in the given menu that
|
|
|
|
* have a key combination assigned to them. */
|
2020-03-16 09:15:01 +00:00
|
|
|
for (f = allfuncs, index = 0; f != NULL && index < number; f = f->next) {
|
2020-11-26 16:12:09 +00:00
|
|
|
size_t thiswidth = itemwidth;
|
|
|
|
|
2017-12-29 18:27:33 +00:00
|
|
|
if ((f->menus & menu) == 0)
|
|
|
|
continue;
|
2004-10-25 15:00:38 +00:00
|
|
|
|
2018-02-24 18:31:11 +00:00
|
|
|
s = first_sc_for(menu, f->func);
|
2020-03-16 09:15:01 +00:00
|
|
|
|
2017-12-29 18:27:33 +00:00
|
|
|
if (s == NULL)
|
|
|
|
continue;
|
2016-08-27 08:12:05 +00:00
|
|
|
|
2020-03-16 09:15:01 +00:00
|
|
|
wmove(bottomwin, 1 + index % 2, (index / 2) * itemwidth);
|
2017-07-15 09:49:56 +00:00
|
|
|
|
2020-11-26 16:31:29 +00:00
|
|
|
/* When the number is uneven, the penultimate item can be double wide. */
|
2020-11-26 16:12:09 +00:00
|
|
|
if ((number % 2) == 1 && (index + 2 == number))
|
|
|
|
thiswidth += itemwidth;
|
|
|
|
|
2020-11-26 16:31:29 +00:00
|
|
|
/* For the last two items, use also the remaining slack. */
|
|
|
|
if (index + 2 >= number)
|
|
|
|
thiswidth += COLS % itemwidth;
|
|
|
|
|
|
|
|
post_one_key(s->keystr, _(f->desc), thiswidth);
|
|
|
|
|
2020-03-16 09:15:01 +00:00
|
|
|
index++;
|
2017-12-29 18:27:33 +00:00
|
|
|
}
|
2001-04-30 11:28:46 +00:00
|
|
|
|
2017-12-29 18:27:33 +00:00
|
|
|
wrefresh(bottomwin);
|
2000-06-06 05:53:49 +00:00
|
|
|
}
|
|
|
|
|
2016-03-23 20:04:33 +00:00
|
|
|
/* Redetermine current_y from the position of current relative to edittop,
|
2017-02-26 16:18:39 +00:00
|
|
|
* and put the cursor in the edit window at (current_y, "current_x"). */
|
2017-07-22 04:26:59 +00:00
|
|
|
void place_the_cursor(void)
|
2002-08-21 16:10:37 +00:00
|
|
|
{
|
2017-12-29 18:27:33 +00:00
|
|
|
ssize_t row = 0;
|
2020-01-26 18:23:37 +00:00
|
|
|
size_t column = xplustabs();
|
2006-05-26 03:02:50 +00:00
|
|
|
|
2014-06-09 20:26:54 +00:00
|
|
|
#ifndef NANO_TINY
|
2017-12-29 18:27:33 +00:00
|
|
|
if (ISSET(SOFTWRAP)) {
|
2019-03-21 16:08:52 +00:00
|
|
|
linestruct *line = openfile->edittop;
|
2017-12-29 18:27:33 +00:00
|
|
|
size_t leftedge;
|
2009-11-11 06:00:33 +00:00
|
|
|
|
2017-12-29 18:27:33 +00:00
|
|
|
row -= chunk_for(openfile->firstcolumn, openfile->edittop);
|
2017-01-21 17:25:39 +00:00
|
|
|
|
2017-12-29 18:27:33 +00:00
|
|
|
/* Calculate how many rows the lines from edittop to current use. */
|
|
|
|
while (line != NULL && line != openfile->current) {
|
2020-05-13 10:41:17 +00:00
|
|
|
row += 1 + extra_chunks_in(line);
|
2017-12-29 18:27:33 +00:00
|
|
|
line = line->next;
|
|
|
|
}
|
2016-03-23 20:04:33 +00:00
|
|
|
|
2017-12-29 18:27:33 +00:00
|
|
|
/* Add the number of wraps in the current line before the cursor. */
|
2020-01-26 18:23:37 +00:00
|
|
|
row += get_chunk_and_edge(column, openfile->current, &leftedge);
|
|
|
|
column -= leftedge;
|
2017-12-29 18:27:33 +00:00
|
|
|
} else
|
2014-06-09 20:26:54 +00:00
|
|
|
#endif
|
2017-12-29 18:27:33 +00:00
|
|
|
{
|
|
|
|
row = openfile->current->lineno - openfile->edittop->lineno;
|
2020-01-26 18:23:37 +00:00
|
|
|
column -= get_page_start(column);
|
2017-12-29 18:27:33 +00:00
|
|
|
}
|
2017-02-26 16:18:39 +00:00
|
|
|
|
2017-12-29 18:27:33 +00:00
|
|
|
if (row < editwinrows)
|
2020-01-26 18:23:37 +00:00
|
|
|
wmove(edit, row, margin + column);
|
2020-01-27 11:06:27 +00:00
|
|
|
#ifndef NANO_TINY
|
|
|
|
else
|
|
|
|
statusline(ALERT, "Misplaced cursor -- please report a bug");
|
|
|
|
#endif
|
2017-02-26 16:18:39 +00:00
|
|
|
|
2017-12-29 18:27:33 +00:00
|
|
|
openfile->current_y = row;
|
2002-08-21 16:10:37 +00:00
|
|
|
}
|
2002-07-19 01:08:59 +00:00
|
|
|
|
2019-06-26 17:36:02 +00:00
|
|
|
/* Draw the given text on the given row of the edit window. line is the
|
2019-06-26 15:56:02 +00:00
|
|
|
* line to be drawn, and converted is the actual string to be written with
|
|
|
|
* tabs and control characters replaced by strings of regular characters.
|
|
|
|
* from_col is the column number of the first character of this "page". */
|
2019-06-26 17:40:06 +00:00
|
|
|
void draw_row(int row, const char *converted, linestruct *line, size_t from_col)
|
2000-06-06 05:53:49 +00:00
|
|
|
{
|
2016-10-20 08:44:29 +00:00
|
|
|
#ifdef ENABLE_LINENUMBERS
|
2017-12-29 18:27:33 +00:00
|
|
|
/* If line numbering is switched on, put a line number in front of
|
|
|
|
* the text -- but only for the parts that are not softwrapped. */
|
|
|
|
if (margin > 0) {
|
|
|
|
wattron(edit, interface_color_pair[LINE_NUMBER]);
|
2016-12-09 17:51:41 +00:00
|
|
|
#ifndef NANO_TINY
|
2017-12-29 18:27:33 +00:00
|
|
|
if (ISSET(SOFTWRAP) && from_col != 0)
|
2019-12-15 13:23:32 +00:00
|
|
|
mvwprintw(edit, row, 0, "%*s", margin - 1, " ");
|
2017-12-29 18:27:33 +00:00
|
|
|
else
|
2016-12-09 17:51:41 +00:00
|
|
|
#endif
|
2019-12-15 13:23:32 +00:00
|
|
|
mvwprintw(edit, row, 0, "%*zd", margin - 1, line->lineno);
|
2017-12-29 18:27:33 +00:00
|
|
|
wattroff(edit, interface_color_pair[LINE_NUMBER]);
|
2020-04-13 09:48:36 +00:00
|
|
|
#ifndef NANO_TINY
|
2020-08-03 08:02:09 +00:00
|
|
|
if (line->has_anchor && (from_col == 0 || !ISSET(SOFTWRAP)))
|
2020-08-03 07:43:55 +00:00
|
|
|
#ifdef ENABLE_UTF8
|
|
|
|
if (using_utf8())
|
2021-09-19 09:42:35 +00:00
|
|
|
wprintw(edit, "\xE2\xAC\xA5"); /* black medium diamond */
|
2020-08-03 07:43:55 +00:00
|
|
|
else
|
|
|
|
#endif
|
|
|
|
wprintw(edit, "+");
|
2020-04-13 09:48:36 +00:00
|
|
|
else
|
|
|
|
#endif
|
|
|
|
wprintw(edit, " ");
|
2017-12-29 18:27:33 +00:00
|
|
|
}
|
2020-09-12 10:21:24 +00:00
|
|
|
#endif /* ENABLE_LINENUMBERS */
|
2003-09-16 01:16:49 +00:00
|
|
|
|
2017-12-29 18:27:33 +00:00
|
|
|
/* First simply write the converted line -- afterward we'll add colors
|
|
|
|
* and the marking highlight on just the pieces that need it. */
|
|
|
|
mvwaddstr(edit, row, margin, converted);
|
2019-06-28 18:07:42 +00:00
|
|
|
|
|
|
|
/* When needed, clear the remainder of the row. */
|
|
|
|
if (is_shorter || ISSET(SOFTWRAP))
|
|
|
|
wclrtoeol(edit);
|
2014-06-04 16:02:51 +00:00
|
|
|
|
2020-06-15 10:38:16 +00:00
|
|
|
#ifndef NANO_TINY
|
2020-04-25 15:19:03 +00:00
|
|
|
if (thebar)
|
|
|
|
mvwaddch(edit, row, COLS - 1, bardata[row]);
|
2020-06-15 10:38:16 +00:00
|
|
|
#endif
|
2001-12-02 04:55:44 +00:00
|
|
|
|
2017-11-01 18:45:33 +00:00
|
|
|
#ifdef ENABLE_COLOR
|
2020-05-01 11:25:15 +00:00
|
|
|
/* If there are color rules (and coloring is turned on), apply them. */
|
|
|
|
if (openfile->syntax && !ISSET(NO_SYNTAX)) {
|
2020-05-01 10:38:02 +00:00
|
|
|
const colortype *varnish = openfile->syntax->color;
|
2017-12-29 18:27:33 +00:00
|
|
|
|
2021-01-29 09:30:05 +00:00
|
|
|
/* If there are multiline regexes, make sure this line has a cache. */
|
2019-06-26 17:36:02 +00:00
|
|
|
if (openfile->syntax->nmultis > 0 && line->multidata == NULL)
|
2021-01-29 09:30:05 +00:00
|
|
|
line->multidata = nmalloc(openfile->syntax->nmultis * sizeof(short));
|
2017-12-29 18:27:33 +00:00
|
|
|
|
|
|
|
/* Iterate through all the coloring regexes. */
|
|
|
|
for (; varnish != NULL; varnish = varnish->next) {
|
|
|
|
size_t index = 0;
|
|
|
|
/* Where in the line we currently begin looking for a match. */
|
2021-01-24 15:44:38 +00:00
|
|
|
int start_col = 0;
|
2017-12-29 18:27:33 +00:00
|
|
|
/* The starting column of a piece to paint. Zero-based. */
|
|
|
|
int paintlen = 0;
|
|
|
|
/* The number of characters to paint. */
|
|
|
|
const char *thetext;
|
|
|
|
/* The place in converted from where painting starts. */
|
|
|
|
regmatch_t match;
|
|
|
|
/* The match positions of a single-line regex. */
|
2019-06-26 17:36:02 +00:00
|
|
|
const linestruct *start_line = line->prev;
|
|
|
|
/* The first line before line that matches 'start'. */
|
2021-02-05 15:05:38 +00:00
|
|
|
linestruct *end_line = line;
|
2017-12-29 18:27:33 +00:00
|
|
|
/* The line that matches 'end'. */
|
|
|
|
regmatch_t startmatch, endmatch;
|
|
|
|
/* The match positions of the start and end regexes. */
|
|
|
|
|
|
|
|
/* First case: varnish is a single-line expression. */
|
|
|
|
if (varnish->end == NULL) {
|
|
|
|
while (index < till_x) {
|
2021-01-22 10:58:53 +00:00
|
|
|
/* If there is no match, go on to the next line. */
|
2019-06-26 17:36:02 +00:00
|
|
|
if (regexec(varnish->start, &line->data[index], 1,
|
2017-12-29 18:27:33 +00:00
|
|
|
&match, (index == 0) ? 0 : REG_NOTBOL) != 0)
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* Translate the match to the beginning of the line. */
|
|
|
|
match.rm_so += index;
|
|
|
|
match.rm_eo += index;
|
|
|
|
index = match.rm_eo;
|
|
|
|
|
2021-01-24 15:56:31 +00:00
|
|
|
/* If the match is offscreen to the right, this rule is done. */
|
|
|
|
if (match.rm_so >= till_x)
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* If the match has length zero, advance over it. */
|
|
|
|
if (match.rm_so == match.rm_eo) {
|
2021-01-24 16:03:22 +00:00
|
|
|
if (line->data[index] == '\0')
|
|
|
|
break;
|
2021-01-24 15:56:31 +00:00
|
|
|
index = step_right(line->data, index);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2021-01-24 11:31:52 +00:00
|
|
|
/* If the match is offscreen to the left, skip to next. */
|
|
|
|
if (match.rm_eo <= from_x)
|
2017-12-29 18:27:33 +00:00
|
|
|
continue;
|
|
|
|
|
2021-01-24 15:44:38 +00:00
|
|
|
if (match.rm_so > from_x)
|
|
|
|
start_col = wideness(line->data, match.rm_so) - from_col;
|
2017-12-29 18:27:33 +00:00
|
|
|
|
|
|
|
thetext = converted + actual_x(converted, start_col);
|
|
|
|
|
2019-06-26 17:36:02 +00:00
|
|
|
paintlen = actual_x(thetext, wideness(line->data,
|
2017-12-29 18:27:33 +00:00
|
|
|
match.rm_eo) - from_col - start_col);
|
|
|
|
|
2021-01-23 16:20:32 +00:00
|
|
|
wattron(edit, varnish->attributes);
|
2019-06-09 18:02:58 +00:00
|
|
|
mvwaddnstr(edit, row, margin + start_col, thetext, paintlen);
|
2021-01-23 16:20:32 +00:00
|
|
|
wattroff(edit, varnish->attributes);
|
2017-12-29 18:27:33 +00:00
|
|
|
}
|
2021-01-23 16:20:32 +00:00
|
|
|
|
|
|
|
continue;
|
2017-12-29 18:27:33 +00:00
|
|
|
}
|
2002-09-27 14:21:59 +00:00
|
|
|
|
2017-12-29 18:27:33 +00:00
|
|
|
/* Second case: varnish is a multiline expression. */
|
|
|
|
|
|
|
|
/* Assume nothing gets painted until proven otherwise below. */
|
2021-01-28 15:11:57 +00:00
|
|
|
line->multidata[varnish->id] = NOTHING;
|
2017-12-29 18:27:33 +00:00
|
|
|
|
2021-01-28 10:57:33 +00:00
|
|
|
/* Apart from the first row, check the multidata of the preceding line:
|
|
|
|
* it tells us about the situation so far, and thus what to do here. */
|
2021-01-27 11:18:42 +00:00
|
|
|
if (row > 0 && start_line != NULL && start_line->multidata != NULL) {
|
2021-01-28 15:11:57 +00:00
|
|
|
if (start_line->multidata[varnish->id] == WHOLELINE ||
|
|
|
|
start_line->multidata[varnish->id] == STARTSHERE ||
|
|
|
|
start_line->multidata[varnish->id] == WOULDBE)
|
2017-12-29 18:27:33 +00:00
|
|
|
goto seek_an_end;
|
2021-01-28 15:11:57 +00:00
|
|
|
if (start_line->multidata[varnish->id] == NOTHING ||
|
|
|
|
start_line->multidata[varnish->id] == ENDSHERE ||
|
|
|
|
start_line->multidata[varnish->id] == JUSTONTHIS)
|
2017-12-29 18:27:33 +00:00
|
|
|
goto step_two;
|
|
|
|
}
|
2005-01-03 22:23:00 +00:00
|
|
|
|
2021-01-28 10:57:33 +00:00
|
|
|
/* The preceding line has no precalculated multidata.
|
|
|
|
* So, do some backtracking to find out what to paint. */
|
2017-12-29 18:27:33 +00:00
|
|
|
|
|
|
|
/* First step: see if there is a line before current that
|
|
|
|
* matches 'start' and is not complemented by an 'end'. */
|
|
|
|
while (start_line != NULL && regexec(varnish->start,
|
2021-01-28 10:57:33 +00:00
|
|
|
start_line->data, 1, &startmatch, 0) == REG_NOMATCH) {
|
2017-12-29 18:27:33 +00:00
|
|
|
/* There is no start on this line; but if there is an end,
|
|
|
|
* there is no need to look for starts on earlier lines. */
|
|
|
|
if (regexec(varnish->end, start_line->data, 0, NULL, 0) == 0)
|
|
|
|
goto step_two;
|
|
|
|
start_line = start_line->prev;
|
|
|
|
}
|
2005-01-03 22:23:00 +00:00
|
|
|
|
2017-12-29 18:27:33 +00:00
|
|
|
/* If no start was found, skip to the next step. */
|
|
|
|
if (start_line == NULL)
|
|
|
|
goto step_two;
|
|
|
|
|
2021-01-28 10:57:33 +00:00
|
|
|
/* If the start has been qualified as an end earlier, believe it. */
|
2017-12-29 18:27:33 +00:00
|
|
|
if (start_line->multidata != NULL &&
|
2021-01-28 15:11:57 +00:00
|
|
|
(start_line->multidata[varnish->id] == ENDSHERE ||
|
|
|
|
start_line->multidata[varnish->id] == JUSTONTHIS))
|
2017-12-29 18:27:33 +00:00
|
|
|
goto step_two;
|
|
|
|
|
2021-01-22 10:58:53 +00:00
|
|
|
/* Maybe there is an end on that same line? If yes, maybe
|
2021-01-28 10:57:33 +00:00
|
|
|
* there is another start after it? And so on, until EOL. */
|
2017-12-29 18:27:33 +00:00
|
|
|
while (TRUE) {
|
|
|
|
/* Begin searching for an end after the start match. */
|
|
|
|
index += startmatch.rm_eo;
|
|
|
|
/* If there is no end after this last start, good. */
|
|
|
|
if (regexec(varnish->end, start_line->data + index, 1, &endmatch,
|
|
|
|
(index == 0) ? 0 : REG_NOTBOL) == REG_NOMATCH)
|
|
|
|
break;
|
|
|
|
/* Begin searching for a new start after the end match. */
|
|
|
|
index += endmatch.rm_eo;
|
|
|
|
/* If both start and end match are mere anchors, advance. */
|
|
|
|
if (startmatch.rm_so == startmatch.rm_eo &&
|
|
|
|
endmatch.rm_so == endmatch.rm_eo) {
|
|
|
|
if (start_line->data[index] == '\0')
|
2021-01-22 11:05:18 +00:00
|
|
|
goto step_two;
|
2019-06-09 17:37:56 +00:00
|
|
|
index = step_right(start_line->data, index);
|
2017-12-29 18:27:33 +00:00
|
|
|
}
|
|
|
|
/* If there is no later start on this line, next step. */
|
|
|
|
if (regexec(varnish->start, start_line->data + index,
|
|
|
|
1, &startmatch, REG_NOTBOL) == REG_NOMATCH)
|
|
|
|
goto step_two;
|
|
|
|
}
|
2017-01-09 10:49:35 +00:00
|
|
|
|
2017-01-23 13:41:25 +00:00
|
|
|
seek_an_end:
|
2017-12-29 18:27:33 +00:00
|
|
|
/* We've already checked that there is no end between the start
|
|
|
|
* and the current line. But is there an end after the start
|
2021-01-28 10:57:33 +00:00
|
|
|
* at all? Because we don't paint unterminated starts. */
|
2021-01-27 11:18:42 +00:00
|
|
|
if (row == 0) {
|
2021-01-28 10:57:33 +00:00
|
|
|
while (end_line != NULL && regexec(varnish->end, end_line->data,
|
|
|
|
1, &endmatch, 0) == REG_NOMATCH)
|
|
|
|
end_line = end_line->next;
|
2021-01-27 11:18:42 +00:00
|
|
|
} else if (regexec(varnish->end, line->data, 1, &endmatch, 0) != 0)
|
|
|
|
end_line = line->next;
|
2017-12-29 18:27:33 +00:00
|
|
|
|
|
|
|
/* If there is no end, there is nothing to paint. */
|
|
|
|
if (end_line == NULL) {
|
2021-01-28 15:11:57 +00:00
|
|
|
line->multidata[varnish->id] = WOULDBE;
|
2021-01-23 16:20:32 +00:00
|
|
|
continue;
|
2017-12-29 18:27:33 +00:00
|
|
|
}
|
2006-05-08 15:57:04 +00:00
|
|
|
|
2021-01-28 10:57:33 +00:00
|
|
|
/* If it was already determined that there is no end... */
|
2021-01-27 11:18:42 +00:00
|
|
|
if (end_line != line && line->prev == start_line && line->prev->multidata &&
|
2021-01-28 15:11:57 +00:00
|
|
|
line->prev->multidata[varnish->id] == WOULDBE) {
|
|
|
|
line->multidata[varnish->id] = WOULDBE;
|
2021-01-27 11:18:42 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2017-12-29 18:27:33 +00:00
|
|
|
/* If the end is on a later line, paint whole line, and be done. */
|
2019-06-26 17:36:02 +00:00
|
|
|
if (end_line != line) {
|
2021-01-23 16:20:32 +00:00
|
|
|
wattron(edit, varnish->attributes);
|
2017-12-29 18:27:33 +00:00
|
|
|
mvwaddnstr(edit, row, margin, converted, -1);
|
2021-01-23 16:20:32 +00:00
|
|
|
wattroff(edit, varnish->attributes);
|
2021-01-28 15:11:57 +00:00
|
|
|
line->multidata[varnish->id] = WHOLELINE;
|
2021-01-23 16:20:32 +00:00
|
|
|
continue;
|
2017-12-29 18:27:33 +00:00
|
|
|
}
|
2005-01-03 22:23:00 +00:00
|
|
|
|
2017-12-29 18:27:33 +00:00
|
|
|
/* Only if it is visible, paint the part to be coloured. */
|
|
|
|
if (endmatch.rm_eo > from_x) {
|
2019-06-26 17:36:02 +00:00
|
|
|
paintlen = actual_x(converted, wideness(line->data,
|
2017-12-29 18:27:33 +00:00
|
|
|
endmatch.rm_eo) - from_col);
|
2021-01-23 16:20:32 +00:00
|
|
|
wattron(edit, varnish->attributes);
|
2017-12-29 18:27:33 +00:00
|
|
|
mvwaddnstr(edit, row, margin, converted, paintlen);
|
2021-01-23 16:20:32 +00:00
|
|
|
wattroff(edit, varnish->attributes);
|
2017-12-29 18:27:33 +00:00
|
|
|
}
|
2021-01-28 15:11:57 +00:00
|
|
|
line->multidata[varnish->id] = ENDSHERE;
|
2005-01-03 22:23:00 +00:00
|
|
|
|
2017-12-29 18:27:33 +00:00
|
|
|
step_two:
|
|
|
|
/* Second step: look for starts on this line, but begin
|
|
|
|
* looking only after an end match, if there is one. */
|
|
|
|
index = (paintlen == 0) ? 0 : endmatch.rm_eo;
|
|
|
|
|
2021-01-29 09:52:40 +00:00
|
|
|
while (regexec(varnish->start, line->data + index, 1, &startmatch,
|
|
|
|
(index == 0) ? 0 : REG_NOTBOL) == 0) {
|
2021-01-28 10:57:33 +00:00
|
|
|
/* Make the match relative to the beginning of the line. */
|
2017-12-29 18:27:33 +00:00
|
|
|
startmatch.rm_so += index;
|
|
|
|
startmatch.rm_eo += index;
|
|
|
|
|
2021-01-24 15:44:38 +00:00
|
|
|
if (startmatch.rm_so > from_x)
|
|
|
|
start_col = wideness(line->data, startmatch.rm_so) - from_col;
|
2017-12-29 18:27:33 +00:00
|
|
|
|
|
|
|
thetext = converted + actual_x(converted, start_col);
|
|
|
|
|
2021-01-29 09:52:40 +00:00
|
|
|
if (regexec(varnish->end, line->data + startmatch.rm_eo, 1, &endmatch,
|
|
|
|
(startmatch.rm_eo == 0) ? 0 : REG_NOTBOL) == 0) {
|
2021-01-28 10:57:33 +00:00
|
|
|
/* Make the match relative to the beginning of the line. */
|
2017-12-29 18:27:33 +00:00
|
|
|
endmatch.rm_so += startmatch.rm_eo;
|
|
|
|
endmatch.rm_eo += startmatch.rm_eo;
|
2021-01-28 10:57:33 +00:00
|
|
|
/* Only paint the match if it is visible on screen
|
|
|
|
* and it is more than zero characters long. */
|
2021-01-29 09:52:40 +00:00
|
|
|
if (endmatch.rm_eo > from_x && endmatch.rm_eo > startmatch.rm_so) {
|
2019-06-26 17:36:02 +00:00
|
|
|
paintlen = actual_x(thetext, wideness(line->data,
|
2021-01-29 09:52:40 +00:00
|
|
|
endmatch.rm_eo) - from_col - start_col);
|
2017-12-29 18:27:33 +00:00
|
|
|
|
2021-01-23 16:20:32 +00:00
|
|
|
wattron(edit, varnish->attributes);
|
2021-01-29 09:52:40 +00:00
|
|
|
mvwaddnstr(edit, row, margin + start_col, thetext, paintlen);
|
2021-01-23 16:20:32 +00:00
|
|
|
wattroff(edit, varnish->attributes);
|
2017-12-29 18:27:33 +00:00
|
|
|
|
2021-01-28 15:11:57 +00:00
|
|
|
line->multidata[varnish->id] = JUSTONTHIS;
|
2017-12-29 18:27:33 +00:00
|
|
|
}
|
|
|
|
index = endmatch.rm_eo;
|
|
|
|
/* If both start and end match are anchors, advance. */
|
|
|
|
if (startmatch.rm_so == startmatch.rm_eo &&
|
2021-01-29 09:52:40 +00:00
|
|
|
endmatch.rm_so == endmatch.rm_eo) {
|
2019-06-26 17:36:02 +00:00
|
|
|
if (line->data[index] == '\0')
|
2017-12-29 18:27:33 +00:00
|
|
|
break;
|
2019-06-26 17:36:02 +00:00
|
|
|
index = step_right(line->data, index);
|
2017-12-29 18:27:33 +00:00
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* There is no end on this line. But maybe on later lines? */
|
2019-06-26 17:36:02 +00:00
|
|
|
end_line = line->next;
|
2017-12-29 18:27:33 +00:00
|
|
|
|
2021-01-29 09:52:40 +00:00
|
|
|
while (end_line && regexec(varnish->end, end_line->data,
|
|
|
|
0, NULL, 0) == REG_NOMATCH)
|
2017-12-29 18:27:33 +00:00
|
|
|
end_line = end_line->next;
|
|
|
|
|
|
|
|
/* If there is no end, we're done with this regex. */
|
|
|
|
if (end_line == NULL) {
|
2021-01-28 15:11:57 +00:00
|
|
|
line->multidata[varnish->id] = WOULDBE;
|
2017-12-29 18:27:33 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Paint the rest of the line, and we're done. */
|
2021-01-23 16:20:32 +00:00
|
|
|
wattron(edit, varnish->attributes);
|
2017-12-29 18:27:33 +00:00
|
|
|
mvwaddnstr(edit, row, margin + start_col, thetext, -1);
|
2021-01-23 16:20:32 +00:00
|
|
|
wattroff(edit, varnish->attributes);
|
2021-02-05 15:05:38 +00:00
|
|
|
|
2021-01-28 15:11:57 +00:00
|
|
|
line->multidata[varnish->id] = STARTSHERE;
|
2021-02-05 15:05:38 +00:00
|
|
|
|
|
|
|
if (end_line->multidata == NULL) {
|
|
|
|
end_line->multidata = nmalloc(openfile->syntax->nmultis * sizeof(short));
|
|
|
|
for (short item = 0; item < openfile->syntax->nmultis; item++)
|
|
|
|
end_line->multidata[item] = 0;
|
|
|
|
}
|
|
|
|
end_line->multidata[varnish->id] = ENDSHERE;
|
|
|
|
|
2017-12-29 18:27:33 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2005-03-10 20:55:11 +00:00
|
|
|
}
|
2017-11-01 18:45:33 +00:00
|
|
|
#endif /* ENABLE_COLOR */
|
2001-12-02 04:55:44 +00:00
|
|
|
|
2019-03-14 18:32:10 +00:00
|
|
|
#ifndef NANO_TINY
|
2019-03-15 13:03:04 +00:00
|
|
|
if (stripe_column > from_col && !inhelp &&
|
2020-01-27 14:36:37 +00:00
|
|
|
(sequel_column == 0 || stripe_column <= sequel_column) &&
|
|
|
|
stripe_column <= from_col + editwincols) {
|
2019-03-14 15:44:55 +00:00
|
|
|
ssize_t target_column = stripe_column - from_col - 1;
|
|
|
|
size_t target_x = actual_x(converted, target_column);
|
|
|
|
char striped_char[MAXCHARLEN];
|
|
|
|
size_t charlen = 1;
|
|
|
|
|
|
|
|
if (*(converted + target_x) != '\0') {
|
2019-10-21 10:35:14 +00:00
|
|
|
charlen = collect_char(converted + target_x, striped_char);
|
2019-04-24 07:08:23 +00:00
|
|
|
target_column = wideness(converted, target_x);
|
2020-11-26 13:25:16 +00:00
|
|
|
#ifdef USING_OLDER_LIBVTE
|
2019-03-15 13:43:15 +00:00
|
|
|
} else if (target_column + 1 == editwincols) {
|
|
|
|
/* Defeat a VTE bug -- see https://sv.gnu.org/bugs/?55896. */
|
2019-03-15 15:41:02 +00:00
|
|
|
#ifdef ENABLE_UTF8
|
2019-03-15 13:43:15 +00:00
|
|
|
if (using_utf8()) {
|
|
|
|
striped_char[0] = '\xC2';
|
|
|
|
striped_char[1] = '\xA0';
|
|
|
|
charlen = 2;
|
|
|
|
} else
|
2019-03-15 15:41:02 +00:00
|
|
|
#endif
|
2019-03-15 13:43:15 +00:00
|
|
|
striped_char[0] = '.';
|
2020-11-26 13:25:16 +00:00
|
|
|
#endif
|
2019-03-14 15:44:55 +00:00
|
|
|
} else
|
2019-03-15 13:43:15 +00:00
|
|
|
striped_char[0] = ' ';
|
2018-12-17 18:57:30 +00:00
|
|
|
|
2019-03-03 10:04:19 +00:00
|
|
|
wattron(edit, interface_color_pair[GUIDE_STRIPE]);
|
2019-03-14 15:44:55 +00:00
|
|
|
mvwaddnstr(edit, row, margin + target_column, striped_char, charlen);
|
2019-03-03 10:04:19 +00:00
|
|
|
wattroff(edit, interface_color_pair[GUIDE_STRIPE]);
|
2018-12-17 18:57:30 +00:00
|
|
|
}
|
|
|
|
|
2019-06-26 17:40:06 +00:00
|
|
|
/* If the line is at least partially selected, paint the marked part. */
|
|
|
|
if (openfile->mark && ((line->lineno >= openfile->mark->lineno &&
|
|
|
|
line->lineno <= openfile->current->lineno) ||
|
|
|
|
(line->lineno <= openfile->mark->lineno &&
|
|
|
|
line->lineno >= openfile->current->lineno))) {
|
2020-03-29 18:17:32 +00:00
|
|
|
linestruct *top, *bot;
|
2017-12-29 18:27:33 +00:00
|
|
|
/* The lines where the marked region begins and ends. */
|
|
|
|
size_t top_x, bot_x;
|
|
|
|
/* The x positions where the marked region begins and ends. */
|
|
|
|
int start_col;
|
|
|
|
/* The column where painting starts. Zero-based. */
|
|
|
|
const char *thetext;
|
|
|
|
/* The place in converted from where painting starts. */
|
|
|
|
int paintlen = -1;
|
|
|
|
/* The number of characters to paint. Negative means "all". */
|
|
|
|
|
2020-03-29 11:14:17 +00:00
|
|
|
get_region(&top, &top_x, &bot, &bot_x);
|
2017-12-29 18:27:33 +00:00
|
|
|
|
2019-06-26 17:36:02 +00:00
|
|
|
if (top->lineno < line->lineno || top_x < from_x)
|
2017-12-29 18:27:33 +00:00
|
|
|
top_x = from_x;
|
2019-06-26 17:36:02 +00:00
|
|
|
if (bot->lineno > line->lineno || bot_x > till_x)
|
2017-12-29 18:27:33 +00:00
|
|
|
bot_x = till_x;
|
|
|
|
|
|
|
|
/* Only paint if the marked part of the line is on this page. */
|
|
|
|
if (top_x < till_x && bot_x > from_x) {
|
|
|
|
/* Compute on which screen column to start painting. */
|
2019-06-26 17:36:02 +00:00
|
|
|
start_col = wideness(line->data, top_x) - from_col;
|
2017-12-29 18:27:33 +00:00
|
|
|
|
|
|
|
if (start_col < 0)
|
|
|
|
start_col = 0;
|
|
|
|
|
|
|
|
thetext = converted + actual_x(converted, start_col);
|
|
|
|
|
|
|
|
/* If the end of the mark is onscreen, compute how many
|
|
|
|
* characters to paint. Otherwise, just paint all. */
|
|
|
|
if (bot_x < till_x) {
|
2019-06-26 17:36:02 +00:00
|
|
|
size_t end_col = wideness(line->data, bot_x) - from_col;
|
2017-12-29 18:27:33 +00:00
|
|
|
paintlen = actual_x(thetext, end_col - start_col);
|
|
|
|
}
|
|
|
|
|
|
|
|
wattron(edit, interface_color_pair[SELECTED_TEXT]);
|
|
|
|
mvwaddnstr(edit, row, margin + start_col, thetext, paintlen);
|
|
|
|
wattroff(edit, interface_color_pair[SELECTED_TEXT]);
|
|
|
|
}
|
2000-06-06 05:53:49 +00:00
|
|
|
}
|
2005-11-15 03:17:35 +00:00
|
|
|
#endif /* !NANO_TINY */
|
2000-06-06 05:53:49 +00:00
|
|
|
}
|
|
|
|
|
2019-06-26 15:56:02 +00:00
|
|
|
/* Redraw the given line so that the character at the given index is visible
|
|
|
|
* -- if necessary, scroll the line horizontally (when not softwrapping).
|
|
|
|
* Return the number of rows "consumed" (relevant when softwrapping). */
|
2019-06-26 17:36:02 +00:00
|
|
|
int update_line(linestruct *line, size_t index)
|
2000-06-06 05:53:49 +00:00
|
|
|
{
|
2019-06-26 07:47:07 +00:00
|
|
|
int row;
|
2017-12-29 18:27:33 +00:00
|
|
|
/* The row in the edit window we will be updating. */
|
|
|
|
char *converted;
|
|
|
|
/* The data of the line with tabs and control characters expanded. */
|
2019-06-26 07:47:07 +00:00
|
|
|
size_t from_col;
|
2017-12-29 18:27:33 +00:00
|
|
|
/* From which column a horizontally scrolled line is displayed. */
|
2000-06-06 05:53:49 +00:00
|
|
|
|
2014-06-09 20:26:54 +00:00
|
|
|
#ifndef NANO_TINY
|
2017-12-29 18:27:33 +00:00
|
|
|
if (ISSET(SOFTWRAP))
|
2019-06-26 17:36:02 +00:00
|
|
|
return update_softwrapped_line(line);
|
2020-01-28 08:35:45 +00:00
|
|
|
|
|
|
|
sequel_column = 0;
|
2014-06-09 20:26:54 +00:00
|
|
|
#endif
|
softwrap: move the updating of a softwrapped line to a new function
The new function, update_softwrapped_line(), is called from inside
update_line() when softwrap mode is on, so that existing calls remain
unchanged. It takes no index, instead displaying edittop from column
firstcolumn, and all other lines from column zero.
If current is on edittop, it's displayed using the edittop rules, but
this is not a problem: if current[current_x] is above edittop at column
firstcolumn, it's offscreen, and that should be handled before calling
update_line() anyway.
Together with the preceding bunch of changes,
this fixes https://savannah.gnu.org/bugs/?47667.
2017-02-01 00:11:05 +00:00
|
|
|
|
2019-06-26 17:36:02 +00:00
|
|
|
row = line->lineno - openfile->edittop->lineno;
|
|
|
|
from_col = get_page_start(wideness(line->data, index));
|
2017-01-13 18:18:08 +00:00
|
|
|
|
2019-06-26 07:47:07 +00:00
|
|
|
/* Expand the piece to be drawn to its representable form, and draw it. */
|
2019-06-26 17:36:02 +00:00
|
|
|
converted = display_string(line->data, from_col, editwincols, TRUE, FALSE);
|
|
|
|
draw_row(row, converted, line, from_col);
|
2017-12-29 18:27:33 +00:00
|
|
|
free(converted);
|
2017-01-13 18:18:08 +00:00
|
|
|
|
2019-02-12 15:16:29 +00:00
|
|
|
if (from_col > 0) {
|
|
|
|
wattron(edit, hilite_attribute);
|
2019-02-11 20:11:22 +00:00
|
|
|
mvwaddch(edit, row, margin, '<');
|
2019-02-12 15:16:29 +00:00
|
|
|
wattroff(edit, hilite_attribute);
|
|
|
|
}
|
2020-01-26 19:01:34 +00:00
|
|
|
if (has_more) {
|
2019-02-12 15:16:29 +00:00
|
|
|
wattron(edit, hilite_attribute);
|
2020-04-25 15:19:03 +00:00
|
|
|
mvwaddch(edit, row, COLS - 1 - thebar, '>');
|
2019-02-12 15:16:29 +00:00
|
|
|
wattroff(edit, hilite_attribute);
|
|
|
|
}
|
2017-01-13 18:18:08 +00:00
|
|
|
|
2021-01-25 15:35:07 +00:00
|
|
|
if (spotlighted && line == openfile->current)
|
2018-09-29 16:19:57 +00:00
|
|
|
spotlight(light_from_col, light_to_col);
|
2018-09-29 16:14:43 +00:00
|
|
|
|
2017-12-29 18:27:33 +00:00
|
|
|
return 1;
|
2000-06-06 05:53:49 +00:00
|
|
|
}
|
|
|
|
|
softwrap: move the updating of a softwrapped line to a new function
The new function, update_softwrapped_line(), is called from inside
update_line() when softwrap mode is on, so that existing calls remain
unchanged. It takes no index, instead displaying edittop from column
firstcolumn, and all other lines from column zero.
If current is on edittop, it's displayed using the edittop rules, but
this is not a problem: if current[current_x] is above edittop at column
firstcolumn, it's offscreen, and that should be handled before calling
update_line() anyway.
Together with the preceding bunch of changes,
this fixes https://savannah.gnu.org/bugs/?47667.
2017-02-01 00:11:05 +00:00
|
|
|
#ifndef NANO_TINY
|
|
|
|
/* Redraw all the chunks of the given line (as far as they fit onscreen),
|
|
|
|
* unless it's edittop, which will be displayed from column firstcolumn.
|
2019-06-26 15:56:02 +00:00
|
|
|
* Return the number of rows that were "consumed". */
|
2019-06-26 17:36:02 +00:00
|
|
|
int update_softwrapped_line(linestruct *line)
|
softwrap: move the updating of a softwrapped line to a new function
The new function, update_softwrapped_line(), is called from inside
update_line() when softwrap mode is on, so that existing calls remain
unchanged. It takes no index, instead displaying edittop from column
firstcolumn, and all other lines from column zero.
If current is on edittop, it's displayed using the edittop rules, but
this is not a problem: if current[current_x] is above edittop at column
firstcolumn, it's offscreen, and that should be handled before calling
update_line() anyway.
Together with the preceding bunch of changes,
this fixes https://savannah.gnu.org/bugs/?47667.
2017-02-01 00:11:05 +00:00
|
|
|
{
|
2017-12-29 18:27:33 +00:00
|
|
|
int row = 0;
|
|
|
|
/* The row in the edit window we will write to. */
|
2019-06-26 17:36:02 +00:00
|
|
|
linestruct *someline = openfile->edittop;
|
2017-12-29 18:27:33 +00:00
|
|
|
/* An iterator needed to find the relevant row. */
|
|
|
|
int starting_row;
|
|
|
|
/* The first row in the edit window that gets updated. */
|
|
|
|
size_t from_col = 0;
|
|
|
|
/* The starting column of the current chunk. */
|
|
|
|
size_t to_col = 0;
|
2019-06-26 17:36:02 +00:00
|
|
|
/* The end column of the current chunk. */
|
2017-12-29 18:27:33 +00:00
|
|
|
char *converted;
|
|
|
|
/* The data of the chunk with tabs and control characters expanded. */
|
2020-03-15 18:01:07 +00:00
|
|
|
bool end_of_line = FALSE;
|
|
|
|
/* Becomes TRUE when the last chunk of the line has been reached. */
|
2017-12-29 18:27:33 +00:00
|
|
|
|
2019-06-26 17:36:02 +00:00
|
|
|
if (line == openfile->edittop)
|
2017-12-29 18:27:33 +00:00
|
|
|
from_col = openfile->firstcolumn;
|
|
|
|
else
|
|
|
|
row -= chunk_for(openfile->firstcolumn, openfile->edittop);
|
softwrap: make the changes to actually allow the chunk width to vary
get_chunk_row() and get_chunk_leftedge() now become wrappers around
get_chunk(); the latter is only used directly in place_the_cursor()
when we need to get both the row and the leftedge. get_chunk() now
uses the proper formula to implement varying chunk width.
Since chunk width now varies, place_the_cursor() sets the x position
relative to the leftedge in a different way that works regardless
of chunk width, update_softwrapped_line() loops until it gets all
softwrap breakpoints instead of calculating the full length in
advance and getting one full row at a time, the chunk iterators
now count leftedges instead of rows, and fix_firstcolumn() does a
full recalculation of the chunk that firstcolumn is on instead of
simply shifting it back.
Also, in update_softwrapped_line(), when a line's softwrap breakpoint
is before the last column of the edit window, a ">" is now added to
the end of it.
The workaround in place_the_cursor() for when two-column characters
straddle the edge of the screen is removed, as it's no longer needed
now that chunks end before such characters.
Furthermore, do_home() and do_end() use xplustabs() instead of
placewewant again when calculating the leftedge, since placewewant
refers to a column that may or may not be available (if it's not,
the cursor will be placed wrongly). Make get_edge_and_target() use
xplustabs() instead of placewewant for the same reason; this also lets
us simplify get_edge_and_target(), since xplustabs() will never be
greater than strlenpt(). Finally, since do_end() now has to calculate
rightedge as well as rightedge_x, use the former to implement the same
time-saving optimizations as in do_home().
The cursor is not yet adjusted when we try to go directly to a column
past the end of a softwrap breakpoint, and placewewant handling in the
vertical movement code is not yet adjusted for varying chunk lengths,
but fixes for these are forthcoming.
This fixes https://savannah.gnu.org/bugs/?49440.
2017-02-22 18:44:53 +00:00
|
|
|
|
2017-12-29 18:27:33 +00:00
|
|
|
/* Find out on which screen row the target line should be shown. */
|
2019-06-26 17:36:02 +00:00
|
|
|
while (someline != line && someline != NULL) {
|
2020-05-13 10:41:17 +00:00
|
|
|
row += 1 + extra_chunks_in(someline);
|
2019-06-26 17:36:02 +00:00
|
|
|
someline = someline->next;
|
2017-12-29 18:27:33 +00:00
|
|
|
}
|
softwrap: make the changes to actually allow the chunk width to vary
get_chunk_row() and get_chunk_leftedge() now become wrappers around
get_chunk(); the latter is only used directly in place_the_cursor()
when we need to get both the row and the leftedge. get_chunk() now
uses the proper formula to implement varying chunk width.
Since chunk width now varies, place_the_cursor() sets the x position
relative to the leftedge in a different way that works regardless
of chunk width, update_softwrapped_line() loops until it gets all
softwrap breakpoints instead of calculating the full length in
advance and getting one full row at a time, the chunk iterators
now count leftedges instead of rows, and fix_firstcolumn() does a
full recalculation of the chunk that firstcolumn is on instead of
simply shifting it back.
Also, in update_softwrapped_line(), when a line's softwrap breakpoint
is before the last column of the edit window, a ">" is now added to
the end of it.
The workaround in place_the_cursor() for when two-column characters
straddle the edge of the screen is removed, as it's no longer needed
now that chunks end before such characters.
Furthermore, do_home() and do_end() use xplustabs() instead of
placewewant again when calculating the leftedge, since placewewant
refers to a column that may or may not be available (if it's not,
the cursor will be placed wrongly). Make get_edge_and_target() use
xplustabs() instead of placewewant for the same reason; this also lets
us simplify get_edge_and_target(), since xplustabs() will never be
greater than strlenpt(). Finally, since do_end() now has to calculate
rightedge as well as rightedge_x, use the former to implement the same
time-saving optimizations as in do_home().
The cursor is not yet adjusted when we try to go directly to a column
past the end of a softwrap breakpoint, and placewewant handling in the
vertical movement code is not yet adjusted for varying chunk lengths,
but fixes for these are forthcoming.
This fixes https://savannah.gnu.org/bugs/?49440.
2017-02-22 18:44:53 +00:00
|
|
|
|
2017-12-29 18:27:33 +00:00
|
|
|
/* If the first chunk is offscreen, don't even try to display it. */
|
|
|
|
if (row < 0 || row >= editwinrows) {
|
|
|
|
statusline(ALERT, "Badness: tried to display a chunk on row %i"
|
|
|
|
" -- please report a bug", row);
|
|
|
|
return 0;
|
|
|
|
}
|
softwrap: move the updating of a softwrapped line to a new function
The new function, update_softwrapped_line(), is called from inside
update_line() when softwrap mode is on, so that existing calls remain
unchanged. It takes no index, instead displaying edittop from column
firstcolumn, and all other lines from column zero.
If current is on edittop, it's displayed using the edittop rules, but
this is not a problem: if current[current_x] is above edittop at column
firstcolumn, it's offscreen, and that should be handled before calling
update_line() anyway.
Together with the preceding bunch of changes,
this fixes https://savannah.gnu.org/bugs/?47667.
2017-02-01 00:11:05 +00:00
|
|
|
|
2017-12-29 18:27:33 +00:00
|
|
|
starting_row = row;
|
|
|
|
|
2020-03-15 18:01:07 +00:00
|
|
|
while (!end_of_line && row < editwinrows) {
|
2019-06-26 17:36:02 +00:00
|
|
|
to_col = get_softwrap_breakpoint(line->data, from_col, &end_of_line);
|
softwrap: make the changes to actually allow the chunk width to vary
get_chunk_row() and get_chunk_leftedge() now become wrappers around
get_chunk(); the latter is only used directly in place_the_cursor()
when we need to get both the row and the leftedge. get_chunk() now
uses the proper formula to implement varying chunk width.
Since chunk width now varies, place_the_cursor() sets the x position
relative to the leftedge in a different way that works regardless
of chunk width, update_softwrapped_line() loops until it gets all
softwrap breakpoints instead of calculating the full length in
advance and getting one full row at a time, the chunk iterators
now count leftedges instead of rows, and fix_firstcolumn() does a
full recalculation of the chunk that firstcolumn is on instead of
simply shifting it back.
Also, in update_softwrapped_line(), when a line's softwrap breakpoint
is before the last column of the edit window, a ">" is now added to
the end of it.
The workaround in place_the_cursor() for when two-column characters
straddle the edge of the screen is removed, as it's no longer needed
now that chunks end before such characters.
Furthermore, do_home() and do_end() use xplustabs() instead of
placewewant again when calculating the leftedge, since placewewant
refers to a column that may or may not be available (if it's not,
the cursor will be placed wrongly). Make get_edge_and_target() use
xplustabs() instead of placewewant for the same reason; this also lets
us simplify get_edge_and_target(), since xplustabs() will never be
greater than strlenpt(). Finally, since do_end() now has to calculate
rightedge as well as rightedge_x, use the former to implement the same
time-saving optimizations as in do_home().
The cursor is not yet adjusted when we try to go directly to a column
past the end of a softwrap breakpoint, and placewewant handling in the
vertical movement code is not yet adjusted for varying chunk lengths,
but fixes for these are forthcoming.
This fixes https://savannah.gnu.org/bugs/?49440.
2017-02-22 18:44:53 +00:00
|
|
|
|
2020-01-27 14:36:37 +00:00
|
|
|
sequel_column = (end_of_line) ? 0 : to_col;
|
|
|
|
|
2017-12-29 18:27:33 +00:00
|
|
|
/* Convert the chunk to its displayable form and draw it. */
|
2019-06-26 17:36:02 +00:00
|
|
|
converted = display_string(line->data, from_col, to_col - from_col,
|
2019-02-27 20:37:53 +00:00
|
|
|
TRUE, FALSE);
|
2019-06-26 17:36:02 +00:00
|
|
|
draw_row(row++, converted, line, from_col);
|
2017-12-29 18:27:33 +00:00
|
|
|
free(converted);
|
|
|
|
|
|
|
|
from_col = to_col;
|
|
|
|
}
|
|
|
|
|
2021-01-25 15:35:07 +00:00
|
|
|
if (spotlighted && line == openfile->current)
|
2019-06-26 08:12:23 +00:00
|
|
|
spotlight_softwrapped(light_from_col, light_to_col);
|
2018-09-29 16:14:43 +00:00
|
|
|
|
2017-12-29 18:27:33 +00:00
|
|
|
return (row - starting_row);
|
softwrap: move the updating of a softwrapped line to a new function
The new function, update_softwrapped_line(), is called from inside
update_line() when softwrap mode is on, so that existing calls remain
unchanged. It takes no index, instead displaying edittop from column
firstcolumn, and all other lines from column zero.
If current is on edittop, it's displayed using the edittop rules, but
this is not a problem: if current[current_x] is above edittop at column
firstcolumn, it's offscreen, and that should be handled before calling
update_line() anyway.
Together with the preceding bunch of changes,
this fixes https://savannah.gnu.org/bugs/?47667.
2017-02-01 00:11:05 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2017-01-31 22:51:06 +00:00
|
|
|
/* Check whether the mark is on, or whether old_column and new_column are on
|
|
|
|
* different "pages" (in softwrap mode, only the former applies), which means
|
|
|
|
* that the relevant line needs to be redrawn. */
|
|
|
|
bool line_needs_update(const size_t old_column, const size_t new_column)
|
2004-05-28 20:44:09 +00:00
|
|
|
{
|
2005-11-15 03:17:35 +00:00
|
|
|
#ifndef NANO_TINY
|
2017-12-29 18:27:33 +00:00
|
|
|
if (openfile->mark)
|
|
|
|
return TRUE;
|
|
|
|
else
|
2004-05-28 20:44:09 +00:00
|
|
|
#endif
|
2017-12-29 18:27:33 +00:00
|
|
|
return (get_page_start(old_column) != get_page_start(new_column));
|
2004-05-28 20:44:09 +00:00
|
|
|
}
|
|
|
|
|
softwrap: add two chunk-iterator functions
These functions, go_back_chunks() and go_forward_chunks(), take a number
of softwrapped chunks (screen rows) to move, a pointer to a buffer, and
a location (specifically, a starting column of a softwrapped chunk). If
they move successfully, they will update the buffer pointer and location
to point to the beginning of the softwrapped chunk they moved to.
Since non-softwrap mode is effectively just a subset of softwrap mode
in which every line takes up one chunk, these functions also work in
non-softwrap mode. In this case, their starting column will always be
zero, as it would be in softwrap mode on a line that takes up one chunk.
Nothing uses these functions yet, but that is forthcoming.
2016-12-30 06:34:13 +00:00
|
|
|
/* Try to move up nrows softwrapped chunks from the given line and the
|
|
|
|
* given column (leftedge). After moving, leftedge will be set to the
|
|
|
|
* starting column of the current chunk. Return the number of chunks we
|
|
|
|
* couldn't move up, which will be zero if we completely succeeded. */
|
2019-03-21 16:08:52 +00:00
|
|
|
int go_back_chunks(int nrows, linestruct **line, size_t *leftedge)
|
softwrap: add two chunk-iterator functions
These functions, go_back_chunks() and go_forward_chunks(), take a number
of softwrapped chunks (screen rows) to move, a pointer to a buffer, and
a location (specifically, a starting column of a softwrapped chunk). If
they move successfully, they will update the buffer pointer and location
to point to the beginning of the softwrapped chunk they moved to.
Since non-softwrap mode is effectively just a subset of softwrap mode
in which every line takes up one chunk, these functions also work in
non-softwrap mode. In this case, their starting column will always be
zero, as it would be in softwrap mode on a line that takes up one chunk.
Nothing uses these functions yet, but that is forthcoming.
2016-12-30 06:34:13 +00:00
|
|
|
{
|
2017-12-29 18:27:33 +00:00
|
|
|
int i;
|
softwrap: add two chunk-iterator functions
These functions, go_back_chunks() and go_forward_chunks(), take a number
of softwrapped chunks (screen rows) to move, a pointer to a buffer, and
a location (specifically, a starting column of a softwrapped chunk). If
they move successfully, they will update the buffer pointer and location
to point to the beginning of the softwrapped chunk they moved to.
Since non-softwrap mode is effectively just a subset of softwrap mode
in which every line takes up one chunk, these functions also work in
non-softwrap mode. In this case, their starting column will always be
zero, as it would be in softwrap mode on a line that takes up one chunk.
Nothing uses these functions yet, but that is forthcoming.
2016-12-30 06:34:13 +00:00
|
|
|
|
|
|
|
#ifndef NANO_TINY
|
2017-12-29 18:27:33 +00:00
|
|
|
if (ISSET(SOFTWRAP)) {
|
|
|
|
/* Recede through the requested number of chunks. */
|
|
|
|
for (i = nrows; i > 0; i--) {
|
|
|
|
size_t chunk = chunk_for(*leftedge, *line);
|
2017-07-18 10:51:07 +00:00
|
|
|
|
2017-12-29 18:27:33 +00:00
|
|
|
*leftedge = 0;
|
2017-07-18 10:51:07 +00:00
|
|
|
|
2017-12-29 18:27:33 +00:00
|
|
|
if (chunk >= i)
|
|
|
|
return go_forward_chunks(chunk - i, line, leftedge);
|
softwrap: add two chunk-iterator functions
These functions, go_back_chunks() and go_forward_chunks(), take a number
of softwrapped chunks (screen rows) to move, a pointer to a buffer, and
a location (specifically, a starting column of a softwrapped chunk). If
they move successfully, they will update the buffer pointer and location
to point to the beginning of the softwrapped chunk they moved to.
Since non-softwrap mode is effectively just a subset of softwrap mode
in which every line takes up one chunk, these functions also work in
non-softwrap mode. In this case, their starting column will always be
zero, as it would be in softwrap mode on a line that takes up one chunk.
Nothing uses these functions yet, but that is forthcoming.
2016-12-30 06:34:13 +00:00
|
|
|
|
2019-03-21 16:23:49 +00:00
|
|
|
if (*line == openfile->filetop)
|
2017-12-29 18:27:33 +00:00
|
|
|
break;
|
softwrap: add two chunk-iterator functions
These functions, go_back_chunks() and go_forward_chunks(), take a number
of softwrapped chunks (screen rows) to move, a pointer to a buffer, and
a location (specifically, a starting column of a softwrapped chunk). If
they move successfully, they will update the buffer pointer and location
to point to the beginning of the softwrapped chunk they moved to.
Since non-softwrap mode is effectively just a subset of softwrap mode
in which every line takes up one chunk, these functions also work in
non-softwrap mode. In this case, their starting column will always be
zero, as it would be in softwrap mode on a line that takes up one chunk.
Nothing uses these functions yet, but that is forthcoming.
2016-12-30 06:34:13 +00:00
|
|
|
|
2017-12-29 18:27:33 +00:00
|
|
|
i -= chunk;
|
|
|
|
*line = (*line)->prev;
|
|
|
|
*leftedge = HIGHEST_POSITIVE;
|
|
|
|
}
|
softwrap: add two chunk-iterator functions
These functions, go_back_chunks() and go_forward_chunks(), take a number
of softwrapped chunks (screen rows) to move, a pointer to a buffer, and
a location (specifically, a starting column of a softwrapped chunk). If
they move successfully, they will update the buffer pointer and location
to point to the beginning of the softwrapped chunk they moved to.
Since non-softwrap mode is effectively just a subset of softwrap mode
in which every line takes up one chunk, these functions also work in
non-softwrap mode. In this case, their starting column will always be
zero, as it would be in softwrap mode on a line that takes up one chunk.
Nothing uses these functions yet, but that is forthcoming.
2016-12-30 06:34:13 +00:00
|
|
|
|
2017-12-29 18:27:33 +00:00
|
|
|
if (*leftedge == HIGHEST_POSITIVE)
|
|
|
|
*leftedge = leftedge_for(*leftedge, *line);
|
|
|
|
} else
|
softwrap: add two chunk-iterator functions
These functions, go_back_chunks() and go_forward_chunks(), take a number
of softwrapped chunks (screen rows) to move, a pointer to a buffer, and
a location (specifically, a starting column of a softwrapped chunk). If
they move successfully, they will update the buffer pointer and location
to point to the beginning of the softwrapped chunk they moved to.
Since non-softwrap mode is effectively just a subset of softwrap mode
in which every line takes up one chunk, these functions also work in
non-softwrap mode. In this case, their starting column will always be
zero, as it would be in softwrap mode on a line that takes up one chunk.
Nothing uses these functions yet, but that is forthcoming.
2016-12-30 06:34:13 +00:00
|
|
|
#endif
|
2017-12-29 18:27:33 +00:00
|
|
|
for (i = nrows; i > 0 && (*line)->prev != NULL; i--)
|
|
|
|
*line = (*line)->prev;
|
softwrap: add two chunk-iterator functions
These functions, go_back_chunks() and go_forward_chunks(), take a number
of softwrapped chunks (screen rows) to move, a pointer to a buffer, and
a location (specifically, a starting column of a softwrapped chunk). If
they move successfully, they will update the buffer pointer and location
to point to the beginning of the softwrapped chunk they moved to.
Since non-softwrap mode is effectively just a subset of softwrap mode
in which every line takes up one chunk, these functions also work in
non-softwrap mode. In this case, their starting column will always be
zero, as it would be in softwrap mode on a line that takes up one chunk.
Nothing uses these functions yet, but that is forthcoming.
2016-12-30 06:34:13 +00:00
|
|
|
|
2017-12-29 18:27:33 +00:00
|
|
|
return i;
|
softwrap: add two chunk-iterator functions
These functions, go_back_chunks() and go_forward_chunks(), take a number
of softwrapped chunks (screen rows) to move, a pointer to a buffer, and
a location (specifically, a starting column of a softwrapped chunk). If
they move successfully, they will update the buffer pointer and location
to point to the beginning of the softwrapped chunk they moved to.
Since non-softwrap mode is effectively just a subset of softwrap mode
in which every line takes up one chunk, these functions also work in
non-softwrap mode. In this case, their starting column will always be
zero, as it would be in softwrap mode on a line that takes up one chunk.
Nothing uses these functions yet, but that is forthcoming.
2016-12-30 06:34:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Try to move down nrows softwrapped chunks from the given line and the
|
|
|
|
* given column (leftedge). After moving, leftedge will be set to the
|
|
|
|
* starting column of the current chunk. Return the number of chunks we
|
|
|
|
* couldn't move down, which will be zero if we completely succeeded. */
|
2019-03-21 16:08:52 +00:00
|
|
|
int go_forward_chunks(int nrows, linestruct **line, size_t *leftedge)
|
softwrap: add two chunk-iterator functions
These functions, go_back_chunks() and go_forward_chunks(), take a number
of softwrapped chunks (screen rows) to move, a pointer to a buffer, and
a location (specifically, a starting column of a softwrapped chunk). If
they move successfully, they will update the buffer pointer and location
to point to the beginning of the softwrapped chunk they moved to.
Since non-softwrap mode is effectively just a subset of softwrap mode
in which every line takes up one chunk, these functions also work in
non-softwrap mode. In this case, their starting column will always be
zero, as it would be in softwrap mode on a line that takes up one chunk.
Nothing uses these functions yet, but that is forthcoming.
2016-12-30 06:34:13 +00:00
|
|
|
{
|
2017-12-29 18:27:33 +00:00
|
|
|
int i;
|
softwrap: add two chunk-iterator functions
These functions, go_back_chunks() and go_forward_chunks(), take a number
of softwrapped chunks (screen rows) to move, a pointer to a buffer, and
a location (specifically, a starting column of a softwrapped chunk). If
they move successfully, they will update the buffer pointer and location
to point to the beginning of the softwrapped chunk they moved to.
Since non-softwrap mode is effectively just a subset of softwrap mode
in which every line takes up one chunk, these functions also work in
non-softwrap mode. In this case, their starting column will always be
zero, as it would be in softwrap mode on a line that takes up one chunk.
Nothing uses these functions yet, but that is forthcoming.
2016-12-30 06:34:13 +00:00
|
|
|
|
|
|
|
#ifndef NANO_TINY
|
2017-12-29 18:27:33 +00:00
|
|
|
if (ISSET(SOFTWRAP)) {
|
|
|
|
size_t current_leftedge = *leftedge;
|
softwrap: add two chunk-iterator functions
These functions, go_back_chunks() and go_forward_chunks(), take a number
of softwrapped chunks (screen rows) to move, a pointer to a buffer, and
a location (specifically, a starting column of a softwrapped chunk). If
they move successfully, they will update the buffer pointer and location
to point to the beginning of the softwrapped chunk they moved to.
Since non-softwrap mode is effectively just a subset of softwrap mode
in which every line takes up one chunk, these functions also work in
non-softwrap mode. In this case, their starting column will always be
zero, as it would be in softwrap mode on a line that takes up one chunk.
Nothing uses these functions yet, but that is forthcoming.
2016-12-30 06:34:13 +00:00
|
|
|
|
2017-12-29 18:27:33 +00:00
|
|
|
/* Advance through the requested number of chunks. */
|
|
|
|
for (i = nrows; i > 0; i--) {
|
|
|
|
bool end_of_line = FALSE;
|
softwrap: make the changes to actually allow the chunk width to vary
get_chunk_row() and get_chunk_leftedge() now become wrappers around
get_chunk(); the latter is only used directly in place_the_cursor()
when we need to get both the row and the leftedge. get_chunk() now
uses the proper formula to implement varying chunk width.
Since chunk width now varies, place_the_cursor() sets the x position
relative to the leftedge in a different way that works regardless
of chunk width, update_softwrapped_line() loops until it gets all
softwrap breakpoints instead of calculating the full length in
advance and getting one full row at a time, the chunk iterators
now count leftedges instead of rows, and fix_firstcolumn() does a
full recalculation of the chunk that firstcolumn is on instead of
simply shifting it back.
Also, in update_softwrapped_line(), when a line's softwrap breakpoint
is before the last column of the edit window, a ">" is now added to
the end of it.
The workaround in place_the_cursor() for when two-column characters
straddle the edge of the screen is removed, as it's no longer needed
now that chunks end before such characters.
Furthermore, do_home() and do_end() use xplustabs() instead of
placewewant again when calculating the leftedge, since placewewant
refers to a column that may or may not be available (if it's not,
the cursor will be placed wrongly). Make get_edge_and_target() use
xplustabs() instead of placewewant for the same reason; this also lets
us simplify get_edge_and_target(), since xplustabs() will never be
greater than strlenpt(). Finally, since do_end() now has to calculate
rightedge as well as rightedge_x, use the former to implement the same
time-saving optimizations as in do_home().
The cursor is not yet adjusted when we try to go directly to a column
past the end of a softwrap breakpoint, and placewewant handling in the
vertical movement code is not yet adjusted for varying chunk lengths,
but fixes for these are forthcoming.
This fixes https://savannah.gnu.org/bugs/?49440.
2017-02-22 18:44:53 +00:00
|
|
|
|
2017-12-29 18:27:33 +00:00
|
|
|
current_leftedge = get_softwrap_breakpoint((*line)->data,
|
|
|
|
current_leftedge, &end_of_line);
|
2017-06-27 11:47:26 +00:00
|
|
|
|
2017-12-29 18:27:33 +00:00
|
|
|
if (!end_of_line)
|
|
|
|
continue;
|
softwrap: add two chunk-iterator functions
These functions, go_back_chunks() and go_forward_chunks(), take a number
of softwrapped chunks (screen rows) to move, a pointer to a buffer, and
a location (specifically, a starting column of a softwrapped chunk). If
they move successfully, they will update the buffer pointer and location
to point to the beginning of the softwrapped chunk they moved to.
Since non-softwrap mode is effectively just a subset of softwrap mode
in which every line takes up one chunk, these functions also work in
non-softwrap mode. In this case, their starting column will always be
zero, as it would be in softwrap mode on a line that takes up one chunk.
Nothing uses these functions yet, but that is forthcoming.
2016-12-30 06:34:13 +00:00
|
|
|
|
2017-12-29 18:27:33 +00:00
|
|
|
if (*line == openfile->filebot)
|
|
|
|
break;
|
softwrap: add two chunk-iterator functions
These functions, go_back_chunks() and go_forward_chunks(), take a number
of softwrapped chunks (screen rows) to move, a pointer to a buffer, and
a location (specifically, a starting column of a softwrapped chunk). If
they move successfully, they will update the buffer pointer and location
to point to the beginning of the softwrapped chunk they moved to.
Since non-softwrap mode is effectively just a subset of softwrap mode
in which every line takes up one chunk, these functions also work in
non-softwrap mode. In this case, their starting column will always be
zero, as it would be in softwrap mode on a line that takes up one chunk.
Nothing uses these functions yet, but that is forthcoming.
2016-12-30 06:34:13 +00:00
|
|
|
|
2017-12-29 18:27:33 +00:00
|
|
|
*line = (*line)->next;
|
|
|
|
current_leftedge = 0;
|
|
|
|
}
|
softwrap: add two chunk-iterator functions
These functions, go_back_chunks() and go_forward_chunks(), take a number
of softwrapped chunks (screen rows) to move, a pointer to a buffer, and
a location (specifically, a starting column of a softwrapped chunk). If
they move successfully, they will update the buffer pointer and location
to point to the beginning of the softwrapped chunk they moved to.
Since non-softwrap mode is effectively just a subset of softwrap mode
in which every line takes up one chunk, these functions also work in
non-softwrap mode. In this case, their starting column will always be
zero, as it would be in softwrap mode on a line that takes up one chunk.
Nothing uses these functions yet, but that is forthcoming.
2016-12-30 06:34:13 +00:00
|
|
|
|
2017-12-29 18:27:33 +00:00
|
|
|
/* Only change leftedge when we actually could move. */
|
|
|
|
if (i < nrows)
|
|
|
|
*leftedge = current_leftedge;
|
|
|
|
} else
|
softwrap: add two chunk-iterator functions
These functions, go_back_chunks() and go_forward_chunks(), take a number
of softwrapped chunks (screen rows) to move, a pointer to a buffer, and
a location (specifically, a starting column of a softwrapped chunk). If
they move successfully, they will update the buffer pointer and location
to point to the beginning of the softwrapped chunk they moved to.
Since non-softwrap mode is effectively just a subset of softwrap mode
in which every line takes up one chunk, these functions also work in
non-softwrap mode. In this case, their starting column will always be
zero, as it would be in softwrap mode on a line that takes up one chunk.
Nothing uses these functions yet, but that is forthcoming.
2016-12-30 06:34:13 +00:00
|
|
|
#endif
|
2017-12-29 18:27:33 +00:00
|
|
|
for (i = nrows; i > 0 && (*line)->next != NULL; i--)
|
|
|
|
*line = (*line)->next;
|
softwrap: add two chunk-iterator functions
These functions, go_back_chunks() and go_forward_chunks(), take a number
of softwrapped chunks (screen rows) to move, a pointer to a buffer, and
a location (specifically, a starting column of a softwrapped chunk). If
they move successfully, they will update the buffer pointer and location
to point to the beginning of the softwrapped chunk they moved to.
Since non-softwrap mode is effectively just a subset of softwrap mode
in which every line takes up one chunk, these functions also work in
non-softwrap mode. In this case, their starting column will always be
zero, as it would be in softwrap mode on a line that takes up one chunk.
Nothing uses these functions yet, but that is forthcoming.
2016-12-30 06:34:13 +00:00
|
|
|
|
2017-12-29 18:27:33 +00:00
|
|
|
return i;
|
softwrap: add two chunk-iterator functions
These functions, go_back_chunks() and go_forward_chunks(), take a number
of softwrapped chunks (screen rows) to move, a pointer to a buffer, and
a location (specifically, a starting column of a softwrapped chunk). If
they move successfully, they will update the buffer pointer and location
to point to the beginning of the softwrapped chunk they moved to.
Since non-softwrap mode is effectively just a subset of softwrap mode
in which every line takes up one chunk, these functions also work in
non-softwrap mode. In this case, their starting column will always be
zero, as it would be in softwrap mode on a line that takes up one chunk.
Nothing uses these functions yet, but that is forthcoming.
2016-12-30 06:34:13 +00:00
|
|
|
}
|
|
|
|
|
2017-01-15 22:01:17 +00:00
|
|
|
/* Return TRUE if there are fewer than a screen's worth of lines between
|
|
|
|
* the line at line number was_lineno (and column was_leftedge, if we're
|
|
|
|
* in softwrap mode) and the line at current[current_x]. */
|
|
|
|
bool less_than_a_screenful(size_t was_lineno, size_t was_leftedge)
|
|
|
|
{
|
|
|
|
#ifndef NANO_TINY
|
2017-12-29 18:27:33 +00:00
|
|
|
if (ISSET(SOFTWRAP)) {
|
2019-03-21 16:08:52 +00:00
|
|
|
linestruct *line = openfile->current;
|
2017-12-29 18:27:33 +00:00
|
|
|
size_t leftedge = leftedge_for(xplustabs(), openfile->current);
|
|
|
|
int rows_left = go_back_chunks(editwinrows - 1, &line, &leftedge);
|
2017-01-15 22:01:17 +00:00
|
|
|
|
2017-12-29 18:27:33 +00:00
|
|
|
return (rows_left > 0 || line->lineno < was_lineno ||
|
|
|
|
(line->lineno == was_lineno && leftedge <= was_leftedge));
|
|
|
|
} else
|
2017-01-15 22:01:17 +00:00
|
|
|
#endif
|
2017-12-29 18:27:33 +00:00
|
|
|
return (openfile->current->lineno - was_lineno < editwinrows);
|
2017-01-15 22:01:17 +00:00
|
|
|
}
|
|
|
|
|
2020-04-25 15:19:03 +00:00
|
|
|
#ifndef NANO_TINY
|
|
|
|
/* Draw a scroll bar on the righthand side of the screen. */
|
|
|
|
void draw_scrollbar(void)
|
|
|
|
{
|
2021-04-21 14:51:33 +00:00
|
|
|
int totallines = openfile->filebot->lineno;
|
|
|
|
int fromline = openfile->edittop->lineno - 1;
|
2021-04-22 09:51:07 +00:00
|
|
|
int coveredlines = editwinrows;
|
|
|
|
|
|
|
|
if (ISSET(SOFTWRAP)) {
|
|
|
|
linestruct *line = openfile->edittop;
|
|
|
|
int extras = extra_chunks_in(line) - chunk_for(openfile->firstcolumn, line);
|
|
|
|
|
|
|
|
while (line->lineno + extras < fromline + editwinrows && line->next) {
|
|
|
|
line = line->next;
|
|
|
|
extras += extra_chunks_in(line);
|
|
|
|
}
|
|
|
|
|
|
|
|
coveredlines = line->lineno - fromline;
|
|
|
|
}
|
|
|
|
|
2021-04-21 14:51:33 +00:00
|
|
|
int lowest = (fromline * editwinrows) / totallines;
|
2021-04-22 09:51:07 +00:00
|
|
|
int highest = lowest + (editwinrows * coveredlines) / totallines;
|
2020-04-25 15:19:03 +00:00
|
|
|
|
2021-04-21 14:51:33 +00:00
|
|
|
if (editwinrows > totallines)
|
2020-04-25 15:19:03 +00:00
|
|
|
highest = editwinrows;
|
|
|
|
|
|
|
|
for (int row = 0; row < editwinrows; row++) {
|
2020-08-28 16:40:10 +00:00
|
|
|
bardata[row] = ' '|interface_color_pair[SCROLL_BAR]|
|
|
|
|
((row < lowest || row > highest) ? A_NORMAL : A_REVERSE);
|
2020-04-25 15:19:03 +00:00
|
|
|
mvwaddch(edit, row, COLS - 1, bardata[row]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2018-03-10 11:24:42 +00:00
|
|
|
/* Scroll the edit window one row in the given direction, and
|
|
|
|
* draw the relevant content on the resultant blank row. */
|
|
|
|
void edit_scroll(bool direction)
|
2004-05-28 20:44:09 +00:00
|
|
|
{
|
2019-03-21 16:08:52 +00:00
|
|
|
linestruct *line;
|
2017-12-29 18:27:33 +00:00
|
|
|
size_t leftedge;
|
2019-04-14 17:28:15 +00:00
|
|
|
int nrows = 1;
|
2017-01-19 19:23:11 +00:00
|
|
|
|
2018-03-10 11:24:42 +00:00
|
|
|
/* Move the top line of the edit window one row up or down. */
|
2017-12-29 18:27:33 +00:00
|
|
|
if (direction == BACKWARD)
|
2019-04-14 17:28:15 +00:00
|
|
|
go_back_chunks(1, &openfile->edittop, &openfile->firstcolumn);
|
2017-12-29 18:27:33 +00:00
|
|
|
else
|
2019-04-14 17:28:15 +00:00
|
|
|
go_forward_chunks(1, &openfile->edittop, &openfile->firstcolumn);
|
2005-07-22 23:17:19 +00:00
|
|
|
|
2018-03-10 11:24:42 +00:00
|
|
|
/* Actually scroll the text of the edit window one row up or down. */
|
2017-12-29 18:27:33 +00:00
|
|
|
scrollok(edit, TRUE);
|
2018-03-10 11:24:42 +00:00
|
|
|
wscrl(edit, (direction == BACKWARD) ? -1 : 1);
|
2017-12-29 18:27:33 +00:00
|
|
|
scrollok(edit, FALSE);
|
2005-07-22 22:56:03 +00:00
|
|
|
|
2017-12-29 18:27:33 +00:00
|
|
|
/* If we're not on the first "page" (when not softwrapping), or the mark
|
|
|
|
* is on, the row next to the scrolled region needs to be redrawn too. */
|
|
|
|
if (line_needs_update(openfile->placewewant, 0) && nrows < editwinrows)
|
|
|
|
nrows++;
|
2005-07-16 22:50:30 +00:00
|
|
|
|
2018-03-10 11:24:42 +00:00
|
|
|
/* If we scrolled backward, the top row needs to be redrawn. */
|
2017-12-29 18:27:33 +00:00
|
|
|
line = openfile->edittop;
|
|
|
|
leftedge = openfile->firstcolumn;
|
2005-07-14 20:37:01 +00:00
|
|
|
|
2018-03-10 11:24:42 +00:00
|
|
|
/* If we scrolled forward, the bottom row needs to be redrawn. */
|
2017-12-29 18:27:33 +00:00
|
|
|
if (direction == FORWARD)
|
|
|
|
go_forward_chunks(editwinrows - nrows, &line, &leftedge);
|
2004-05-28 20:44:09 +00:00
|
|
|
|
2017-03-27 23:06:54 +00:00
|
|
|
#ifndef NANO_TINY
|
2020-04-25 15:19:03 +00:00
|
|
|
if (thebar)
|
|
|
|
draw_scrollbar();
|
|
|
|
|
2017-12-29 18:27:33 +00:00
|
|
|
if (ISSET(SOFTWRAP)) {
|
|
|
|
/* Compensate for the earlier chunks of a softwrapped line. */
|
|
|
|
nrows += chunk_for(leftedge, line);
|
2017-04-01 19:32:59 +00:00
|
|
|
|
2017-12-29 18:27:33 +00:00
|
|
|
/* Don't compensate for the chunks that are offscreen. */
|
|
|
|
if (line == openfile->edittop)
|
|
|
|
nrows -= chunk_for(openfile->firstcolumn, line);
|
|
|
|
}
|
2017-03-27 23:06:54 +00:00
|
|
|
#endif
|
2017-03-29 08:13:08 +00:00
|
|
|
|
2018-03-10 11:24:42 +00:00
|
|
|
/* Draw new content on the blank row (and on the bordering row too
|
|
|
|
* when it was deemed necessary). */
|
2017-12-29 18:27:33 +00:00
|
|
|
while (nrows > 0 && line != NULL) {
|
|
|
|
nrows -= update_line(line, (line == openfile->current) ?
|
|
|
|
openfile->current_x : 0);
|
|
|
|
line = line->next;
|
|
|
|
}
|
2004-05-28 20:44:09 +00:00
|
|
|
}
|
|
|
|
|
2017-05-05 10:33:25 +00:00
|
|
|
#ifndef NANO_TINY
|
2017-02-22 18:31:57 +00:00
|
|
|
/* Get the column number after leftedge where we can break the given text, and
|
|
|
|
* return it. This will always be editwincols or less after leftedge. Set
|
|
|
|
* end_of_line to TRUE if we reach the end of the line while searching the
|
|
|
|
* text. Assume leftedge is the leftmost column of a softwrapped chunk. */
|
|
|
|
size_t get_softwrap_breakpoint(const char *text, size_t leftedge,
|
2017-12-29 18:27:33 +00:00
|
|
|
bool *end_of_line)
|
|
|
|
{
|
|
|
|
size_t goal_column = leftedge + editwincols;
|
|
|
|
/* The place at or before which text must be broken. */
|
|
|
|
size_t breaking_col = goal_column;
|
|
|
|
/* The column where text can be broken, when there's no better. */
|
|
|
|
size_t column = 0;
|
|
|
|
/* Current column position in text. */
|
|
|
|
size_t last_blank_col = 0;
|
|
|
|
/* The column position of the last seen whitespace character. */
|
|
|
|
const char *farthest_blank = NULL;
|
|
|
|
/* A pointer to the last seen whitespace character in text. */
|
|
|
|
|
|
|
|
/* First find the place in text where the current chunk starts. */
|
|
|
|
while (*text != '\0' && column < leftedge)
|
2019-10-21 10:21:46 +00:00
|
|
|
text += advance_over(text, &column);
|
2017-12-29 18:27:33 +00:00
|
|
|
|
|
|
|
/* Now find the place in text where this chunk should end. */
|
|
|
|
while (*text != '\0' && column <= goal_column) {
|
|
|
|
/* When breaking at blanks, do it *before* the target column. */
|
2020-03-12 11:29:44 +00:00
|
|
|
if (ISSET(AT_BLANKS) && is_blank_char(text) && column < goal_column) {
|
2017-12-29 18:27:33 +00:00
|
|
|
farthest_blank = text;
|
|
|
|
last_blank_col = column;
|
|
|
|
}
|
2017-03-07 16:36:43 +00:00
|
|
|
|
2017-12-29 18:27:33 +00:00
|
|
|
breaking_col = (*text == '\t' ? goal_column : column);
|
2019-10-21 10:21:46 +00:00
|
|
|
text += advance_over(text, &column);
|
2017-12-29 18:27:33 +00:00
|
|
|
}
|
2017-02-22 18:31:57 +00:00
|
|
|
|
2017-12-29 18:27:33 +00:00
|
|
|
/* If we didn't overshoot the limit, we've found a breaking point;
|
|
|
|
* and we've reached EOL if we didn't even *reach* the limit. */
|
|
|
|
if (column <= goal_column) {
|
|
|
|
*end_of_line = (column < goal_column);
|
|
|
|
return column;
|
|
|
|
}
|
2017-02-22 18:31:57 +00:00
|
|
|
|
2017-12-29 18:27:33 +00:00
|
|
|
/* If we're softwrapping at blanks and we found at least one blank, break
|
|
|
|
* after that blank -- if it doesn't overshoot the screen's edge. */
|
|
|
|
if (farthest_blank != NULL) {
|
2019-10-21 10:21:46 +00:00
|
|
|
advance_over(farthest_blank, &last_blank_col);
|
2017-08-04 20:43:14 +00:00
|
|
|
|
2017-12-29 18:27:33 +00:00
|
|
|
if (last_blank_col <= goal_column)
|
|
|
|
return last_blank_col;
|
2017-03-07 16:36:43 +00:00
|
|
|
|
2017-12-29 18:27:33 +00:00
|
|
|
/* If it's a tab that overshoots, break at the screen's edge. */
|
|
|
|
if (*farthest_blank == '\t')
|
|
|
|
breaking_col = goal_column;
|
|
|
|
}
|
2017-08-04 20:43:14 +00:00
|
|
|
|
2017-12-29 18:27:33 +00:00
|
|
|
/* Otherwise, break at the last character that doesn't overshoot. */
|
|
|
|
return (editwincols > 1) ? breaking_col : column - 1;
|
2017-02-22 18:31:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Get the row of the softwrapped chunk of the given line that column is on,
|
|
|
|
* relative to the first row (zero-based), and return it. If leftedge isn't
|
|
|
|
* NULL, return the leftmost column of the chunk in it. */
|
2019-03-21 16:08:52 +00:00
|
|
|
size_t get_chunk_and_edge(size_t column, linestruct *line, size_t *leftedge)
|
2017-02-22 18:31:57 +00:00
|
|
|
{
|
2017-12-29 18:27:33 +00:00
|
|
|
size_t current_chunk = 0, start_col = 0, end_col;
|
|
|
|
bool end_of_line = FALSE;
|
2017-02-22 18:31:57 +00:00
|
|
|
|
2017-12-29 18:27:33 +00:00
|
|
|
while (TRUE) {
|
|
|
|
end_col = get_softwrap_breakpoint(line->data, start_col, &end_of_line);
|
2017-02-22 18:31:57 +00:00
|
|
|
|
2017-12-29 18:27:33 +00:00
|
|
|
/* We reached the end of the line and/or found column, so get out. */
|
2020-01-31 15:05:51 +00:00
|
|
|
if (end_of_line || (start_col <= column && column < end_col)) {
|
2017-12-29 18:27:33 +00:00
|
|
|
if (leftedge != NULL)
|
|
|
|
*leftedge = start_col;
|
|
|
|
return current_chunk;
|
|
|
|
}
|
2017-02-22 18:31:57 +00:00
|
|
|
|
2017-12-29 18:27:33 +00:00
|
|
|
current_chunk++;
|
|
|
|
start_col = end_col;
|
|
|
|
}
|
2017-02-22 18:31:57 +00:00
|
|
|
}
|
|
|
|
|
2020-05-13 10:41:17 +00:00
|
|
|
/* Return how many extra rows the given line needs when softwrapping. */
|
|
|
|
size_t extra_chunks_in(linestruct *line)
|
|
|
|
{
|
|
|
|
return get_chunk_and_edge((size_t)-1, line, NULL);
|
|
|
|
}
|
|
|
|
|
2017-02-19 17:51:50 +00:00
|
|
|
/* Return the row of the softwrapped chunk of the given line that column is on,
|
|
|
|
* relative to the first row (zero-based). */
|
2019-03-21 16:08:52 +00:00
|
|
|
size_t chunk_for(size_t column, linestruct *line)
|
2017-02-19 17:51:50 +00:00
|
|
|
{
|
2020-05-13 10:29:44 +00:00
|
|
|
return get_chunk_and_edge(column, line, NULL);
|
2017-02-19 17:51:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Return the leftmost column of the softwrapped chunk of the given line that
|
2020-05-13 10:41:17 +00:00
|
|
|
* the given column is on. */
|
2019-03-21 16:08:52 +00:00
|
|
|
size_t leftedge_for(size_t column, linestruct *line)
|
2017-02-19 17:51:50 +00:00
|
|
|
{
|
2020-05-13 10:29:44 +00:00
|
|
|
size_t leftedge;
|
2017-08-24 20:03:07 +00:00
|
|
|
|
2020-05-13 10:29:44 +00:00
|
|
|
get_chunk_and_edge(column, line, &leftedge);
|
softwrap: make the changes to actually allow the chunk width to vary
get_chunk_row() and get_chunk_leftedge() now become wrappers around
get_chunk(); the latter is only used directly in place_the_cursor()
when we need to get both the row and the leftedge. get_chunk() now
uses the proper formula to implement varying chunk width.
Since chunk width now varies, place_the_cursor() sets the x position
relative to the leftedge in a different way that works regardless
of chunk width, update_softwrapped_line() loops until it gets all
softwrap breakpoints instead of calculating the full length in
advance and getting one full row at a time, the chunk iterators
now count leftedges instead of rows, and fix_firstcolumn() does a
full recalculation of the chunk that firstcolumn is on instead of
simply shifting it back.
Also, in update_softwrapped_line(), when a line's softwrap breakpoint
is before the last column of the edit window, a ">" is now added to
the end of it.
The workaround in place_the_cursor() for when two-column characters
straddle the edge of the screen is removed, as it's no longer needed
now that chunks end before such characters.
Furthermore, do_home() and do_end() use xplustabs() instead of
placewewant again when calculating the leftedge, since placewewant
refers to a column that may or may not be available (if it's not,
the cursor will be placed wrongly). Make get_edge_and_target() use
xplustabs() instead of placewewant for the same reason; this also lets
us simplify get_edge_and_target(), since xplustabs() will never be
greater than strlenpt(). Finally, since do_end() now has to calculate
rightedge as well as rightedge_x, use the former to implement the same
time-saving optimizations as in do_home().
The cursor is not yet adjusted when we try to go directly to a column
past the end of a softwrap breakpoint, and placewewant handling in the
vertical movement code is not yet adjusted for varying chunk lengths,
but fixes for these are forthcoming.
This fixes https://savannah.gnu.org/bugs/?49440.
2017-02-22 18:44:53 +00:00
|
|
|
|
2020-05-13 10:29:44 +00:00
|
|
|
return leftedge;
|
2017-02-19 17:51:50 +00:00
|
|
|
}
|
|
|
|
|
2017-03-23 21:29:28 +00:00
|
|
|
/* Ensure that firstcolumn is at the starting column of the softwrapped chunk
|
softwrap: adjust firstcolumn when the window width changes
If the number of columns in the edit window changes (which currently
only happens in two places: in regenerate_screen(), called when the
window is resized; and in main(), when line numbering mode is toggled),
the display will break if we're in softwrap mode and firstcolumn is
nonzero. This is because the column width of softwrapped chunks has
changed, and firstcolumn is no longer the starting column of a chunk,
an assumption that all code using firstcolumn relies on.
To fix this problem, add a new function, ensure_firstcolumn_is_aligned(),
to adjust firstcolumn to the starting column of the chunk it's on, and
use it when the number of columns in the edit window changes.
(Note that this function uses the simplest possible fix, and could
probably be made more sophisticated.)
2017-01-23 19:40:03 +00:00
|
|
|
* it's on. We need to do this when the number of columns of the edit window
|
|
|
|
* has changed, because then the width of softwrapped chunks has changed. */
|
|
|
|
void ensure_firstcolumn_is_aligned(void)
|
|
|
|
{
|
2020-06-06 16:57:17 +00:00
|
|
|
if (ISSET(SOFTWRAP))
|
2020-05-13 10:01:55 +00:00
|
|
|
openfile->firstcolumn = leftedge_for(openfile->firstcolumn,
|
|
|
|
openfile->edittop);
|
2020-06-06 16:57:17 +00:00
|
|
|
else
|
2020-05-13 10:01:55 +00:00
|
|
|
openfile->firstcolumn = 0;
|
2017-05-03 22:10:46 +00:00
|
|
|
|
2017-12-29 18:27:33 +00:00
|
|
|
/* If smooth scrolling is on, make sure the viewport doesn't center. */
|
|
|
|
focusing = FALSE;
|
softwrap: adjust firstcolumn when the window width changes
If the number of columns in the edit window changes (which currently
only happens in two places: in regenerate_screen(), called when the
window is resized; and in main(), when line numbering mode is toggled),
the display will break if we're in softwrap mode and firstcolumn is
nonzero. This is because the column width of softwrapped chunks has
changed, and firstcolumn is no longer the starting column of a chunk,
an assumption that all code using firstcolumn relies on.
To fix this problem, add a new function, ensure_firstcolumn_is_aligned(),
to adjust firstcolumn to the starting column of the chunk it's on, and
use it when the number of columns in the edit window changes.
(Note that this function uses the simplest possible fix, and could
probably be made more sophisticated.)
2017-01-23 19:40:03 +00:00
|
|
|
}
|
2017-06-29 19:53:49 +00:00
|
|
|
#endif /* !NANO_TINY */
|
|
|
|
|
|
|
|
/* When in softwrap mode, and the given column is on or after the breakpoint of
|
|
|
|
* a softwrapped chunk, shift it back to the last column before the breakpoint.
|
|
|
|
* The given column is relative to the given leftedge in current. The returned
|
|
|
|
* column is relative to the start of the text. */
|
|
|
|
size_t actual_last_column(size_t leftedge, size_t column)
|
|
|
|
{
|
|
|
|
#ifndef NANO_TINY
|
2017-12-29 18:27:33 +00:00
|
|
|
if (ISSET(SOFTWRAP)) {
|
2019-04-12 11:35:22 +00:00
|
|
|
bool last_chunk = FALSE;
|
2017-12-29 18:27:33 +00:00
|
|
|
size_t end_col = get_softwrap_breakpoint(openfile->current->data,
|
|
|
|
leftedge, &last_chunk) - leftedge;
|
|
|
|
|
|
|
|
/* If we're not on the last chunk, we're one column past the end of
|
|
|
|
* the row. Shifting back one column might put us in the middle of
|
|
|
|
* a multi-column character, but actual_x() will fix that later. */
|
|
|
|
if (!last_chunk)
|
|
|
|
end_col--;
|
|
|
|
|
|
|
|
if (column > end_col)
|
|
|
|
column = end_col;
|
|
|
|
}
|
2017-05-05 10:33:25 +00:00
|
|
|
#endif
|
softwrap: adjust firstcolumn when the window width changes
If the number of columns in the edit window changes (which currently
only happens in two places: in regenerate_screen(), called when the
window is resized; and in main(), when line numbering mode is toggled),
the display will break if we're in softwrap mode and firstcolumn is
nonzero. This is because the column width of softwrapped chunks has
changed, and firstcolumn is no longer the starting column of a chunk,
an assumption that all code using firstcolumn relies on.
To fix this problem, add a new function, ensure_firstcolumn_is_aligned(),
to adjust firstcolumn to the starting column of the chunk it's on, and
use it when the number of columns in the edit window changes.
(Note that this function uses the simplest possible fix, and could
probably be made more sophisticated.)
2017-01-23 19:40:03 +00:00
|
|
|
|
2017-12-29 18:27:33 +00:00
|
|
|
return leftedge + column;
|
2017-06-29 19:53:49 +00:00
|
|
|
}
|
|
|
|
|
2021-04-23 10:04:19 +00:00
|
|
|
/* Return TRUE if current[current_x] is before the viewport. */
|
2017-01-19 02:31:33 +00:00
|
|
|
bool current_is_above_screen(void)
|
|
|
|
{
|
2017-01-21 17:18:17 +00:00
|
|
|
#ifndef NANO_TINY
|
2017-12-29 18:27:33 +00:00
|
|
|
if (ISSET(SOFTWRAP))
|
|
|
|
return (openfile->current->lineno < openfile->edittop->lineno ||
|
|
|
|
(openfile->current->lineno == openfile->edittop->lineno &&
|
|
|
|
xplustabs() < openfile->firstcolumn));
|
|
|
|
else
|
2017-01-21 17:18:17 +00:00
|
|
|
#endif
|
2017-12-29 18:27:33 +00:00
|
|
|
return (openfile->current->lineno < openfile->edittop->lineno);
|
2017-01-19 02:31:33 +00:00
|
|
|
}
|
|
|
|
|
2021-04-23 10:04:19 +00:00
|
|
|
/* Return TRUE if current[current_x] is beyond the viewport. */
|
2017-01-19 02:31:33 +00:00
|
|
|
bool current_is_below_screen(void)
|
|
|
|
{
|
|
|
|
#ifndef NANO_TINY
|
2017-12-29 18:27:33 +00:00
|
|
|
if (ISSET(SOFTWRAP)) {
|
2019-03-21 16:08:52 +00:00
|
|
|
linestruct *line = openfile->edittop;
|
2017-12-29 18:27:33 +00:00
|
|
|
size_t leftedge = openfile->firstcolumn;
|
|
|
|
|
|
|
|
/* If current[current_x] is more than a screen's worth of lines after
|
|
|
|
* edittop at column firstcolumn, it's below the screen. */
|
|
|
|
return (go_forward_chunks(editwinrows - 1, &line, &leftedge) == 0 &&
|
|
|
|
(line->lineno < openfile->current->lineno ||
|
|
|
|
(line->lineno == openfile->current->lineno &&
|
2021-04-23 10:04:19 +00:00
|
|
|
leftedge < leftedge_for(xplustabs(), openfile->current))));
|
2017-12-29 18:27:33 +00:00
|
|
|
} else
|
2017-01-19 02:31:33 +00:00
|
|
|
#endif
|
2017-12-29 18:27:33 +00:00
|
|
|
return (openfile->current->lineno >=
|
|
|
|
openfile->edittop->lineno + editwinrows);
|
2017-01-19 02:31:33 +00:00
|
|
|
}
|
|
|
|
|
2021-04-23 10:04:19 +00:00
|
|
|
/* Return TRUE if current[current_x] is outside the viewport. */
|
2017-01-19 02:31:33 +00:00
|
|
|
bool current_is_offscreen(void)
|
|
|
|
{
|
2017-12-29 18:27:33 +00:00
|
|
|
return (current_is_above_screen() || current_is_below_screen());
|
2017-01-19 02:31:33 +00:00
|
|
|
}
|
|
|
|
|
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. */
|
2019-03-21 16:08:52 +00:00
|
|
|
void edit_redraw(linestruct *old_current, update_type manner)
|
2004-05-28 20:44:09 +00:00
|
|
|
{
|
2017-12-29 18:27:33 +00:00
|
|
|
size_t was_pww = openfile->placewewant;
|
2016-04-10 19:16:19 +00:00
|
|
|
|
2017-12-29 18:27:33 +00:00
|
|
|
openfile->placewewant = xplustabs();
|
2016-04-10 19:16:19 +00:00
|
|
|
|
2017-12-29 18:27:33 +00:00
|
|
|
/* If the current line is offscreen, scroll until it's onscreen. */
|
|
|
|
if (current_is_offscreen()) {
|
2019-01-29 19:23:13 +00:00
|
|
|
adjust_viewport(ISSET(JUMPY_SCROLLING) ? CENTERING : manner);
|
2017-12-29 18:27:33 +00:00
|
|
|
refresh_needed = TRUE;
|
|
|
|
return;
|
|
|
|
}
|
2005-08-01 21:05:29 +00:00
|
|
|
|
2006-05-26 03:04:24 +00:00
|
|
|
#ifndef NANO_TINY
|
2017-12-29 18:27:33 +00:00
|
|
|
/* If the mark is on, update all lines between old_current and current. */
|
|
|
|
if (openfile->mark) {
|
2019-03-21 16:08:52 +00:00
|
|
|
linestruct *line = old_current;
|
2005-07-14 18:01:08 +00:00
|
|
|
|
2017-12-29 18:27:33 +00:00
|
|
|
while (line != openfile->current) {
|
|
|
|
update_line(line, 0);
|
2005-07-16 02:12:18 +00:00
|
|
|
|
2017-12-29 18:27:33 +00:00
|
|
|
line = (line->lineno > openfile->current->lineno) ?
|
|
|
|
line->prev : line->next;
|
|
|
|
}
|
|
|
|
} else
|
2016-04-27 15:45:36 +00:00
|
|
|
#endif
|
2017-12-29 18:27:33 +00:00
|
|
|
/* Otherwise, update old_current only if it differs from current
|
|
|
|
* and was horizontally scrolled. */
|
|
|
|
if (old_current != openfile->current && get_page_start(was_pww) > 0)
|
|
|
|
update_line(old_current, 0);
|
2016-04-11 18:40:21 +00:00
|
|
|
|
2017-12-29 18:27:33 +00:00
|
|
|
/* Update current if the mark is on or it has changed "page", or if it
|
|
|
|
* differs from old_current and needs to be horizontally scrolled. */
|
|
|
|
if (line_needs_update(was_pww, openfile->placewewant) ||
|
|
|
|
(old_current != openfile->current &&
|
|
|
|
get_page_start(openfile->placewewant) > 0))
|
|
|
|
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)
|
|
|
|
{
|
2019-03-21 16:08:52 +00:00
|
|
|
linestruct *line;
|
2017-12-29 18:27:33 +00:00
|
|
|
int row = 0;
|
2005-07-16 22:47:12 +00:00
|
|
|
|
2017-11-01 18:45:33 +00:00
|
|
|
#ifdef ENABLE_COLOR
|
2020-04-29 10:07:31 +00:00
|
|
|
/* When needed and useful, initialize the colors for the current syntax. */
|
2020-05-01 11:25:15 +00:00
|
|
|
if (openfile->syntax && !have_palette && !ISSET(NO_SYNTAX) && has_colors())
|
2020-04-28 14:38:27 +00:00
|
|
|
prepare_palette();
|
2017-04-27 19:42:36 +00:00
|
|
|
#endif
|
|
|
|
|
2017-12-29 18:27:33 +00:00
|
|
|
/* If the current line is out of view, get it back on screen. */
|
|
|
|
if (current_is_offscreen())
|
2019-01-29 19:23:13 +00:00
|
|
|
adjust_viewport((focusing || ISSET(JUMPY_SCROLLING)) ? CENTERING : FLOWING);
|
2000-06-06 05:53:49 +00:00
|
|
|
|
2020-04-25 15:19:03 +00:00
|
|
|
#ifndef NANO_TINY
|
|
|
|
if (thebar)
|
|
|
|
draw_scrollbar();
|
|
|
|
#endif
|
|
|
|
|
2021-01-26 14:41:02 +00:00
|
|
|
//#define TIMEREFRESH 123
|
|
|
|
#ifdef TIMEREFRESH
|
|
|
|
#include <time.h>
|
|
|
|
clock_t start = clock();
|
|
|
|
#endif
|
|
|
|
|
2017-12-29 18:27:33 +00:00
|
|
|
line = openfile->edittop;
|
2016-12-23 11:51:04 +00:00
|
|
|
|
2017-12-29 18:27:33 +00:00
|
|
|
while (row < editwinrows && line != NULL) {
|
|
|
|
if (line == openfile->current)
|
|
|
|
row += update_line(line, openfile->current_x);
|
|
|
|
else
|
|
|
|
row += update_line(line, 0);
|
|
|
|
line = line->next;
|
|
|
|
}
|
2005-07-16 22:47:12 +00:00
|
|
|
|
2020-04-25 15:19:03 +00:00
|
|
|
while (row < editwinrows) {
|
|
|
|
blank_row(edit, row);
|
|
|
|
#ifndef NANO_TINY
|
|
|
|
if (thebar)
|
|
|
|
mvwaddch(edit, row, COLS - 1, bardata[row]);
|
|
|
|
#endif
|
|
|
|
row++;
|
|
|
|
}
|
2005-07-16 22:47:12 +00:00
|
|
|
|
2021-01-26 14:41:02 +00:00
|
|
|
#ifdef TIMEREFRESH
|
|
|
|
statusline(INFO, "Refresh: %.1f ms", 1000 * (double)(clock() - start) / CLOCKS_PER_SEC);
|
|
|
|
#endif
|
|
|
|
|
2017-12-29 18:27:33 +00:00
|
|
|
place_the_cursor();
|
|
|
|
wnoutrefresh(edit);
|
2016-10-21 11:52:40 +00:00
|
|
|
|
2017-12-29 18:27:33 +00:00
|
|
|
refresh_needed = FALSE;
|
2000-06-06 05:53:49 +00:00
|
|
|
}
|
|
|
|
|
2017-04-24 17:44:51 +00:00
|
|
|
/* Move edittop so that current is on the screen. manner says how:
|
|
|
|
* STATIONARY means that the cursor should stay on the same screen row,
|
|
|
|
* CENTERING means that current should end up in the middle of the screen,
|
|
|
|
* and FLOWING means that it should scroll no more than needed to bring
|
|
|
|
* current into view. */
|
2016-10-20 19:11:11 +00:00
|
|
|
void adjust_viewport(update_type manner)
|
2000-06-06 05:53:49 +00:00
|
|
|
{
|
2017-12-29 18:27:33 +00:00
|
|
|
int goal = 0;
|
2005-07-16 22:47:12 +00:00
|
|
|
|
2017-12-29 18:27:33 +00:00
|
|
|
if (manner == STATIONARY)
|
|
|
|
goal = openfile->current_y;
|
|
|
|
else if (manner == CENTERING)
|
|
|
|
goal = editwinrows / 2;
|
|
|
|
else if (!current_is_above_screen())
|
|
|
|
goal = editwinrows - 1;
|
2004-08-27 17:02:05 +00:00
|
|
|
|
2017-12-29 18:27:33 +00:00
|
|
|
openfile->edittop = openfile->current;
|
2014-06-09 20:26:54 +00:00
|
|
|
#ifndef NANO_TINY
|
2017-12-29 18:27:33 +00:00
|
|
|
if (ISSET(SOFTWRAP))
|
|
|
|
openfile->firstcolumn = leftedge_for(xplustabs(), openfile->current);
|
2014-06-09 20:26:54 +00:00
|
|
|
#endif
|
2017-01-20 01:24:51 +00:00
|
|
|
|
2017-12-29 18:27:33 +00:00
|
|
|
/* Move edittop back goal rows, starting at current[current_x]. */
|
|
|
|
go_back_chunks(goal, &openfile->edittop, &openfile->firstcolumn);
|
2000-06-06 05:53:49 +00:00
|
|
|
}
|
|
|
|
|
2020-05-31 14:41:07 +00:00
|
|
|
/* Tell curses to unconditionally redraw whatever was on the screen. */
|
|
|
|
void full_refresh(void)
|
2002-09-06 20:35:28 +00:00
|
|
|
{
|
2017-12-29 18:27:33 +00:00
|
|
|
wrefresh(curscr);
|
2005-03-17 17:56:48 +00:00
|
|
|
}
|
|
|
|
|
2020-05-31 14:41:07 +00:00
|
|
|
/* Draw all elements of the screen. That is: the title bar plus the content
|
|
|
|
* of the edit window (when not in the file browser), and the bottom bars. */
|
2020-05-31 14:14:43 +00:00
|
|
|
void draw_all_subwindows(void)
|
2005-03-17 17:56:48 +00:00
|
|
|
{
|
2021-01-05 10:49:03 +00:00
|
|
|
if (currmenu & ~(MBROWSER|MWHEREISFILE|MGOTODIR))
|
2017-12-29 18:27:33 +00:00
|
|
|
titlebar(title);
|
2017-04-25 15:51:45 +00:00
|
|
|
#ifdef ENABLE_HELP
|
2019-05-29 10:44:23 +00:00
|
|
|
if (inhelp) {
|
2019-05-31 07:15:12 +00:00
|
|
|
close_buffer();
|
2019-05-29 10:44:23 +00:00
|
|
|
wrap_help_text_into_buffer();
|
|
|
|
} else
|
2017-04-22 16:27:01 +00:00
|
|
|
#endif
|
2021-01-05 10:49:03 +00:00
|
|
|
if (currmenu & ~(MBROWSER|MWHEREISFILE|MGOTODIR))
|
2017-12-29 18:27:33 +00:00
|
|
|
edit_refresh();
|
|
|
|
bottombars(currmenu);
|
2002-09-06 20:35:28 +00:00
|
|
|
}
|
|
|
|
|
2020-08-21 14:06:38 +00:00
|
|
|
/* Display on the status bar details about the current cursor position. */
|
2020-07-03 07:32:25 +00:00
|
|
|
void report_cursor_position(void)
|
2000-06-06 05:53:49 +00:00
|
|
|
{
|
2020-08-21 14:03:59 +00:00
|
|
|
size_t fullwidth = breadth(openfile->current->data) + 1;
|
|
|
|
size_t column = xplustabs() + 1;
|
2017-12-29 18:27:33 +00:00
|
|
|
int linepct, colpct, charpct;
|
2020-08-21 14:03:59 +00:00
|
|
|
char saved_byte;
|
|
|
|
size_t sum;
|
2000-06-06 05:53:49 +00:00
|
|
|
|
2017-12-29 18:27:33 +00:00
|
|
|
saved_byte = openfile->current->data[openfile->current_x];
|
|
|
|
openfile->current->data[openfile->current_x] = '\0';
|
2005-08-01 02:18:05 +00:00
|
|
|
|
2020-08-21 14:06:38 +00:00
|
|
|
/* Determine the size of the file up to the cursor. */
|
2020-04-09 10:27:07 +00:00
|
|
|
sum = number_of_characters_in(openfile->filetop, openfile->current);
|
2005-08-01 02:18:05 +00:00
|
|
|
|
2017-12-29 18:27:33 +00:00
|
|
|
openfile->current->data[openfile->current_x] = saved_byte;
|
2016-12-11 10:18:28 +00:00
|
|
|
|
2020-08-21 14:06:38 +00:00
|
|
|
/* Calculate the percentages. */
|
2017-12-29 18:27:33 +00:00
|
|
|
linepct = 100 * openfile->current->lineno / openfile->filebot->lineno;
|
2020-08-21 14:03:59 +00:00
|
|
|
colpct = 100 * column / fullwidth;
|
2017-12-29 18:27:33 +00:00
|
|
|
charpct = (openfile->totsize == 0) ? 0 : 100 * sum / openfile->totsize;
|
2005-06-28 20:04:14 +00:00
|
|
|
|
2020-12-08 16:09:07 +00:00
|
|
|
statusline(INFO,
|
2021-03-14 14:50:23 +00:00
|
|
|
_("line %*zd/%zd (%2d%%), col %2zu/%2zu (%3d%%), char %*zu/%zu (%2d%%)"),
|
|
|
|
digits(openfile->filebot->lineno),
|
2020-08-21 14:06:38 +00:00
|
|
|
openfile->current->lineno, openfile->filebot->lineno, linepct,
|
2021-03-14 14:50:23 +00:00
|
|
|
column, fullwidth, colpct,
|
|
|
|
digits(openfile->totsize), sum, openfile->totsize, charpct);
|
2000-06-06 05:53:49 +00:00
|
|
|
}
|
|
|
|
|
2020-07-03 17:03:40 +00:00
|
|
|
/* Highlight the text between the given two columns on the current line. */
|
2018-09-29 16:19:57 +00:00
|
|
|
void spotlight(size_t from_col, size_t to_col)
|
2000-12-05 11:36:41 +00:00
|
|
|
{
|
2019-06-26 08:18:32 +00:00
|
|
|
size_t right_edge = get_page_start(from_col) + editwincols;
|
2020-07-03 17:03:40 +00:00
|
|
|
bool overshoots = (to_col > right_edge);
|
2017-12-29 18:27:33 +00:00
|
|
|
char *word;
|
2002-07-19 01:08:59 +00:00
|
|
|
|
2017-12-29 18:27:33 +00:00
|
|
|
place_the_cursor();
|
2017-06-27 10:34:11 +00:00
|
|
|
|
2019-02-11 23:16:00 +00:00
|
|
|
/* Limit the end column to the edge of the screen. */
|
2020-07-03 17:03:40 +00:00
|
|
|
if (overshoots)
|
2019-02-11 23:16:00 +00:00
|
|
|
to_col = right_edge;
|
|
|
|
|
2020-07-03 17:03:40 +00:00
|
|
|
/* If the target text is of zero length, highlight a space instead. */
|
2017-12-29 18:27:33 +00:00
|
|
|
if (to_col == from_col) {
|
2019-10-13 10:24:27 +00:00
|
|
|
word = copy_of(" ");
|
2017-12-29 18:27:33 +00:00
|
|
|
to_col++;
|
|
|
|
} else
|
|
|
|
word = display_string(openfile->current->data, from_col,
|
2019-02-11 23:16:00 +00:00
|
|
|
to_col - from_col, FALSE, overshoots);
|
2017-03-06 07:34:45 +00:00
|
|
|
|
2021-03-03 08:39:49 +00:00
|
|
|
wattron(edit, interface_color_pair[SPOTLIGHTED]);
|
2019-02-11 23:16:00 +00:00
|
|
|
waddnstr(edit, word, actual_x(word, to_col));
|
|
|
|
if (overshoots)
|
2020-04-25 15:19:03 +00:00
|
|
|
mvwaddch(edit, openfile->current_y, COLS - 1 - thebar, '>');
|
2021-03-03 08:39:49 +00:00
|
|
|
wattroff(edit, interface_color_pair[SPOTLIGHTED]);
|
2016-12-01 14:14:41 +00:00
|
|
|
|
2017-12-29 18:27:33 +00:00
|
|
|
free(word);
|
2017-03-06 07:34:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifndef NANO_TINY
|
2020-07-03 17:03:40 +00:00
|
|
|
/* Highlight the text between the given two columns on the current line. */
|
2018-09-29 16:19:57 +00:00
|
|
|
void spotlight_softwrapped(size_t from_col, size_t to_col)
|
2017-03-06 07:34:45 +00:00
|
|
|
{
|
2020-06-15 07:45:01 +00:00
|
|
|
ssize_t row;
|
2017-12-29 18:27:33 +00:00
|
|
|
size_t leftedge = leftedge_for(from_col, openfile->current);
|
|
|
|
size_t break_col;
|
|
|
|
bool end_of_line = FALSE;
|
|
|
|
char *word;
|
2017-03-06 07:34:45 +00:00
|
|
|
|
2019-06-26 08:12:23 +00:00
|
|
|
place_the_cursor();
|
2020-06-15 07:45:01 +00:00
|
|
|
row = openfile->current_y;
|
2019-06-26 08:12:23 +00:00
|
|
|
|
2017-12-29 18:27:33 +00:00
|
|
|
while (row < editwinrows) {
|
|
|
|
break_col = get_softwrap_breakpoint(openfile->current->data,
|
|
|
|
leftedge, &end_of_line);
|
2017-03-06 07:34:45 +00:00
|
|
|
|
2020-07-03 17:03:40 +00:00
|
|
|
/* If the highlighting ends on this chunk, we can stop after it. */
|
2017-12-29 18:27:33 +00:00
|
|
|
if (break_col >= to_col) {
|
|
|
|
end_of_line = TRUE;
|
|
|
|
break_col = to_col;
|
|
|
|
}
|
2017-03-06 07:34:45 +00:00
|
|
|
|
2020-07-03 17:03:40 +00:00
|
|
|
/* If the target text is of zero length, highlight a space instead. */
|
2017-12-29 18:27:33 +00:00
|
|
|
if (break_col == from_col) {
|
2019-10-13 10:24:27 +00:00
|
|
|
word = copy_of(" ");
|
2017-12-29 18:27:33 +00:00
|
|
|
break_col++;
|
|
|
|
} else
|
|
|
|
word = display_string(openfile->current->data, from_col,
|
2019-02-27 20:37:53 +00:00
|
|
|
break_col - from_col, FALSE, FALSE);
|
2017-03-06 07:34:45 +00:00
|
|
|
|
2021-03-03 08:39:49 +00:00
|
|
|
wattron(edit, interface_color_pair[SPOTLIGHTED]);
|
2017-12-29 18:27:33 +00:00
|
|
|
waddnstr(edit, word, actual_x(word, break_col));
|
2021-03-03 08:39:49 +00:00
|
|
|
wattroff(edit, interface_color_pair[SPOTLIGHTED]);
|
2017-03-06 07:34:45 +00:00
|
|
|
|
2017-12-29 18:27:33 +00:00
|
|
|
free(word);
|
2017-03-06 07:34:45 +00:00
|
|
|
|
2017-12-29 18:27:33 +00:00
|
|
|
if (end_of_line)
|
|
|
|
break;
|
|
|
|
|
2019-06-26 09:18:02 +00:00
|
|
|
wmove(edit, ++row, margin);
|
2017-12-29 18:27:33 +00:00
|
|
|
|
|
|
|
leftedge = break_col;
|
|
|
|
from_col = break_col;
|
|
|
|
}
|
2000-12-05 11:36:41 +00:00
|
|
|
}
|
2017-03-06 07:34:45 +00:00
|
|
|
#endif
|
2000-12-05 11:36:41 +00:00
|
|
|
|
2017-11-01 19:33:14 +00:00
|
|
|
#ifdef ENABLE_EXTRA
|
2020-05-29 16:45:14 +00:00
|
|
|
#define CREDIT_LEN 54
|
|
|
|
#define XLCREDIT_LEN 9
|
2002-07-21 15:44:13 +00:00
|
|
|
|
2020-05-06 15:29:20 +00:00
|
|
|
/* Fully blank the terminal screen, then slowly "crawl" the credits over it.
|
|
|
|
* Abort the crawl upon any keystroke. */
|
2000-11-24 20:45:14 +00:00
|
|
|
void do_credits(void)
|
|
|
|
{
|
2019-02-20 15:43:03 +00:00
|
|
|
bool with_empty_line = ISSET(EMPTY_LINE);
|
|
|
|
bool with_help = !ISSET(NO_HELP);
|
2017-12-29 18:27:33 +00:00
|
|
|
int kbinput = ERR, crpos = 0, xlpos = 0;
|
|
|
|
const char *credits[CREDIT_LEN] = {
|
2017-12-29 20:35:14 +00:00
|
|
|
NULL, /* "The nano text editor" */
|
|
|
|
NULL, /* "version" */
|
2017-12-29 18:27:33 +00:00
|
|
|
VERSION,
|
|
|
|
"",
|
2017-12-29 20:35:14 +00:00
|
|
|
NULL, /* "Brought to you by:" */
|
2017-12-29 18:27:33 +00:00
|
|
|
"Chris Allegretta",
|
2018-05-16 09:01:56 +00:00
|
|
|
"Benno Schulenberg",
|
|
|
|
"David Lawrence Ramsey",
|
2017-12-29 18:27:33 +00:00
|
|
|
"Jordi Mallach",
|
2018-05-16 09:01:56 +00:00
|
|
|
"David Benbennick",
|
|
|
|
"Rocco Corsi",
|
|
|
|
"Mike Frysinger",
|
2017-12-29 18:27:33 +00:00
|
|
|
"Adam Rogoyski",
|
|
|
|
"Rob Siemborski",
|
|
|
|
"Mark Majeres",
|
|
|
|
"Ken Tyler",
|
|
|
|
"Sven Guckes",
|
|
|
|
"Bill Soudan",
|
|
|
|
"Christian Weisgerber",
|
|
|
|
"Erik Andersen",
|
|
|
|
"Big Gaute",
|
|
|
|
"Joshua Jensen",
|
|
|
|
"Ryan Krebs",
|
|
|
|
"Albert Chin",
|
|
|
|
"",
|
2017-12-29 20:35:14 +00:00
|
|
|
NULL, /* "Special thanks to:" */
|
2017-12-29 18:27:33 +00:00
|
|
|
"Monique, Brielle & Joseph",
|
|
|
|
"Plattsburgh State University",
|
|
|
|
"Benet Laboratories",
|
|
|
|
"Amy Allegretta",
|
|
|
|
"Linda Young",
|
|
|
|
"Jeremy Robichaud",
|
|
|
|
"Richard Kolb II",
|
2017-12-29 20:35:14 +00:00
|
|
|
NULL, /* "The Free Software Foundation" */
|
2017-12-29 18:27:33 +00:00
|
|
|
"Linus Torvalds",
|
2017-12-29 20:35:14 +00:00
|
|
|
NULL, /* "the many translators and the TP" */
|
|
|
|
NULL, /* "For ncurses:" */
|
2017-12-29 18:27:33 +00:00
|
|
|
"Thomas Dickey",
|
|
|
|
"Pavel Curtis",
|
|
|
|
"Zeyd Ben-Halim",
|
|
|
|
"Eric S. Raymond",
|
2017-12-29 20:35:14 +00:00
|
|
|
NULL, /* "and anyone else we forgot..." */
|
|
|
|
NULL, /* "Thank you for using nano!" */
|
2017-12-29 18:27:33 +00:00
|
|
|
"",
|
|
|
|
"",
|
|
|
|
"",
|
|
|
|
"",
|
2021-01-11 13:21:03 +00:00
|
|
|
"(C) 2021",
|
2017-12-29 18:27:33 +00:00
|
|
|
"Free Software Foundation, Inc.",
|
|
|
|
"",
|
|
|
|
"",
|
|
|
|
"",
|
|
|
|
"",
|
|
|
|
"https://nano-editor.org/"
|
|
|
|
};
|
|
|
|
|
|
|
|
const char *xlcredits[XLCREDIT_LEN] = {
|
|
|
|
N_("The nano text editor"),
|
|
|
|
N_("version"),
|
|
|
|
N_("Brought to you by:"),
|
|
|
|
N_("Special thanks to:"),
|
|
|
|
N_("The Free Software Foundation"),
|
|
|
|
N_("the many translators and the TP"),
|
|
|
|
N_("For ncurses:"),
|
|
|
|
N_("and anyone else we forgot..."),
|
|
|
|
N_("Thank you for using nano!")
|
|
|
|
};
|
|
|
|
|
2019-02-20 15:43:03 +00:00
|
|
|
if (with_empty_line || with_help) {
|
2019-01-29 19:46:37 +00:00
|
|
|
UNSET(EMPTY_LINE);
|
2017-12-29 18:27:33 +00:00
|
|
|
SET(NO_HELP);
|
|
|
|
window_init();
|
|
|
|
}
|
2005-08-14 19:25:16 +00:00
|
|
|
|
2017-12-29 18:27:33 +00:00
|
|
|
nodelay(edit, TRUE);
|
2020-05-06 15:29:20 +00:00
|
|
|
scrollok(edit, TRUE);
|
2005-08-14 19:25:16 +00:00
|
|
|
|
2017-12-29 18:27:33 +00:00
|
|
|
blank_titlebar();
|
|
|
|
blank_edit();
|
|
|
|
blank_statusbar();
|
2005-08-14 21:17:37 +00:00
|
|
|
|
2017-12-29 18:27:33 +00:00
|
|
|
wrefresh(topwin);
|
|
|
|
wrefresh(edit);
|
|
|
|
wrefresh(bottomwin);
|
|
|
|
napms(700);
|
2000-11-24 20:45:14 +00:00
|
|
|
|
2017-12-29 18:27:33 +00:00
|
|
|
for (crpos = 0; crpos < CREDIT_LEN + editwinrows / 2; crpos++) {
|
|
|
|
if (crpos < CREDIT_LEN) {
|
|
|
|
const char *what;
|
2004-05-18 01:20:36 +00:00
|
|
|
|
2017-12-29 18:27:33 +00:00
|
|
|
if (credits[crpos] == NULL)
|
|
|
|
what = _(xlcredits[xlpos++]);
|
|
|
|
else
|
|
|
|
what = credits[crpos];
|
2005-03-15 06:58:02 +00:00
|
|
|
|
2017-12-29 18:27:33 +00:00
|
|
|
mvwaddstr(edit, editwinrows - 1 - (editwinrows % 2),
|
2020-05-06 15:29:20 +00:00
|
|
|
COLS / 2 - breadth(what) / 2 - 1, what);
|
|
|
|
wrefresh(edit);
|
2017-12-29 18:27:33 +00:00
|
|
|
}
|
2005-03-15 06:34:09 +00:00
|
|
|
|
2017-12-29 18:27:33 +00:00
|
|
|
if ((kbinput = wgetch(edit)) != ERR)
|
|
|
|
break;
|
2005-08-14 21:17:37 +00:00
|
|
|
|
2020-05-06 15:29:20 +00:00
|
|
|
napms(700);
|
2017-12-29 18:27:33 +00:00
|
|
|
wscrl(edit, 1);
|
|
|
|
wrefresh(edit);
|
2005-08-14 21:17:37 +00:00
|
|
|
|
2017-12-29 18:27:33 +00:00
|
|
|
if ((kbinput = wgetch(edit)) != ERR)
|
|
|
|
break;
|
2005-08-14 21:17:37 +00:00
|
|
|
|
2020-05-06 15:29:20 +00:00
|
|
|
napms(700);
|
2017-12-29 18:27:33 +00:00
|
|
|
wscrl(edit, 1);
|
|
|
|
wrefresh(edit);
|
|
|
|
}
|
2000-11-24 20:45:14 +00:00
|
|
|
|
2017-12-29 18:27:33 +00:00
|
|
|
if (kbinput != ERR)
|
|
|
|
ungetch(kbinput);
|
2005-06-07 03:20:35 +00:00
|
|
|
|
2019-02-20 15:43:03 +00:00
|
|
|
if (with_empty_line)
|
2019-01-29 19:46:37 +00:00
|
|
|
SET(EMPTY_LINE);
|
2019-02-20 15:43:03 +00:00
|
|
|
if (with_help)
|
2017-12-29 18:27:33 +00:00
|
|
|
UNSET(NO_HELP);
|
|
|
|
window_init();
|
2005-08-14 19:25:16 +00:00
|
|
|
|
2020-05-06 15:29:20 +00:00
|
|
|
scrollok(edit, FALSE);
|
2017-12-29 18:27:33 +00:00
|
|
|
nodelay(edit, FALSE);
|
2005-08-14 19:25:16 +00:00
|
|
|
|
2020-05-31 14:14:43 +00:00
|
|
|
draw_all_subwindows();
|
2002-01-19 01:59:37 +00:00
|
|
|
}
|
2017-11-01 19:33:14 +00:00
|
|
|
#endif /* ENABLE_EXTRA */
|