0
|
1 /* Communication module for TTY terminals.
|
|
2 Copyright (C) 1994, 1995 Board of Trustees, University of Illinois.
|
|
3 Copyright (C) 1995 Sun Microsystems, Inc.
|
|
4 Copyright (C) 1995, 1996 Ben Wing.
|
|
5 Copyright (C) 1996 Chuck Thompson.
|
|
6
|
|
7 This file is part of XEmacs.
|
|
8
|
|
9 XEmacs is free software; you can redistribute it and/or modify it
|
|
10 under the terms of the GNU General Public License as published by the
|
|
11 Free Software Foundation; either version 2, or (at your option) any
|
|
12 later version.
|
|
13
|
|
14 XEmacs is distributed in the hope that it will be useful, but WITHOUT
|
|
15 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
16 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
17 for more details.
|
|
18
|
|
19 You should have received a copy of the GNU General Public License
|
|
20 along with XEmacs; see the file COPYING. If not, write to
|
|
21 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
22 Boston, MA 02111-1307, USA. */
|
|
23
|
|
24 /* Synched up with: Not completely synched with FSF. Mostly divergent
|
|
25 from FSF. */
|
|
26
|
|
27 /* This file has been Mule-ized. */
|
|
28
|
|
29 /* Written by Chuck Thompson. */
|
|
30 /* Color support added by Ben Wing. */
|
|
31
|
|
32 #include <config.h>
|
|
33 #include "lisp.h"
|
|
34
|
|
35 #include "buffer.h"
|
|
36 #include "console-tty.h"
|
|
37 #include "events.h"
|
|
38 #include "faces.h"
|
|
39 #include "frame.h"
|
|
40 #include "glyphs.h"
|
|
41 #include "lstream.h"
|
|
42 #include "objects-tty.h"
|
|
43 #include "redisplay.h"
|
|
44 #include "sysdep.h"
|
|
45 #include "window.h"
|
|
46
|
|
47 /* These headers #define all kinds of common words like "columns"...
|
|
48 What a bunch of losers. If we were to include them, we'd have to
|
|
49 include them last to prevent them from messing up our own header
|
|
50 files (struct slot names, etc.). But it turns out that there are
|
|
51 other conflicts as well on some systems, so screw it: we'll just
|
|
52 re-declare the routines we use and assume the code in this file is
|
|
53 invoking them correctly. */
|
|
54 /* # include <curses.h> */
|
|
55 /* # include <term.h> */
|
185
|
56 #ifdef __cplusplus
|
|
57 extern "C" {
|
|
58 #endif
|
0
|
59 extern int tgetent (CONST char *, CONST char *);
|
|
60 extern int tgetflag (CONST char *);
|
|
61 extern int tgetnum (CONST char *);
|
|
62 extern char *tgetstr (CONST char *, char **);
|
|
63 extern void tputs (CONST char *, int, void (*)(int));
|
185
|
64 #ifdef __cplusplus
|
|
65 }
|
|
66 #endif
|
0
|
67 #define FORCE_CURSOR_UPDATE(c) send_string_to_tty_console (c, 0, 0)
|
|
68 #define OUTPUTN(c, a, n) \
|
|
69 do { \
|
|
70 cmputc_console = c; \
|
|
71 FORCE_CURSOR_UPDATE (c); \
|
|
72 tputs (a, n, cmputc); \
|
|
73 } while (0)
|
|
74 #define OUTPUT1(c, a) OUTPUTN (c, a, 1)
|
|
75 #define OUTPUTN_IF(c, a, n) \
|
|
76 do { \
|
|
77 cmputc_console = c; \
|
|
78 FORCE_CURSOR_UPDATE (c); \
|
|
79 if (a) \
|
|
80 tputs (a, n, cmputc); \
|
|
81 } while (0)
|
|
82 #define OUTPUT1_IF(c, a) OUTPUTN_IF (c, a, 1)
|
|
83
|
|
84 static void tty_output_emchar_dynarr (struct window *w,
|
|
85 struct display_line *dl,
|
185
|
86 Emchar_dynarr *buf, int xpos,
|
0
|
87 face_index findex,
|
|
88 int cursor);
|
|
89 static void tty_output_bufbyte_string (struct window *w,
|
|
90 struct display_line *dl,
|
|
91 Bufbyte *str, Bytecount len,
|
|
92 int xpos, face_index findex,
|
|
93 int cursor);
|
|
94 static void tty_turn_on_face (struct window *w, face_index findex);
|
|
95 static void tty_turn_off_face (struct window *w, face_index findex);
|
|
96 static void tty_turn_on_frame_face (struct frame *f, Lisp_Object face);
|
|
97 static void tty_turn_off_frame_face (struct frame *f, Lisp_Object face);
|
|
98
|
|
99 static void term_get_fkeys (Lisp_Object keymap, char **address);
|
|
100
|
|
101 /*****************************************************************************
|
|
102 tty_text_width
|
|
103
|
|
104 tty's don't have fonts (that we use at least), so everything is
|
|
105 considered to be fixed width. In other words, we just return len.
|
|
106 ****************************************************************************/
|
|
107 static int
|
|
108 tty_text_width (struct face_cachel *cachel, CONST Emchar *str,
|
|
109 Charcount len)
|
|
110 {
|
|
111 return emchar_string_displayed_columns (str, len);
|
|
112 }
|
|
113
|
|
114 /*****************************************************************************
|
|
115 tty_divider_width
|
|
116
|
|
117 Return the width of the vertical divider. This is a function because
|
|
118 divider_width is a console method.
|
|
119 ****************************************************************************/
|
|
120 static int
|
|
121 tty_divider_width (void)
|
|
122 {
|
|
123 return 1;
|
|
124 }
|
|
125
|
|
126 /*****************************************************************************
|
|
127 tty_divider_height
|
|
128
|
|
129 Return the width of the horizontal divider. This is a function
|
|
130 because divider_height is a console method.
|
|
131 ****************************************************************************/
|
|
132 static int
|
|
133 tty_divider_height (void)
|
|
134 {
|
|
135 return 1;
|
|
136 }
|
|
137
|
|
138 /*****************************************************************************
|
|
139 tty_eol_cursor_width
|
|
140
|
|
141 Return the width of the end-of-line cursor. This is a function
|
|
142 because eol_cursor_width is a console method.
|
|
143 ****************************************************************************/
|
|
144 static int
|
|
145 tty_eol_cursor_width (void)
|
|
146 {
|
|
147 return 1;
|
|
148 }
|
|
149
|
|
150 /*****************************************************************************
|
|
151 tty_output_begin
|
|
152
|
|
153 Perform any necessary initialization prior to an update.
|
|
154 ****************************************************************************/
|
|
155 #ifdef DEBUG_XEMACS
|
|
156 void tty_output_begin (struct device *d);
|
|
157 void
|
|
158 #else
|
|
159 static void
|
|
160 #endif
|
|
161 tty_output_begin (struct device *d)
|
|
162 {
|
|
163 #ifndef HAVE_TERMIOS
|
|
164 /* Termcap requires `ospeed' to be a global variable so we have to
|
|
165 always set it for whatever tty console we are actually currently
|
|
166 working with. */
|
|
167 ospeed = DEVICE_TTY_DATA (d)->ospeed;
|
|
168 #endif
|
|
169 }
|
|
170
|
|
171 /*****************************************************************************
|
|
172 tty_output_end
|
|
173
|
|
174 Perform any necessary flushing of queues when an update has completed.
|
|
175 ****************************************************************************/
|
|
176 #ifdef DEBUG_XEMACS
|
|
177 void tty_output_end (struct device *d);
|
|
178 void
|
|
179 #else
|
|
180 static void
|
|
181 #endif
|
|
182 tty_output_end (struct device *d)
|
|
183 {
|
|
184 struct console *c = XCONSOLE (DEVICE_CONSOLE (d));
|
|
185
|
|
186 FORCE_CURSOR_UPDATE (c);
|
|
187 Lstream_flush (XLSTREAM (CONSOLE_TTY_DATA (c)->outstream));
|
|
188 }
|
|
189
|
|
190 /*****************************************************************************
|
|
191 tty_output_display_block
|
|
192
|
|
193 Given a display line, a block number for that start line, output all
|
|
194 runes between start and end in the specified display block.
|
|
195 ****************************************************************************/
|
|
196 static void
|
|
197 tty_output_display_block (struct window *w, struct display_line *dl, int block,
|
|
198 int start, int end, int start_pixpos,
|
|
199 int cursor_start, int cursor_width,
|
|
200 int cursor_height)
|
|
201 {
|
|
202 struct frame *f = XFRAME (w->frame);
|
185
|
203 Emchar_dynarr *buf = Dynarr_new (Emchar);
|
0
|
204
|
|
205 struct display_block *db = Dynarr_atp (dl->display_blocks, block);
|
|
206 rune_dynarr *rba = db->runes;
|
|
207 struct rune *rb;
|
|
208
|
|
209 int elt = start;
|
|
210 face_index findex;
|
|
211 int xpos;
|
|
212
|
|
213 rb = Dynarr_atp (rba, elt);
|
|
214
|
|
215 if (!rb)
|
|
216 {
|
|
217 /* Nothing to do so don't do anything. */
|
|
218 return;
|
|
219 }
|
|
220 else
|
|
221 {
|
|
222 findex = rb->findex;
|
|
223 xpos = rb->xpos;
|
|
224 }
|
|
225
|
|
226 if (end < 0)
|
|
227 end = Dynarr_length (rba);
|
|
228
|
|
229 Dynarr_reset (buf);
|
|
230
|
|
231 while (elt < end && Dynarr_atp (rba, elt)->xpos < start_pixpos)
|
|
232 {
|
|
233 elt++;
|
|
234 findex = Dynarr_atp (rba, elt)->findex;
|
|
235 xpos = Dynarr_atp (rba, elt)->xpos;
|
|
236 }
|
|
237
|
|
238 while (elt < end)
|
|
239 {
|
|
240 rb = Dynarr_atp (rba, elt);
|
|
241
|
|
242 if (rb->findex == findex && rb->type == RUNE_CHAR
|
|
243 && rb->object.chr.ch != '\n'
|
|
244 && (rb->cursor_type != CURSOR_ON
|
|
245 || NILP (w->text_cursor_visible_p)))
|
|
246 {
|
|
247 Dynarr_add (buf, rb->object.chr.ch);
|
|
248 elt++;
|
|
249 }
|
|
250 else
|
|
251 {
|
|
252 if (Dynarr_length (buf))
|
|
253 {
|
|
254 tty_output_emchar_dynarr (w, dl, buf, xpos, findex, 0);
|
|
255 xpos = rb->xpos;
|
|
256 }
|
|
257 Dynarr_reset (buf);
|
|
258
|
|
259 if (rb->type == RUNE_CHAR)
|
|
260 {
|
|
261 findex = rb->findex;
|
|
262 xpos = rb->xpos;
|
|
263
|
|
264 if (rb->object.chr.ch == '\n')
|
|
265 {
|
|
266 /* Clear in case a cursor was formerly here. */
|
|
267
|
|
268 Dynarr_add (buf, ' ');
|
|
269 tty_output_emchar_dynarr (w, dl, buf, rb->xpos,
|
|
270 DEFAULT_INDEX, 0);
|
|
271 Dynarr_reset (buf);
|
|
272
|
|
273 cmgoto (f, dl->ypos - 1, rb->xpos);
|
|
274
|
|
275 elt++;
|
|
276 }
|
|
277 else if (rb->cursor_type == CURSOR_ON)
|
|
278 {
|
|
279 /* There is not a distinct eol cursor on tty's. */
|
|
280
|
|
281 Dynarr_add (buf, rb->object.chr.ch);
|
|
282 tty_output_emchar_dynarr (w, dl, buf, xpos, findex, 0);
|
|
283 Dynarr_reset (buf);
|
|
284
|
|
285 cmgoto (f, dl->ypos - 1, xpos);
|
|
286
|
|
287 xpos += rb->width;
|
|
288 elt++;
|
|
289 }
|
|
290 }
|
|
291 /* #### RUNE_HLINE is actualy a little more complicated than this
|
|
292 but at the moment it is only used to draw a turned off
|
|
293 modeline and this will suffice for that. */
|
|
294 else if (rb->type == RUNE_BLANK || rb->type == RUNE_HLINE)
|
|
295 {
|
|
296 Emchar ch_to_add;
|
|
297 int size = rb->width;
|
|
298
|
|
299 if (rb->type == RUNE_BLANK)
|
|
300 ch_to_add = ' ';
|
|
301 else
|
|
302 ch_to_add = '-';
|
|
303
|
|
304 while (size--)
|
|
305 Dynarr_add (buf, ch_to_add);
|
|
306 tty_output_emchar_dynarr (w, dl, buf, rb->xpos, findex, 0);
|
|
307
|
|
308 if (xpos >= cursor_start
|
|
309 && cursor_start < xpos + Dynarr_length (buf))
|
|
310 {
|
|
311 cmgoto (f, dl->ypos - 1, cursor_start);
|
|
312 }
|
|
313
|
|
314 Dynarr_reset (buf);
|
|
315
|
|
316 elt++;
|
|
317 if (elt < end)
|
|
318 {
|
|
319 rb = Dynarr_atp (rba, elt);
|
|
320
|
|
321 findex = rb->findex;
|
|
322 xpos = rb->xpos;
|
|
323 }
|
|
324 }
|
|
325 else if (rb->type == RUNE_DGLYPH)
|
|
326 {
|
|
327 Lisp_Object window;
|
|
328 Lisp_Object instance;
|
|
329
|
|
330 XSETWINDOW (window, w);
|
|
331 instance = glyph_image_instance (rb->object.dglyph.glyph,
|
|
332 window, ERROR_ME_NOT, 1);
|
|
333
|
|
334 if (IMAGE_INSTANCEP (instance))
|
|
335 switch (XIMAGE_INSTANCE_TYPE (instance))
|
|
336 {
|
|
337 case IMAGE_TEXT:
|
|
338 {
|
|
339 Bufbyte *temptemp;
|
|
340 Lisp_Object string =
|
|
341 XIMAGE_INSTANCE_TEXT_STRING (instance);
|
16
|
342 Bytecount len = XSTRING_LENGTH (string);
|
0
|
343
|
|
344 /* In the unlikely instance that a garbage-collect
|
|
345 occurs during encoding, we at least need to
|
|
346 copy the string.
|
|
347 */
|
|
348 temptemp = (Bufbyte *) alloca (len);
|
16
|
349 memcpy (temptemp, XSTRING_DATA (string), len);
|
0
|
350 {
|
|
351 int i;
|
|
352
|
|
353 /* Now truncate the first rb->object.dglyph.xoffset
|
|
354 columns. */
|
|
355 for (i = 0; i < rb->object.dglyph.xoffset;)
|
|
356 {
|
70
|
357 #ifdef MULE
|
|
358 Emchar ch = charptr_emchar (temptemp);
|
|
359 i += XCHARSET_COLUMNS (CHAR_CHARSET (ch));
|
|
360 #else
|
0
|
361 i++; /* telescope this */
|
70
|
362 #endif
|
0
|
363 INC_CHARPTR (temptemp);
|
|
364 }
|
|
365
|
|
366 /* If we truncated one column too many, then
|
|
367 add a space at the beginning. */
|
|
368 if (i > rb->object.dglyph.xoffset)
|
|
369 {
|
|
370 assert (i > 0);
|
|
371 *--temptemp = ' ';
|
|
372 i--;
|
|
373 }
|
|
374 len -= i;
|
|
375 }
|
|
376
|
|
377 tty_output_bufbyte_string (w, dl, temptemp, len,
|
|
378 xpos, findex, 0);
|
185
|
379
|
0
|
380 if (xpos >= cursor_start
|
|
381 && (cursor_start <
|
|
382 xpos + (bufbyte_string_displayed_columns
|
|
383 (temptemp, len))))
|
|
384 {
|
|
385 cmgoto (f, dl->ypos - 1, cursor_start);
|
|
386 }
|
|
387 }
|
|
388 break;
|
|
389
|
|
390 case IMAGE_MONO_PIXMAP:
|
|
391 case IMAGE_COLOR_PIXMAP:
|
|
392 case IMAGE_SUBWINDOW:
|
|
393 /* just do nothing here */
|
|
394 break;
|
|
395
|
|
396 case IMAGE_POINTER:
|
|
397 abort ();
|
|
398
|
|
399 case IMAGE_NOTHING:
|
|
400 /* nothing is as nothing does */
|
|
401 break;
|
|
402
|
|
403 default:
|
|
404 abort ();
|
|
405 }
|
|
406
|
|
407 xpos += rb->width;
|
|
408 elt++;
|
|
409 }
|
|
410 else
|
|
411 abort ();
|
|
412 }
|
|
413 }
|
|
414
|
|
415 if (Dynarr_length (buf))
|
|
416 tty_output_emchar_dynarr (w, dl, buf, xpos, findex, 0);
|
|
417 Dynarr_free (buf);
|
|
418
|
|
419 }
|
|
420
|
|
421
|
|
422
|
|
423 /*****************************************************************************
|
|
424 tty_output_vertical_divider
|
|
425
|
|
426 Draw a vertical divider down the left side of the given window.
|
|
427 ****************************************************************************/
|
|
428 static void
|
|
429 tty_output_vertical_divider (struct window *w, int clear)
|
|
430 {
|
|
431 struct frame *f = XFRAME (w->frame);
|
|
432 struct console *c = XCONSOLE (FRAME_CONSOLE (f));
|
|
433 int line;
|
169
|
434 int y_top = WINDOW_TEXT_TOP (w);
|
|
435 int y_bot = WINDOW_TEXT_BOTTOM (w);
|
0
|
436 unsigned char divv = '|';
|
|
437
|
122
|
438 tty_turn_on_face (w, MODELINE_INDEX);
|
169
|
439 for (line = y_top; line < y_bot; line++)
|
0
|
440 {
|
|
441 cmgoto (f, line, WINDOW_TEXT_LEFT (w) - 1);
|
|
442 send_string_to_tty_console (c, &divv, 1);
|
|
443 TTY_INC_CURSOR_X (c, 1);
|
|
444 }
|
|
445
|
|
446 /* Draw the divider in the modeline. */
|
169
|
447 cmgoto (f, y_bot, WINDOW_TEXT_LEFT (w) - 1);
|
0
|
448 send_string_to_tty_console (c, &divv, 1);
|
|
449 TTY_INC_CURSOR_X (c, 1);
|
|
450 tty_turn_off_face (w, MODELINE_INDEX);
|
|
451 }
|
|
452
|
|
453 /****************************************************************************
|
|
454 tty_clear_region
|
|
455
|
|
456 Clear the area in the box defined by the given parameters.
|
|
457 ****************************************************************************/
|
|
458 static void
|
|
459 tty_clear_region (Lisp_Object window, face_index findex, int x, int y,
|
|
460 int width, int height)
|
|
461 {
|
|
462 struct window *w = XWINDOW (window);
|
|
463 struct frame *f = XFRAME (w->frame);
|
|
464 struct console *c = XCONSOLE (FRAME_CONSOLE (f));
|
|
465 int line;
|
|
466
|
|
467 if (!width || !height)
|
|
468 return;
|
|
469
|
|
470 tty_turn_on_face (w, findex);
|
|
471 for (line = y; line < y + height; line++)
|
|
472 {
|
|
473 int col;
|
|
474
|
|
475 cmgoto (f, line, x);
|
|
476
|
|
477 if (window_is_leftmost (w)
|
|
478 && window_is_rightmost (w)
|
|
479 && TTY_SE (c).clr_to_eol)
|
|
480 {
|
|
481 OUTPUT1 (c, TTY_SE (c).clr_to_eol);
|
|
482 }
|
|
483 else
|
|
484 {
|
|
485 unsigned char sp = ' ';
|
|
486 /* #### Of course, this is all complete and utter crap. */
|
|
487 for (col = x; col < x + width; col++)
|
|
488 send_string_to_tty_console (c, &sp, 1);
|
|
489 TTY_INC_CURSOR_X (c, width);
|
|
490 }
|
|
491 }
|
|
492 tty_turn_off_face (w, findex);
|
|
493 cmgoto (f, y, x);
|
|
494 }
|
|
495
|
|
496 /*****************************************************************************
|
|
497 tty_clear_to_window_end
|
|
498
|
|
499 Clear the area between ypos1 and ypos2. Each margin area and the
|
|
500 text area is handled separately since they may each have their own
|
|
501 background color.
|
|
502 ****************************************************************************/
|
|
503 static void
|
|
504 tty_clear_to_window_end (struct window *w, int ypos1, int ypos2)
|
|
505 {
|
|
506 struct frame *f = XFRAME (w->frame);
|
|
507 struct console *c = XCONSOLE (FRAME_CONSOLE (f));
|
|
508 int x, width;
|
|
509
|
|
510 x = WINDOW_TEXT_LEFT (w);
|
|
511 width = WINDOW_TEXT_WIDTH (w);
|
|
512
|
|
513 if (window_is_rightmost (w))
|
|
514 {
|
|
515 /* #### Optimize to use clr_to_eol function of tty if available, if
|
|
516 the window is the entire width of the frame. */
|
|
517 /* #### Is this actually an optimization? */
|
|
518 int line;
|
|
519 tty_turn_on_face (w, DEFAULT_INDEX);
|
|
520 for (line = ypos1; line < ypos2; line++)
|
|
521 {
|
|
522 cmgoto (XFRAME (w->frame), line, x);
|
|
523 OUTPUT1 (c, TTY_SE (c).clr_to_eol);
|
|
524 }
|
|
525 tty_turn_off_face (w, DEFAULT_INDEX);
|
|
526 }
|
|
527 else
|
|
528 {
|
|
529 Lisp_Object window;
|
|
530
|
|
531 XSETWINDOW (window, w);
|
|
532 tty_clear_region (window, DEFAULT_INDEX, x, ypos1, width, ypos2 - ypos1);
|
|
533 }
|
|
534 }
|
|
535
|
|
536 /****************************************************************************
|
|
537 tty_clear_frame
|
|
538
|
|
539 Clear the entire frame.
|
|
540 ****************************************************************************/
|
|
541 static void
|
|
542 tty_clear_frame (struct frame *f)
|
|
543 {
|
|
544 struct console *c = XCONSOLE (FRAME_CONSOLE (f));
|
|
545
|
|
546 tty_turn_on_frame_face (f, Vdefault_face);
|
|
547 if (TTY_SE (c).clr_frame)
|
|
548 {
|
|
549 OUTPUT1 (c, TTY_SE (c).clr_frame);
|
|
550 #ifdef NOT_SURE
|
|
551 FRAME_CURSOR_X (f) = 0;
|
|
552 FRAME_CURSOR_Y (f) = 0;
|
|
553 #endif
|
|
554 }
|
|
555 else
|
|
556 {
|
|
557 #ifdef NOT_SURE
|
|
558 internal_cursor_to (f, 0, 0);
|
|
559 clear_to_end (f);
|
|
560 #else
|
|
561 /* #### Not implemented. */
|
|
562 fprintf (stderr, "Not yet.\n");
|
|
563 #endif
|
|
564 }
|
|
565 tty_turn_off_frame_face (f, Vdefault_face);
|
|
566 }
|
|
567
|
|
568 static void
|
|
569 tty_output_bufbyte_string (struct window *w, struct display_line *dl,
|
|
570 Bufbyte *str, Bytecount len, int xpos,
|
|
571 face_index findex, int cursor)
|
|
572 {
|
|
573 struct frame *f = XFRAME (w->frame);
|
|
574 struct console *c = XCONSOLE (FRAME_CONSOLE (f));
|
|
575
|
|
576 /* First position the cursor. */
|
|
577 cmgoto (f, dl->ypos - 1, xpos);
|
|
578
|
|
579 /* Enable any face properties. */
|
|
580 tty_turn_on_face (w, findex);
|
|
581
|
|
582 send_string_to_tty_console (c, str, len);
|
|
583 TTY_INC_CURSOR_X (c, bufbyte_string_displayed_columns (str, len));
|
|
584
|
|
585 /* Turn the face properties back off. */
|
|
586 tty_turn_off_face (w, findex);
|
|
587 }
|
|
588
|
185
|
589 static Bufbyte_dynarr *tty_output_emchar_dynarr_dynarr;
|
0
|
590
|
|
591 /*****************************************************************************
|
|
592 tty_output_emchar_dynarr
|
|
593
|
|
594 Given a string and a starting position, output that string in the
|
|
595 given face. If cursor is true, draw a cursor around the string.
|
|
596 ****************************************************************************/
|
|
597 static void
|
|
598 tty_output_emchar_dynarr (struct window *w, struct display_line *dl,
|
185
|
599 Emchar_dynarr *buf, int xpos, face_index findex,
|
0
|
600 int cursor)
|
|
601 {
|
|
602 if (!tty_output_emchar_dynarr_dynarr)
|
|
603 tty_output_emchar_dynarr_dynarr = Dynarr_new (Bufbyte);
|
|
604 else
|
|
605 Dynarr_reset (tty_output_emchar_dynarr_dynarr);
|
|
606
|
|
607 convert_emchar_string_into_bufbyte_dynarr (Dynarr_atp (buf, 0),
|
|
608 Dynarr_length (buf),
|
|
609 tty_output_emchar_dynarr_dynarr);
|
|
610
|
|
611 tty_output_bufbyte_string (w, dl,
|
|
612 Dynarr_atp (tty_output_emchar_dynarr_dynarr, 0),
|
|
613 Dynarr_length (tty_output_emchar_dynarr_dynarr),
|
|
614 xpos, findex, cursor);
|
|
615 }
|
|
616
|
|
617 #if 0
|
|
618
|
185
|
619 static Bufbyte_dynarr *sidcs_dynarr;
|
0
|
620
|
|
621 static void
|
|
622 substitute_in_dynamic_color_string (Lisp_Object spec, Lisp_Object string)
|
|
623 {
|
|
624 int i;
|
16
|
625 Bufbyte *specdata = XSTRING_DATA (spec);
|
|
626 Bytecount speclen = XSTRING_LENGTH (spec);
|
0
|
627
|
|
628 if (!sidcs_dynarr)
|
|
629 sidcs_dynarr = Dynarr_new (Bufbyte);
|
|
630 else
|
|
631 Dynarr_reset (sidcs_dynarr);
|
|
632
|
|
633 for (i = 0; i < speclen; i++)
|
|
634 {
|
|
635 if (specdata[i] == '%' && specdata[i+1] == '%')
|
|
636 {
|
|
637 Dynarr_add (sidcs_dynarr, '%');
|
|
638 i++;
|
|
639 }
|
|
640 else if (specdata[i] == '%' && specdata[i+1] == 's')
|
|
641 {
|
16
|
642 Dynarr_add_many (sidcs_dynarr,
|
|
643 XSTRING_DATA (string),
|
|
644 XSTRING_LENGTH (string));
|
0
|
645 i++;
|
|
646 }
|
|
647 else
|
|
648 Dynarr_add (sidcs_dynarr, specdata[i]);
|
|
649 }
|
|
650 }
|
|
651
|
|
652 #endif
|
|
653
|
|
654 static void
|
|
655 set_foreground_to (struct console *c, Lisp_Object sym)
|
|
656 {
|
|
657 Lisp_Object result;
|
|
658 Bufbyte *escseq = 0;
|
|
659 Bytecount escseqlen = 0;
|
|
660
|
|
661 result = assq_no_quit (sym, Vtty_color_alist);
|
|
662 if (!NILP (result))
|
|
663 {
|
|
664 Lisp_Object esc_seq = XCAR (XCDR (result));
|
16
|
665 escseq = XSTRING_DATA (esc_seq);
|
|
666 escseqlen = XSTRING_LENGTH (esc_seq);
|
0
|
667 }
|
|
668 #if 0
|
|
669 else if (STRINGP (Vtty_dynamic_color_fg))
|
|
670 {
|
|
671 substitute_in_dynamic_color_string (Vtty_dynamic_color_fg,
|
|
672 Fsymbol_name (sym));
|
|
673 escseq = Dynarr_atp (sidcs_dynarr, 0);
|
|
674 escseqlen = Dynarr_length (sidcs_dynarr);
|
|
675 }
|
|
676 #endif
|
|
677
|
|
678 if (escseq)
|
|
679 {
|
|
680 send_string_to_tty_console (c, escseq, escseqlen);
|
|
681 }
|
|
682 }
|
|
683
|
|
684 static void
|
|
685 set_background_to (struct console *c, Lisp_Object sym)
|
|
686 {
|
|
687 Lisp_Object result;
|
|
688 Bufbyte *escseq = 0;
|
|
689 Bytecount escseqlen = 0;
|
|
690
|
|
691 result = assq_no_quit (sym, Vtty_color_alist);
|
|
692 if (!NILP (result))
|
|
693 {
|
|
694 Lisp_Object esc_seq = XCDR (XCDR (result));
|
16
|
695 escseq = XSTRING_DATA (esc_seq);
|
|
696 escseqlen = XSTRING_LENGTH (esc_seq);
|
0
|
697 }
|
|
698 #if 0
|
|
699 else if (STRINGP (Vtty_dynamic_color_bg))
|
|
700 {
|
|
701 substitute_in_dynamic_color_string (Vtty_dynamic_color_bg,
|
|
702 Fsymbol_name (sym));
|
|
703 escseq = Dynarr_atp (sidcs_dynarr, 0);
|
|
704 escseqlen = Dynarr_length (sidcs_dynarr);
|
|
705 }
|
|
706 #endif
|
|
707
|
|
708 if (escseq)
|
|
709 {
|
|
710 send_string_to_tty_console (c, escseq, escseqlen);
|
|
711 }
|
|
712 }
|
|
713
|
|
714 static void
|
|
715 tty_turn_on_face_1 (struct console *c, int highlight_p,
|
|
716 int blinking_p, int dim_p, int underline_p,
|
|
717 int reverse_p, Lisp_Object cinst_fore,
|
|
718 Lisp_Object cinst_back)
|
|
719 {
|
|
720 if (highlight_p)
|
|
721 {
|
|
722 OUTPUT1_IF (c, TTY_SD (c).turn_on_bold);
|
|
723 }
|
|
724
|
|
725 if (blinking_p)
|
|
726 {
|
|
727 OUTPUT1_IF (c, TTY_SD (c).turn_on_blinking);
|
|
728 }
|
|
729
|
|
730 if (dim_p)
|
|
731 {
|
|
732 OUTPUT1_IF (c, TTY_SD (c).turn_on_dim);
|
|
733 }
|
|
734
|
|
735 if (underline_p)
|
|
736 {
|
|
737 /* #### punt for now if underline mode is glitchy */
|
|
738 if (!TTY_FLAGS (c).underline_width)
|
|
739 {
|
|
740 OUTPUT1_IF (c, TTY_SD (c).begin_underline);
|
|
741 }
|
|
742 }
|
|
743
|
|
744 if (reverse_p)
|
|
745 {
|
|
746 /* #### punt for now if standout mode is glitchy */
|
|
747 if (!TTY_FLAGS (c).standout_width)
|
|
748 {
|
|
749 OUTPUT1_IF (c, TTY_SD (c).begin_standout);
|
|
750 }
|
|
751 else
|
|
752 reverse_p = 0;
|
|
753 }
|
|
754
|
|
755 if (reverse_p)
|
|
756 {
|
|
757 Lisp_Object temp = cinst_fore;
|
|
758 cinst_fore = cinst_back;
|
|
759 cinst_back = temp;
|
|
760 }
|
|
761
|
|
762 if (COLOR_INSTANCEP (cinst_fore)
|
|
763 && !EQ (cinst_fore, Vthe_null_color_instance))
|
|
764 set_foreground_to (c, COLOR_INSTANCE_TTY_SYMBOL
|
|
765 (XCOLOR_INSTANCE (cinst_fore)));
|
|
766
|
|
767 if (COLOR_INSTANCEP (cinst_back)
|
|
768 && !EQ (cinst_back, Vthe_null_color_instance))
|
|
769 set_background_to (c, COLOR_INSTANCE_TTY_SYMBOL
|
|
770 (XCOLOR_INSTANCE (cinst_back)));
|
|
771 }
|
|
772
|
|
773 /*****************************************************************************
|
|
774 tty_turn_on_face
|
|
775
|
|
776 Turn on all set properties of the given face.
|
|
777 ****************************************************************************/
|
|
778 static void
|
|
779 tty_turn_on_face (struct window *w, face_index findex)
|
|
780 {
|
|
781 struct frame *f = XFRAME (w->frame);
|
|
782 struct console *c = XCONSOLE (FRAME_CONSOLE (f));
|
|
783
|
185
|
784 tty_turn_on_face_1 (c,
|
0
|
785 WINDOW_FACE_CACHEL_HIGHLIGHT_P (w, findex),
|
|
786 WINDOW_FACE_CACHEL_BLINKING_P (w, findex),
|
|
787 WINDOW_FACE_CACHEL_DIM_P (w, findex),
|
|
788 WINDOW_FACE_CACHEL_UNDERLINE_P (w, findex),
|
|
789 WINDOW_FACE_CACHEL_REVERSE_P (w, findex),
|
|
790 WINDOW_FACE_CACHEL_FOREGROUND (w, findex),
|
|
791 WINDOW_FACE_CACHEL_BACKGROUND (w, findex));
|
|
792 }
|
|
793
|
|
794 /*****************************************************************************
|
|
795 tty_turn_off_face
|
|
796
|
|
797 Turn off all set properties of the given face (revert to default
|
|
798 face). We assume that tty_turn_on_face has been called for the given
|
|
799 face so that it's properties are actually active.
|
|
800 ****************************************************************************/
|
|
801 static void
|
|
802 tty_turn_off_face (struct window *w, face_index findex)
|
|
803 {
|
|
804 struct frame *f = XFRAME (w->frame);
|
|
805 struct console *c = XCONSOLE (FRAME_CONSOLE (f));
|
|
806
|
|
807 if (WINDOW_FACE_CACHEL_REVERSE_P (w, findex))
|
|
808 {
|
|
809 /* #### punt for now if standout mode is glitchy */
|
|
810 if (!TTY_FLAGS (c).standout_width)
|
|
811 {
|
|
812 OUTPUT1_IF (c, TTY_SD (c).end_standout);
|
|
813 }
|
|
814 }
|
|
815
|
|
816 if (WINDOW_FACE_CACHEL_UNDERLINE_P (w, findex))
|
|
817 {
|
|
818 /* #### punt for now if underline mode is glitchy */
|
|
819 if (!TTY_FLAGS (c).underline_width)
|
|
820 {
|
|
821 OUTPUT1_IF (c, TTY_SD (c).end_underline);
|
|
822 }
|
|
823 }
|
|
824
|
|
825 if (WINDOW_FACE_CACHEL_HIGHLIGHT_P (w, findex) ||
|
|
826 WINDOW_FACE_CACHEL_BLINKING_P (w, findex) ||
|
|
827 WINDOW_FACE_CACHEL_DIM_P (w, findex) ||
|
|
828 !EQ (WINDOW_FACE_CACHEL_FOREGROUND (w, findex),
|
|
829 Vthe_null_color_instance) ||
|
|
830 !EQ (WINDOW_FACE_CACHEL_BACKGROUND (w, findex),
|
|
831 Vthe_null_color_instance))
|
|
832 {
|
|
833 OUTPUT1_IF (c, TTY_SD (c).turn_off_attributes);
|
|
834 }
|
|
835 }
|
|
836
|
|
837 /*****************************************************************************
|
|
838 tty_turn_on_frame_face
|
|
839
|
|
840 Turn on all set properties of the given face.
|
|
841 ****************************************************************************/
|
|
842 static void
|
|
843 tty_turn_on_frame_face (struct frame *f, Lisp_Object face)
|
|
844 {
|
|
845 Lisp_Object frame = Qnil;
|
|
846 struct console *c = XCONSOLE (FRAME_CONSOLE (f));
|
185
|
847
|
0
|
848 XSETFRAME (frame, f);
|
185
|
849 tty_turn_on_face_1 (c,
|
0
|
850 FACE_HIGHLIGHT_P (face, frame),
|
|
851 FACE_BLINKING_P (face, frame),
|
|
852 FACE_DIM_P (face, frame),
|
|
853 FACE_UNDERLINE_P (face, frame),
|
|
854 FACE_REVERSE_P (face, frame),
|
|
855 FACE_FOREGROUND (face, frame),
|
|
856 FACE_BACKGROUND (face, frame));
|
|
857 }
|
|
858
|
|
859 /*****************************************************************************
|
|
860 tty_turn_off_frame_face
|
|
861
|
|
862 Turn off all set properties of the given face (revert to default
|
|
863 face). We assume that tty_turn_on_face has been called for the given
|
|
864 face so that it's properties are actually active.
|
|
865 ****************************************************************************/
|
|
866 static void
|
|
867 tty_turn_off_frame_face (struct frame *f, Lisp_Object face)
|
|
868 {
|
|
869 Lisp_Object frame = Qnil;
|
|
870 struct console *c = XCONSOLE (FRAME_CONSOLE (f));
|
|
871
|
|
872 XSETFRAME (frame, f);
|
|
873
|
|
874 if (FACE_REVERSE_P (face, frame))
|
|
875 {
|
|
876 /* #### punt for now if standout mode is glitchy */
|
|
877 if (!TTY_FLAGS (c).standout_width)
|
|
878 {
|
|
879 OUTPUT1_IF (c, TTY_SD (c).end_standout);
|
|
880 }
|
|
881 }
|
|
882
|
|
883 if (FACE_UNDERLINE_P (face, frame))
|
|
884 {
|
|
885 /* #### punt for now if underline mode is glitchy */
|
|
886 if (!TTY_FLAGS (c).underline_width)
|
|
887 {
|
|
888 OUTPUT1_IF (c, TTY_SD (c).end_underline);
|
|
889 }
|
|
890 }
|
|
891
|
|
892 if (FACE_HIGHLIGHT_P (face, frame) ||
|
|
893 FACE_BLINKING_P (face, frame) ||
|
|
894 FACE_DIM_P (face, frame) ||
|
|
895 !EQ (FACE_FOREGROUND (face, frame), Vthe_null_color_instance) ||
|
|
896 !EQ (FACE_BACKGROUND (face, frame), Vthe_null_color_instance))
|
|
897 {
|
|
898 OUTPUT1_IF (c, TTY_SD (c).turn_off_attributes);
|
|
899 }
|
|
900 }
|
|
901
|
|
902 /*****************************************************************************
|
|
903 set_tty_modes
|
|
904
|
|
905 Sets up various parameters on tty modes.
|
|
906 ****************************************************************************/
|
|
907 void
|
|
908 set_tty_modes (struct console *c)
|
|
909 {
|
|
910 if (!CONSOLE_TTY_P (c))
|
|
911 return;
|
|
912
|
|
913 OUTPUT1_IF (c, TTY_SD (c).init_motion);
|
|
914 OUTPUT1_IF (c, TTY_SD (c).cursor_visible);
|
|
915 OUTPUT1_IF (c, TTY_SD (c).keypad_on);
|
|
916 }
|
|
917
|
|
918 /*****************************************************************************
|
|
919 reset_tty_modes
|
|
920
|
|
921 Restore default state of tty.
|
|
922 ****************************************************************************/
|
|
923 void
|
|
924 reset_tty_modes (struct console *c)
|
|
925 {
|
|
926 if (!CONSOLE_TTY_P (c))
|
|
927 return;
|
|
928
|
122
|
929 OUTPUT1_IF (c, TTY_SD (c).orig_pair);
|
0
|
930 OUTPUT1_IF (c, TTY_SD (c).keypad_off);
|
|
931 OUTPUT1_IF (c, TTY_SD (c).cursor_normal);
|
|
932 OUTPUT1_IF (c, TTY_SD (c).end_motion);
|
|
933 tty_output_end (XDEVICE (CONSOLE_SELECTED_DEVICE (c)));
|
|
934 }
|
|
935
|
|
936 /*****************************************************************************
|
|
937 tty_redisplay_shutdown
|
|
938
|
|
939 Clear the frame and position the cursor properly for exiting.
|
|
940 ****************************************************************************/
|
|
941 void
|
|
942 tty_redisplay_shutdown (struct console *c)
|
|
943 {
|
|
944 Lisp_Object dev = CONSOLE_SELECTED_DEVICE (c);
|
|
945
|
|
946 if (!GC_NILP (dev))
|
|
947 {
|
|
948 Lisp_Object frm = DEVICE_SELECTED_FRAME (XDEVICE (dev));
|
|
949
|
|
950 if (!GC_NILP (frm))
|
|
951 {
|
|
952 struct frame *f = XFRAME (frm);
|
|
953
|
|
954 /* Clear the bottom line of the frame. */
|
|
955 tty_clear_region (FRAME_SELECTED_WINDOW (f), DEFAULT_INDEX, 0,
|
|
956 f->height, f->width, 1);
|
|
957
|
|
958 /* And then stick the cursor there. */
|
|
959 cmgoto (f, f->height, 0);
|
|
960 tty_output_end (XDEVICE (dev));
|
|
961 }
|
|
962 }
|
|
963 }
|
|
964
|
|
965
|
|
966 /* #### Everything below here is old shit. It should either be moved
|
|
967 up or removed. */
|
|
968
|
|
969
|
|
970 /* FLAGS - these don't need to be console local since only one console
|
|
971 can be being updated at a time. */
|
|
972 static int insert_mode_on; /* nonzero if in insert mode */
|
|
973 static int standout_mode_on; /* nonzero if in standout mode */
|
|
974 static int underline_mode_on; /* nonzero if in underline mode */
|
|
975 static int alternate_mode_on; /* nonzero if in alternate char set */
|
|
976 static int attributes_on; /* nonzero if any attributes on */
|
|
977
|
|
978 #ifdef NOT_YET
|
|
979 static void
|
|
980 turn_on_insert (struct frame *f)
|
|
981 {
|
|
982 struct console *c = XCONSOLE (FRAME_CONSOLE (f));
|
|
983
|
|
984 if (!insert_mode_on)
|
|
985 OUTPUT1_IF (c, TTY_SE (c).begin_ins_mode);
|
|
986 insert_mode_on = 1;
|
|
987 }
|
|
988
|
|
989 static void
|
|
990 turn_off_insert (struct frame *f)
|
|
991 {
|
|
992 struct console *c = XCONSOLE (FRAME_CONSOLE (f));
|
|
993
|
|
994 if (insert_mode_on)
|
|
995 OUTPUT1 (c, TTY_SE (c).end_ins_mode);
|
|
996 insert_mode_on = 0;
|
|
997 }
|
|
998
|
|
999 static void
|
|
1000 internal_cursor_to (struct frame *f, int row, int col)
|
|
1001 {
|
|
1002 struct console *c = XCONSOLE (FRAME_CONSOLE (f));
|
|
1003
|
|
1004 if (!TTY_FLAGS (c).insert_mode_motion)
|
|
1005 turn_off_insert (f);
|
|
1006 if (!TTY_FLAGS (c).standout_motion)
|
|
1007 {
|
|
1008 turn_off_standout (f);
|
|
1009 turn_off_underline (f);
|
|
1010 turn_off_alternate (f);
|
|
1011 }
|
|
1012
|
|
1013 cmgoto (f, row, col);
|
|
1014 }
|
|
1015
|
|
1016 static void
|
|
1017 clear_to_end (struct frame *f)
|
|
1018 {
|
|
1019 struct console *c = XCONSOLE (FRAME_CONSOLE (f));
|
|
1020
|
|
1021 /* assumes cursor is already positioned */
|
|
1022 if (TTY_SE (c).clr_from_cursor)
|
|
1023 {
|
|
1024 OUTPUT1 (c, TTY_SE (c).clr_from_cursor);
|
|
1025 }
|
|
1026 else
|
|
1027 {
|
|
1028 int line = FRAME_CURSOR_Y (f);
|
|
1029
|
|
1030 while (line < FRAME_HEIGHT (f))
|
|
1031 {
|
|
1032 internal_cursor_to (f, line, 0);
|
|
1033 OUTPUT1 (c, TTY_SE (c).clr_to_eol);
|
|
1034 }
|
|
1035 }
|
|
1036 }
|
|
1037 #endif /* 0 */
|
|
1038
|
|
1039 #if 0
|
|
1040 /*
|
|
1041 * clear from last visible line on window to window end (presumably
|
|
1042 * the line above window's modeline
|
|
1043 */
|
|
1044 static void
|
|
1045 tty_clear_window_end (struct window *w, int ystart, int yend)
|
|
1046 {
|
|
1047 struct console *c = XCONSOLE (WINDOW_CONSOLE (w));
|
|
1048 int line;
|
|
1049
|
|
1050 for (line = ystart; line < yend; line++)
|
|
1051 {
|
|
1052 cmgoto (XFRAME (w->frame), line, 0);
|
|
1053 OUTPUT1 (c, TTY_SE (c).clr_to_eol);
|
|
1054 }
|
|
1055 }
|
|
1056
|
|
1057 #endif /* 0 */
|
|
1058
|
|
1059 static int
|
|
1060 tty_flash (struct device *d)
|
|
1061 {
|
|
1062 struct console *c = XCONSOLE (DEVICE_CONSOLE (d));
|
|
1063 if (TTY_SD (c).visual_bell)
|
|
1064 {
|
|
1065 OUTPUT1 (c, TTY_SD (c).visual_bell);
|
|
1066 Lstream_flush (XLSTREAM (CONSOLE_TTY_DATA (c)->outstream));
|
|
1067 return 1;
|
|
1068 }
|
|
1069 else
|
|
1070 return 0;
|
|
1071 }
|
|
1072
|
|
1073 /*
|
|
1074 * tty_ring_bell - sound an audio beep.
|
|
1075 */
|
|
1076 static void
|
|
1077 tty_ring_bell (struct device *d, int volume, int pitch, int duration)
|
|
1078 {
|
|
1079 struct console *c = XCONSOLE (DEVICE_CONSOLE (d));
|
|
1080
|
82
|
1081 if (volume)
|
|
1082 {
|
|
1083 OUTPUT1 (c, TTY_SD (c).audio_bell);
|
|
1084 Lstream_flush (XLSTREAM (CONSOLE_TTY_DATA (c)->outstream));
|
|
1085 }
|
0
|
1086 }
|
|
1087
|
|
1088
|
|
1089 int
|
|
1090 init_tty_for_redisplay (struct device *d, char *terminal_type)
|
|
1091 {
|
|
1092 int status;
|
|
1093 char entry_buffer[2044];
|
|
1094 /* char temp_buffer[2044]; */
|
|
1095 char *bufptr;
|
|
1096 struct console *c = XCONSOLE (DEVICE_CONSOLE (d));
|
|
1097
|
|
1098 /* What we should really do is allocate just enough space for
|
|
1099 the actual strings that are stored; but this would require
|
|
1100 doing this after all the tgetstr()s and adjusting all the
|
|
1101 pointers. */
|
|
1102 CONSOLE_TTY_DATA (c)->term_entry_buffer = (char *) xmalloc (2044);
|
185
|
1103 bufptr = CONSOLE_TTY_DATA (c)->term_entry_buffer;
|
0
|
1104
|
209
|
1105 #if !defined(WIN32)
|
|
1106 /* SIGTT* don't exist under win32 */
|
2
|
1107 EMACS_BLOCK_SIGNAL (SIGTTOU);
|
209
|
1108 #endif
|
0
|
1109 status = tgetent (entry_buffer, terminal_type);
|
209
|
1110 #if !defined(WIN32)
|
2
|
1111 EMACS_UNBLOCK_SIGNAL (SIGTTOU);
|
209
|
1112 #endif
|
0
|
1113 #if 0
|
|
1114 if (status < 0)
|
|
1115 return TTY_UNABLE_OPEN_DATABASE;
|
|
1116 else if (status == 0)
|
|
1117 return TTY_TYPE_UNDEFINED;
|
|
1118 #endif
|
|
1119 /* Under Linux at least, <0 is returned for TTY_TYPE_UNDEFINED. --ben */
|
|
1120 if (status <= 0)
|
|
1121 return TTY_TYPE_UNDEFINED;
|
|
1122
|
|
1123 /*
|
|
1124 * Establish the terminal size.
|
|
1125 */
|
|
1126 /* First try to get the info from the system. If that fails, check
|
|
1127 the termcap entry. */
|
|
1128 get_tty_device_size (d, &CONSOLE_TTY_DATA (c)->width,
|
|
1129 &CONSOLE_TTY_DATA (c)->height);
|
|
1130
|
|
1131 if (CONSOLE_TTY_DATA (c)->width <= 0)
|
|
1132 CONSOLE_TTY_DATA (c)->width = tgetnum ("co");
|
|
1133 if (CONSOLE_TTY_DATA (c)->height <= 0)
|
|
1134 CONSOLE_TTY_DATA (c)->height = tgetnum ("li");
|
|
1135
|
|
1136 if (CONSOLE_TTY_DATA (c)->width <= 0 || CONSOLE_TTY_DATA (c)->height <= 0)
|
|
1137 return TTY_SIZE_UNSPECIFIED;
|
|
1138
|
|
1139 /*
|
|
1140 * Initialize cursor motion information.
|
|
1141 */
|
|
1142
|
|
1143 /* local cursor movement */
|
|
1144 TTY_CM (c).up = tgetstr ("up", &bufptr);
|
|
1145 TTY_CM (c).down = tgetstr ("do", &bufptr);
|
|
1146 TTY_CM (c).left = tgetstr ("le", &bufptr);
|
|
1147 TTY_CM (c).right = tgetstr ("nd", &bufptr);
|
|
1148 TTY_CM (c).home = tgetstr ("ho", &bufptr);
|
|
1149 TTY_CM (c).low_left = tgetstr ("ll", &bufptr);
|
|
1150 TTY_CM (c).car_return = tgetstr ("cr", &bufptr);
|
|
1151
|
|
1152 /* absolute cursor motion */
|
|
1153 TTY_CM (c).abs = tgetstr ("cm", &bufptr);
|
|
1154 TTY_CM (c).hor_abs = tgetstr ("ch", &bufptr);
|
|
1155 TTY_CM (c).ver_abs = tgetstr ("cv", &bufptr);
|
|
1156
|
|
1157 /* Verify that the terminal is powerful enough to run Emacs */
|
|
1158 if (!TTY_CM (c).abs)
|
|
1159 {
|
|
1160 if (!TTY_CM (c).up || !TTY_CM (c).down
|
|
1161 || !TTY_CM (c).left || !TTY_CM (c).right)
|
|
1162 return TTY_TYPE_INSUFFICIENT;
|
|
1163 }
|
|
1164
|
|
1165 /* parameterized local cursor movement */
|
|
1166 TTY_CM (c).multi_up = tgetstr ("UP", &bufptr);
|
|
1167 TTY_CM (c).multi_down = tgetstr ("DO", &bufptr);
|
|
1168 TTY_CM (c).multi_left = tgetstr ("LE", &bufptr);
|
|
1169 TTY_CM (c).multi_right = tgetstr ("RI", &bufptr);
|
|
1170
|
|
1171 /* scrolling */
|
|
1172 TTY_CM (c).scroll_forw = tgetstr ("sf", &bufptr);
|
|
1173 TTY_CM (c).scroll_back = tgetstr ("sr", &bufptr);
|
|
1174 TTY_CM (c).multi_scroll_forw = tgetstr ("SF", &bufptr);
|
|
1175 TTY_CM (c).multi_scroll_back = tgetstr ("SR", &bufptr);
|
|
1176 TTY_CM (c).set_scroll_region = tgetstr ("cs", &bufptr);
|
|
1177
|
|
1178
|
|
1179 /*
|
|
1180 * Initialize screen editing information.
|
|
1181 */
|
|
1182
|
|
1183 /* adding to the screen */
|
|
1184 TTY_SE (c).ins_line = tgetstr ("al", &bufptr);
|
|
1185 TTY_SE (c).multi_ins_line = tgetstr ("AL", &bufptr);
|
|
1186 TTY_SE (c).repeat = tgetstr ("rp", &bufptr);
|
|
1187 TTY_SE (c).begin_ins_mode = tgetstr ("im", &bufptr);
|
|
1188 TTY_SE (c).end_ins_mode = tgetstr ("ei", &bufptr);
|
|
1189 TTY_SE (c).ins_char = tgetstr ("ic", &bufptr);
|
|
1190 TTY_SE (c).multi_ins_char = tgetstr ("IC", &bufptr);
|
|
1191 TTY_SE (c).insert_pad = tgetstr ("ip", &bufptr);
|
|
1192
|
|
1193 /* deleting from the screen */
|
|
1194 TTY_SE (c).clr_frame = tgetstr ("cl", &bufptr);
|
|
1195 TTY_SE (c).clr_from_cursor = tgetstr ("cd", &bufptr);
|
|
1196 TTY_SE (c).clr_to_eol = tgetstr ("ce", &bufptr);
|
|
1197 TTY_SE (c).del_line = tgetstr ("dl", &bufptr);
|
|
1198 TTY_SE (c).multi_del_line = tgetstr ("DL", &bufptr);
|
|
1199 TTY_SE (c).del_char = tgetstr ("dc", &bufptr);
|
|
1200 TTY_SE (c).multi_del_char = tgetstr ("DC", &bufptr);
|
|
1201 TTY_SE (c).begin_del_mode = tgetstr ("dm", &bufptr);
|
|
1202 TTY_SE (c).end_del_mode = tgetstr ("ed", &bufptr);
|
|
1203 TTY_SE (c).erase_at_cursor = tgetstr ("ec", &bufptr);
|
|
1204
|
|
1205
|
|
1206 /*
|
|
1207 * Initialize screen display information.
|
|
1208 */
|
|
1209 TTY_SD (c).begin_standout = tgetstr ("so", &bufptr);
|
|
1210 TTY_SD (c).end_standout = tgetstr ("se", &bufptr);
|
|
1211 TTY_SD (c).begin_underline = tgetstr ("us", &bufptr);
|
|
1212 TTY_SD (c).end_underline = tgetstr ("ue", &bufptr);
|
|
1213 TTY_SD (c).begin_alternate = tgetstr ("as", &bufptr);
|
|
1214 TTY_SD (c).end_alternate = tgetstr ("ae", &bufptr);
|
|
1215 TTY_SD (c).turn_on_reverse = tgetstr ("mr", &bufptr);
|
|
1216 TTY_SD (c).turn_on_blinking = tgetstr ("mb", &bufptr);
|
|
1217 TTY_SD (c).turn_on_bold = tgetstr ("md", &bufptr);
|
|
1218 TTY_SD (c).turn_on_dim = tgetstr ("mh", &bufptr);
|
|
1219 TTY_SD (c).turn_off_attributes = tgetstr ("me", &bufptr);
|
122
|
1220 TTY_SD (c).orig_pair = tgetstr ("op", &bufptr);
|
0
|
1221
|
|
1222 TTY_SD (c).visual_bell = tgetstr ("vb", &bufptr);
|
|
1223 TTY_SD (c).audio_bell = tgetstr ("bl", &bufptr);
|
|
1224 if (!TTY_SD (c).audio_bell)
|
|
1225 {
|
|
1226 /* If audio_bell doesn't get set, then assume C-g. This is gross and
|
|
1227 ugly but is what Emacs has done from time immortal. */
|
|
1228 TTY_SD (c).audio_bell = "\07";
|
|
1229 }
|
|
1230
|
|
1231 TTY_SD (c).cursor_visible = tgetstr ("ve", &bufptr);
|
|
1232 TTY_SD (c).cursor_normal = tgetstr ("vs", &bufptr);
|
|
1233 TTY_SD (c).init_motion = tgetstr ("ti", &bufptr);
|
|
1234 TTY_SD (c).end_motion = tgetstr ("te", &bufptr);
|
|
1235 TTY_SD (c).keypad_on = tgetstr ("ks", &bufptr);
|
|
1236 TTY_SD (c).keypad_off = tgetstr ("ke", &bufptr);
|
|
1237
|
|
1238
|
|
1239 /*
|
|
1240 * Initialize additional terminal information.
|
|
1241 */
|
|
1242 TTY_FLAGS (c).must_write_spaces = tgetflag ("in");
|
|
1243 TTY_FLAGS (c).insert_mode_motion = tgetflag ("mi");
|
|
1244 TTY_FLAGS (c).standout_motion = tgetflag ("ms");
|
|
1245 TTY_FLAGS (c).memory_above_frame = tgetflag ("da");
|
|
1246 TTY_FLAGS (c).memory_below_frame = tgetflag ("db");
|
|
1247 TTY_FLAGS (c).standout_width = tgetnum ("sg");
|
|
1248 TTY_FLAGS (c).underline_width = tgetnum ("ug");
|
|
1249
|
|
1250 if (TTY_FLAGS (c).standout_width == -1)
|
|
1251 TTY_FLAGS (c).standout_width = 0;
|
|
1252 if (TTY_FLAGS (c).underline_width == -1)
|
|
1253 TTY_FLAGS (c).underline_width = 0;
|
|
1254
|
185
|
1255 TTY_FLAGS (c).meta_key =
|
0
|
1256 eight_bit_tty (d) ? tgetflag ("km") || tgetflag ("MT") ? 1 : 2 : 0;
|
185
|
1257
|
|
1258
|
0
|
1259 /*
|
|
1260 * Setup the costs tables for this tty console.
|
|
1261 */
|
|
1262 cm_cost_init (c);
|
|
1263
|
|
1264 /*
|
|
1265 * Initialize local flags.
|
|
1266 */
|
|
1267 insert_mode_on = 0;
|
|
1268 standout_mode_on = 0;
|
|
1269 underline_mode_on = 0;
|
|
1270 alternate_mode_on = 0;
|
|
1271 attributes_on = 0;
|
|
1272
|
|
1273 /*
|
|
1274 * Attempt to initialise the function_key_map to
|
|
1275 * some kind of sensible value
|
|
1276 */
|
|
1277
|
|
1278 term_get_fkeys (c->function_key_map, &bufptr);
|
|
1279
|
|
1280 {
|
|
1281 /* check for ANSI set-foreground and set-background strings,
|
|
1282 and assume color if so.
|
|
1283
|
|
1284 #### we should support the other (non-ANSI) ways of specifying
|
|
1285 color, too. */
|
|
1286 char foobuf[500];
|
|
1287 char *fooptr = foobuf;
|
185
|
1288 if ((tgetstr ("AB", &fooptr) && tgetstr ("AF", &fooptr)) ||
|
|
1289 (tgetstr ("Sf", &fooptr) && tgetstr ("Sb", &fooptr)) ||
|
|
1290 ((tgetnum ("Co") > 0) && (tgetnum ("pa") > 0)))
|
0
|
1291 DEVICE_CLASS (d) = Qcolor;
|
|
1292 else
|
|
1293 DEVICE_CLASS (d) = Qmono;
|
|
1294 }
|
|
1295
|
|
1296 return TTY_INIT_SUCCESS;
|
|
1297 }
|
|
1298
|
|
1299 struct fkey_table
|
|
1300 {
|
|
1301 CONST char *cap, *name;
|
|
1302 };
|
|
1303
|
|
1304 /* Termcap capability names that correspond directly to X keysyms.
|
|
1305 Some of these (marked "terminfo") aren't supplied by old-style
|
|
1306 (Berkeley) termcap entries. They're listed in X keysym order;
|
|
1307 except we put the keypad keys first, so that if they clash with
|
|
1308 other keys (as on the IBM PC keyboard) they get overridden.
|
|
1309 */
|
|
1310
|
|
1311 static struct fkey_table keys[] =
|
|
1312 {
|
|
1313 {"kh", "home"}, /* termcap */
|
|
1314 {"kl", "left"}, /* termcap */
|
|
1315 {"ku", "up"}, /* termcap */
|
|
1316 {"kr", "right"}, /* termcap */
|
|
1317 {"kd", "down"}, /* termcap */
|
|
1318 {"%8", "prior"}, /* terminfo */
|
|
1319 {"%5", "next"}, /* terminfo */
|
|
1320 {"@7", "end"}, /* terminfo */
|
|
1321 {"@1", "begin"}, /* terminfo */
|
|
1322 {"*6", "select"}, /* terminfo */
|
|
1323 {"%9", "print"}, /* terminfo */
|
|
1324 {"@4", "execute"}, /* terminfo --- actually the `command' key */
|
|
1325 /*
|
|
1326 * "insert" --- see below
|
|
1327 */
|
|
1328 {"&8", "undo"}, /* terminfo */
|
|
1329 {"%0", "redo"}, /* terminfo */
|
|
1330 {"%7", "menu"}, /* terminfo --- actually the `options' key */
|
|
1331 {"@0", "find"}, /* terminfo */
|
|
1332 {"@2", "cancel"}, /* terminfo */
|
|
1333 {"%1", "help"}, /* terminfo */
|
|
1334 /*
|
|
1335 * "break" goes here, but can't be reliably intercepted with termcap
|
|
1336 */
|
|
1337 {"&4", "reset"}, /* terminfo --- actually `restart' */
|
|
1338 /*
|
|
1339 * "system" and "user" --- no termcaps
|
|
1340 */
|
|
1341 {"kE", "clearline"}, /* terminfo */
|
|
1342 {"kA", "insertline"}, /* terminfo */
|
|
1343 {"kL", "deleteline"}, /* terminfo */
|
|
1344 {"kI", "insertchar"}, /* terminfo */
|
|
1345 {"kD", "delete"}, /* terminfo */
|
|
1346 {"kB", "backtab"}, /* terminfo */
|
|
1347 /*
|
74
|
1348 * "kp-backtab", "kp-space", "kp-tab" --- no termcaps
|
0
|
1349 */
|
74
|
1350 {"@8", "kp-enter"}, /* terminfo */
|
0
|
1351 /*
|
74
|
1352 * "kp-f1", "kp-f2", "kp-f3" "kp-f4",
|
|
1353 * "kp-multiply", "kp-add", "kp-separator",
|
|
1354 * "kp-subtract", "kp-decimal", "kp-divide", "kp-0";
|
0
|
1355 * --- no termcaps for any of these.
|
|
1356 */
|
74
|
1357 {"K4", "kp-1"}, /* terminfo */
|
0
|
1358 /*
|
74
|
1359 * "kp-2" --- no termcap
|
0
|
1360 */
|
74
|
1361 {"K5", "kp-3"}, /* terminfo */
|
0
|
1362 /*
|
74
|
1363 * "kp-4" --- no termcap
|
0
|
1364 */
|
74
|
1365 {"K2", "kp-5"}, /* terminfo */
|
0
|
1366 /*
|
74
|
1367 * "kp-6" --- no termcap
|
0
|
1368 */
|
74
|
1369 {"K1", "kp-7"}, /* terminfo */
|
0
|
1370 /*
|
74
|
1371 * "kp-8" --- no termcap
|
0
|
1372 */
|
74
|
1373 {"K3", "kp-9"}, /* terminfo */
|
0
|
1374 /*
|
74
|
1375 * "kp-equal" --- no termcap
|
0
|
1376 */
|
|
1377 {"k1", "f1"},
|
|
1378 {"k2", "f2"},
|
|
1379 {"k3", "f3"},
|
|
1380 {"k4", "f4"},
|
|
1381 {"k5", "f5"},
|
|
1382 {"k6", "f6"},
|
|
1383 {"k7", "f7"},
|
|
1384 {"k8", "f8"},
|
|
1385 {"k9", "f9"},
|
|
1386 };
|
|
1387
|
|
1388 static char **term_get_fkeys_arg;
|
|
1389
|
|
1390 static Lisp_Object term_get_fkeys_1 (Lisp_Object keymap);
|
|
1391 static Lisp_Object term_get_fkeys_error (Lisp_Object err, Lisp_Object arg);
|
|
1392
|
|
1393 /* Find the escape codes sent by the function keys for Vfunction_key_map.
|
185
|
1394 This function scans the termcap function key sequence entries, and
|
0
|
1395 adds entries to Vfunction_key_map for each function key it finds. */
|
|
1396
|
|
1397 static void
|
|
1398 term_get_fkeys (Lisp_Object keymap, char **address)
|
|
1399 {
|
|
1400 /* We run the body of the function (term_get_fkeys_1) and ignore all Lisp
|
|
1401 errors during the call. The only errors should be from Fdefine_key
|
|
1402 when given a key sequence containing an invalid prefix key. If the
|
|
1403 termcap defines function keys which use a prefix that is already bound
|
|
1404 to a command by the default bindings, we should silently ignore that
|
|
1405 function key specification, rather than giving the user an error and
|
|
1406 refusing to run at all on such a terminal. */
|
|
1407
|
|
1408 term_get_fkeys_arg = address;
|
|
1409
|
|
1410 condition_case_1 (Qerror,
|
|
1411 term_get_fkeys_1, keymap,
|
|
1412 term_get_fkeys_error, Qnil);
|
|
1413 }
|
|
1414
|
|
1415 static Lisp_Object
|
|
1416 term_get_fkeys_error (Lisp_Object err, Lisp_Object arg)
|
|
1417 {
|
|
1418 return arg;
|
|
1419 }
|
|
1420
|
|
1421 static Lisp_Object
|
|
1422 term_get_fkeys_1 (Lisp_Object function_key_map)
|
|
1423 {
|
|
1424 int i;
|
|
1425
|
|
1426 char **address = term_get_fkeys_arg;
|
|
1427
|
193
|
1428 for (i = 0; i < countof (keys); i++)
|
0
|
1429 {
|
|
1430 char *sequence = tgetstr (keys[i].cap, address);
|
|
1431 if (sequence)
|
|
1432 Fdefine_key (function_key_map,
|
193
|
1433 build_ext_string (sequence, FORMAT_BINARY),
|
0
|
1434 vector1 (intern (keys[i].name)));
|
|
1435 }
|
|
1436
|
|
1437 /* The uses of the "k0" capability are inconsistent; sometimes it
|
|
1438 describes F10, whereas othertimes it describes F0 and "k;" describes F10.
|
|
1439 We will attempt to politely accommodate both systems by testing for
|
|
1440 "k;", and if it is present, assuming that "k0" denotes F0, otherwise F10.
|
|
1441 */
|
|
1442 {
|
|
1443 char *k_semi = tgetstr ("k;", address);
|
|
1444 char *k0 = tgetstr ("k0", address);
|
|
1445 CONST char *k0_name = "f10";
|
|
1446
|
|
1447 if (k_semi)
|
|
1448 {
|
193
|
1449 Fdefine_key (function_key_map, build_ext_string (k_semi, FORMAT_BINARY),
|
0
|
1450 vector1 (intern ("f10")));
|
|
1451 k0_name = "f0";
|
|
1452 }
|
|
1453
|
|
1454 if (k0)
|
193
|
1455 Fdefine_key (function_key_map, build_ext_string (k0, FORMAT_BINARY),
|
0
|
1456 vector1 (intern (k0_name)));
|
|
1457 }
|
|
1458
|
|
1459 /* Set up cookies for numbered function keys above f10. */
|
|
1460 {
|
|
1461 char fcap[3], fkey[4];
|
|
1462
|
|
1463 fcap[0] = 'F'; fcap[2] = '\0';
|
|
1464 for (i = 11; i < 64; i++)
|
|
1465 {
|
|
1466 if (i <= 19)
|
|
1467 fcap[1] = '1' + i - 11;
|
|
1468 else if (i <= 45)
|
|
1469 fcap[1] = 'A' + i - 20;
|
|
1470 else
|
|
1471 fcap[1] = 'a' + i - 46;
|
|
1472
|
|
1473 {
|
|
1474 char *sequence = tgetstr (fcap, address);
|
|
1475 if (sequence)
|
|
1476 {
|
|
1477 sprintf (fkey, "f%d", i);
|
|
1478 Fdefine_key (function_key_map,
|
193
|
1479 build_ext_string (sequence, FORMAT_BINARY),
|
0
|
1480 vector1 (intern (fkey)));
|
|
1481 }
|
|
1482 }
|
|
1483 }
|
|
1484 }
|
|
1485
|
|
1486 /*
|
|
1487 * Various mappings to try and get a better fit.
|
|
1488 */
|
|
1489 {
|
|
1490 #define CONDITIONAL_REASSIGN(cap1, cap2, sym) \
|
|
1491 if (!tgetstr (cap1, address)) \
|
|
1492 { \
|
|
1493 char *sequence = tgetstr (cap2, address); \
|
|
1494 if (sequence) \
|
|
1495 Fdefine_key (function_key_map, \
|
193
|
1496 build_ext_string (sequence, FORMAT_BINARY), \
|
0
|
1497 vector1 (intern (sym))); \
|
|
1498 }
|
185
|
1499
|
0
|
1500 /* if there's no key_next keycap, map key_npage to `next' keysym */
|
|
1501 CONDITIONAL_REASSIGN ("%5", "kN", "next");
|
|
1502 /* if there's no key_prev keycap, map key_ppage to `previous' keysym */
|
|
1503 CONDITIONAL_REASSIGN ("%8", "kP", "prior");
|
|
1504 /* if there's no key_dc keycap, map key_ic to `insert' keysym */
|
|
1505 CONDITIONAL_REASSIGN ("kD", "kI", "insert");
|
|
1506
|
|
1507 /* IBM has their own non-standard dialect of terminfo.
|
|
1508 If the standard name isn't found, try the IBM name. */
|
|
1509 CONDITIONAL_REASSIGN ("kB", "KO", "backtab");
|
|
1510 CONDITIONAL_REASSIGN ("@4", "kJ", "execute"); /* actually "action" */
|
|
1511 CONDITIONAL_REASSIGN ("@4", "kc", "execute"); /* actually "command" */
|
|
1512 CONDITIONAL_REASSIGN ("%7", "ki", "menu");
|
|
1513 CONDITIONAL_REASSIGN ("@7", "kw", "end");
|
|
1514 CONDITIONAL_REASSIGN ("F1", "k<", "f11");
|
|
1515 CONDITIONAL_REASSIGN ("F2", "k>", "f12");
|
|
1516 CONDITIONAL_REASSIGN ("%1", "kq", "help");
|
|
1517 CONDITIONAL_REASSIGN ("*6", "kU", "select");
|
|
1518 #undef CONDITIONAL_REASSIGN
|
|
1519 }
|
|
1520
|
|
1521 return Qnil;
|
|
1522 }
|
|
1523
|
|
1524
|
|
1525 /************************************************************************/
|
|
1526 /* initialization */
|
|
1527 /************************************************************************/
|
|
1528
|
|
1529 void
|
|
1530 console_type_create_redisplay_tty (void)
|
|
1531 {
|
|
1532 /* redisplay methods */
|
|
1533 CONSOLE_HAS_METHOD (tty, text_width);
|
|
1534 CONSOLE_HAS_METHOD (tty, output_display_block);
|
|
1535 CONSOLE_HAS_METHOD (tty, output_vertical_divider);
|
|
1536 CONSOLE_HAS_METHOD (tty, divider_width);
|
|
1537 CONSOLE_HAS_METHOD (tty, divider_height);
|
|
1538 CONSOLE_HAS_METHOD (tty, eol_cursor_width);
|
|
1539 CONSOLE_HAS_METHOD (tty, clear_to_window_end);
|
|
1540 CONSOLE_HAS_METHOD (tty, clear_region);
|
|
1541 CONSOLE_HAS_METHOD (tty, clear_frame);
|
|
1542 CONSOLE_HAS_METHOD (tty, output_begin);
|
|
1543 CONSOLE_HAS_METHOD (tty, output_end);
|
|
1544 CONSOLE_HAS_METHOD (tty, flash);
|
|
1545 CONSOLE_HAS_METHOD (tty, ring_bell);
|
|
1546 }
|