1 /* Terminal management xterm and rxvt support
2 Copyright (C) 1995, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
3 2007, 2009 Free Software Foundation, Inc.
6 Andrew Borodin <aborodin@vmail.ru>, 2009.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
23 * \brief Source: Terminal management xterm and rxvt support
32 #include <sys/types.h>
35 #include "lib/global.h"
36 #include "lib/util.h" /* is_printable() */
37 #include "tty.h" /* tty_gotoyx, tty_print_char */
39 #include "src/consaver/cons.saver.h" /* console_flag */
41 /*** global variables ****************************************************************************/
43 /* This flag is set by xterm detection routine in function main() */
44 /* It is used by function view_other_cmd() */
47 extern int keybar_visible
;
49 /*** file scope macro definitions ****************************************************************/
51 /*** file scope type declarations ****************************************************************/
53 /*** file scope variables ************************************************************************/
55 static gboolean rxvt_extensions
= FALSE
;
57 /*** file scope functions ************************************************************************/
58 /* --------------------------------------------------------------------------------------------- */
60 /* my own wierd protocol base 16 - paul */
67 while (read (0, &c
, 1) != 1);
71 while (read (0, &c
, 1) != 1);
76 /* --------------------------------------------------------------------------------------------- */
88 return select (1, &fds
, 0, 0, &tv
);
91 /* --------------------------------------------------------------------------------------------- */
92 /*** public functions ****************************************************************************/
93 /* --------------------------------------------------------------------------------------------- */
96 do_enter_ca_mode (void)
100 fprintf (stdout
, /* ESC_STR ")0" */ ESC_STR
"7" ESC_STR
"[?47h");
105 /* --------------------------------------------------------------------------------------------- */
108 do_exit_ca_mode (void)
112 fprintf (stdout
, ESC_STR
"[?47l" ESC_STR
"8" ESC_STR
"[m");
117 /* --------------------------------------------------------------------------------------------- */
120 show_rxvt_contents (int starty
, unsigned char y1
, unsigned char y2
)
123 int bytes
, i
, j
, cols
= 0;
125 y1
+= (keybar_visible
!= 0); /* i don't knwo why we need this - paul */
126 y2
+= (keybar_visible
!= 0);
127 while (anything_ready ())
128 tty_lowlevel_getch ();
130 /* my own wierd protocol base 26 - paul */
131 printf ("\033CL%c%c%c%c\n", (y1
/ 26) + 'A', (y1
% 26) + 'A', (y2
/ 26) + 'A', (y2
% 26) + 'A');
133 bytes
= (y2
- y1
) * (COLS
+ 1) + 1; /* *should* be the number of bytes read */
135 k
= g_malloc (bytes
);
144 for (cols
= 1;; cols
++)
153 for (i
= 0; i
< j
; i
++)
156 tty_gotoyx (starty
+ (i
/ cols
), 0);
157 tty_print_char (is_printable (k
[i
]) ? k
[i
] : ' ');
162 /* --------------------------------------------------------------------------------------------- */
165 look_for_rxvt_extensions (void)
167 static gboolean been_called
= FALSE
;
171 const char *e
= getenv ("RXVT_EXT");
172 rxvt_extensions
= ((e
!= NULL
) && (strcmp (e
, "1.0") == 0));
179 return rxvt_extensions
;
182 /* --------------------------------------------------------------------------------------------- */