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