added a new parameter for completion flags to input_new
[midnight-commander.git] / src / rxvt.c
blobda658f2e5c8045cb9c725af1764ee5b5cb91a9cc
1 /* rxvt.c - gives output lines on rxvt with a special rxvt patch
2 Copyright (C) 1997 Paul Sheer
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 #include <config.h>
21 #include <stdio.h>
22 #include <stdlib.h>
23 #include <string.h>
25 #include <sys/types.h>
26 #include <unistd.h>
28 #include "global.h"
29 #include "tty.h" /* move, addch */
30 #include "cons.saver.h"
32 static int rxvt_extensions = 0;
34 int look_for_rxvt_extensions (void)
36 static int been_called = 0;
37 const char *e;
38 if (!been_called) {
39 rxvt_extensions = 0;
40 e = getenv ("RXVT_EXT");
41 if (e)
42 if (!strcmp (e, "1.0"))
43 rxvt_extensions = 1;
44 been_called = 1;
46 if (rxvt_extensions)
47 console_flag = 4;
48 return rxvt_extensions;
51 /* my own wierd protocol base 16 - paul */
52 static int rxvt_getc (void)
54 int r;
55 unsigned char c;
56 while (read (0, &c, 1) != 1);
57 if (c == '\n')
58 return -1;
59 r = (c - 'A') * 16;
60 while (read (0, &c, 1) != 1);
61 r += (c - 'A');
62 return r;
65 extern int keybar_visible;
67 static int anything_ready (void)
69 fd_set fds;
70 struct timeval tv;
72 FD_ZERO (&fds);
73 FD_SET (0, &fds);
74 tv.tv_sec = 0;
75 tv.tv_usec = 0;
76 return select (1, &fds, 0, 0, &tv);
79 void show_rxvt_contents (int starty, unsigned char y1, unsigned char y2)
81 unsigned char *k;
82 int bytes, i, j, cols = 0;
83 y1 += (keybar_visible != 0); /* i don't knwo why we need this - paul */
84 y2 += (keybar_visible != 0);
85 while (anything_ready ())
86 getch ();
88 /* my own wierd protocol base 26 - paul */
89 printf ("\033CL%c%c%c%c\n",
90 (y1 / 26) + 'A', (y1 % 26) + 'A',
91 (y2 / 26) + 'A', (y2 % 26) + 'A');
93 bytes = (y2 - y1) * (COLS + 1) + 1; /* *should* be the number of bytes read */
94 j = 0;
95 k = g_malloc (bytes);
96 for (;;) {
97 int c;
98 c = rxvt_getc ();
99 if (c < 0)
100 break;
101 if (j < bytes)
102 k[j++] = c;
103 for (cols = 1;;cols++) {
104 c = rxvt_getc ();
105 if (c < 0)
106 break;
107 if (j < bytes)
108 k[j++] = c;
111 for (i = 0; i < j; i++) {
112 if ((i % cols) == 0)
113 move (starty + (i / cols), 0);
114 addch (is_printable (k[i]) ? k[i] : ' ');
116 g_free (k);