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;
|
|
428 int y1 = WINDOW_TEXT_TOP (w);
|
|
429 int y2 = WINDOW_TEXT_BOTTOM (w);
|
|
430 unsigned char divv = '|';
|
|
431
|
70
|
432 tty_turn_on_face (w, DEFAULT_INDEX);
|
0
|
433 for (line = y1; line < y2; line++)
|
|
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 }
|
70
|
439 tty_turn_off_face (w, DEFAULT_INDEX);
|
0
|
440
|
|
441 /* Draw the divider in the modeline. */
|
|
442 cmgoto (f, y2, WINDOW_TEXT_LEFT (w) - 1);
|
70
|
443 tty_turn_on_face (w, MODELINE_INDEX);
|
0
|
444 send_string_to_tty_console (c, &divv, 1);
|
|
445 TTY_INC_CURSOR_X (c, 1);
|
|
446 tty_turn_off_face (w, MODELINE_INDEX);
|
|
447 }
|
|
448
|
|
449 /****************************************************************************
|
|
450 tty_clear_region
|
|
451
|
|
452 Clear the area in the box defined by the given parameters.
|
|
453 ****************************************************************************/
|
|
454 static void
|
|
455 tty_clear_region (Lisp_Object window, face_index findex, int x, int y,
|
|
456 int width, int height)
|
|
457 {
|
|
458 struct window *w = XWINDOW (window);
|
|
459 struct frame *f = XFRAME (w->frame);
|
|
460 struct console *c = XCONSOLE (FRAME_CONSOLE (f));
|
|
461 int line;
|
|
462
|
|
463 if (!width || !height)
|
|
464 return;
|
|
465
|
|
466 tty_turn_on_face (w, findex);
|
|
467 for (line = y; line < y + height; line++)
|
|
468 {
|
|
469 int col;
|
|
470
|
|
471 cmgoto (f, line, x);
|
|
472
|
|
473 if (window_is_leftmost (w)
|
|
474 && window_is_rightmost (w)
|
|
475 && TTY_SE (c).clr_to_eol)
|
|
476 {
|
|
477 OUTPUT1 (c, TTY_SE (c).clr_to_eol);
|
|
478 }
|
|
479 else
|
|
480 {
|
|
481 unsigned char sp = ' ';
|
|
482 /* #### Of course, this is all complete and utter crap. */
|
|
483 for (col = x; col < x + width; col++)
|
|
484 send_string_to_tty_console (c, &sp, 1);
|
|
485 TTY_INC_CURSOR_X (c, width);
|
|
486 }
|
|
487 }
|
|
488 tty_turn_off_face (w, findex);
|
|
489 cmgoto (f, y, x);
|
|
490 }
|
|
491
|
|
492 /*****************************************************************************
|
|
493 tty_clear_to_window_end
|
|
494
|
|
495 Clear the area between ypos1 and ypos2. Each margin area and the
|
|
496 text area is handled separately since they may each have their own
|
|
497 background color.
|
|
498 ****************************************************************************/
|
|
499 static void
|
|
500 tty_clear_to_window_end (struct window *w, int ypos1, int ypos2)
|
|
501 {
|
|
502 struct frame *f = XFRAME (w->frame);
|
|
503 struct console *c = XCONSOLE (FRAME_CONSOLE (f));
|
|
504 int x, width;
|
|
505
|
|
506 x = WINDOW_TEXT_LEFT (w);
|
|
507 width = WINDOW_TEXT_WIDTH (w);
|
|
508
|
|
509 if (window_is_rightmost (w))
|
|
510 {
|
|
511 /* #### Optimize to use clr_to_eol function of tty if available, if
|
|
512 the window is the entire width of the frame. */
|
|
513 /* #### Is this actually an optimization? */
|
|
514 int line;
|
|
515 tty_turn_on_face (w, DEFAULT_INDEX);
|
|
516 for (line = ypos1; line < ypos2; line++)
|
|
517 {
|
|
518 cmgoto (XFRAME (w->frame), line, x);
|
|
519 OUTPUT1 (c, TTY_SE (c).clr_to_eol);
|
|
520 }
|
|
521 tty_turn_off_face (w, DEFAULT_INDEX);
|
|
522 }
|
|
523 else
|
|
524 {
|
|
525 Lisp_Object window;
|
|
526
|
|
527 XSETWINDOW (window, w);
|
|
528 tty_clear_region (window, DEFAULT_INDEX, x, ypos1, width, ypos2 - ypos1);
|
|
529 }
|
|
530 }
|
|
531
|
|
532 /****************************************************************************
|
|
533 tty_clear_frame
|
|
534
|
|
535 Clear the entire frame.
|
|
536 ****************************************************************************/
|
|
537 static void
|
|
538 tty_clear_frame (struct frame *f)
|
|
539 {
|
|
540 struct console *c = XCONSOLE (FRAME_CONSOLE (f));
|
|
541
|
|
542 tty_turn_on_frame_face (f, Vdefault_face);
|
|
543 if (TTY_SE (c).clr_frame)
|
|
544 {
|
|
545 OUTPUT1 (c, TTY_SE (c).clr_frame);
|
|
546 #ifdef NOT_SURE
|
|
547 FRAME_CURSOR_X (f) = 0;
|
|
548 FRAME_CURSOR_Y (f) = 0;
|
|
549 #endif
|
|
550 }
|
|
551 else
|
|
552 {
|
|
553 #ifdef NOT_SURE
|
|
554 internal_cursor_to (f, 0, 0);
|
|
555 clear_to_end (f);
|
|
556 #else
|
|
557 /* #### Not implemented. */
|
|
558 fprintf (stderr, "Not yet.\n");
|
|
559 #endif
|
|
560 }
|
|
561 tty_turn_off_frame_face (f, Vdefault_face);
|
|
562 }
|
|
563
|
|
564 static void
|
|
565 tty_output_bufbyte_string (struct window *w, struct display_line *dl,
|
|
566 Bufbyte *str, Bytecount len, int xpos,
|
|
567 face_index findex, int cursor)
|
|
568 {
|
|
569 struct frame *f = XFRAME (w->frame);
|
|
570 struct console *c = XCONSOLE (FRAME_CONSOLE (f));
|
|
571
|
|
572 /* First position the cursor. */
|
|
573 cmgoto (f, dl->ypos - 1, xpos);
|
|
574
|
|
575 /* Enable any face properties. */
|
|
576 tty_turn_on_face (w, findex);
|
|
577
|
|
578 send_string_to_tty_console (c, str, len);
|
|
579 TTY_INC_CURSOR_X (c, bufbyte_string_displayed_columns (str, len));
|
|
580
|
|
581 /* Turn the face properties back off. */
|
|
582 tty_turn_off_face (w, findex);
|
|
583 }
|
|
584
|
|
585 static bufbyte_dynarr *tty_output_emchar_dynarr_dynarr;
|
|
586
|
|
587 /*****************************************************************************
|
|
588 tty_output_emchar_dynarr
|
|
589
|
|
590 Given a string and a starting position, output that string in the
|
|
591 given face. If cursor is true, draw a cursor around the string.
|
|
592 ****************************************************************************/
|
|
593 static void
|
|
594 tty_output_emchar_dynarr (struct window *w, struct display_line *dl,
|
|
595 emchar_dynarr *buf, int xpos, face_index findex,
|
|
596 int cursor)
|
|
597 {
|
|
598 if (!tty_output_emchar_dynarr_dynarr)
|
|
599 tty_output_emchar_dynarr_dynarr = Dynarr_new (Bufbyte);
|
|
600 else
|
|
601 Dynarr_reset (tty_output_emchar_dynarr_dynarr);
|
|
602
|
|
603 convert_emchar_string_into_bufbyte_dynarr (Dynarr_atp (buf, 0),
|
|
604 Dynarr_length (buf),
|
|
605 tty_output_emchar_dynarr_dynarr);
|
|
606
|
|
607 tty_output_bufbyte_string (w, dl,
|
|
608 Dynarr_atp (tty_output_emchar_dynarr_dynarr, 0),
|
|
609 Dynarr_length (tty_output_emchar_dynarr_dynarr),
|
|
610 xpos, findex, cursor);
|
|
611 }
|
|
612
|
|
613 #if 0
|
|
614
|
|
615 static bufbyte_dynarr *sidcs_dynarr;
|
|
616
|
|
617 static void
|
|
618 substitute_in_dynamic_color_string (Lisp_Object spec, Lisp_Object string)
|
|
619 {
|
|
620 int i;
|
16
|
621 Bufbyte *specdata = XSTRING_DATA (spec);
|
|
622 Bytecount speclen = XSTRING_LENGTH (spec);
|
0
|
623
|
|
624 if (!sidcs_dynarr)
|
|
625 sidcs_dynarr = Dynarr_new (Bufbyte);
|
|
626 else
|
|
627 Dynarr_reset (sidcs_dynarr);
|
|
628
|
|
629 for (i = 0; i < speclen; i++)
|
|
630 {
|
|
631 if (specdata[i] == '%' && specdata[i+1] == '%')
|
|
632 {
|
|
633 Dynarr_add (sidcs_dynarr, '%');
|
|
634 i++;
|
|
635 }
|
|
636 else if (specdata[i] == '%' && specdata[i+1] == 's')
|
|
637 {
|
16
|
638 Dynarr_add_many (sidcs_dynarr,
|
|
639 XSTRING_DATA (string),
|
|
640 XSTRING_LENGTH (string));
|
0
|
641 i++;
|
|
642 }
|
|
643 else
|
|
644 Dynarr_add (sidcs_dynarr, specdata[i]);
|
|
645 }
|
|
646 }
|
|
647
|
|
648 #endif
|
|
649
|
|
650 static void
|
|
651 set_foreground_to (struct console *c, Lisp_Object sym)
|
|
652 {
|
|
653 Lisp_Object result;
|
|
654 Bufbyte *escseq = 0;
|
|
655 Bytecount escseqlen = 0;
|
|
656
|
|
657 result = assq_no_quit (sym, Vtty_color_alist);
|
|
658 if (!NILP (result))
|
|
659 {
|
|
660 Lisp_Object esc_seq = XCAR (XCDR (result));
|
16
|
661 escseq = XSTRING_DATA (esc_seq);
|
|
662 escseqlen = XSTRING_LENGTH (esc_seq);
|
0
|
663 }
|
|
664 #if 0
|
|
665 else if (STRINGP (Vtty_dynamic_color_fg))
|
|
666 {
|
|
667 substitute_in_dynamic_color_string (Vtty_dynamic_color_fg,
|
|
668 Fsymbol_name (sym));
|
|
669 escseq = Dynarr_atp (sidcs_dynarr, 0);
|
|
670 escseqlen = Dynarr_length (sidcs_dynarr);
|
|
671 }
|
|
672 #endif
|
|
673
|
|
674 if (escseq)
|
|
675 {
|
|
676 send_string_to_tty_console (c, escseq, escseqlen);
|
|
677 }
|
|
678 }
|
|
679
|
|
680 static void
|
|
681 set_background_to (struct console *c, Lisp_Object sym)
|
|
682 {
|
|
683 Lisp_Object result;
|
|
684 Bufbyte *escseq = 0;
|
|
685 Bytecount escseqlen = 0;
|
|
686
|
|
687 result = assq_no_quit (sym, Vtty_color_alist);
|
|
688 if (!NILP (result))
|
|
689 {
|
|
690 Lisp_Object esc_seq = XCDR (XCDR (result));
|
16
|
691 escseq = XSTRING_DATA (esc_seq);
|
|
692 escseqlen = XSTRING_LENGTH (esc_seq);
|
0
|
693 }
|
|
694 #if 0
|
|
695 else if (STRINGP (Vtty_dynamic_color_bg))
|
|
696 {
|
|
697 substitute_in_dynamic_color_string (Vtty_dynamic_color_bg,
|
|
698 Fsymbol_name (sym));
|
|
699 escseq = Dynarr_atp (sidcs_dynarr, 0);
|
|
700 escseqlen = Dynarr_length (sidcs_dynarr);
|
|
701 }
|
|
702 #endif
|
|
703
|
|
704 if (escseq)
|
|
705 {
|
|
706 send_string_to_tty_console (c, escseq, escseqlen);
|
|
707 }
|
|
708 }
|
|
709
|
|
710 static void
|
|
711 tty_turn_on_face_1 (struct console *c, int highlight_p,
|
|
712 int blinking_p, int dim_p, int underline_p,
|
|
713 int reverse_p, Lisp_Object cinst_fore,
|
|
714 Lisp_Object cinst_back)
|
|
715 {
|
|
716 if (highlight_p)
|
|
717 {
|
|
718 OUTPUT1_IF (c, TTY_SD (c).turn_on_bold);
|
|
719 }
|
|
720
|
|
721 if (blinking_p)
|
|
722 {
|
|
723 OUTPUT1_IF (c, TTY_SD (c).turn_on_blinking);
|
|
724 }
|
|
725
|
|
726 if (dim_p)
|
|
727 {
|
|
728 OUTPUT1_IF (c, TTY_SD (c).turn_on_dim);
|
|
729 }
|
|
730
|
|
731 if (underline_p)
|
|
732 {
|
|
733 /* #### punt for now if underline mode is glitchy */
|
|
734 if (!TTY_FLAGS (c).underline_width)
|
|
735 {
|
|
736 OUTPUT1_IF (c, TTY_SD (c).begin_underline);
|
|
737 }
|
|
738 }
|
|
739
|
|
740 if (reverse_p)
|
|
741 {
|
|
742 /* #### punt for now if standout mode is glitchy */
|
|
743 if (!TTY_FLAGS (c).standout_width)
|
|
744 {
|
|
745 OUTPUT1_IF (c, TTY_SD (c).begin_standout);
|
|
746 }
|
|
747 else
|
|
748 reverse_p = 0;
|
|
749 }
|
|
750
|
|
751 if (reverse_p)
|
|
752 {
|
|
753 Lisp_Object temp = cinst_fore;
|
|
754 cinst_fore = cinst_back;
|
|
755 cinst_back = temp;
|
|
756 }
|
|
757
|
|
758 if (COLOR_INSTANCEP (cinst_fore)
|
|
759 && !EQ (cinst_fore, Vthe_null_color_instance))
|
|
760 set_foreground_to (c, COLOR_INSTANCE_TTY_SYMBOL
|
|
761 (XCOLOR_INSTANCE (cinst_fore)));
|
|
762
|
|
763 if (COLOR_INSTANCEP (cinst_back)
|
|
764 && !EQ (cinst_back, Vthe_null_color_instance))
|
|
765 set_background_to (c, COLOR_INSTANCE_TTY_SYMBOL
|
|
766 (XCOLOR_INSTANCE (cinst_back)));
|
|
767 }
|
|
768
|
|
769 /*****************************************************************************
|
|
770 tty_turn_on_face
|
|
771
|
|
772 Turn on all set properties of the given face.
|
|
773 ****************************************************************************/
|
|
774 static void
|
|
775 tty_turn_on_face (struct window *w, face_index findex)
|
|
776 {
|
|
777 struct frame *f = XFRAME (w->frame);
|
|
778 struct console *c = XCONSOLE (FRAME_CONSOLE (f));
|
|
779
|
|
780 tty_turn_on_face_1 (c,
|
|
781 WINDOW_FACE_CACHEL_HIGHLIGHT_P (w, findex),
|
|
782 WINDOW_FACE_CACHEL_BLINKING_P (w, findex),
|
|
783 WINDOW_FACE_CACHEL_DIM_P (w, findex),
|
|
784 WINDOW_FACE_CACHEL_UNDERLINE_P (w, findex),
|
|
785 WINDOW_FACE_CACHEL_REVERSE_P (w, findex),
|
|
786 WINDOW_FACE_CACHEL_FOREGROUND (w, findex),
|
|
787 WINDOW_FACE_CACHEL_BACKGROUND (w, findex));
|
|
788 }
|
|
789
|
|
790 /*****************************************************************************
|
|
791 tty_turn_off_face
|
|
792
|
|
793 Turn off all set properties of the given face (revert to default
|
|
794 face). We assume that tty_turn_on_face has been called for the given
|
|
795 face so that it's properties are actually active.
|
|
796 ****************************************************************************/
|
|
797 static void
|
|
798 tty_turn_off_face (struct window *w, face_index findex)
|
|
799 {
|
|
800 struct frame *f = XFRAME (w->frame);
|
|
801 struct console *c = XCONSOLE (FRAME_CONSOLE (f));
|
|
802
|
|
803 if (WINDOW_FACE_CACHEL_REVERSE_P (w, findex))
|
|
804 {
|
|
805 /* #### punt for now if standout mode is glitchy */
|
|
806 if (!TTY_FLAGS (c).standout_width)
|
|
807 {
|
|
808 OUTPUT1_IF (c, TTY_SD (c).end_standout);
|
|
809 }
|
|
810 }
|
|
811
|
|
812 if (WINDOW_FACE_CACHEL_UNDERLINE_P (w, findex))
|
|
813 {
|
|
814 /* #### punt for now if underline mode is glitchy */
|
|
815 if (!TTY_FLAGS (c).underline_width)
|
|
816 {
|
|
817 OUTPUT1_IF (c, TTY_SD (c).end_underline);
|
|
818 }
|
|
819 }
|
|
820
|
|
821 if (WINDOW_FACE_CACHEL_HIGHLIGHT_P (w, findex) ||
|
|
822 WINDOW_FACE_CACHEL_BLINKING_P (w, findex) ||
|
|
823 WINDOW_FACE_CACHEL_DIM_P (w, findex) ||
|
|
824 !EQ (WINDOW_FACE_CACHEL_FOREGROUND (w, findex),
|
|
825 Vthe_null_color_instance) ||
|
|
826 !EQ (WINDOW_FACE_CACHEL_BACKGROUND (w, findex),
|
|
827 Vthe_null_color_instance))
|
|
828 {
|
|
829 OUTPUT1_IF (c, TTY_SD (c).turn_off_attributes);
|
|
830 }
|
|
831 }
|
|
832
|
|
833 /*****************************************************************************
|
|
834 tty_turn_on_frame_face
|
|
835
|
|
836 Turn on all set properties of the given face.
|
|
837 ****************************************************************************/
|
|
838 static void
|
|
839 tty_turn_on_frame_face (struct frame *f, Lisp_Object face)
|
|
840 {
|
|
841 Lisp_Object frame = Qnil;
|
|
842 struct console *c = XCONSOLE (FRAME_CONSOLE (f));
|
|
843
|
|
844 XSETFRAME (frame, f);
|
|
845 tty_turn_on_face_1 (c,
|
|
846 FACE_HIGHLIGHT_P (face, frame),
|
|
847 FACE_BLINKING_P (face, frame),
|
|
848 FACE_DIM_P (face, frame),
|
|
849 FACE_UNDERLINE_P (face, frame),
|
|
850 FACE_REVERSE_P (face, frame),
|
|
851 FACE_FOREGROUND (face, frame),
|
|
852 FACE_BACKGROUND (face, frame));
|
|
853 }
|
|
854
|
|
855 /*****************************************************************************
|
|
856 tty_turn_off_frame_face
|
|
857
|
|
858 Turn off all set properties of the given face (revert to default
|
|
859 face). We assume that tty_turn_on_face has been called for the given
|
|
860 face so that it's properties are actually active.
|
|
861 ****************************************************************************/
|
|
862 static void
|
|
863 tty_turn_off_frame_face (struct frame *f, Lisp_Object face)
|
|
864 {
|
|
865 Lisp_Object frame = Qnil;
|
|
866 struct console *c = XCONSOLE (FRAME_CONSOLE (f));
|
|
867
|
|
868 XSETFRAME (frame, f);
|
|
869
|
|
870 if (FACE_REVERSE_P (face, frame))
|
|
871 {
|
|
872 /* #### punt for now if standout mode is glitchy */
|
|
873 if (!TTY_FLAGS (c).standout_width)
|
|
874 {
|
|
875 OUTPUT1_IF (c, TTY_SD (c).end_standout);
|
|
876 }
|
|
877 }
|
|
878
|
|
879 if (FACE_UNDERLINE_P (face, frame))
|
|
880 {
|
|
881 /* #### punt for now if underline mode is glitchy */
|
|
882 if (!TTY_FLAGS (c).underline_width)
|
|
883 {
|
|
884 OUTPUT1_IF (c, TTY_SD (c).end_underline);
|
|
885 }
|
|
886 }
|
|
887
|
|
888 if (FACE_HIGHLIGHT_P (face, frame) ||
|
|
889 FACE_BLINKING_P (face, frame) ||
|
|
890 FACE_DIM_P (face, frame) ||
|
|
891 !EQ (FACE_FOREGROUND (face, frame), Vthe_null_color_instance) ||
|
|
892 !EQ (FACE_BACKGROUND (face, frame), Vthe_null_color_instance))
|
|
893 {
|
|
894 OUTPUT1_IF (c, TTY_SD (c).turn_off_attributes);
|
|
895 }
|
|
896 }
|
|
897
|
|
898 /*****************************************************************************
|
|
899 set_tty_modes
|
|
900
|
|
901 Sets up various parameters on tty modes.
|
|
902 ****************************************************************************/
|
|
903 void
|
|
904 set_tty_modes (struct console *c)
|
|
905 {
|
|
906 if (!CONSOLE_TTY_P (c))
|
|
907 return;
|
|
908
|
|
909 OUTPUT1_IF (c, TTY_SD (c).init_motion);
|
|
910 OUTPUT1_IF (c, TTY_SD (c).cursor_visible);
|
|
911 OUTPUT1_IF (c, TTY_SD (c).keypad_on);
|
|
912 }
|
|
913
|
|
914 /*****************************************************************************
|
|
915 reset_tty_modes
|
|
916
|
|
917 Restore default state of tty.
|
|
918 ****************************************************************************/
|
|
919 void
|
|
920 reset_tty_modes (struct console *c)
|
|
921 {
|
|
922 if (!CONSOLE_TTY_P (c))
|
|
923 return;
|
|
924
|
|
925 OUTPUT1_IF (c, TTY_SD (c).keypad_off);
|
|
926 OUTPUT1_IF (c, TTY_SD (c).cursor_normal);
|
|
927 OUTPUT1_IF (c, TTY_SD (c).end_motion);
|
|
928 tty_output_end (XDEVICE (CONSOLE_SELECTED_DEVICE (c)));
|
|
929 }
|
|
930
|
|
931 /*****************************************************************************
|
|
932 tty_redisplay_shutdown
|
|
933
|
|
934 Clear the frame and position the cursor properly for exiting.
|
|
935 ****************************************************************************/
|
|
936 void
|
|
937 tty_redisplay_shutdown (struct console *c)
|
|
938 {
|
|
939 Lisp_Object dev = CONSOLE_SELECTED_DEVICE (c);
|
|
940
|
|
941 if (!GC_NILP (dev))
|
|
942 {
|
|
943 Lisp_Object frm = DEVICE_SELECTED_FRAME (XDEVICE (dev));
|
|
944
|
|
945 if (!GC_NILP (frm))
|
|
946 {
|
|
947 struct frame *f = XFRAME (frm);
|
|
948
|
|
949 /* Clear the bottom line of the frame. */
|
|
950 tty_clear_region (FRAME_SELECTED_WINDOW (f), DEFAULT_INDEX, 0,
|
|
951 f->height, f->width, 1);
|
|
952
|
|
953 /* And then stick the cursor there. */
|
|
954 cmgoto (f, f->height, 0);
|
|
955 tty_output_end (XDEVICE (dev));
|
|
956 }
|
|
957 }
|
|
958 }
|
|
959
|
|
960
|
|
961 /* #### Everything below here is old shit. It should either be moved
|
|
962 up or removed. */
|
|
963
|
|
964
|
|
965 /* FLAGS - these don't need to be console local since only one console
|
|
966 can be being updated at a time. */
|
|
967 static int insert_mode_on; /* nonzero if in insert mode */
|
|
968 static int standout_mode_on; /* nonzero if in standout mode */
|
|
969 static int underline_mode_on; /* nonzero if in underline mode */
|
|
970 static int alternate_mode_on; /* nonzero if in alternate char set */
|
|
971 static int attributes_on; /* nonzero if any attributes on */
|
|
972
|
|
973 #ifdef NOT_YET
|
|
974 static void
|
|
975 turn_on_insert (struct frame *f)
|
|
976 {
|
|
977 struct console *c = XCONSOLE (FRAME_CONSOLE (f));
|
|
978
|
|
979 if (!insert_mode_on)
|
|
980 OUTPUT1_IF (c, TTY_SE (c).begin_ins_mode);
|
|
981 insert_mode_on = 1;
|
|
982 }
|
|
983
|
|
984 static void
|
|
985 turn_off_insert (struct frame *f)
|
|
986 {
|
|
987 struct console *c = XCONSOLE (FRAME_CONSOLE (f));
|
|
988
|
|
989 if (insert_mode_on)
|
|
990 OUTPUT1 (c, TTY_SE (c).end_ins_mode);
|
|
991 insert_mode_on = 0;
|
|
992 }
|
|
993
|
|
994 static void
|
|
995 internal_cursor_to (struct frame *f, int row, int col)
|
|
996 {
|
|
997 struct console *c = XCONSOLE (FRAME_CONSOLE (f));
|
|
998
|
|
999 if (!TTY_FLAGS (c).insert_mode_motion)
|
|
1000 turn_off_insert (f);
|
|
1001 if (!TTY_FLAGS (c).standout_motion)
|
|
1002 {
|
|
1003 turn_off_standout (f);
|
|
1004 turn_off_underline (f);
|
|
1005 turn_off_alternate (f);
|
|
1006 }
|
|
1007
|
|
1008 cmgoto (f, row, col);
|
|
1009 }
|
|
1010
|
|
1011 static void
|
|
1012 clear_to_end (struct frame *f)
|
|
1013 {
|
|
1014 struct console *c = XCONSOLE (FRAME_CONSOLE (f));
|
|
1015
|
|
1016 /* assumes cursor is already positioned */
|
|
1017 if (TTY_SE (c).clr_from_cursor)
|
|
1018 {
|
|
1019 OUTPUT1 (c, TTY_SE (c).clr_from_cursor);
|
|
1020 }
|
|
1021 else
|
|
1022 {
|
|
1023 int line = FRAME_CURSOR_Y (f);
|
|
1024
|
|
1025 while (line < FRAME_HEIGHT (f))
|
|
1026 {
|
|
1027 internal_cursor_to (f, line, 0);
|
|
1028 OUTPUT1 (c, TTY_SE (c).clr_to_eol);
|
|
1029 }
|
|
1030 }
|
|
1031 }
|
|
1032 #endif /* 0 */
|
|
1033
|
|
1034 #if 0
|
|
1035 /*
|
|
1036 * clear from last visible line on window to window end (presumably
|
|
1037 * the line above window's modeline
|
|
1038 */
|
|
1039 static void
|
|
1040 tty_clear_window_end (struct window *w, int ystart, int yend)
|
|
1041 {
|
|
1042 struct console *c = XCONSOLE (WINDOW_CONSOLE (w));
|
|
1043 int line;
|
|
1044
|
|
1045 for (line = ystart; line < yend; line++)
|
|
1046 {
|
|
1047 cmgoto (XFRAME (w->frame), line, 0);
|
|
1048 OUTPUT1 (c, TTY_SE (c).clr_to_eol);
|
|
1049 }
|
|
1050 }
|
|
1051
|
|
1052 #endif /* 0 */
|
|
1053
|
|
1054 static int
|
|
1055 tty_flash (struct device *d)
|
|
1056 {
|
|
1057 struct console *c = XCONSOLE (DEVICE_CONSOLE (d));
|
|
1058 if (TTY_SD (c).visual_bell)
|
|
1059 {
|
|
1060 OUTPUT1 (c, TTY_SD (c).visual_bell);
|
|
1061 Lstream_flush (XLSTREAM (CONSOLE_TTY_DATA (c)->outstream));
|
|
1062 return 1;
|
|
1063 }
|
|
1064 else
|
|
1065 return 0;
|
|
1066 }
|
|
1067
|
|
1068 /*
|
|
1069 * tty_ring_bell - sound an audio beep.
|
|
1070 */
|
|
1071 static void
|
|
1072 tty_ring_bell (struct device *d, int volume, int pitch, int duration)
|
|
1073 {
|
|
1074 struct console *c = XCONSOLE (DEVICE_CONSOLE (d));
|
|
1075
|
82
|
1076 if (volume)
|
|
1077 {
|
|
1078 OUTPUT1 (c, TTY_SD (c).audio_bell);
|
|
1079 Lstream_flush (XLSTREAM (CONSOLE_TTY_DATA (c)->outstream));
|
|
1080 }
|
0
|
1081 }
|
|
1082
|
|
1083
|
|
1084 int
|
|
1085 init_tty_for_redisplay (struct device *d, char *terminal_type)
|
|
1086 {
|
|
1087 int status;
|
|
1088 char entry_buffer[2044];
|
|
1089 /* char temp_buffer[2044]; */
|
|
1090 char *bufptr;
|
|
1091 struct console *c = XCONSOLE (DEVICE_CONSOLE (d));
|
|
1092
|
|
1093 /* What we should really do is allocate just enough space for
|
|
1094 the actual strings that are stored; but this would require
|
|
1095 doing this after all the tgetstr()s and adjusting all the
|
|
1096 pointers. */
|
|
1097 CONSOLE_TTY_DATA (c)->term_entry_buffer = (char *) xmalloc (2044);
|
|
1098 bufptr = CONSOLE_TTY_DATA (c)->term_entry_buffer;
|
|
1099
|
2
|
1100 EMACS_BLOCK_SIGNAL (SIGTTOU);
|
0
|
1101 status = tgetent (entry_buffer, terminal_type);
|
2
|
1102 EMACS_UNBLOCK_SIGNAL (SIGTTOU);
|
0
|
1103 #if 0
|
|
1104 if (status < 0)
|
|
1105 return TTY_UNABLE_OPEN_DATABASE;
|
|
1106 else if (status == 0)
|
|
1107 return TTY_TYPE_UNDEFINED;
|
|
1108 #endif
|
|
1109 /* Under Linux at least, <0 is returned for TTY_TYPE_UNDEFINED. --ben */
|
|
1110 if (status <= 0)
|
|
1111 return TTY_TYPE_UNDEFINED;
|
|
1112
|
|
1113 /*
|
|
1114 * Establish the terminal size.
|
|
1115 */
|
|
1116 /* First try to get the info from the system. If that fails, check
|
|
1117 the termcap entry. */
|
|
1118 get_tty_device_size (d, &CONSOLE_TTY_DATA (c)->width,
|
|
1119 &CONSOLE_TTY_DATA (c)->height);
|
|
1120
|
|
1121 if (CONSOLE_TTY_DATA (c)->width <= 0)
|
|
1122 CONSOLE_TTY_DATA (c)->width = tgetnum ("co");
|
|
1123 if (CONSOLE_TTY_DATA (c)->height <= 0)
|
|
1124 CONSOLE_TTY_DATA (c)->height = tgetnum ("li");
|
|
1125
|
|
1126 if (CONSOLE_TTY_DATA (c)->width <= 0 || CONSOLE_TTY_DATA (c)->height <= 0)
|
|
1127 return TTY_SIZE_UNSPECIFIED;
|
|
1128
|
|
1129 /*
|
|
1130 * Initialize cursor motion information.
|
|
1131 */
|
|
1132
|
|
1133 /* local cursor movement */
|
|
1134 TTY_CM (c).up = tgetstr ("up", &bufptr);
|
|
1135 TTY_CM (c).down = tgetstr ("do", &bufptr);
|
|
1136 TTY_CM (c).left = tgetstr ("le", &bufptr);
|
|
1137 TTY_CM (c).right = tgetstr ("nd", &bufptr);
|
|
1138 TTY_CM (c).home = tgetstr ("ho", &bufptr);
|
|
1139 TTY_CM (c).low_left = tgetstr ("ll", &bufptr);
|
|
1140 TTY_CM (c).car_return = tgetstr ("cr", &bufptr);
|
|
1141
|
|
1142 /* absolute cursor motion */
|
|
1143 TTY_CM (c).abs = tgetstr ("cm", &bufptr);
|
|
1144 TTY_CM (c).hor_abs = tgetstr ("ch", &bufptr);
|
|
1145 TTY_CM (c).ver_abs = tgetstr ("cv", &bufptr);
|
|
1146
|
|
1147 /* Verify that the terminal is powerful enough to run Emacs */
|
|
1148 if (!TTY_CM (c).abs)
|
|
1149 {
|
|
1150 if (!TTY_CM (c).up || !TTY_CM (c).down
|
|
1151 || !TTY_CM (c).left || !TTY_CM (c).right)
|
|
1152 return TTY_TYPE_INSUFFICIENT;
|
|
1153 }
|
|
1154
|
|
1155 /* parameterized local cursor movement */
|
|
1156 TTY_CM (c).multi_up = tgetstr ("UP", &bufptr);
|
|
1157 TTY_CM (c).multi_down = tgetstr ("DO", &bufptr);
|
|
1158 TTY_CM (c).multi_left = tgetstr ("LE", &bufptr);
|
|
1159 TTY_CM (c).multi_right = tgetstr ("RI", &bufptr);
|
|
1160
|
|
1161 /* scrolling */
|
|
1162 TTY_CM (c).scroll_forw = tgetstr ("sf", &bufptr);
|
|
1163 TTY_CM (c).scroll_back = tgetstr ("sr", &bufptr);
|
|
1164 TTY_CM (c).multi_scroll_forw = tgetstr ("SF", &bufptr);
|
|
1165 TTY_CM (c).multi_scroll_back = tgetstr ("SR", &bufptr);
|
|
1166 TTY_CM (c).set_scroll_region = tgetstr ("cs", &bufptr);
|
|
1167
|
|
1168
|
|
1169 /*
|
|
1170 * Initialize screen editing information.
|
|
1171 */
|
|
1172
|
|
1173 /* adding to the screen */
|
|
1174 TTY_SE (c).ins_line = tgetstr ("al", &bufptr);
|
|
1175 TTY_SE (c).multi_ins_line = tgetstr ("AL", &bufptr);
|
|
1176 TTY_SE (c).repeat = tgetstr ("rp", &bufptr);
|
|
1177 TTY_SE (c).begin_ins_mode = tgetstr ("im", &bufptr);
|
|
1178 TTY_SE (c).end_ins_mode = tgetstr ("ei", &bufptr);
|
|
1179 TTY_SE (c).ins_char = tgetstr ("ic", &bufptr);
|
|
1180 TTY_SE (c).multi_ins_char = tgetstr ("IC", &bufptr);
|
|
1181 TTY_SE (c).insert_pad = tgetstr ("ip", &bufptr);
|
|
1182
|
|
1183 /* deleting from the screen */
|
|
1184 TTY_SE (c).clr_frame = tgetstr ("cl", &bufptr);
|
|
1185 TTY_SE (c).clr_from_cursor = tgetstr ("cd", &bufptr);
|
|
1186 TTY_SE (c).clr_to_eol = tgetstr ("ce", &bufptr);
|
|
1187 TTY_SE (c).del_line = tgetstr ("dl", &bufptr);
|
|
1188 TTY_SE (c).multi_del_line = tgetstr ("DL", &bufptr);
|
|
1189 TTY_SE (c).del_char = tgetstr ("dc", &bufptr);
|
|
1190 TTY_SE (c).multi_del_char = tgetstr ("DC", &bufptr);
|
|
1191 TTY_SE (c).begin_del_mode = tgetstr ("dm", &bufptr);
|
|
1192 TTY_SE (c).end_del_mode = tgetstr ("ed", &bufptr);
|
|
1193 TTY_SE (c).erase_at_cursor = tgetstr ("ec", &bufptr);
|
|
1194
|
|
1195
|
|
1196 /*
|
|
1197 * Initialize screen display information.
|
|
1198 */
|
|
1199 TTY_SD (c).begin_standout = tgetstr ("so", &bufptr);
|
|
1200 TTY_SD (c).end_standout = tgetstr ("se", &bufptr);
|
|
1201 TTY_SD (c).begin_underline = tgetstr ("us", &bufptr);
|
|
1202 TTY_SD (c).end_underline = tgetstr ("ue", &bufptr);
|
|
1203 TTY_SD (c).begin_alternate = tgetstr ("as", &bufptr);
|
|
1204 TTY_SD (c).end_alternate = tgetstr ("ae", &bufptr);
|
|
1205 TTY_SD (c).turn_on_reverse = tgetstr ("mr", &bufptr);
|
|
1206 TTY_SD (c).turn_on_blinking = tgetstr ("mb", &bufptr);
|
|
1207 TTY_SD (c).turn_on_bold = tgetstr ("md", &bufptr);
|
|
1208 TTY_SD (c).turn_on_dim = tgetstr ("mh", &bufptr);
|
|
1209 TTY_SD (c).turn_off_attributes = tgetstr ("me", &bufptr);
|
|
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 }
|