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