2011-10-15 14:56:47 +04:00
|
|
|
/*
|
|
|
|
Terminal management xterm and rxvt support
|
|
|
|
|
2023-01-03 11:30:57 +03:00
|
|
|
Copyright (C) 1995-2023
|
2014-02-12 10:33:10 +04:00
|
|
|
Free Software Foundation, Inc.
|
2010-11-08 13:21:45 +03:00
|
|
|
|
2009-06-12 14:55:06 +04:00
|
|
|
Written by:
|
|
|
|
Andrew Borodin <aborodin@vmail.ru>, 2009.
|
2010-11-08 13:21:45 +03:00
|
|
|
|
2011-10-15 14:56:47 +04:00
|
|
|
This file is part of the Midnight Commander.
|
|
|
|
|
|
|
|
The Midnight Commander 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.
|
2009-05-24 13:39:14 +04:00
|
|
|
|
2011-10-15 14:56:47 +04:00
|
|
|
The Midnight Commander is distributed in the hope that it will be useful,
|
1998-02-27 07:54:42 +03:00
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
2011-10-15 14:56:47 +04:00
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
1998-02-27 07:54:42 +03:00
|
|
|
|
2009-02-05 21:28:18 +03:00
|
|
|
/** \file win.c
|
2009-06-04 16:47:01 +04:00
|
|
|
* \brief Source: Terminal management xterm and rxvt support
|
2009-02-05 21:28:18 +03:00
|
|
|
*/
|
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
#include <config.h>
|
2005-02-08 12:04:03 +03:00
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
#include <stdio.h>
|
2009-08-20 09:28:21 +04:00
|
|
|
#include <stdlib.h>
|
2009-05-08 14:01:05 +04:00
|
|
|
#include <string.h>
|
2019-09-22 17:29:50 +03:00
|
|
|
#ifdef HAVE_SYS_SELECT_H
|
|
|
|
#include <sys/select.h>
|
|
|
|
#else
|
|
|
|
#include <sys/time.h>
|
2009-06-04 16:47:01 +04:00
|
|
|
#include <sys/types.h>
|
|
|
|
#include <unistd.h>
|
2019-09-22 17:29:50 +03:00
|
|
|
#endif
|
2009-03-07 15:23:15 +03:00
|
|
|
|
2010-01-20 18:11:52 +03:00
|
|
|
#include "lib/global.h"
|
2010-11-11 16:58:29 +03:00
|
|
|
#include "lib/util.h" /* is_printable() */
|
2011-09-02 13:30:59 +04:00
|
|
|
#include "tty-internal.h"
|
2010-11-08 13:21:45 +03:00
|
|
|
#include "tty.h" /* tty_gotoyx, tty_print_char */
|
2010-01-07 02:57:27 +03:00
|
|
|
#include "win.h"
|
2009-06-04 16:47:01 +04:00
|
|
|
|
2010-11-08 13:21:45 +03:00
|
|
|
/*** global variables ****************************************************************************/
|
2009-06-04 16:47:01 +04:00
|
|
|
|
2011-09-02 13:30:59 +04:00
|
|
|
char *smcup = NULL;
|
|
|
|
char *rmcup = NULL;
|
|
|
|
|
2010-11-08 13:21:45 +03:00
|
|
|
/*** file scope macro definitions ****************************************************************/
|
2009-06-04 16:47:01 +04:00
|
|
|
|
2010-11-08 13:21:45 +03:00
|
|
|
/*** file scope type declarations ****************************************************************/
|
2009-06-04 16:47:01 +04:00
|
|
|
|
Update template for .c files.
Add section for forward declarations of local functions. This section is
located before file scope variables because functions can be used in
strucutres (see find.c for example):
/*** forward declarations (file scope functions) *************************************************/
/* button callbacks */
static int start_stop (WButton * button, int action);
static int find_do_view_file (WButton * button, int action);
static int find_do_edit_file (WButton * button, int action);
/*** file scope variables ************************************************************************/
static struct
{
...
bcback_fn callback;
} fbuts[] =
{
...
{ B_STOP, NORMAL_BUTTON, N_("S&uspend"), 0, 0, NULL, start_stop },
...
{ B_VIEW, NORMAL_BUTTON, N_("&View - F3"), 0, 0, NULL, find_do_view_file },
{ B_VIEW, NORMAL_BUTTON, N_("&Edit - F4"), 0, 0, NULL, find_do_edit_file }
};
Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
2023-02-24 09:27:11 +03:00
|
|
|
/*** forward declarations (file scope functions) *************************************************/
|
|
|
|
|
2010-11-08 13:21:45 +03:00
|
|
|
/*** file scope variables ************************************************************************/
|
2009-06-04 16:47:01 +04:00
|
|
|
|
|
|
|
static gboolean rxvt_extensions = FALSE;
|
|
|
|
|
Update template for .c files.
Add section for forward declarations of local functions. This section is
located before file scope variables because functions can be used in
strucutres (see find.c for example):
/*** forward declarations (file scope functions) *************************************************/
/* button callbacks */
static int start_stop (WButton * button, int action);
static int find_do_view_file (WButton * button, int action);
static int find_do_edit_file (WButton * button, int action);
/*** file scope variables ************************************************************************/
static struct
{
...
bcback_fn callback;
} fbuts[] =
{
...
{ B_STOP, NORMAL_BUTTON, N_("S&uspend"), 0, 0, NULL, start_stop },
...
{ B_VIEW, NORMAL_BUTTON, N_("&View - F3"), 0, 0, NULL, find_do_view_file },
{ B_VIEW, NORMAL_BUTTON, N_("&Edit - F4"), 0, 0, NULL, find_do_edit_file }
};
Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
2023-02-24 09:27:11 +03:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
2010-11-08 13:21:45 +03:00
|
|
|
/*** file scope functions ************************************************************************/
|
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
2009-06-04 16:47:01 +04:00
|
|
|
|
2013-06-13 03:29:07 +04:00
|
|
|
/* my own weird protocol base 16 - paul */
|
2009-06-04 16:47:01 +04:00
|
|
|
static int
|
|
|
|
rxvt_getc (void)
|
|
|
|
{
|
|
|
|
int r;
|
|
|
|
unsigned char c;
|
|
|
|
|
2009-09-17 02:07:04 +04:00
|
|
|
while (read (0, &c, 1) != 1);
|
2009-06-04 16:47:01 +04:00
|
|
|
if (c == '\n')
|
2009-09-17 02:07:04 +04:00
|
|
|
return -1;
|
2009-06-04 16:47:01 +04:00
|
|
|
r = (c - 'A') * 16;
|
2009-09-17 02:07:04 +04:00
|
|
|
while (read (0, &c, 1) != 1);
|
2009-06-04 16:47:01 +04:00
|
|
|
r += (c - 'A');
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
2010-11-08 13:21:45 +03:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
2009-06-04 16:47:01 +04:00
|
|
|
static int
|
|
|
|
anything_ready (void)
|
|
|
|
{
|
|
|
|
fd_set fds;
|
|
|
|
struct timeval tv;
|
|
|
|
|
|
|
|
FD_ZERO (&fds);
|
|
|
|
FD_SET (0, &fds);
|
|
|
|
tv.tv_sec = 0;
|
|
|
|
tv.tv_usec = 0;
|
|
|
|
return select (1, &fds, 0, 0, &tv);
|
|
|
|
}
|
|
|
|
|
2010-11-08 13:21:45 +03:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
/*** public functions ****************************************************************************/
|
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
2003-10-26 10:02:13 +03:00
|
|
|
|
2009-06-04 16:47:01 +04:00
|
|
|
void
|
|
|
|
show_rxvt_contents (int starty, unsigned char y1, unsigned char y2)
|
|
|
|
{
|
|
|
|
unsigned char *k;
|
|
|
|
int bytes, i, j, cols = 0;
|
|
|
|
|
Fix various typos in the source code (closes MidnightCommander/mc#177).
Found via `codespell -S
po,doc,./misc/syntax,./src/vfs/extfs/helpers/README.it -L
parm,rouge,sav,ect,vie,te,dum,clen,wee,dynamc,childs,ths,fo,nin,unx,nd,iif,iterm,ser,makrs,wil`
Co-authored-by: Yury V. Zaytsev <yury@shurup.com>
Signed-off-by: Kian-Meng Ang <kianmeng@cpan.org>
Signed-off-by: Yury V. Zaytsev <yury@shurup.com>
2023-01-10 06:02:52 +03:00
|
|
|
y1 += mc_global.keybar_visible != 0 ? 1 : 0; /* i don't know why we need this - paul */
|
2019-12-02 21:58:58 +03:00
|
|
|
y2 += mc_global.keybar_visible != 0 ? 1 : 0;
|
2009-06-04 16:47:01 +04:00
|
|
|
while (anything_ready ())
|
2009-09-17 02:07:04 +04:00
|
|
|
tty_lowlevel_getch ();
|
2009-06-04 16:47:01 +04:00
|
|
|
|
2013-06-13 03:29:07 +04:00
|
|
|
/* my own weird protocol base 26 - paul */
|
2011-10-15 14:56:47 +04:00
|
|
|
printf (ESC_STR "CL%c%c%c%c\n", (y1 / 26) + 'A', (y1 % 26) + 'A', (y2 / 26) + 'A',
|
|
|
|
(y2 % 26) + 'A');
|
2009-06-04 16:47:01 +04:00
|
|
|
|
2009-09-17 02:07:04 +04:00
|
|
|
bytes = (y2 - y1) * (COLS + 1) + 1; /* *should* be the number of bytes read */
|
2009-06-04 16:47:01 +04:00
|
|
|
j = 0;
|
|
|
|
k = g_malloc (bytes);
|
2012-10-21 18:16:44 +04:00
|
|
|
while (TRUE)
|
2010-11-08 13:21:45 +03:00
|
|
|
{
|
2009-09-17 02:07:04 +04:00
|
|
|
int c;
|
2012-10-21 18:16:44 +04:00
|
|
|
|
2009-09-17 02:07:04 +04:00
|
|
|
c = rxvt_getc ();
|
|
|
|
if (c < 0)
|
|
|
|
break;
|
|
|
|
if (j < bytes)
|
|
|
|
k[j++] = c;
|
2010-11-08 13:21:45 +03:00
|
|
|
for (cols = 1;; cols++)
|
|
|
|
{
|
2009-09-17 02:07:04 +04:00
|
|
|
c = rxvt_getc ();
|
|
|
|
if (c < 0)
|
|
|
|
break;
|
|
|
|
if (j < bytes)
|
|
|
|
k[j++] = c;
|
|
|
|
}
|
2009-06-04 16:47:01 +04:00
|
|
|
}
|
2010-11-08 13:21:45 +03:00
|
|
|
for (i = 0; i < j; i++)
|
|
|
|
{
|
2009-09-17 02:07:04 +04:00
|
|
|
if ((i % cols) == 0)
|
|
|
|
tty_gotoyx (starty + (i / cols), 0);
|
|
|
|
tty_print_char (is_printable (k[i]) ? k[i] : ' ');
|
2009-06-04 16:47:01 +04:00
|
|
|
}
|
|
|
|
g_free (k);
|
|
|
|
}
|
|
|
|
|
2010-11-08 13:21:45 +03:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
2009-06-04 16:47:01 +04:00
|
|
|
gboolean
|
|
|
|
look_for_rxvt_extensions (void)
|
|
|
|
{
|
|
|
|
static gboolean been_called = FALSE;
|
|
|
|
|
2010-11-08 13:21:45 +03:00
|
|
|
if (!been_called)
|
|
|
|
{
|
2009-09-17 02:07:04 +04:00
|
|
|
const char *e = getenv ("RXVT_EXT");
|
|
|
|
rxvt_extensions = ((e != NULL) && (strcmp (e, "1.0") == 0));
|
|
|
|
been_called = TRUE;
|
2009-06-04 16:47:01 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (rxvt_extensions)
|
2011-02-10 18:02:54 +03:00
|
|
|
mc_global.tty.console_flag = '\004';
|
2009-06-04 16:47:01 +04:00
|
|
|
|
|
|
|
return rxvt_extensions;
|
2003-10-26 10:02:13 +03:00
|
|
|
}
|
2010-11-08 13:21:45 +03:00
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------- */
|