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