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