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