1 /* Terminal control module for terminals described by TERMCAP
2 Copyright (C) 1985-1987, 1993-1995, 1998, 2000-2013 Free Software
5 This file is part of GNU Emacs.
7 GNU Emacs is free software: you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
12 GNU Emacs is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
20 /* New redisplay, TTY faces by Gerd Moellmann <gerd@gnu.org>. */
33 #include "character.h"
37 #include "composite.h"
41 #include "termhooks.h"
42 #include "dispextern.h"
45 #include "blockinput.h"
46 #include "syssignal.h"
48 #include "intervals.h"
51 static int been_here
= -1;
55 #include "../lwlib/lwlib.h"
65 /* The name of the default console device. */
67 #define DEV_TTY "CONOUT$"
70 #define DEV_TTY "/dev/tty"
73 static void tty_set_scroll_region (struct frame
*f
, int start
, int stop
);
74 static void turn_on_face (struct frame
*, int face_id
);
75 static void turn_off_face (struct frame
*, int face_id
);
76 static void tty_turn_off_highlight (struct tty_display_info
*);
77 static void tty_show_cursor (struct tty_display_info
*);
78 static void tty_hide_cursor (struct tty_display_info
*);
79 static void tty_background_highlight (struct tty_display_info
*tty
);
80 static struct terminal
*get_tty_terminal (Lisp_Object
, bool);
81 static void clear_tty_hooks (struct terminal
*terminal
);
82 static void set_tty_hooks (struct terminal
*terminal
);
83 static void dissociate_if_controlling_tty (int fd
);
84 static void delete_tty (struct terminal
*);
85 static _Noreturn
void maybe_fatal (bool, struct terminal
*,
86 const char *, const char *, ...)
87 ATTRIBUTE_FORMAT_PRINTF (3, 5) ATTRIBUTE_FORMAT_PRINTF (4, 5);
88 static _Noreturn
void vfatal (const char *str
, va_list ap
)
89 ATTRIBUTE_FORMAT_PRINTF (1, 0);
92 #define OUTPUT(tty, a) \
93 emacs_tputs ((tty), a, \
94 FRAME_LINES (XFRAME (selected_frame)) - curY (tty), \
97 #define OUTPUT1(tty, a) emacs_tputs ((tty), a, 1, cmputc)
98 #define OUTPUTL(tty, a, lines) emacs_tputs ((tty), a, lines, cmputc)
100 #define OUTPUT_IF(tty, a) \
106 #define OUTPUT1_IF(tty, a) do { if (a) emacs_tputs ((tty), a, 1, cmputc); } while (0)
108 /* Display space properties */
110 /* Chain of all tty device parameters. */
111 struct tty_display_info
*tty_list
;
113 /* Meaning of bits in no_color_video. Each bit set means that the
114 corresponding attribute cannot be combined with colors. */
118 NC_STANDOUT
= 1 << 0,
119 NC_UNDERLINE
= 1 << 1,
130 /* The largest frame width in any call to calculate_costs. */
132 static int max_frame_cols
;
137 #include <sys/fcntl.h>
139 /* The device for which we have enabled gpm support (or NULL). */
140 struct tty_display_info
*gpm_tty
= NULL
;
142 /* Last recorded mouse coordinates. */
143 static int last_mouse_x
, last_mouse_y
;
144 #endif /* HAVE_GPM */
146 /* Ring the bell on a tty. */
149 tty_ring_bell (struct frame
*f
)
151 struct tty_display_info
*tty
= FRAME_TTY (f
);
155 OUTPUT (tty
, (tty
->TS_visible_bell
&& visible_bell
156 ? tty
->TS_visible_bell
158 fflush (tty
->output
);
162 /* Set up termcap modes for Emacs. */
165 tty_set_terminal_modes (struct terminal
*terminal
)
167 struct tty_display_info
*tty
= terminal
->display_info
.tty
;
171 if (tty
->TS_termcap_modes
)
172 OUTPUT (tty
, tty
->TS_termcap_modes
);
175 /* Output enough newlines to scroll all the old screen contents
176 off the screen, so it won't be overwritten and lost. */
179 for (i
= 0; i
< FRAME_LINES (XFRAME (selected_frame
)); i
++)
183 OUTPUT_IF (tty
, visible_cursor
? tty
->TS_cursor_visible
: tty
->TS_cursor_normal
);
184 OUTPUT_IF (tty
, tty
->TS_keypad_mode
);
186 fflush (tty
->output
);
190 /* Reset termcap modes before exiting Emacs. */
193 tty_reset_terminal_modes (struct terminal
*terminal
)
195 struct tty_display_info
*tty
= terminal
->display_info
.tty
;
199 tty_turn_off_highlight (tty
);
200 tty_turn_off_insert (tty
);
201 OUTPUT_IF (tty
, tty
->TS_end_keypad_mode
);
202 OUTPUT_IF (tty
, tty
->TS_cursor_normal
);
203 OUTPUT_IF (tty
, tty
->TS_end_termcap_modes
);
204 OUTPUT_IF (tty
, tty
->TS_orig_pair
);
205 /* Output raw CR so kernel can track the cursor hpos. */
208 fflush (tty
->output
);
212 /* Flag the end of a display update on a termcap terminal. */
215 tty_update_end (struct frame
*f
)
217 struct tty_display_info
*tty
= FRAME_TTY (f
);
219 if (!XWINDOW (selected_window
)->cursor_off_p
)
220 tty_show_cursor (tty
);
221 tty_turn_off_insert (tty
);
222 tty_background_highlight (tty
);
223 fflush (tty
->output
);
226 /* The implementation of set_terminal_window for termcap frames. */
229 tty_set_terminal_window (struct frame
*f
, int size
)
231 struct tty_display_info
*tty
= FRAME_TTY (f
);
233 tty
->specified_window
= size
? size
: FRAME_LINES (f
);
234 if (FRAME_SCROLL_REGION_OK (f
))
235 tty_set_scroll_region (f
, 0, tty
->specified_window
);
239 tty_set_scroll_region (struct frame
*f
, int start
, int stop
)
242 struct tty_display_info
*tty
= FRAME_TTY (f
);
244 if (tty
->TS_set_scroll_region
)
245 buf
= tparam (tty
->TS_set_scroll_region
, 0, 0, start
, stop
- 1, 0, 0);
246 else if (tty
->TS_set_scroll_region_1
)
247 buf
= tparam (tty
->TS_set_scroll_region_1
, 0, 0,
248 FRAME_LINES (f
), start
,
249 FRAME_LINES (f
) - stop
,
252 buf
= tparam (tty
->TS_set_window
, 0, 0, start
, 0, stop
, FRAME_COLS (f
));
261 tty_turn_on_insert (struct tty_display_info
*tty
)
263 if (!tty
->insert_mode
)
264 OUTPUT (tty
, tty
->TS_insert_mode
);
265 tty
->insert_mode
= 1;
269 tty_turn_off_insert (struct tty_display_info
*tty
)
271 if (tty
->insert_mode
)
272 OUTPUT (tty
, tty
->TS_end_insert_mode
);
273 tty
->insert_mode
= 0;
276 /* Handle highlighting. */
279 tty_turn_off_highlight (struct tty_display_info
*tty
)
281 if (tty
->standout_mode
)
282 OUTPUT_IF (tty
, tty
->TS_end_standout_mode
);
283 tty
->standout_mode
= 0;
287 tty_turn_on_highlight (struct tty_display_info
*tty
)
289 if (!tty
->standout_mode
)
290 OUTPUT_IF (tty
, tty
->TS_standout_mode
);
291 tty
->standout_mode
= 1;
295 tty_toggle_highlight (struct tty_display_info
*tty
)
297 if (tty
->standout_mode
)
298 tty_turn_off_highlight (tty
);
300 tty_turn_on_highlight (tty
);
304 /* Make cursor invisible. */
307 tty_hide_cursor (struct tty_display_info
*tty
)
309 if (tty
->cursor_hidden
== 0)
311 tty
->cursor_hidden
= 1;
313 w32con_hide_cursor ();
315 OUTPUT_IF (tty
, tty
->TS_cursor_invisible
);
321 /* Ensure that cursor is visible. */
324 tty_show_cursor (struct tty_display_info
*tty
)
326 if (tty
->cursor_hidden
)
328 tty
->cursor_hidden
= 0;
330 w32con_show_cursor ();
332 OUTPUT_IF (tty
, tty
->TS_cursor_normal
);
334 OUTPUT_IF (tty
, tty
->TS_cursor_visible
);
340 /* Set standout mode to the state it should be in for
341 empty space inside windows. What this is,
342 depends on the user option inverse-video. */
345 tty_background_highlight (struct tty_display_info
*tty
)
348 tty_turn_on_highlight (tty
);
350 tty_turn_off_highlight (tty
);
353 /* Set standout mode to the mode specified for the text to be output. */
356 tty_highlight_if_desired (struct tty_display_info
*tty
)
359 tty_turn_on_highlight (tty
);
361 tty_turn_off_highlight (tty
);
365 /* Move cursor to row/column position VPOS/HPOS. HPOS/VPOS are
366 frame-relative coordinates. */
369 tty_cursor_to (struct frame
*f
, int vpos
, int hpos
)
371 struct tty_display_info
*tty
= FRAME_TTY (f
);
373 /* Detect the case where we are called from reset_sys_modes
374 and the costs have never been calculated. Do nothing. */
375 if (! tty
->costs_set
)
378 if (curY (tty
) == vpos
379 && curX (tty
) == hpos
)
381 if (!tty
->TF_standout_motion
)
382 tty_background_highlight (tty
);
383 if (!tty
->TF_insmode_motion
)
384 tty_turn_off_insert (tty
);
385 cmgoto (tty
, vpos
, hpos
);
388 /* Similar but don't take any account of the wasted characters. */
391 tty_raw_cursor_to (struct frame
*f
, int row
, int col
)
393 struct tty_display_info
*tty
= FRAME_TTY (f
);
395 if (curY (tty
) == row
396 && curX (tty
) == col
)
398 if (!tty
->TF_standout_motion
)
399 tty_background_highlight (tty
);
400 if (!tty
->TF_insmode_motion
)
401 tty_turn_off_insert (tty
);
402 cmgoto (tty
, row
, col
);
405 /* Erase operations */
407 /* Clear from cursor to end of frame on a termcap device. */
410 tty_clear_to_end (struct frame
*f
)
413 struct tty_display_info
*tty
= FRAME_TTY (f
);
415 if (tty
->TS_clr_to_bottom
)
417 tty_background_highlight (tty
);
418 OUTPUT (tty
, tty
->TS_clr_to_bottom
);
422 for (i
= curY (tty
); i
< FRAME_LINES (f
); i
++)
425 clear_end_of_line (f
, FRAME_COLS (f
));
430 /* Clear an entire termcap frame. */
433 tty_clear_frame (struct frame
*f
)
435 struct tty_display_info
*tty
= FRAME_TTY (f
);
437 if (tty
->TS_clr_frame
)
439 tty_background_highlight (tty
);
440 OUTPUT (tty
, tty
->TS_clr_frame
);
450 /* An implementation of clear_end_of_line for termcap frames.
452 Note that the cursor may be moved, on terminals lacking a `ce' string. */
455 tty_clear_end_of_line (struct frame
*f
, int first_unused_hpos
)
458 struct tty_display_info
*tty
= FRAME_TTY (f
);
460 /* Detect the case where we are called from reset_sys_modes
461 and the costs have never been calculated. Do nothing. */
462 if (! tty
->costs_set
)
465 if (curX (tty
) >= first_unused_hpos
)
467 tty_background_highlight (tty
);
468 if (tty
->TS_clr_line
)
470 OUTPUT1 (tty
, tty
->TS_clr_line
);
473 { /* have to do it the hard way */
474 tty_turn_off_insert (tty
);
476 /* Do not write in last row last col with Auto-wrap on. */
478 && curY (tty
) == FrameRows (tty
) - 1
479 && first_unused_hpos
== FrameCols (tty
))
482 for (i
= curX (tty
); i
< first_unused_hpos
; i
++)
485 fputc (' ', tty
->termscript
);
486 fputc (' ', tty
->output
);
488 cmplus (tty
, first_unused_hpos
- curX (tty
));
492 /* Buffers to store the source and result of code conversion for terminal. */
493 static unsigned char *encode_terminal_src
;
494 static unsigned char *encode_terminal_dst
;
495 /* Allocated sizes of the above buffers. */
496 static ptrdiff_t encode_terminal_src_size
;
497 static ptrdiff_t encode_terminal_dst_size
;
499 /* Encode SRC_LEN glyphs starting at SRC to terminal output codes.
500 Set CODING->produced to the byte-length of the resulting byte
501 sequence, and return a pointer to that byte sequence. */
507 encode_terminal_code (struct glyph
*src
, int src_len
,
508 struct coding_system
*coding
)
510 struct glyph
*src_end
= src
+ src_len
;
512 ptrdiff_t nchars
, nbytes
, required
;
513 ptrdiff_t tlen
= GLYPH_TABLE_LENGTH
;
514 register Lisp_Object
*tbase
= GLYPH_TABLE_BASE
;
515 Lisp_Object charset_list
;
517 /* Allocate sufficient size of buffer to store all characters in
518 multibyte-form. But, it may be enlarged on demand if
519 Vglyph_table contains a string or a composite glyph is
521 if (min (PTRDIFF_MAX
, SIZE_MAX
) / MAX_MULTIBYTE_LENGTH
< src_len
)
522 memory_full (SIZE_MAX
);
524 required
*= MAX_MULTIBYTE_LENGTH
;
525 if (encode_terminal_src_size
< required
)
527 encode_terminal_src
= xrealloc (encode_terminal_src
, required
);
528 encode_terminal_src_size
= required
;
531 charset_list
= coding_charset_list (coding
);
533 buf
= encode_terminal_src
;
535 while (src
< src_end
)
537 if (src
->type
== COMPOSITE_GLYPH
)
539 struct composition
*cmp
IF_LINT (= NULL
);
540 Lisp_Object gstring
IF_LINT (= Qnil
);
543 nbytes
= buf
- encode_terminal_src
;
544 if (src
->u
.cmp
.automatic
)
546 gstring
= composition_gstring_from_id (src
->u
.cmp
.id
);
547 required
= src
->slice
.cmp
.to
- src
->slice
.cmp
.from
+ 1;
551 cmp
= composition_table
[src
->u
.cmp
.id
];
552 required
= cmp
->glyph_len
;
553 required
*= MAX_MULTIBYTE_LENGTH
;
556 if (encode_terminal_src_size
- nbytes
< required
)
558 encode_terminal_src
=
559 xpalloc (encode_terminal_src
, &encode_terminal_src_size
,
560 required
- (encode_terminal_src_size
- nbytes
),
562 buf
= encode_terminal_src
+ nbytes
;
565 if (src
->u
.cmp
.automatic
)
566 for (i
= src
->slice
.cmp
.from
; i
<= src
->slice
.cmp
.to
; i
++)
568 Lisp_Object g
= LGSTRING_GLYPH (gstring
, i
);
569 int c
= LGLYPH_CHAR (g
);
571 if (! char_charset (c
, charset_list
, NULL
))
573 buf
+= CHAR_STRING (c
, buf
);
577 for (i
= 0; i
< cmp
->glyph_len
; i
++)
579 int c
= COMPOSITION_GLYPH (cmp
, i
);
581 /* TAB in a composition means display glyphs with
582 padding space on the left or right. */
585 if (char_charset (c
, charset_list
, NULL
))
587 if (CHAR_WIDTH (c
) == 0
588 && i
> 0 && COMPOSITION_GLYPH (cmp
, i
- 1) == '\t')
589 /* Should be left-padded */
591 buf
+= CHAR_STRING (' ', buf
);
597 buf
+= CHAR_STRING (c
, buf
);
601 /* We must skip glyphs to be padded for a wide character. */
602 else if (! CHAR_GLYPH_PADDING_P (*src
))
609 SET_GLYPH_FROM_CHAR_GLYPH (g
, src
[0]);
611 if (GLYPH_INVALID_P (g
) || GLYPH_SIMPLE_P (tbase
, tlen
, g
))
613 /* This glyph doesn't have an entry in Vglyph_table. */
618 /* This glyph has an entry in Vglyph_table,
619 so process any alias before testing for simpleness. */
620 GLYPH_FOLLOW_ALIASES (tbase
, tlen
, g
);
622 if (GLYPH_SIMPLE_P (tbase
, tlen
, g
))
623 /* We set the multi-byte form of a character in G
624 (that should be an ASCII character) at WORKBUF. */
627 /* We have a string in Vglyph_table. */
628 string
= tbase
[GLYPH_CHAR (g
)];
633 nbytes
= buf
- encode_terminal_src
;
634 if (encode_terminal_src_size
- nbytes
< MAX_MULTIBYTE_LENGTH
)
636 encode_terminal_src
=
637 xpalloc (encode_terminal_src
, &encode_terminal_src_size
,
638 MAX_MULTIBYTE_LENGTH
, -1, 1);
639 buf
= encode_terminal_src
+ nbytes
;
642 || char_charset (c
, charset_list
, NULL
))
644 /* Store the multibyte form of C at BUF. */
645 buf
+= CHAR_STRING (c
, buf
);
650 /* C is not encodable. */
653 while (src
+ 1 < src_end
&& CHAR_GLYPH_PADDING_P (src
[1]))
663 if (! STRING_MULTIBYTE (string
))
664 string
= string_to_multibyte (string
);
665 nbytes
= buf
- encode_terminal_src
;
666 if (encode_terminal_src_size
- nbytes
< SBYTES (string
))
668 encode_terminal_src
=
669 xpalloc (encode_terminal_src
, &encode_terminal_src_size
,
671 - (encode_terminal_src_size
- nbytes
)),
673 buf
= encode_terminal_src
+ nbytes
;
675 memcpy (buf
, SDATA (string
), SBYTES (string
));
676 buf
+= SBYTES (string
);
677 nchars
+= SCHARS (string
);
685 coding
->produced
= 0;
689 nbytes
= buf
- encode_terminal_src
;
690 coding
->source
= encode_terminal_src
;
691 if (encode_terminal_dst_size
== 0)
693 encode_terminal_dst
= xrealloc (encode_terminal_dst
,
694 encode_terminal_src_size
);
695 encode_terminal_dst_size
= encode_terminal_src_size
;
697 coding
->destination
= encode_terminal_dst
;
698 coding
->dst_bytes
= encode_terminal_dst_size
;
699 encode_coding_object (coding
, Qnil
, 0, 0, nchars
, nbytes
, Qnil
);
700 /* coding->destination may have been reallocated. */
701 encode_terminal_dst
= coding
->destination
;
702 encode_terminal_dst_size
= coding
->dst_bytes
;
704 return (encode_terminal_dst
);
709 /* An implementation of write_glyphs for termcap frames. */
712 tty_write_glyphs (struct frame
*f
, struct glyph
*string
, int len
)
714 unsigned char *conversion_buffer
;
715 struct coding_system
*coding
;
718 struct tty_display_info
*tty
= FRAME_TTY (f
);
720 tty_turn_off_insert (tty
);
721 tty_hide_cursor (tty
);
723 /* Don't dare write in last column of bottom line, if Auto-Wrap,
724 since that would scroll the whole frame on some terminals. */
727 && curY (tty
) + 1 == FRAME_LINES (f
)
728 && (curX (tty
) + len
) == FRAME_COLS (f
))
735 /* If terminal_coding does any conversion, use it, otherwise use
736 safe_terminal_coding. We can't use CODING_REQUIRE_ENCODING here
737 because it always return 1 if the member src_multibyte is 1. */
738 coding
= (FRAME_TERMINAL_CODING (f
)->common_flags
& CODING_REQUIRE_ENCODING_MASK
739 ? FRAME_TERMINAL_CODING (f
) : &safe_terminal_coding
);
740 /* The mode bit CODING_MODE_LAST_BLOCK should be set to 1 only at
742 coding
->mode
&= ~CODING_MODE_LAST_BLOCK
;
744 for (stringlen
= len
; stringlen
!= 0; stringlen
-= n
)
746 /* Identify a run of glyphs with the same face. */
747 int face_id
= string
->face_id
;
749 for (n
= 1; n
< stringlen
; ++n
)
750 if (string
[n
].face_id
!= face_id
)
753 /* Turn appearance modes of the face of the run on. */
754 tty_highlight_if_desired (tty
);
755 turn_on_face (f
, face_id
);
758 /* This is the last run. */
759 coding
->mode
|= CODING_MODE_LAST_BLOCK
;
760 conversion_buffer
= encode_terminal_code (string
, n
, coding
);
761 if (coding
->produced
> 0)
764 fwrite (conversion_buffer
, 1, coding
->produced
, tty
->output
);
765 if (ferror (tty
->output
))
766 clearerr (tty
->output
);
768 fwrite (conversion_buffer
, 1, coding
->produced
, tty
->termscript
);
773 /* Turn appearance modes off. */
774 turn_off_face (f
, face_id
);
775 tty_turn_off_highlight (tty
);
781 #ifdef HAVE_GPM /* Only used by GPM code. */
784 tty_write_glyphs_with_face (register struct frame
*f
, register struct glyph
*string
,
785 register int len
, register int face_id
)
787 unsigned char *conversion_buffer
;
788 struct coding_system
*coding
;
790 struct tty_display_info
*tty
= FRAME_TTY (f
);
792 tty_turn_off_insert (tty
);
793 tty_hide_cursor (tty
);
795 /* Don't dare write in last column of bottom line, if Auto-Wrap,
796 since that would scroll the whole frame on some terminals. */
799 && curY (tty
) + 1 == FRAME_LINES (f
)
800 && (curX (tty
) + len
) == FRAME_COLS (f
))
807 /* If terminal_coding does any conversion, use it, otherwise use
808 safe_terminal_coding. We can't use CODING_REQUIRE_ENCODING here
809 because it always return 1 if the member src_multibyte is 1. */
810 coding
= (FRAME_TERMINAL_CODING (f
)->common_flags
& CODING_REQUIRE_ENCODING_MASK
811 ? FRAME_TERMINAL_CODING (f
) : &safe_terminal_coding
);
812 /* The mode bit CODING_MODE_LAST_BLOCK should be set to 1 only at
814 coding
->mode
&= ~CODING_MODE_LAST_BLOCK
;
816 /* Turn appearance modes of the face. */
817 tty_highlight_if_desired (tty
);
818 turn_on_face (f
, face_id
);
820 coding
->mode
|= CODING_MODE_LAST_BLOCK
;
821 conversion_buffer
= encode_terminal_code (string
, len
, coding
);
822 if (coding
->produced
> 0)
825 fwrite (conversion_buffer
, 1, coding
->produced
, tty
->output
);
826 if (ferror (tty
->output
))
827 clearerr (tty
->output
);
829 fwrite (conversion_buffer
, 1, coding
->produced
, tty
->termscript
);
833 /* Turn appearance modes off. */
834 turn_off_face (f
, face_id
);
835 tty_turn_off_highlight (tty
);
841 /* An implementation of insert_glyphs for termcap frames. */
844 tty_insert_glyphs (struct frame
*f
, struct glyph
*start
, int len
)
847 struct glyph
*glyph
= NULL
;
848 unsigned char *conversion_buffer
;
849 unsigned char space
[1];
850 struct coding_system
*coding
;
852 struct tty_display_info
*tty
= FRAME_TTY (f
);
854 if (tty
->TS_ins_multi_chars
)
856 buf
= tparam (tty
->TS_ins_multi_chars
, 0, 0, len
, 0, 0, 0);
860 write_glyphs (f
, start
, len
);
864 tty_turn_on_insert (tty
);
868 space
[0] = SPACEGLYPH
;
870 /* If terminal_coding does any conversion, use it, otherwise use
871 safe_terminal_coding. We can't use CODING_REQUIRE_ENCODING here
872 because it always return 1 if the member src_multibyte is 1. */
873 coding
= (FRAME_TERMINAL_CODING (f
)->common_flags
& CODING_REQUIRE_ENCODING_MASK
874 ? FRAME_TERMINAL_CODING (f
) : &safe_terminal_coding
);
875 /* The mode bit CODING_MODE_LAST_BLOCK should be set to 1 only at
877 coding
->mode
&= ~CODING_MODE_LAST_BLOCK
;
881 OUTPUT1_IF (tty
, tty
->TS_ins_char
);
884 conversion_buffer
= space
;
885 coding
->produced
= 1;
889 tty_highlight_if_desired (tty
);
890 turn_on_face (f
, start
->face_id
);
893 /* We must open sufficient space for a character which
894 occupies more than one column. */
895 while (len
&& CHAR_GLYPH_PADDING_P (*start
))
897 OUTPUT1_IF (tty
, tty
->TS_ins_char
);
902 /* This is the last glyph. */
903 coding
->mode
|= CODING_MODE_LAST_BLOCK
;
905 conversion_buffer
= encode_terminal_code (glyph
, 1, coding
);
908 if (coding
->produced
> 0)
911 fwrite (conversion_buffer
, 1, coding
->produced
, tty
->output
);
912 if (ferror (tty
->output
))
913 clearerr (tty
->output
);
915 fwrite (conversion_buffer
, 1, coding
->produced
, tty
->termscript
);
919 OUTPUT1_IF (tty
, tty
->TS_pad_inserted_char
);
922 turn_off_face (f
, glyph
->face_id
);
923 tty_turn_off_highlight (tty
);
930 /* An implementation of delete_glyphs for termcap frames. */
933 tty_delete_glyphs (struct frame
*f
, int n
)
938 struct tty_display_info
*tty
= FRAME_TTY (f
);
940 if (tty
->delete_in_insert_mode
)
942 tty_turn_on_insert (tty
);
946 tty_turn_off_insert (tty
);
947 OUTPUT_IF (tty
, tty
->TS_delete_mode
);
950 if (tty
->TS_del_multi_chars
)
952 buf
= tparam (tty
->TS_del_multi_chars
, 0, 0, n
, 0, 0, 0);
957 for (i
= 0; i
< n
; i
++)
958 OUTPUT1 (tty
, tty
->TS_del_char
);
959 if (!tty
->delete_in_insert_mode
)
960 OUTPUT_IF (tty
, tty
->TS_end_delete_mode
);
963 /* An implementation of ins_del_lines for termcap frames. */
966 tty_ins_del_lines (struct frame
*f
, int vpos
, int n
)
968 struct tty_display_info
*tty
= FRAME_TTY (f
);
970 n
> 0 ? tty
->TS_ins_multi_lines
: tty
->TS_del_multi_lines
;
971 const char *single
= n
> 0 ? tty
->TS_ins_line
: tty
->TS_del_line
;
972 const char *scroll
= n
> 0 ? tty
->TS_rev_scroll
: tty
->TS_fwd_scroll
;
977 /* If the lines below the insertion are being pushed
978 into the end of the window, this is the same as clearing;
979 and we know the lines are already clear, since the matching
980 deletion has already been done. So can ignore this. */
981 /* If the lines below the deletion are blank lines coming
982 out of the end of the window, don't bother,
983 as there will be a matching inslines later that will flush them. */
984 if (FRAME_SCROLL_REGION_OK (f
)
985 && vpos
+ i
>= tty
->specified_window
)
987 if (!FRAME_MEMORY_BELOW_FRAME (f
)
988 && vpos
+ i
>= FRAME_LINES (f
))
993 raw_cursor_to (f
, vpos
, 0);
994 tty_background_highlight (tty
);
995 buf
= tparam (multi
, 0, 0, i
, 0, 0, 0);
1001 raw_cursor_to (f
, vpos
, 0);
1002 tty_background_highlight (tty
);
1004 OUTPUT (tty
, single
);
1005 if (tty
->TF_teleray
)
1010 tty_set_scroll_region (f
, vpos
, tty
->specified_window
);
1012 raw_cursor_to (f
, tty
->specified_window
- 1, 0);
1014 raw_cursor_to (f
, vpos
, 0);
1015 tty_background_highlight (tty
);
1017 OUTPUTL (tty
, scroll
, tty
->specified_window
- vpos
);
1018 tty_set_scroll_region (f
, 0, tty
->specified_window
);
1021 if (!FRAME_SCROLL_REGION_OK (f
)
1022 && FRAME_MEMORY_BELOW_FRAME (f
)
1025 cursor_to (f
, FRAME_LINES (f
) + n
, 0);
1030 /* Compute cost of sending "str", in characters,
1031 not counting any line-dependent padding. */
1034 string_cost (const char *str
)
1038 tputs (str
, 0, evalcost
);
1042 /* Compute cost of sending "str", in characters,
1043 counting any line-dependent padding at one line. */
1046 string_cost_one_line (const char *str
)
1050 tputs (str
, 1, evalcost
);
1054 /* Compute per line amount of line-dependent padding,
1055 in tenths of characters. */
1058 per_line_cost (const char *str
)
1062 tputs (str
, 0, evalcost
);
1065 tputs (str
, 10, evalcost
);
1069 /* char_ins_del_cost[n] is cost of inserting N characters.
1070 char_ins_del_cost[-n] is cost of deleting N characters.
1071 The length of this vector is based on max_frame_cols. */
1073 int *char_ins_del_vector
;
1075 #define char_ins_del_cost(f) (&char_ins_del_vector[FRAME_COLS ((f))])
1079 calculate_ins_del_char_costs (struct frame
*f
)
1081 struct tty_display_info
*tty
= FRAME_TTY (f
);
1082 int ins_startup_cost
, del_startup_cost
;
1083 int ins_cost_per_char
, del_cost_per_char
;
1087 if (tty
->TS_ins_multi_chars
)
1089 ins_cost_per_char
= 0;
1090 ins_startup_cost
= string_cost_one_line (tty
->TS_ins_multi_chars
);
1092 else if (tty
->TS_ins_char
|| tty
->TS_pad_inserted_char
1093 || (tty
->TS_insert_mode
&& tty
->TS_end_insert_mode
))
1095 ins_startup_cost
= (30 * (string_cost (tty
->TS_insert_mode
)
1096 + string_cost (tty
->TS_end_insert_mode
))) / 100;
1097 ins_cost_per_char
= (string_cost_one_line (tty
->TS_ins_char
)
1098 + string_cost_one_line (tty
->TS_pad_inserted_char
));
1102 ins_startup_cost
= 9999;
1103 ins_cost_per_char
= 0;
1106 if (tty
->TS_del_multi_chars
)
1108 del_cost_per_char
= 0;
1109 del_startup_cost
= string_cost_one_line (tty
->TS_del_multi_chars
);
1111 else if (tty
->TS_del_char
)
1113 del_startup_cost
= (string_cost (tty
->TS_delete_mode
)
1114 + string_cost (tty
->TS_end_delete_mode
));
1115 if (tty
->delete_in_insert_mode
)
1116 del_startup_cost
/= 2;
1117 del_cost_per_char
= string_cost_one_line (tty
->TS_del_char
);
1121 del_startup_cost
= 9999;
1122 del_cost_per_char
= 0;
1125 /* Delete costs are at negative offsets */
1126 p
= &char_ins_del_cost (f
)[0];
1127 for (i
= FRAME_COLS (f
); --i
>= 0;)
1128 *--p
= (del_startup_cost
+= del_cost_per_char
);
1130 /* Doing nothing is free */
1131 p
= &char_ins_del_cost (f
)[0];
1134 /* Insert costs are at positive offsets */
1135 for (i
= FRAME_COLS (f
); --i
>= 0;)
1136 *p
++ = (ins_startup_cost
+= ins_cost_per_char
);
1140 calculate_costs (struct frame
*frame
)
1142 FRAME_COST_BAUD_RATE (frame
) = baud_rate
;
1144 if (FRAME_TERMCAP_P (frame
))
1146 struct tty_display_info
*tty
= FRAME_TTY (frame
);
1147 register const char *f
= (tty
->TS_set_scroll_region
1148 ? tty
->TS_set_scroll_region
1149 : tty
->TS_set_scroll_region_1
);
1151 FRAME_SCROLL_REGION_COST (frame
) = string_cost (f
);
1155 /* These variables are only used for terminal stuff. They are
1156 allocated once for the terminal frame of X-windows emacs, but not
1159 char_ins_del_vector (i.e., char_ins_del_cost) isn't used because
1160 X turns off char_ins_del_ok. */
1162 max_frame_cols
= max (max_frame_cols
, FRAME_COLS (frame
));
1163 if ((min (PTRDIFF_MAX
, SIZE_MAX
) / sizeof (int) - 1) / 2
1165 memory_full (SIZE_MAX
);
1167 char_ins_del_vector
=
1168 xrealloc (char_ins_del_vector
,
1169 (sizeof (int) + 2 * sizeof (int) * max_frame_cols
));
1171 memset (char_ins_del_vector
, 0,
1172 (sizeof (int) + 2 * sizeof (int) * max_frame_cols
));
1175 if (f
&& (!tty
->TS_ins_line
&& !tty
->TS_del_line
))
1176 do_line_insertion_deletion_costs (frame
,
1177 tty
->TS_rev_scroll
, tty
->TS_ins_multi_lines
,
1178 tty
->TS_fwd_scroll
, tty
->TS_del_multi_lines
,
1181 do_line_insertion_deletion_costs (frame
,
1182 tty
->TS_ins_line
, tty
->TS_ins_multi_lines
,
1183 tty
->TS_del_line
, tty
->TS_del_multi_lines
,
1186 calculate_ins_del_char_costs (frame
);
1188 /* Don't use TS_repeat if its padding is worse than sending the chars */
1189 if (tty
->TS_repeat
&& per_line_cost (tty
->TS_repeat
) * baud_rate
< 9000)
1190 tty
->RPov
= string_cost (tty
->TS_repeat
);
1192 tty
->RPov
= FRAME_COLS (frame
) * 2;
1194 cmcostinit (FRAME_TTY (frame
)); /* set up cursor motion costs */
1199 const char *cap
, *name
;
1202 /* Termcap capability names that correspond directly to X keysyms.
1203 Some of these (marked "terminfo") aren't supplied by old-style
1204 (Berkeley) termcap entries. They're listed in X keysym order;
1205 except we put the keypad keys first, so that if they clash with
1206 other keys (as on the IBM PC keyboard) they get overridden.
1209 static const struct fkey_table keys
[] =
1211 {"kh", "home"}, /* termcap */
1212 {"kl", "left"}, /* termcap */
1213 {"ku", "up"}, /* termcap */
1214 {"kr", "right"}, /* termcap */
1215 {"kd", "down"}, /* termcap */
1216 {"%8", "prior"}, /* terminfo */
1217 {"%5", "next"}, /* terminfo */
1218 {"@7", "end"}, /* terminfo */
1219 {"@1", "begin"}, /* terminfo */
1220 {"*6", "select"}, /* terminfo */
1221 {"%9", "print"}, /* terminfo */
1222 {"@4", "execute"}, /* terminfo --- actually the `command' key */
1224 * "insert" --- see below
1226 {"&8", "undo"}, /* terminfo */
1227 {"%0", "redo"}, /* terminfo */
1228 {"%7", "menu"}, /* terminfo --- actually the `options' key */
1229 {"@0", "find"}, /* terminfo */
1230 {"@2", "cancel"}, /* terminfo */
1231 {"%1", "help"}, /* terminfo */
1233 * "break" goes here, but can't be reliably intercepted with termcap
1235 {"&4", "reset"}, /* terminfo --- actually `restart' */
1237 * "system" and "user" --- no termcaps
1239 {"kE", "clearline"}, /* terminfo */
1240 {"kA", "insertline"}, /* terminfo */
1241 {"kL", "deleteline"}, /* terminfo */
1242 {"kI", "insertchar"}, /* terminfo */
1243 {"kD", "deletechar"}, /* terminfo */
1244 {"kB", "backtab"}, /* terminfo */
1246 * "kp_backtab", "kp-space", "kp-tab" --- no termcaps
1248 {"@8", "kp-enter"}, /* terminfo */
1250 * "kp-f1", "kp-f2", "kp-f3" "kp-f4",
1251 * "kp-multiply", "kp-add", "kp-separator",
1252 * "kp-subtract", "kp-decimal", "kp-divide", "kp-0";
1253 * --- no termcaps for any of these.
1255 {"K4", "kp-1"}, /* terminfo */
1257 * "kp-2" --- no termcap
1259 {"K5", "kp-3"}, /* terminfo */
1261 * "kp-4" --- no termcap
1263 {"K2", "kp-5"}, /* terminfo */
1265 * "kp-6" --- no termcap
1267 {"K1", "kp-7"}, /* terminfo */
1269 * "kp-8" --- no termcap
1271 {"K3", "kp-9"}, /* terminfo */
1273 * "kp-equal" --- no termcap
1285 {"&0", "S-cancel"}, /*shifted cancel key*/
1286 {"&9", "S-begin"}, /*shifted begin key*/
1287 {"*0", "S-find"}, /*shifted find key*/
1288 {"*1", "S-execute"}, /*shifted execute? actually shifted command key*/
1289 {"*4", "S-delete"}, /*shifted delete-character key*/
1290 {"*7", "S-end"}, /*shifted end key*/
1291 {"*8", "S-clearline"}, /*shifted clear-to end-of-line key*/
1292 {"#1", "S-help"}, /*shifted help key*/
1293 {"#2", "S-home"}, /*shifted home key*/
1294 {"#3", "S-insert"}, /*shifted insert-character key*/
1295 {"#4", "S-left"}, /*shifted left-arrow key*/
1296 {"%d", "S-menu"}, /*shifted menu? actually shifted options key*/
1297 {"%c", "S-next"}, /*shifted next key*/
1298 {"%e", "S-prior"}, /*shifted previous key*/
1299 {"%f", "S-print"}, /*shifted print key*/
1300 {"%g", "S-redo"}, /*shifted redo key*/
1301 {"%i", "S-right"}, /*shifted right-arrow key*/
1302 {"!3", "S-undo"} /*shifted undo key*/
1306 static char **term_get_fkeys_address
;
1307 static KBOARD
*term_get_fkeys_kboard
;
1308 static Lisp_Object
term_get_fkeys_1 (void);
1310 /* Find the escape codes sent by the function keys for Vinput_decode_map.
1311 This function scans the termcap function key sequence entries, and
1312 adds entries to Vinput_decode_map for each function key it finds. */
1315 term_get_fkeys (char **address
, KBOARD
*kboard
)
1317 /* We run the body of the function (term_get_fkeys_1) and ignore all Lisp
1318 errors during the call. The only errors should be from Fdefine_key
1319 when given a key sequence containing an invalid prefix key. If the
1320 termcap defines function keys which use a prefix that is already bound
1321 to a command by the default bindings, we should silently ignore that
1322 function key specification, rather than giving the user an error and
1323 refusing to run at all on such a terminal. */
1325 term_get_fkeys_address
= address
;
1326 term_get_fkeys_kboard
= kboard
;
1327 internal_condition_case (term_get_fkeys_1
, Qerror
, Fidentity
);
1331 term_get_fkeys_1 (void)
1335 char **address
= term_get_fkeys_address
;
1336 KBOARD
*kboard
= term_get_fkeys_kboard
;
1338 /* This can happen if CANNOT_DUMP or with strange options. */
1339 if (!KEYMAPP (KVAR (kboard
, Vinput_decode_map
)))
1340 kset_input_decode_map (kboard
, Fmake_sparse_keymap (Qnil
));
1342 for (i
= 0; i
< (sizeof (keys
) / sizeof (keys
[0])); i
++)
1344 char *sequence
= tgetstr (keys
[i
].cap
, address
);
1346 Fdefine_key (KVAR (kboard
, Vinput_decode_map
), build_string (sequence
),
1347 Fmake_vector (make_number (1),
1348 intern (keys
[i
].name
)));
1351 /* The uses of the "k0" capability are inconsistent; sometimes it
1352 describes F10, whereas othertimes it describes F0 and "k;" describes F10.
1353 We will attempt to politely accommodate both systems by testing for
1354 "k;", and if it is present, assuming that "k0" denotes F0, otherwise F10.
1357 const char *k_semi
= tgetstr ("k;", address
);
1358 const char *k0
= tgetstr ("k0", address
);
1359 const char *k0_name
= "f10";
1364 /* Define f0 first, so that f10 takes precedence in case the
1365 key sequences happens to be the same. */
1366 Fdefine_key (KVAR (kboard
, Vinput_decode_map
), build_string (k0
),
1367 Fmake_vector (make_number (1), intern ("f0")));
1368 Fdefine_key (KVAR (kboard
, Vinput_decode_map
), build_string (k_semi
),
1369 Fmake_vector (make_number (1), intern ("f10")));
1372 Fdefine_key (KVAR (kboard
, Vinput_decode_map
), build_string (k0
),
1373 Fmake_vector (make_number (1), intern (k0_name
)));
1376 /* Set up cookies for numbered function keys above f10. */
1378 char fcap
[3], fkey
[4];
1380 fcap
[0] = 'F'; fcap
[2] = '\0';
1381 for (i
= 11; i
< 64; i
++)
1384 fcap
[1] = '1' + i
- 11;
1386 fcap
[1] = 'A' + i
- 20;
1388 fcap
[1] = 'a' + i
- 46;
1391 char *sequence
= tgetstr (fcap
, address
);
1394 sprintf (fkey
, "f%d", i
);
1395 Fdefine_key (KVAR (kboard
, Vinput_decode_map
), build_string (sequence
),
1396 Fmake_vector (make_number (1),
1404 * Various mappings to try and get a better fit.
1407 #define CONDITIONAL_REASSIGN(cap1, cap2, sym) \
1408 if (!tgetstr (cap1, address)) \
1410 char *sequence = tgetstr (cap2, address); \
1412 Fdefine_key (KVAR (kboard, Vinput_decode_map), build_string (sequence), \
1413 Fmake_vector (make_number (1), \
1417 /* if there's no key_next keycap, map key_npage to `next' keysym */
1418 CONDITIONAL_REASSIGN ("%5", "kN", "next");
1419 /* if there's no key_prev keycap, map key_ppage to `previous' keysym */
1420 CONDITIONAL_REASSIGN ("%8", "kP", "prior");
1421 /* if there's no key_dc keycap, map key_ic to `insert' keysym */
1422 CONDITIONAL_REASSIGN ("kD", "kI", "insert");
1423 /* if there's no key_end keycap, map key_ll to 'end' keysym */
1424 CONDITIONAL_REASSIGN ("@7", "kH", "end");
1426 /* IBM has their own non-standard dialect of terminfo.
1427 If the standard name isn't found, try the IBM name. */
1428 CONDITIONAL_REASSIGN ("kB", "KO", "backtab");
1429 CONDITIONAL_REASSIGN ("@4", "kJ", "execute"); /* actually "action" */
1430 CONDITIONAL_REASSIGN ("@4", "kc", "execute"); /* actually "command" */
1431 CONDITIONAL_REASSIGN ("%7", "ki", "menu");
1432 CONDITIONAL_REASSIGN ("@7", "kw", "end");
1433 CONDITIONAL_REASSIGN ("F1", "k<", "f11");
1434 CONDITIONAL_REASSIGN ("F2", "k>", "f12");
1435 CONDITIONAL_REASSIGN ("%1", "kq", "help");
1436 CONDITIONAL_REASSIGN ("*6", "kU", "select");
1437 #undef CONDITIONAL_REASSIGN
1442 #endif /* not DOS_NT */
1445 /***********************************************************************
1446 Character Display Information
1447 ***********************************************************************/
1448 static void append_glyph (struct it
*);
1449 static void append_composite_glyph (struct it
*);
1450 static void produce_composite_glyph (struct it
*);
1451 static void append_glyphless_glyph (struct it
*, int, const char *);
1452 static void produce_glyphless_glyph (struct it
*, Lisp_Object
);
1454 /* Append glyphs to IT's glyph_row. Called from produce_glyphs for
1455 terminal frames if IT->glyph_row != NULL. IT->char_to_display is
1456 the character for which to produce glyphs; IT->face_id contains the
1457 character's face. Padding glyphs are appended if IT->c has a
1458 IT->pixel_width > 1. */
1461 append_glyph (struct it
*it
)
1463 struct glyph
*glyph
, *end
;
1466 eassert (it
->glyph_row
);
1467 glyph
= (it
->glyph_row
->glyphs
[it
->area
]
1468 + it
->glyph_row
->used
[it
->area
]);
1469 end
= it
->glyph_row
->glyphs
[1 + it
->area
];
1471 /* If the glyph row is reversed, we need to prepend the glyph rather
1473 if (it
->glyph_row
->reversed_p
&& it
->area
== TEXT_AREA
)
1476 int move_by
= it
->pixel_width
;
1478 /* Make room for the new glyphs. */
1479 if (move_by
> end
- glyph
) /* don't overstep end of this area */
1480 move_by
= end
- glyph
;
1481 for (g
= glyph
- 1; g
>= it
->glyph_row
->glyphs
[it
->area
]; g
--)
1483 glyph
= it
->glyph_row
->glyphs
[it
->area
];
1484 end
= glyph
+ move_by
;
1487 /* BIDI Note: we put the glyphs of a "multi-pixel" character left to
1488 right, even in the REVERSED_P case, since (a) all of its u.ch are
1489 identical, and (b) the PADDING_P flag needs to be set for the
1490 leftmost one, because we write to the terminal left-to-right. */
1492 i
< it
->pixel_width
&& glyph
< end
;
1495 glyph
->type
= CHAR_GLYPH
;
1496 glyph
->pixel_width
= 1;
1497 glyph
->u
.ch
= it
->char_to_display
;
1498 glyph
->face_id
= it
->face_id
;
1499 glyph
->padding_p
= i
> 0;
1500 glyph
->charpos
= CHARPOS (it
->position
);
1501 glyph
->object
= it
->object
;
1504 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
1505 if ((it
->bidi_it
.type
& 7) != it
->bidi_it
.type
)
1507 glyph
->bidi_type
= it
->bidi_it
.type
;
1511 glyph
->resolved_level
= 0;
1512 glyph
->bidi_type
= UNKNOWN_BT
;
1515 ++it
->glyph_row
->used
[it
->area
];
1520 /* For external use. */
1522 tty_append_glyph (struct it
*it
)
1528 /* Produce glyphs for the display element described by IT. *IT
1529 specifies what we want to produce a glyph for (character, image, ...),
1530 and where in the glyph matrix we currently are (glyph row and hpos).
1531 produce_glyphs fills in output fields of *IT with information such as the
1532 pixel width and height of a character, and maybe output actual glyphs at
1533 the same time if IT->glyph_row is non-null. For an overview, see
1534 the explanation in dispextern.h, before the definition of the
1535 display_element_type enumeration.
1537 produce_glyphs also stores the result of glyph width, ascent
1538 etc. computations in *IT.
1540 IT->glyph_row may be null, in which case produce_glyphs does not
1541 actually fill in the glyphs. This is used in the move_* functions
1542 in xdisp.c for text width and height computations.
1544 Callers usually don't call produce_glyphs directly;
1545 instead they use the macro PRODUCE_GLYPHS. */
1548 produce_glyphs (struct it
*it
)
1550 /* If a hook is installed, let it do the work. */
1552 /* Nothing but characters are supported on terminal frames. */
1553 eassert (it
->what
== IT_CHARACTER
1554 || it
->what
== IT_COMPOSITION
1555 || it
->what
== IT_STRETCH
1556 || it
->what
== IT_GLYPHLESS
);
1558 if (it
->what
== IT_STRETCH
)
1560 produce_stretch_glyph (it
);
1564 if (it
->what
== IT_COMPOSITION
)
1566 produce_composite_glyph (it
);
1570 if (it
->what
== IT_GLYPHLESS
)
1572 produce_glyphless_glyph (it
, Qnil
);
1576 if (it
->char_to_display
>= 040 && it
->char_to_display
< 0177)
1578 it
->pixel_width
= it
->nglyphs
= 1;
1582 else if (it
->char_to_display
== '\n')
1583 it
->pixel_width
= it
->nglyphs
= 0;
1584 else if (it
->char_to_display
== '\t')
1586 int absolute_x
= (it
->current_x
1587 + it
->continuation_lines_width
);
1589 = (((1 + absolute_x
+ it
->tab_width
- 1)
1594 /* If part of the TAB has been displayed on the previous line
1595 which is continued now, continuation_lines_width will have
1596 been incremented already by the part that fitted on the
1597 continued line. So, we will get the right number of spaces
1599 nspaces
= next_tab_x
- absolute_x
;
1605 it
->char_to_display
= ' ';
1606 it
->pixel_width
= it
->len
= 1;
1612 it
->pixel_width
= nspaces
;
1613 it
->nglyphs
= nspaces
;
1615 else if (CHAR_BYTE8_P (it
->char_to_display
))
1617 /* Coming here means that we must send the raw 8-bit byte as is
1618 to the terminal. Although there's no way to know how many
1619 columns it occupies on a screen, it is a good assumption that
1620 a single byte code has 1-column width. */
1621 it
->pixel_width
= it
->nglyphs
= 1;
1627 Lisp_Object charset_list
= FRAME_TERMINAL (it
->f
)->charset_list
;
1629 if (char_charset (it
->char_to_display
, charset_list
, NULL
))
1631 it
->pixel_width
= CHAR_WIDTH (it
->char_to_display
);
1632 it
->nglyphs
= it
->pixel_width
;
1638 Lisp_Object acronym
= lookup_glyphless_char_display (-1, it
);
1640 eassert (it
->what
== IT_GLYPHLESS
);
1641 produce_glyphless_glyph (it
, acronym
);
1646 /* Advance current_x by the pixel width as a convenience for
1648 if (it
->area
== TEXT_AREA
)
1649 it
->current_x
+= it
->pixel_width
;
1650 it
->ascent
= it
->max_ascent
= it
->phys_ascent
= it
->max_phys_ascent
= 0;
1651 it
->descent
= it
->max_descent
= it
->phys_descent
= it
->max_phys_descent
= 1;
1654 /* Append glyphs to IT's glyph_row for the composition IT->cmp_id.
1655 Called from produce_composite_glyph for terminal frames if
1656 IT->glyph_row != NULL. IT->face_id contains the character's
1660 append_composite_glyph (struct it
*it
)
1662 struct glyph
*glyph
;
1664 eassert (it
->glyph_row
);
1665 glyph
= it
->glyph_row
->glyphs
[it
->area
] + it
->glyph_row
->used
[it
->area
];
1666 if (glyph
< it
->glyph_row
->glyphs
[1 + it
->area
])
1668 /* If the glyph row is reversed, we need to prepend the glyph
1669 rather than append it. */
1670 if (it
->glyph_row
->reversed_p
&& it
->area
== TEXT_AREA
)
1674 /* Make room for the new glyph. */
1675 for (g
= glyph
- 1; g
>= it
->glyph_row
->glyphs
[it
->area
]; g
--)
1677 glyph
= it
->glyph_row
->glyphs
[it
->area
];
1679 glyph
->type
= COMPOSITE_GLYPH
;
1680 glyph
->pixel_width
= it
->pixel_width
;
1681 glyph
->u
.cmp
.id
= it
->cmp_it
.id
;
1682 if (it
->cmp_it
.ch
< 0)
1684 glyph
->u
.cmp
.automatic
= 0;
1685 glyph
->u
.cmp
.id
= it
->cmp_it
.id
;
1689 glyph
->u
.cmp
.automatic
= 1;
1690 glyph
->u
.cmp
.id
= it
->cmp_it
.id
;
1691 glyph
->slice
.cmp
.from
= it
->cmp_it
.from
;
1692 glyph
->slice
.cmp
.to
= it
->cmp_it
.to
- 1;
1695 glyph
->face_id
= it
->face_id
;
1696 glyph
->padding_p
= 0;
1697 glyph
->charpos
= CHARPOS (it
->position
);
1698 glyph
->object
= it
->object
;
1701 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
1702 if ((it
->bidi_it
.type
& 7) != it
->bidi_it
.type
)
1704 glyph
->bidi_type
= it
->bidi_it
.type
;
1708 glyph
->resolved_level
= 0;
1709 glyph
->bidi_type
= UNKNOWN_BT
;
1712 ++it
->glyph_row
->used
[it
->area
];
1718 /* Produce a composite glyph for iterator IT. IT->cmp_id is the ID of
1719 the composition. We simply produces components of the composition
1720 assuming that the terminal has a capability to layout/render it
1724 produce_composite_glyph (struct it
*it
)
1726 if (it
->cmp_it
.ch
< 0)
1728 struct composition
*cmp
= composition_table
[it
->cmp_it
.id
];
1730 it
->pixel_width
= cmp
->width
;
1734 Lisp_Object gstring
= composition_gstring_from_id (it
->cmp_it
.id
);
1736 it
->pixel_width
= composition_gstring_width (gstring
, it
->cmp_it
.from
,
1737 it
->cmp_it
.to
, NULL
);
1741 append_composite_glyph (it
);
1745 /* Append a glyph for a glyphless character to IT->glyph_row. FACE_ID
1746 is a face ID to be used for the glyph. What is actually appended
1747 are glyphs of type CHAR_GLYPH whose characters are in STR (which
1748 comes from it->nglyphs bytes). */
1751 append_glyphless_glyph (struct it
*it
, int face_id
, const char *str
)
1753 struct glyph
*glyph
, *end
;
1756 eassert (it
->glyph_row
);
1757 glyph
= it
->glyph_row
->glyphs
[it
->area
] + it
->glyph_row
->used
[it
->area
];
1758 end
= it
->glyph_row
->glyphs
[1 + it
->area
];
1760 /* If the glyph row is reversed, we need to prepend the glyph rather
1762 if (it
->glyph_row
->reversed_p
&& it
->area
== TEXT_AREA
)
1765 int move_by
= it
->pixel_width
;
1767 /* Make room for the new glyphs. */
1768 if (move_by
> end
- glyph
) /* don't overstep end of this area */
1769 move_by
= end
- glyph
;
1770 for (g
= glyph
- 1; g
>= it
->glyph_row
->glyphs
[it
->area
]; g
--)
1772 glyph
= it
->glyph_row
->glyphs
[it
->area
];
1773 end
= glyph
+ move_by
;
1778 glyph
->type
= CHAR_GLYPH
;
1779 glyph
->pixel_width
= 1;
1780 glyph
->face_id
= face_id
;
1781 glyph
->padding_p
= 0;
1782 glyph
->charpos
= CHARPOS (it
->position
);
1783 glyph
->object
= it
->object
;
1786 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
1787 if ((it
->bidi_it
.type
& 7) != it
->bidi_it
.type
)
1789 glyph
->bidi_type
= it
->bidi_it
.type
;
1793 glyph
->resolved_level
= 0;
1794 glyph
->bidi_type
= UNKNOWN_BT
;
1797 /* BIDI Note: we put the glyphs of characters left to right, even in
1798 the REVERSED_P case because we write to the terminal
1800 for (i
= 0; i
< it
->nglyphs
&& glyph
< end
; ++i
)
1803 glyph
[0] = glyph
[-1];
1804 glyph
->u
.ch
= str
[i
];
1805 ++it
->glyph_row
->used
[it
->area
];
1810 /* Produce glyphs for a glyphless character for iterator IT.
1811 IT->glyphless_method specifies which method to use for displaying
1812 the character. See the description of enum
1813 glyphless_display_method in dispextern.h for the details.
1815 ACRONYM, if non-nil, is an acronym string for the character.
1817 The glyphs actually produced are of type CHAR_GLYPH. */
1820 produce_glyphless_glyph (struct it
*it
, Lisp_Object acronym
)
1822 int len
, face_id
= merge_glyphless_glyph_face (it
);
1823 char buf
[sizeof "\\x" + max (6, (sizeof it
->c
* CHAR_BIT
+ 3) / 4)];
1824 char const *str
= " ";
1826 if (it
->glyphless_method
== GLYPHLESS_DISPLAY_THIN_SPACE
)
1828 /* As there's no way to produce a thin space, we produce a space
1829 of canonical width. */
1832 else if (it
->glyphless_method
== GLYPHLESS_DISPLAY_EMPTY_BOX
)
1834 len
= CHAR_WIDTH (it
->c
);
1839 len
= sprintf (buf
, "[%.*s]", len
, str
);
1844 if (it
->glyphless_method
== GLYPHLESS_DISPLAY_ACRONYM
)
1846 if (! STRINGP (acronym
) && CHAR_TABLE_P (Vglyphless_char_display
))
1847 acronym
= CHAR_TABLE_REF (Vglyphless_char_display
, it
->c
);
1848 if (CONSP (acronym
))
1849 acronym
= XCDR (acronym
);
1851 str
= STRINGP (acronym
) ? SSDATA (acronym
) : "";
1852 for (len
= 0; len
< 6 && str
[len
] && ASCII_BYTE_P (str
[len
]); len
++)
1853 buf
[1 + len
] = str
[len
];
1859 eassert (it
->glyphless_method
== GLYPHLESS_DISPLAY_HEX_CODE
);
1860 len
= (it
->c
< 0x10000 ? sprintf (buf
, "\\u%04X", it
->c
)
1861 : it
->c
<= MAX_UNICODE_CHAR
? sprintf (buf
, "\\U%06X", it
->c
)
1862 : sprintf (buf
, "\\x%06X", it
->c
));
1867 it
->pixel_width
= len
;
1870 append_glyphless_glyph (it
, face_id
, str
);
1874 /***********************************************************************
1876 ***********************************************************************/
1878 /* Value is non-zero if attribute ATTR may be used. ATTR should be
1879 one of the enumerators from enum no_color_bit, or a bit set built
1880 from them. Some display attributes may not be used together with
1881 color; the termcap capability `NC' specifies which ones. */
1883 #define MAY_USE_WITH_COLORS_P(tty, ATTR) \
1884 (tty->TN_max_colors > 0 \
1885 ? (tty->TN_no_color_video & (ATTR)) == 0 \
1888 /* Turn appearances of face FACE_ID on tty frame F on.
1889 FACE_ID is a realized face ID number, in the face cache. */
1892 turn_on_face (struct frame
*f
, int face_id
)
1894 struct face
*face
= FACE_FROM_ID (f
, face_id
);
1895 long fg
= face
->foreground
;
1896 long bg
= face
->background
;
1897 struct tty_display_info
*tty
= FRAME_TTY (f
);
1899 /* Do this first because TS_end_standout_mode may be the same
1900 as TS_exit_attribute_mode, which turns all appearances off. */
1901 if (MAY_USE_WITH_COLORS_P (tty
, NC_REVERSE
))
1903 if (tty
->TN_max_colors
> 0)
1905 if (fg
>= 0 && bg
>= 0)
1907 /* If the terminal supports colors, we can set them
1908 below without using reverse video. The face's fg
1909 and bg colors are set as they should appear on
1910 the screen, i.e. they take the inverse-video'ness
1911 of the face already into account. */
1913 else if (inverse_video
)
1915 if (fg
== FACE_TTY_DEFAULT_FG_COLOR
1916 || bg
== FACE_TTY_DEFAULT_BG_COLOR
)
1917 tty_toggle_highlight (tty
);
1921 if (fg
== FACE_TTY_DEFAULT_BG_COLOR
1922 || bg
== FACE_TTY_DEFAULT_FG_COLOR
)
1923 tty_toggle_highlight (tty
);
1928 /* If we can't display colors, use reverse video
1929 if the face specifies that. */
1932 if (fg
== FACE_TTY_DEFAULT_FG_COLOR
1933 || bg
== FACE_TTY_DEFAULT_BG_COLOR
)
1934 tty_toggle_highlight (tty
);
1938 if (fg
== FACE_TTY_DEFAULT_BG_COLOR
1939 || bg
== FACE_TTY_DEFAULT_FG_COLOR
)
1940 tty_toggle_highlight (tty
);
1945 if (face
->tty_bold_p
&& MAY_USE_WITH_COLORS_P (tty
, NC_BOLD
))
1946 OUTPUT1_IF (tty
, tty
->TS_enter_bold_mode
);
1948 if (face
->tty_italic_p
&& MAY_USE_WITH_COLORS_P (tty
, NC_ITALIC
))
1950 if (tty
->TS_enter_italic_mode
)
1951 OUTPUT1 (tty
, tty
->TS_enter_italic_mode
);
1953 /* Italics mode is unavailable on many terminals. In that
1954 case, map slant to dimmed text; we want italic text to
1955 appear different and dimming is not otherwise used. */
1956 OUTPUT1 (tty
, tty
->TS_enter_dim_mode
);
1959 if (face
->tty_underline_p
&& MAY_USE_WITH_COLORS_P (tty
, NC_UNDERLINE
))
1960 OUTPUT1_IF (tty
, tty
->TS_enter_underline_mode
);
1962 if (tty
->TN_max_colors
> 0)
1967 ts
= tty
->standout_mode
? tty
->TS_set_background
: tty
->TS_set_foreground
;
1970 p
= tparam (ts
, NULL
, 0, fg
, 0, 0, 0);
1975 ts
= tty
->standout_mode
? tty
->TS_set_foreground
: tty
->TS_set_background
;
1978 p
= tparam (ts
, NULL
, 0, bg
, 0, 0, 0);
1986 /* Turn off appearances of face FACE_ID on tty frame F. */
1989 turn_off_face (struct frame
*f
, int face_id
)
1991 struct face
*face
= FACE_FROM_ID (f
, face_id
);
1992 struct tty_display_info
*tty
= FRAME_TTY (f
);
1994 eassert (face
!= NULL
);
1996 if (tty
->TS_exit_attribute_mode
)
1998 /* Capability "me" will turn off appearance modes double-bright,
1999 half-bright, reverse-video, standout, underline. It may or
2000 may not turn off alt-char-mode. */
2001 if (face
->tty_bold_p
2002 || face
->tty_italic_p
2003 || face
->tty_reverse_p
2004 || face
->tty_underline_p
)
2006 OUTPUT1_IF (tty
, tty
->TS_exit_attribute_mode
);
2007 if (strcmp (tty
->TS_exit_attribute_mode
, tty
->TS_end_standout_mode
) == 0)
2008 tty
->standout_mode
= 0;
2013 /* If we don't have "me" we can only have those appearances
2014 that have exit sequences defined. */
2015 if (face
->tty_underline_p
)
2016 OUTPUT_IF (tty
, tty
->TS_exit_underline_mode
);
2019 /* Switch back to default colors. */
2020 if (tty
->TN_max_colors
> 0
2021 && ((face
->foreground
!= FACE_TTY_DEFAULT_COLOR
2022 && face
->foreground
!= FACE_TTY_DEFAULT_FG_COLOR
)
2023 || (face
->background
!= FACE_TTY_DEFAULT_COLOR
2024 && face
->background
!= FACE_TTY_DEFAULT_BG_COLOR
)))
2025 OUTPUT1_IF (tty
, tty
->TS_orig_pair
);
2029 /* Return true if the terminal on frame F supports all of the
2030 capabilities in CAPS simultaneously, with foreground and background
2031 colors FG and BG. */
2034 tty_capable_p (struct tty_display_info
*tty
, unsigned int caps
,
2035 unsigned long fg
, unsigned long bg
)
2037 #define TTY_CAPABLE_P_TRY(tty, cap, TS, NC_bit) \
2038 if ((caps & (cap)) && (!(TS) || !MAY_USE_WITH_COLORS_P(tty, NC_bit))) \
2041 TTY_CAPABLE_P_TRY (tty
, TTY_CAP_INVERSE
, tty
->TS_standout_mode
, NC_REVERSE
);
2042 TTY_CAPABLE_P_TRY (tty
, TTY_CAP_UNDERLINE
, tty
->TS_enter_underline_mode
, NC_UNDERLINE
);
2043 TTY_CAPABLE_P_TRY (tty
, TTY_CAP_BOLD
, tty
->TS_enter_bold_mode
, NC_BOLD
);
2044 TTY_CAPABLE_P_TRY (tty
, TTY_CAP_DIM
, tty
->TS_enter_dim_mode
, NC_DIM
);
2045 TTY_CAPABLE_P_TRY (tty
, TTY_CAP_ITALIC
, tty
->TS_enter_italic_mode
, NC_ITALIC
);
2051 /* Return non-zero if the terminal is capable to display colors. */
2053 DEFUN ("tty-display-color-p", Ftty_display_color_p
, Stty_display_color_p
,
2055 doc
: /* Return non-nil if the tty device TERMINAL can display colors.
2057 TERMINAL can be a terminal object, a frame, or nil (meaning the
2058 selected frame's terminal). This function always returns nil if
2059 TERMINAL does not refer to a text terminal. */)
2060 (Lisp_Object terminal
)
2062 struct terminal
*t
= get_tty_terminal (terminal
, 0);
2066 return t
->display_info
.tty
->TN_max_colors
> 0 ? Qt
: Qnil
;
2069 /* Return the number of supported colors. */
2070 DEFUN ("tty-display-color-cells", Ftty_display_color_cells
,
2071 Stty_display_color_cells
, 0, 1, 0,
2072 doc
: /* Return the number of colors supported by the tty device TERMINAL.
2074 TERMINAL can be a terminal object, a frame, or nil (meaning the
2075 selected frame's terminal). This function always returns 0 if
2076 TERMINAL does not refer to a text terminal. */)
2077 (Lisp_Object terminal
)
2079 struct terminal
*t
= get_tty_terminal (terminal
, 0);
2081 return make_number (0);
2083 return make_number (t
->display_info
.tty
->TN_max_colors
);
2088 /* Declare here rather than in the function, as in the rest of Emacs,
2089 to work around an HPUX compiler bug (?). See
2090 http://lists.gnu.org/archive/html/emacs-devel/2007-08/msg00410.html */
2091 static int default_max_colors
;
2092 static int default_max_pairs
;
2093 static int default_no_color_video
;
2094 static char *default_orig_pair
;
2095 static char *default_set_foreground
;
2096 static char *default_set_background
;
2098 /* Save or restore the default color-related capabilities of this
2101 tty_default_color_capabilities (struct tty_display_info
*tty
, bool save
)
2106 xfree (default_orig_pair
);
2107 default_orig_pair
= tty
->TS_orig_pair
? xstrdup (tty
->TS_orig_pair
) : NULL
;
2109 xfree (default_set_foreground
);
2110 default_set_foreground
= tty
->TS_set_foreground
? xstrdup (tty
->TS_set_foreground
)
2113 xfree (default_set_background
);
2114 default_set_background
= tty
->TS_set_background
? xstrdup (tty
->TS_set_background
)
2117 default_max_colors
= tty
->TN_max_colors
;
2118 default_max_pairs
= tty
->TN_max_pairs
;
2119 default_no_color_video
= tty
->TN_no_color_video
;
2123 tty
->TS_orig_pair
= default_orig_pair
;
2124 tty
->TS_set_foreground
= default_set_foreground
;
2125 tty
->TS_set_background
= default_set_background
;
2126 tty
->TN_max_colors
= default_max_colors
;
2127 tty
->TN_max_pairs
= default_max_pairs
;
2128 tty
->TN_no_color_video
= default_no_color_video
;
2132 /* Setup one of the standard tty color schemes according to MODE.
2133 MODE's value is generally the number of colors which we want to
2134 support; zero means set up for the default capabilities, the ones
2135 we saw at init_tty time; -1 means turn off color support. */
2137 tty_setup_colors (struct tty_display_info
*tty
, int mode
)
2139 /* Canonicalize all negative values of MODE. */
2145 case -1: /* no colors at all */
2146 tty
->TN_max_colors
= 0;
2147 tty
->TN_max_pairs
= 0;
2148 tty
->TN_no_color_video
= 0;
2149 tty
->TS_set_foreground
= tty
->TS_set_background
= tty
->TS_orig_pair
= NULL
;
2151 case 0: /* default colors, if any */
2153 tty_default_color_capabilities (tty
, 0);
2155 case 8: /* 8 standard ANSI colors */
2156 tty
->TS_orig_pair
= "\033[0m";
2158 tty
->TS_set_foreground
= "\033[3%p1%dm";
2159 tty
->TS_set_background
= "\033[4%p1%dm";
2161 tty
->TS_set_foreground
= "\033[3%dm";
2162 tty
->TS_set_background
= "\033[4%dm";
2164 tty
->TN_max_colors
= 8;
2165 tty
->TN_max_pairs
= 64;
2166 tty
->TN_no_color_video
= 0;
2172 set_tty_color_mode (struct tty_display_info
*tty
, struct frame
*f
)
2174 Lisp_Object tem
, val
;
2175 Lisp_Object color_mode
;
2177 Lisp_Object tty_color_mode_alist
2178 = Fintern_soft (build_string ("tty-color-mode-alist"), Qnil
);
2180 tem
= assq_no_quit (Qtty_color_mode
, f
->param_alist
);
2181 val
= CONSP (tem
) ? XCDR (tem
) : Qnil
;
2185 else if (SYMBOLP (tty_color_mode_alist
))
2187 tem
= Fassq (val
, Fsymbol_value (tty_color_mode_alist
));
2188 color_mode
= CONSP (tem
) ? XCDR (tem
) : Qnil
;
2193 mode
= TYPE_RANGED_INTEGERP (int, color_mode
) ? XINT (color_mode
) : 0;
2195 if (mode
!= tty
->previous_color_mode
)
2197 tty
->previous_color_mode
= mode
;
2198 tty_setup_colors (tty
, mode
);
2199 /* This recomputes all the faces given the new color definitions. */
2200 safe_call (1, intern ("tty-set-up-initial-frame-faces"));
2204 #endif /* !DOS_NT */
2208 /* Return the tty display object specified by TERMINAL. */
2210 static struct terminal
*
2211 get_tty_terminal (Lisp_Object terminal
, bool throw)
2213 struct terminal
*t
= get_terminal (terminal
, throw);
2215 if (t
&& t
->type
!= output_termcap
&& t
->type
!= output_msdos_raw
)
2218 error ("Device %d is not a termcap terminal device", t
->id
);
2226 /* Return an active termcap device that uses the tty device with the
2229 This function ignores suspended devices.
2231 Returns NULL if the named terminal device is not opened. */
2234 get_named_tty (const char *name
)
2240 for (t
= terminal_list
; t
; t
= t
->next_terminal
)
2242 if ((t
->type
== output_termcap
|| t
->type
== output_msdos_raw
)
2243 && !strcmp (t
->display_info
.tty
->name
, name
)
2244 && TERMINAL_ACTIVE_P (t
))
2252 DEFUN ("tty-type", Ftty_type
, Stty_type
, 0, 1, 0,
2253 doc
: /* Return the type of the tty device that TERMINAL uses.
2254 Returns nil if TERMINAL is not on a tty device.
2256 TERMINAL can be a terminal object, a frame, or nil (meaning the
2257 selected frame's terminal). */)
2258 (Lisp_Object terminal
)
2260 struct terminal
*t
= get_terminal (terminal
, 1);
2262 if (t
->type
!= output_termcap
&& t
->type
!= output_msdos_raw
)
2265 if (t
->display_info
.tty
->type
)
2266 return build_string (t
->display_info
.tty
->type
);
2271 DEFUN ("controlling-tty-p", Fcontrolling_tty_p
, Scontrolling_tty_p
, 0, 1, 0,
2272 doc
: /* Return non-nil if TERMINAL is the controlling tty of the Emacs process.
2274 TERMINAL can be a terminal object, a frame, or nil (meaning the
2275 selected frame's terminal). This function always returns nil if
2276 TERMINAL is not on a tty device. */)
2277 (Lisp_Object terminal
)
2279 struct terminal
*t
= get_terminal (terminal
, 1);
2281 if ((t
->type
!= output_termcap
&& t
->type
!= output_msdos_raw
)
2282 || strcmp (t
->display_info
.tty
->name
, DEV_TTY
) != 0)
2288 DEFUN ("tty-no-underline", Ftty_no_underline
, Stty_no_underline
, 0, 1, 0,
2289 doc
: /* Declare that the tty used by TERMINAL does not handle underlining.
2290 This is used to override the terminfo data, for certain terminals that
2291 do not really do underlining, but say that they do. This function has
2292 no effect if used on a non-tty terminal.
2294 TERMINAL can be a terminal object, a frame or nil (meaning the
2295 selected frame's terminal). This function always returns nil if
2296 TERMINAL does not refer to a text terminal. */)
2297 (Lisp_Object terminal
)
2299 struct terminal
*t
= get_terminal (terminal
, 1);
2301 if (t
->type
== output_termcap
)
2302 t
->display_info
.tty
->TS_enter_underline_mode
= 0;
2306 DEFUN ("tty-top-frame", Ftty_top_frame
, Stty_top_frame
, 0, 1, 0,
2307 doc
: /* Return the topmost terminal frame on TERMINAL.
2308 TERMINAL can be a terminal object, a frame or nil (meaning the
2309 selected frame's terminal). This function returns nil if TERMINAL
2310 does not refer to a text terminal. Otherwise, it returns the
2311 top-most frame on the text terminal. */)
2312 (Lisp_Object terminal
)
2314 struct terminal
*t
= get_terminal (terminal
, 1);
2316 if (t
->type
== output_termcap
)
2317 return t
->display_info
.tty
->top_frame
;
2323 DEFUN ("suspend-tty", Fsuspend_tty
, Ssuspend_tty
, 0, 1, 0,
2324 doc
: /* Suspend the terminal device TTY.
2326 The device is restored to its default state, and Emacs ceases all
2327 access to the tty device. Frames that use the device are not deleted,
2328 but input is not read from them and if they change, their display is
2331 TTY may be a terminal object, a frame, or nil for the terminal device
2332 of the currently selected frame.
2334 This function runs `suspend-tty-functions' after suspending the
2335 device. The functions are run with one arg, the id of the suspended
2338 `suspend-tty' does nothing if it is called on a device that is already
2341 A suspended tty may be resumed by calling `resume-tty' on it. */)
2344 struct terminal
*t
= get_tty_terminal (tty
, 1);
2348 error ("Unknown tty device");
2350 f
= t
->display_info
.tty
->input
;
2354 /* First run `suspend-tty-functions' and then clean up the tty
2355 state because `suspend-tty-functions' might need to change
2357 Lisp_Object args
[2];
2358 args
[0] = intern ("suspend-tty-functions");
2359 XSETTERMINAL (args
[1], t
);
2360 Frun_hook_with_args (2, args
);
2362 reset_sys_modes (t
->display_info
.tty
);
2363 delete_keyboard_wait_descriptor (fileno (f
));
2367 if (f
!= t
->display_info
.tty
->output
)
2368 fclose (t
->display_info
.tty
->output
);
2371 t
->display_info
.tty
->input
= 0;
2372 t
->display_info
.tty
->output
= 0;
2374 if (FRAMEP (t
->display_info
.tty
->top_frame
))
2375 SET_FRAME_VISIBLE (XFRAME (t
->display_info
.tty
->top_frame
), 0);
2379 /* Clear display hooks to prevent further output. */
2380 clear_tty_hooks (t
);
2385 DEFUN ("resume-tty", Fresume_tty
, Sresume_tty
, 0, 1, 0,
2386 doc
: /* Resume the previously suspended terminal device TTY.
2387 The terminal is opened and reinitialized. Frames that are on the
2388 suspended terminal are revived.
2390 It is an error to resume a terminal while another terminal is active
2393 This function runs `resume-tty-functions' after resuming the terminal.
2394 The functions are run with one arg, the id of the resumed terminal
2397 `resume-tty' does nothing if it is called on a device that is not
2400 TTY may be a terminal object, a frame, or nil (meaning the selected
2401 frame's terminal). */)
2404 struct terminal
*t
= get_tty_terminal (tty
, 1);
2408 error ("Unknown tty device");
2410 if (!t
->display_info
.tty
->input
)
2412 if (get_named_tty (t
->display_info
.tty
->name
))
2413 error ("Cannot resume display while another display is active on the same device");
2416 t
->display_info
.tty
->output
= stdout
;
2417 t
->display_info
.tty
->input
= stdin
;
2419 fd
= emacs_open (t
->display_info
.tty
->name
, O_RDWR
| O_NOCTTY
, 0);
2420 t
->display_info
.tty
->input
= t
->display_info
.tty
->output
2421 = fd
< 0 ? 0 : fdopen (fd
, "w+");
2423 if (! t
->display_info
.tty
->input
)
2425 int open_errno
= errno
;
2427 report_file_errno ("Cannot reopen tty device",
2428 build_string (t
->display_info
.tty
->name
),
2432 if (!O_IGNORE_CTTY
&& strcmp (t
->display_info
.tty
->name
, DEV_TTY
) != 0)
2433 dissociate_if_controlling_tty (fd
);
2436 add_keyboard_wait_descriptor (fd
);
2438 if (FRAMEP (t
->display_info
.tty
->top_frame
))
2440 struct frame
*f
= XFRAME (t
->display_info
.tty
->top_frame
);
2442 int old_height
= FRAME_COLS (f
);
2443 int old_width
= FRAME_LINES (f
);
2445 /* Check if terminal/window size has changed while the frame
2447 get_tty_size (fileno (t
->display_info
.tty
->input
), &width
, &height
);
2448 if (width
!= old_width
|| height
!= old_height
)
2449 change_frame_size (f
, height
, width
, 0, 0, 0);
2450 SET_FRAME_VISIBLE (XFRAME (t
->display_info
.tty
->top_frame
), 1);
2454 init_sys_modes (t
->display_info
.tty
);
2457 /* Run `resume-tty-functions'. */
2458 Lisp_Object args
[2];
2459 args
[0] = intern ("resume-tty-functions");
2460 XSETTERMINAL (args
[1], t
);
2461 Frun_hook_with_args (2, args
);
2471 /***********************************************************************
2473 ***********************************************************************/
2477 #ifndef HAVE_WINDOW_SYSTEM
2479 term_mouse_moveto (int x
, int y
)
2481 /* TODO: how to set mouse position?
2484 name = (const char *) ttyname (0);
2485 fd = emacs_open (name, O_WRONLY, 0);
2486 SOME_FUNCTION (x, y, fd);
2489 last_mouse_y = y; */
2491 #endif /* HAVE_WINDOW_SYSTEM */
2493 /* Implementation of draw_row_with_mouse_face for TTY/GPM. */
2495 tty_draw_row_with_mouse_face (struct window
*w
, struct glyph_row
*row
,
2496 int start_hpos
, int end_hpos
,
2497 enum draw_glyphs_face draw
)
2499 int nglyphs
= end_hpos
- start_hpos
;
2500 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
2501 struct tty_display_info
*tty
= FRAME_TTY (f
);
2502 int face_id
= tty
->mouse_highlight
.mouse_face_face_id
;
2503 int save_x
, save_y
, pos_x
, pos_y
;
2505 if (end_hpos
>= row
->used
[TEXT_AREA
])
2506 nglyphs
= row
->used
[TEXT_AREA
] - start_hpos
;
2508 pos_y
= row
->y
+ WINDOW_TOP_EDGE_Y (w
);
2509 pos_x
= row
->used
[LEFT_MARGIN_AREA
] + start_hpos
+ WINDOW_LEFT_EDGE_X (w
);
2511 /* Save current cursor co-ordinates. */
2512 save_y
= curY (tty
);
2513 save_x
= curX (tty
);
2514 cursor_to (f
, pos_y
, pos_x
);
2516 if (draw
== DRAW_MOUSE_FACE
)
2517 tty_write_glyphs_with_face (f
, row
->glyphs
[TEXT_AREA
] + start_hpos
,
2519 else if (draw
== DRAW_NORMAL_TEXT
)
2520 write_glyphs (f
, row
->glyphs
[TEXT_AREA
] + start_hpos
, nglyphs
);
2522 cursor_to (f
, save_y
, save_x
);
2526 term_mouse_movement (struct frame
*frame
, Gpm_Event
*event
)
2528 /* Has the mouse moved off the glyph it was on at the last sighting? */
2529 if (event
->x
!= last_mouse_x
|| event
->y
!= last_mouse_y
)
2531 frame
->mouse_moved
= 1;
2532 note_mouse_highlight (frame
, event
->x
, event
->y
);
2533 /* Remember which glyph we're now on. */
2534 last_mouse_x
= event
->x
;
2535 last_mouse_y
= event
->y
;
2541 /* Return the Time that corresponds to T. Wrap around on overflow. */
2543 timeval_to_Time (struct timeval
const *t
)
2549 ms
= t
->tv_usec
/ 1000;
2553 /* Return the current position of the mouse.
2555 Set *f to the frame the mouse is in, or zero if the mouse is in no
2556 Emacs frame. If it is set to zero, all the other arguments are
2559 Set *bar_window to Qnil, and *x and *y to the column and
2560 row of the character cell the mouse is over.
2562 Set *timeptr to the time the mouse was at the returned position.
2564 This clears mouse_moved until the next motion
2567 term_mouse_position (struct frame
**fp
, int insist
, Lisp_Object
*bar_window
,
2568 enum scroll_bar_part
*part
, Lisp_Object
*x
,
2569 Lisp_Object
*y
, Time
*timeptr
)
2573 *fp
= SELECTED_FRAME ();
2574 (*fp
)->mouse_moved
= 0;
2579 XSETINT (*x
, last_mouse_x
);
2580 XSETINT (*y
, last_mouse_y
);
2581 gettimeofday(&now
, 0);
2582 *timeptr
= timeval_to_Time (&now
);
2585 /* Prepare a mouse-event in *RESULT for placement in the input queue.
2587 If the event is a button press, then note that we have grabbed
2591 term_mouse_click (struct input_event
*result
, Gpm_Event
*event
,
2597 result
->kind
= GPM_CLICK_EVENT
;
2598 for (i
= 0, j
= GPM_B_LEFT
; i
< 3; i
++, j
>>= 1 )
2600 if (event
->buttons
& j
) {
2601 result
->code
= i
; /* button number */
2605 gettimeofday(&now
, 0);
2606 result
->timestamp
= timeval_to_Time (&now
);
2608 if (event
->type
& GPM_UP
)
2609 result
->modifiers
= up_modifier
;
2610 else if (event
->type
& GPM_DOWN
)
2611 result
->modifiers
= down_modifier
;
2613 result
->modifiers
= 0;
2615 if (event
->type
& GPM_SINGLE
)
2616 result
->modifiers
|= click_modifier
;
2618 if (event
->type
& GPM_DOUBLE
)
2619 result
->modifiers
|= double_modifier
;
2621 if (event
->type
& GPM_TRIPLE
)
2622 result
->modifiers
|= triple_modifier
;
2624 if (event
->type
& GPM_DRAG
)
2625 result
->modifiers
|= drag_modifier
;
2627 if (!(event
->type
& (GPM_MOVE
| GPM_DRAG
))) {
2630 if (event
->modifiers
& (1 << 0))
2631 result
->modifiers
|= shift_modifier
;
2634 if (event
->modifiers
& (1 << 2))
2635 result
->modifiers
|= ctrl_modifier
;
2637 /* 1 << KG_ALT || KG_ALTGR */
2638 if (event
->modifiers
& (1 << 3)
2639 || event
->modifiers
& (1 << 1))
2640 result
->modifiers
|= meta_modifier
;
2643 XSETINT (result
->x
, event
->x
);
2644 XSETINT (result
->y
, event
->y
);
2645 XSETFRAME (result
->frame_or_window
, f
);
2651 handle_one_term_event (struct tty_display_info
*tty
, Gpm_Event
*event
, struct input_event
* hold_quit
)
2653 struct frame
*f
= XFRAME (tty
->top_frame
);
2654 struct input_event ie
;
2662 if (event
->type
& (GPM_MOVE
| GPM_DRAG
)) {
2663 previous_help_echo_string
= help_echo_string
;
2664 help_echo_string
= Qnil
;
2666 Gpm_DrawPointer (event
->x
, event
->y
, fileno (tty
->output
));
2668 if (!term_mouse_movement (f
, event
))
2669 help_echo_string
= previous_help_echo_string
;
2671 /* If the contents of the global variable help_echo_string
2672 has changed, generate a HELP_EVENT. */
2673 if (!NILP (help_echo_string
)
2674 || !NILP (previous_help_echo_string
))
2681 term_mouse_click (&ie
, event
, f
);
2685 if (ie
.kind
!= NO_EVENT
)
2687 kbd_buffer_store_event_hold (&ie
, hold_quit
);
2692 && !(hold_quit
&& hold_quit
->kind
!= NO_EVENT
))
2697 XSETFRAME (frame
, f
);
2701 gen_help_event (help_echo_string
, frame
, help_echo_window
,
2702 help_echo_object
, help_echo_pos
);
2709 DEFUN ("gpm-mouse-start", Fgpm_mouse_start
, Sgpm_mouse_start
,
2711 doc
: /* Open a connection to Gpm.
2712 Gpm-mouse can only be activated for one tty at a time. */)
2715 struct frame
*f
= SELECTED_FRAME ();
2716 struct tty_display_info
*tty
2717 = ((f
)->output_method
== output_termcap
2718 ? (f
)->terminal
->display_info
.tty
: NULL
);
2719 Gpm_Connect connection
;
2722 error ("Gpm-mouse only works in the GNU/Linux console");
2724 return Qnil
; /* Already activated, nothing to do. */
2726 error ("Gpm-mouse can only be activated for one tty at a time");
2728 connection
.eventMask
= ~0;
2729 connection
.defaultMask
= ~GPM_HARD
;
2730 connection
.maxMod
= ~0;
2731 connection
.minMod
= 0;
2734 if (Gpm_Open (&connection
, 0) < 0)
2735 error ("Gpm-mouse failed to connect to the gpm daemon");
2739 /* `init_sys_modes' arranges for mouse movements sent through gpm_fd
2740 to generate SIGIOs. Apparently we need to call reset_sys_modes
2741 before calling init_sys_modes. */
2742 reset_sys_modes (tty
);
2743 init_sys_modes (tty
);
2744 add_gpm_wait_descriptor (gpm_fd
);
2753 delete_gpm_wait_descriptor (fd
);
2754 while (Gpm_Close()); /* close all the stack */
2758 DEFUN ("gpm-mouse-stop", Fgpm_mouse_stop
, Sgpm_mouse_stop
,
2760 doc
: /* Close a connection to Gpm. */)
2763 struct frame
*f
= SELECTED_FRAME ();
2764 struct tty_display_info
*tty
2765 = ((f
)->output_method
== output_termcap
2766 ? (f
)->terminal
->display_info
.tty
: NULL
);
2768 if (!tty
|| gpm_tty
!= tty
)
2769 return Qnil
; /* Not activated on this terminal, nothing to do. */
2774 #endif /* HAVE_GPM */
2777 /***********************************************************************
2779 ***********************************************************************/
2781 #if defined (HAVE_MENUS) && !defined (MSDOS)
2783 /* TTY menu implementation and main ideas are borrowed from msdos.c.
2785 However, unlike on MSDOS, where the menu text is drawn directly to
2786 the display video memory, on a TTY we use display_string (see
2787 display_tty_menu_item in xdisp.c) to put the glyphs produced from
2788 the menu items into the frame's 'desired_matrix' glyph matrix, and
2789 then call update_frame_with_menu to deliver the results to the
2790 glass. The previous contents of the screen, in the form of the
2791 current_matrix, is stashed away, and used to restore screen
2792 contents when the menu selection changes or when the final
2793 selection is made and the menu should be popped down.
2795 The idea of this implementation was suggested by Gerd Moellmann. */
2797 #define TTYM_FAILURE -1
2798 #define TTYM_SUCCESS 1
2799 #define TTYM_NO_SELECT 2
2800 #define TTYM_IA_SELECT 3
2804 /* These hold text of the current and the previous menu help messages. */
2805 static const char *menu_help_message
, *prev_menu_help_message
;
2806 /* Pane number and item number of the menu item which generated the
2807 last menu help message. */
2808 static int menu_help_paneno
, menu_help_itemno
;
2810 static Lisp_Object Qtty_menu_navigation_map
, Qtty_menu_exit
;
2811 static Lisp_Object Qtty_menu_prev_item
, Qtty_menu_next_item
;
2812 static Lisp_Object Qtty_menu_next_menu
, Qtty_menu_prev_menu
;
2813 static Lisp_Object Qtty_menu_select
, Qtty_menu_ignore
;
2814 static Lisp_Object Qtty_menu_mouse_movement
;
2816 typedef struct tty_menu_struct
2820 struct tty_menu_struct
**submenu
;
2821 int *panenumber
; /* Also used as enabled flag. */
2822 ptrdiff_t allocated
;
2825 const char **help_text
;
2828 /* Create a brand new menu structure. */
2831 tty_menu_create (void)
2833 return xzalloc (sizeof *tty_menu_create ());
2836 /* Allocate some (more) memory for MENU ensuring that there is room for one
2840 tty_menu_make_room (tty_menu
*menu
)
2842 if (menu
->allocated
== menu
->count
)
2844 ptrdiff_t allocated
= menu
->allocated
;
2845 menu
->text
= xpalloc (menu
->text
, &allocated
, 1, -1, sizeof *menu
->text
);
2846 menu
->text
= xrealloc (menu
->text
, allocated
* sizeof *menu
->text
);
2847 menu
->submenu
= xrealloc (menu
->submenu
,
2848 allocated
* sizeof *menu
->submenu
);
2849 menu
->panenumber
= xrealloc (menu
->panenumber
,
2850 allocated
* sizeof *menu
->panenumber
);
2851 menu
->help_text
= xrealloc (menu
->help_text
,
2852 allocated
* sizeof *menu
->help_text
);
2853 menu
->allocated
= allocated
;
2857 /* Search the given menu structure for a given pane number. */
2860 tty_menu_search_pane (tty_menu
*menu
, int pane
)
2865 for (i
= 0; i
< menu
->count
; i
++)
2866 if (menu
->submenu
[i
])
2868 if (pane
== menu
->panenumber
[i
])
2869 return menu
->submenu
[i
];
2870 if ((try = tty_menu_search_pane (menu
->submenu
[i
], pane
)))
2873 return (tty_menu
*) 0;
2876 /* Determine how much screen space a given menu needs. */
2879 tty_menu_calc_size (tty_menu
*menu
, int *width
, int *height
)
2881 int i
, h2
, w2
, maxsubwidth
, maxheight
;
2883 maxsubwidth
= menu
->width
;
2884 maxheight
= menu
->count
;
2885 for (i
= 0; i
< menu
->count
; i
++)
2887 if (menu
->submenu
[i
])
2889 tty_menu_calc_size (menu
->submenu
[i
], &w2
, &h2
);
2890 if (w2
> maxsubwidth
) maxsubwidth
= w2
;
2891 if (i
+ h2
> maxheight
) maxheight
= i
+ h2
;
2894 *width
= maxsubwidth
;
2895 *height
= maxheight
;
2899 mouse_get_xy (int *x
, int *y
)
2901 struct frame
*sf
= SELECTED_FRAME ();
2902 Lisp_Object lmx
= Qnil
, lmy
= Qnil
, lisp_dummy
;
2903 enum scroll_bar_part part_dummy
;
2906 if (FRAME_TERMINAL (sf
)->mouse_position_hook
)
2907 (*FRAME_TERMINAL (sf
)->mouse_position_hook
) (&sf
, -1,
2908 &lisp_dummy
, &part_dummy
,
2918 /* Display MENU at (X,Y) using FACES, starting with FIRST_ITEM
2922 tty_menu_display (tty_menu
*menu
, int x
, int y
, int pn
, int *faces
,
2923 int mx
, int my
, int first_item
, int disp_help
)
2925 int i
, face
, width
, enabled
, mousehere
, row
, col
;
2926 struct frame
*sf
= SELECTED_FRAME ();
2927 struct tty_display_info
*tty
= FRAME_TTY (sf
);
2928 /* Don't try to display more menu items than the console can display
2929 using the available screen lines. Exclude the echo area line, as
2930 it will be overwritten by the help-echo anyway. */
2931 int max_items
= min (menu
->count
- first_item
, FRAME_LINES (sf
) - 1 - y
);
2933 menu_help_message
= NULL
;
2935 width
= menu
->width
;
2936 col
= cursorX (tty
);
2937 row
= cursorY (tty
);
2938 for (i
= 0; i
< max_items
; i
++)
2940 int max_width
= width
+ 2; /* +2 for padding blanks on each side */
2941 int j
= i
+ first_item
;
2943 if (menu
->submenu
[j
])
2944 max_width
+= 2; /* for displaying " >" after the item */
2946 = (!menu
->submenu
[j
] && menu
->panenumber
[j
]) || (menu
->submenu
[j
]);
2947 mousehere
= (y
+ i
== my
&& x
<= mx
&& mx
< x
+ max_width
);
2948 face
= faces
[enabled
+ mousehere
* 2];
2949 /* Display the menu help string for the i-th menu item even if
2950 the menu item is currently disabled. That's what the GUI
2952 if (disp_help
&& enabled
+ mousehere
* 2 >= 2)
2954 menu_help_message
= menu
->help_text
[j
];
2955 menu_help_paneno
= pn
- 1;
2956 menu_help_itemno
= j
;
2958 display_tty_menu_item (menu
->text
[j
], max_width
, face
, x
, y
+ i
,
2959 menu
->submenu
[j
] != NULL
);
2961 update_frame_with_menu (sf
);
2962 cursor_to (sf
, row
, col
);
2965 /* --------------------------- X Menu emulation ---------------------- */
2967 /* Create a new pane and place it on the outer-most level. */
2970 tty_menu_add_pane (tty_menu
*menu
, const char *txt
)
2973 const unsigned char *p
;
2975 tty_menu_make_room (menu
);
2976 menu
->submenu
[menu
->count
] = tty_menu_create ();
2977 menu
->text
[menu
->count
] = (char *)txt
;
2978 menu
->panenumber
[menu
->count
] = ++menu
->panecount
;
2979 menu
->help_text
[menu
->count
] = NULL
;
2982 /* Update the menu width, if necessary. */
2983 for (len
= 0, p
= (unsigned char *) txt
; *p
; )
2986 int ch
= STRING_CHAR_AND_LENGTH (p
, ch_len
);
2988 len
+= CHAR_WIDTH (ch
);
2992 if (len
> menu
->width
)
2995 return menu
->panecount
;
2998 /* Create a new item in a menu pane. */
3001 tty_menu_add_selection (tty_menu
*menu
, int pane
,
3002 char *txt
, int enable
, char const *help_text
)
3008 if (!(menu
= tty_menu_search_pane (menu
, pane
)))
3009 return TTYM_FAILURE
;
3010 tty_menu_make_room (menu
);
3011 menu
->submenu
[menu
->count
] = (tty_menu
*) 0;
3012 menu
->text
[menu
->count
] = txt
;
3013 menu
->panenumber
[menu
->count
] = enable
;
3014 menu
->help_text
[menu
->count
] = help_text
;
3017 /* Update the menu width, if necessary. */
3018 for (len
= 0, p
= (unsigned char *) txt
; *p
; )
3021 int ch
= STRING_CHAR_AND_LENGTH (p
, ch_len
);
3023 len
+= CHAR_WIDTH (ch
);
3027 if (len
> menu
->width
)
3030 return TTYM_SUCCESS
;
3033 /* Decide where the menu would be placed if requested at (X,Y). */
3036 tty_menu_locate (tty_menu
*menu
, int x
, int y
,
3037 int *ulx
, int *uly
, int *width
, int *height
)
3039 tty_menu_calc_size (menu
, width
, height
);
3045 struct tty_menu_state
3047 struct glyph_matrix
*screen_behind
;
3053 /* Save away the contents of frame F's current frame matrix, and
3054 enable all its rows. Value is a glyph matrix holding the contents
3055 of F's current frame matrix with all its glyph rows enabled. */
3057 static struct glyph_matrix
*
3058 save_and_enable_current_matrix (struct frame
*f
)
3061 struct glyph_matrix
*saved
= xzalloc (sizeof *saved
);
3062 saved
->nrows
= f
->current_matrix
->nrows
;
3063 saved
->rows
= xzalloc (saved
->nrows
* sizeof *saved
->rows
);
3065 for (i
= 0; i
< saved
->nrows
; ++i
)
3067 struct glyph_row
*from
= f
->current_matrix
->rows
+ i
;
3068 struct glyph_row
*to
= saved
->rows
+ i
;
3069 ptrdiff_t nbytes
= from
->used
[TEXT_AREA
] * sizeof (struct glyph
);
3071 to
->glyphs
[TEXT_AREA
] = xmalloc (nbytes
);
3072 memcpy (to
->glyphs
[TEXT_AREA
], from
->glyphs
[TEXT_AREA
], nbytes
);
3073 to
->used
[TEXT_AREA
] = from
->used
[TEXT_AREA
];
3074 /* Make sure every row is enabled, or else update_frame will not
3075 redraw them. (Rows that are identical to what is already on
3076 screen will not be redrawn anyway.) */
3078 to
->hash
= from
->hash
;
3084 /* Restore the contents of frame F's desired frame matrix from SAVED,
3085 and free memory associated with SAVED. */
3088 restore_desired_matrix (struct frame
*f
, struct glyph_matrix
*saved
)
3092 for (i
= 0; i
< saved
->nrows
; ++i
)
3094 struct glyph_row
*from
= saved
->rows
+ i
;
3095 struct glyph_row
*to
= f
->desired_matrix
->rows
+ i
;
3096 ptrdiff_t nbytes
= from
->used
[TEXT_AREA
] * sizeof (struct glyph
);
3098 eassert (to
->glyphs
[TEXT_AREA
] != from
->glyphs
[TEXT_AREA
]);
3099 memcpy (to
->glyphs
[TEXT_AREA
], from
->glyphs
[TEXT_AREA
], nbytes
);
3100 to
->used
[TEXT_AREA
] = from
->used
[TEXT_AREA
];
3101 to
->enabled_p
= from
->enabled_p
;
3102 to
->hash
= from
->hash
;
3107 free_saved_screen (struct glyph_matrix
*saved
)
3112 return; /* already freed */
3114 for (i
= 0; i
< saved
->nrows
; ++i
)
3116 struct glyph_row
*from
= saved
->rows
+ i
;
3118 xfree (from
->glyphs
[TEXT_AREA
]);
3121 xfree (saved
->rows
);
3125 /* Update the display of frame F from its saved contents. */
3127 screen_update (struct frame
*f
, struct glyph_matrix
*mtx
)
3129 restore_desired_matrix (f
, mtx
);
3130 update_frame_with_menu (f
);
3136 MI_ITEM_SELECTED
= 1,
3139 MI_SCROLL_FORWARD
= 4,
3143 /* Read user input and return X and Y coordinates where that input
3144 puts us. We only consider mouse movement and click events, and
3145 keyboard movement commands; the rest are ignored. */
3147 read_menu_input (struct frame
*sf
, int *x
, int *y
, int min_y
, int max_y
,
3152 *first_time
= false;
3153 sf
->mouse_moved
= 1;
3158 int usable_input
= 1;
3159 mi_result st
= MI_CONTINUE
;
3160 struct tty_display_info
*tty
= FRAME_TTY (sf
);
3161 Lisp_Object saved_mouse_tracking
= do_mouse_tracking
;
3163 /* Signal the keyboard reading routines we are displaying a menu
3164 on this terminal. */
3165 tty
->showing_menu
= 1;
3166 /* We want mouse movements be reported by read_menu_command. */
3167 do_mouse_tracking
= Qt
;
3169 cmd
= read_menu_command ();
3170 } while (NILP (cmd
));
3171 tty
->showing_menu
= 0;
3172 do_mouse_tracking
= saved_mouse_tracking
;
3174 if (EQ (cmd
, Qt
) || EQ (cmd
, Qtty_menu_exit
))
3175 return MI_QUIT_MENU
;
3176 if (EQ (cmd
, Qtty_menu_mouse_movement
))
3177 mouse_get_xy (x
, y
);
3178 else if (EQ (cmd
, Qtty_menu_next_menu
))
3183 else if (EQ (cmd
, Qtty_menu_prev_menu
))
3188 else if (EQ (cmd
, Qtty_menu_next_item
))
3193 st
= MI_SCROLL_FORWARD
;
3195 else if (EQ (cmd
, Qtty_menu_prev_item
))
3200 st
= MI_SCROLL_BACK
;
3202 else if (EQ (cmd
, Qtty_menu_select
))
3203 st
= MI_ITEM_SELECTED
;
3204 else if (!EQ (cmd
, Qtty_menu_ignore
))
3207 sf
->mouse_moved
= 1;
3213 /* Display menu, wait for user's response, and return that response. */
3215 tty_menu_activate (tty_menu
*menu
, int *pane
, int *selidx
,
3216 int x0
, int y0
, char **txt
,
3217 void (*help_callback
)(char const *, int, int),
3220 struct tty_menu_state
*state
;
3221 int statecount
, x
, y
, i
, leave
, onepane
;
3222 int result
IF_LINT (= 0);
3223 int title_faces
[4]; /* face to display the menu title */
3224 int faces
[4], buffers_num_deleted
= 0;
3225 struct frame
*sf
= SELECTED_FRAME ();
3226 struct tty_display_info
*tty
= FRAME_TTY (sf
);
3228 Lisp_Object selectface
;
3231 /* Don't allow non-positive x0 and y0, lest the menu will wrap
3232 around the display. */
3238 state
= alloca (menu
->panecount
* sizeof (struct tty_menu_state
));
3239 memset (state
, 0, sizeof (*state
));
3241 = lookup_derived_face (sf
, intern ("tty-menu-disabled-face"),
3242 DEFAULT_FACE_ID
, 1);
3244 = lookup_derived_face (sf
, intern ("tty-menu-enabled-face"),
3245 DEFAULT_FACE_ID
, 1);
3246 selectface
= intern ("tty-menu-selected-face");
3247 faces
[2] = lookup_derived_face (sf
, selectface
,
3249 faces
[3] = lookup_derived_face (sf
, selectface
,
3252 /* Make sure the menu title is always displayed with
3253 `tty-menu-selected-face', no matter where the mouse pointer is. */
3254 for (i
= 0; i
< 4; i
++)
3255 title_faces
[i
] = faces
[3];
3259 /* Don't let the title for the "Buffers" popup menu include a
3260 digit (which is ugly).
3262 This is a terrible kludge, but I think the "Buffers" case is
3263 the only one where the title includes a number, so it doesn't
3264 seem to be necessary to make this more general. */
3265 if (strncmp (menu
->text
[0], "Buffers 1", 9) == 0)
3267 menu
->text
[0][7] = '\0';
3268 buffers_num_deleted
= 1;
3271 /* Force update of the current frame, so that the desired and the
3272 current matrices are identical. */
3273 update_frame_with_menu (sf
);
3274 state
[0].menu
= menu
;
3275 state
[0].screen_behind
= save_and_enable_current_matrix (sf
);
3277 /* Display the menu title. We subtract 1 from x0 and y0 because we
3278 want to interpret them as zero-based column and row coordinates,
3279 and also because we want the first item of the menu, not its
3280 title, to appear at x0,y0. */
3281 tty_menu_display (menu
, x0
- 1, y0
- 1, 1, title_faces
, x0
- 1, y0
- 1, 0, 0);
3283 /* Turn off the cursor. Otherwise it shows through the menu
3284 panes, which is ugly. */
3285 tty_hide_cursor (tty
);
3286 if (buffers_num_deleted
)
3287 menu
->text
[0][7] = ' ';
3288 if ((onepane
= menu
->count
== 1 && menu
->submenu
[0]))
3290 menu
->width
= menu
->submenu
[0]->width
;
3291 state
[0].menu
= menu
->submenu
[0];
3295 state
[0].menu
= menu
;
3297 state
[0].x
= x0
- 1;
3299 state
[0].pane
= onepane
;
3308 mi_result input_status
;
3309 int min_y
= state
[0].y
;
3310 int max_y
= min (min_y
+ state
[0].menu
->count
, FRAME_LINES (sf
) - 1) - 1;
3312 input_status
= read_menu_input (sf
, &x
, &y
, min_y
, max_y
, &first_time
);
3316 switch (input_status
)
3319 /* Remove the last help-echo, so that it doesn't
3320 re-appear after "Quit". */
3321 show_help_echo (Qnil
, Qnil
, Qnil
, Qnil
);
3322 result
= TTYM_NO_SELECT
;
3336 case MI_SCROLL_FORWARD
:
3337 if (y
- min_y
== state
[0].menu
->count
- 1 - first_item
)
3346 case MI_SCROLL_BACK
:
3347 if (first_item
== 0)
3350 first_item
= state
[0].menu
->count
- 1 - (y
- min_y
);
3357 /* MI_ITEM_SELECTED is handled below, so nothing to do. */
3361 if (sf
->mouse_moved
&& input_status
!= MI_QUIT_MENU
)
3363 sf
->mouse_moved
= 0;
3364 result
= TTYM_IA_SELECT
;
3365 for (i
= 0; i
< statecount
; i
++)
3366 if (state
[i
].x
<= x
&& x
< state
[i
].x
+ state
[i
].menu
->width
+ 2)
3368 int dy
= y
- state
[i
].y
+ first_item
;
3369 if (0 <= dy
&& dy
< state
[i
].menu
->count
)
3371 if (!state
[i
].menu
->submenu
[dy
])
3373 if (state
[i
].menu
->panenumber
[dy
])
3374 result
= TTYM_SUCCESS
;
3376 result
= TTYM_IA_SELECT
;
3378 *pane
= state
[i
].pane
- 1;
3380 /* We hit some part of a menu, so drop extra menus that
3381 have been opened. That does not include an open and
3383 if (i
!= statecount
- 2
3384 || state
[i
].menu
->submenu
[dy
] != state
[i
+1].menu
)
3385 while (i
!= statecount
- 1)
3388 screen_update (sf
, state
[statecount
].screen_behind
);
3389 state
[statecount
].screen_behind
= NULL
;
3391 if (i
== statecount
- 1 && state
[i
].menu
->submenu
[dy
])
3393 tty_menu_display (state
[i
].menu
,
3397 faces
, x
, y
, first_item
, 1);
3398 state
[statecount
].menu
= state
[i
].menu
->submenu
[dy
];
3399 state
[statecount
].pane
= state
[i
].menu
->panenumber
[dy
];
3400 state
[statecount
].screen_behind
3401 = save_and_enable_current_matrix (sf
);
3403 = state
[i
].x
+ state
[i
].menu
->width
+ 2;
3404 state
[statecount
].y
= y
;
3409 tty_menu_display (state
[statecount
- 1].menu
,
3410 state
[statecount
- 1].x
,
3411 state
[statecount
- 1].y
,
3412 state
[statecount
- 1].pane
,
3413 faces
, x
, y
, first_item
, 1);
3414 tty_hide_cursor (tty
);
3415 fflush (tty
->output
);
3418 /* Display the help-echo message for the currently-selected menu
3420 if ((menu_help_message
|| prev_menu_help_message
)
3421 && menu_help_message
!= prev_menu_help_message
)
3423 help_callback (menu_help_message
,
3424 menu_help_paneno
, menu_help_itemno
);
3425 tty_hide_cursor (tty
);
3426 fflush (tty
->output
);
3427 prev_menu_help_message
= menu_help_message
;
3431 sf
->mouse_moved
= 0;
3432 screen_update (sf
, state
[0].screen_behind
);
3433 while (statecount
--)
3434 free_saved_screen (state
[statecount
].screen_behind
);
3435 tty_show_cursor (tty
); /* turn cursor back on */
3436 fflush (tty
->output
);
3438 /* Clean up any mouse events that are waiting inside Emacs event queue.
3439 These events are likely to be generated before the menu was even
3440 displayed, probably because the user pressed and released the button
3441 (which invoked the menu) too quickly. If we don't remove these events,
3442 Emacs will process them after we return and surprise the user. */
3443 discard_mouse_events ();
3444 if (!kbd_buffer_events_waiting ())
3445 clear_input_pending ();
3449 /* Dispose of a menu. */
3452 tty_menu_destroy (tty_menu
*menu
)
3455 if (menu
->allocated
)
3457 for (i
= 0; i
< menu
->count
; i
++)
3458 if (menu
->submenu
[i
])
3459 tty_menu_destroy (menu
->submenu
[i
]);
3461 xfree (menu
->submenu
);
3462 xfree (menu
->panenumber
);
3463 xfree (menu
->help_text
);
3466 menu_help_message
= prev_menu_help_message
= NULL
;
3469 /* Show help HELP_STRING, or clear help if HELP_STRING is null.
3471 PANE is the pane number, and ITEM is the menu item number in
3472 the menu (currently not used). */
3475 tty_menu_help_callback (char const *help_string
, int pane
, int item
)
3477 Lisp_Object
*first_item
;
3478 Lisp_Object pane_name
;
3479 Lisp_Object menu_object
;
3481 first_item
= XVECTOR (menu_items
)->u
.contents
;
3482 if (EQ (first_item
[0], Qt
))
3483 pane_name
= first_item
[MENU_ITEMS_PANE_NAME
];
3484 else if (EQ (first_item
[0], Qquote
))
3485 /* This shouldn't happen, see xmenu_show. */
3486 pane_name
= empty_unibyte_string
;
3488 pane_name
= first_item
[MENU_ITEMS_ITEM_NAME
];
3490 /* (menu-item MENU-NAME PANE-NUMBER) */
3491 menu_object
= list3 (Qmenu_item
, pane_name
, make_number (pane
));
3492 show_help_echo (help_string
? build_string (help_string
) : Qnil
,
3493 Qnil
, menu_object
, make_number (item
));
3497 tty_pop_down_menu (Lisp_Object arg
)
3499 tty_menu
*menu
= XSAVE_POINTER (arg
, 0);
3502 tty_menu_destroy (menu
);
3506 /* Return the zero-based index of the last menu-bar item on frame F. */
3508 tty_menu_last_menubar_item (struct frame
*f
)
3512 eassert (FRAME_TERMCAP_P (f
) && FRAME_LIVE_P (f
));
3513 if (FRAME_TERMCAP_P (f
) && FRAME_LIVE_P (f
))
3515 Lisp_Object items
= FRAME_MENU_BAR_ITEMS (f
);
3517 while (i
< ASIZE (items
))
3521 str
= AREF (items
, i
+ 1);
3526 i
-= 4; /* went one too far */
3531 /* Find in frame F's menu bar the menu item that is next or previous
3532 to the item at X/Y, and return that item's position in X/Y. WHICH
3533 says which one--next or previous--item to look for. X and Y are
3534 measured in character cells. This should only be called on TTY
3537 tty_menu_new_item_coords (struct frame
*f
, int which
, int *x
, int *y
)
3539 eassert (FRAME_TERMCAP_P (f
) && FRAME_LIVE_P (f
));
3540 if (FRAME_TERMCAP_P (f
) && FRAME_LIVE_P (f
))
3542 Lisp_Object items
= FRAME_MENU_BAR_ITEMS (f
);
3543 int last_i
= tty_menu_last_menubar_item (f
);
3546 /* This loop assumes a single menu-bar line, and will fail to
3547 find an item if it is not in the first line. Note that
3548 make_lispy_event in keyboard.c makes the same assumption. */
3549 for (i
= 0, prev_x
= -1; i
< ASIZE (items
); i
+= 4)
3551 Lisp_Object pos
, str
;
3554 str
= AREF (items
, i
+ 1);
3555 pos
= AREF (items
, i
+ 3);
3560 /* We use <= so the blank between 2 items on a TTY is
3561 considered part of the previous item. */
3562 && *x
<= ix
+ menu_item_width (SDATA (str
)))
3564 /* Found current item. Now compute the X coordinate of
3565 the previous or next item. */
3566 if (which
== TTYM_NEXT
)
3569 *x
= XINT (AREF (items
, i
+ 4 + 3));
3571 *x
= 0; /* wrap around to the first item */
3573 else if (prev_x
< 0)
3575 /* Wrap around to the last item. */
3576 *x
= XINT (AREF (items
, last_i
+ 3));
3588 tty_menu_show (struct frame
*f
, int x
, int y
, int for_click
, int keymaps
,
3589 Lisp_Object title
, int kbd_navigation
, const char **error_name
)
3592 int pane
, selidx
, lpane
, status
;
3593 Lisp_Object entry
, pane_prefix
;
3595 int ulx
, uly
, width
, height
;
3597 int dispwidth
, dispheight
;
3598 int i
, j
, lines
, maxlines
;
3600 ptrdiff_t specpdl_count
;
3602 eassert (FRAME_TERMCAP_P (f
));
3605 if (menu_items_n_panes
== 0)
3608 if (menu_items_used
<= MENU_ITEMS_PANE_LENGTH
)
3610 *error_name
= "Empty menu";
3614 /* Make the menu on that window. */
3615 menu
= tty_menu_create ();
3618 *error_name
= "Can't create menu";
3622 /* Don't GC while we prepare and show the menu, because we give the
3623 menu functions pointers to the contents of strings. */
3624 specpdl_count
= inhibit_garbage_collection ();
3626 /* Adjust coordinates to be root-window-relative. */
3627 item_x
= x
+= f
->left_pos
;
3628 item_y
= y
+= f
->top_pos
;
3630 /* Create all the necessary panes and their items. */
3631 maxwidth
= maxlines
= lines
= i
= 0;
3632 lpane
= TTYM_FAILURE
;
3633 while (i
< menu_items_used
)
3635 if (EQ (AREF (menu_items
, i
), Qt
))
3637 /* Create a new pane. */
3638 Lisp_Object pane_name
, prefix
;
3639 const char *pane_string
;
3641 maxlines
= max (maxlines
, lines
);
3643 pane_name
= AREF (menu_items
, i
+ MENU_ITEMS_PANE_NAME
);
3644 prefix
= AREF (menu_items
, i
+ MENU_ITEMS_PANE_PREFIX
);
3645 pane_string
= (NILP (pane_name
)
3646 ? "" : SSDATA (pane_name
));
3647 if (keymaps
&& !NILP (prefix
))
3650 lpane
= tty_menu_add_pane (menu
, pane_string
);
3651 if (lpane
== TTYM_FAILURE
)
3653 tty_menu_destroy (menu
);
3654 *error_name
= "Can't create pane";
3658 i
+= MENU_ITEMS_PANE_LENGTH
;
3660 /* Find the width of the widest item in this pane. */
3662 while (j
< menu_items_used
)
3665 item
= AREF (menu_items
, j
);
3673 width
= SBYTES (item
);
3674 if (width
> maxwidth
)
3677 j
+= MENU_ITEMS_ITEM_LENGTH
;
3680 /* Ignore a nil in the item list.
3681 It's meaningful only for dialog boxes. */
3682 else if (EQ (AREF (menu_items
, i
), Qquote
))
3686 /* Create a new item within current pane. */
3687 Lisp_Object item_name
, enable
, descrip
, help
;
3689 char const *help_string
;
3691 item_name
= AREF (menu_items
, i
+ MENU_ITEMS_ITEM_NAME
);
3692 enable
= AREF (menu_items
, i
+ MENU_ITEMS_ITEM_ENABLE
);
3693 descrip
= AREF (menu_items
, i
+ MENU_ITEMS_ITEM_EQUIV_KEY
);
3694 help
= AREF (menu_items
, i
+ MENU_ITEMS_ITEM_HELP
);
3695 help_string
= STRINGP (help
) ? SSDATA (help
) : NULL
;
3697 if (!NILP (descrip
))
3699 /* if alloca is fast, use that to make the space,
3700 to reduce gc needs. */
3701 item_data
= (char *) alloca (maxwidth
+ SBYTES (descrip
) + 1);
3702 memcpy (item_data
, SSDATA (item_name
), SBYTES (item_name
));
3703 for (j
= SCHARS (item_name
); j
< maxwidth
; j
++)
3705 memcpy (item_data
+ j
, SSDATA (descrip
), SBYTES (descrip
));
3706 item_data
[j
+ SBYTES (descrip
)] = 0;
3709 item_data
= SSDATA (item_name
);
3711 if (lpane
== TTYM_FAILURE
3712 || (tty_menu_add_selection (menu
, lpane
, item_data
,
3713 !NILP (enable
), help_string
)
3716 tty_menu_destroy (menu
);
3717 *error_name
= "Can't add selection to menu";
3721 i
+= MENU_ITEMS_ITEM_LENGTH
;
3726 maxlines
= max (maxlines
, lines
);
3728 /* All set and ready to fly. */
3729 dispwidth
= f
->text_cols
;
3730 dispheight
= f
->text_lines
;
3731 x
= min (x
, dispwidth
);
3732 y
= min (y
, dispheight
);
3735 tty_menu_locate (menu
, x
, y
, &ulx
, &uly
, &width
, &height
);
3736 if (ulx
+ width
> dispwidth
)
3738 x
-= (ulx
+ width
) - dispwidth
;
3739 ulx
= dispwidth
- width
;
3741 if (uly
+ height
> dispheight
)
3743 y
-= (uly
+ height
) - dispheight
;
3744 uly
= dispheight
- height
;
3747 if (FRAME_HAS_MINIBUF_P (f
) && uly
+height
> dispheight
- 2)
3749 /* Move the menu away of the echo area, to avoid overwriting the
3750 menu with help echo messages or vice versa. */
3751 if (BUFFERP (echo_area_buffer
[0]) && WINDOWP (echo_area_window
))
3753 y
-= WINDOW_TOTAL_LINES (XWINDOW (echo_area_window
)) + 1;
3754 uly
-= WINDOW_TOTAL_LINES (XWINDOW (echo_area_window
)) + 1;
3763 if (ulx
< 0) x
-= ulx
;
3764 if (uly
< 0) y
-= uly
;
3767 /* This code doesn't make sense on a TTY, since it can easily annul
3768 the adjustments above that carefully avoid truncation of the menu
3769 items. I think it was written to fix some problem that only
3773 /* If position was not given by a mouse click, adjust so upper left
3774 corner of the menu as a whole ends up at given coordinates. This
3775 is what x-popup-menu says in its documentation. */
3777 y
+= 1.5*height
/(maxlines
+2);
3783 record_unwind_protect (tty_pop_down_menu
, make_save_ptr (menu
));
3785 specbind (Qoverriding_terminal_local_map
,
3786 Fsymbol_value (Qtty_menu_navigation_map
));
3787 status
= tty_menu_activate (menu
, &pane
, &selidx
, x
, y
, &datap
,
3788 tty_menu_help_callback
, kbd_navigation
);
3789 entry
= pane_prefix
= Qnil
;
3794 /* Find the item number SELIDX in pane number PANE. */
3796 while (i
< menu_items_used
)
3798 if (EQ (AREF (menu_items
, i
), Qt
))
3802 = AREF (menu_items
, i
+ MENU_ITEMS_PANE_PREFIX
);
3804 i
+= MENU_ITEMS_PANE_LENGTH
;
3813 = AREF (menu_items
, i
+ MENU_ITEMS_ITEM_VALUE
);
3816 entry
= Fcons (entry
, Qnil
);
3817 if (!NILP (pane_prefix
))
3818 entry
= Fcons (pane_prefix
, entry
);
3824 i
+= MENU_ITEMS_ITEM_LENGTH
;
3831 tty_menu_new_item_coords (f
, status
, &item_x
, &item_y
);
3832 entry
= Fcons (make_number (item_x
), make_number (item_y
));
3836 *error_name
= "Can't activate menu";
3837 case TTYM_IA_SELECT
:
3839 case TTYM_NO_SELECT
:
3840 /* Make "Cancel" equivalent to C-g unless FOR_CLICK (which means
3841 the menu was invoked with a mouse event as POSITION). */
3843 Fsignal (Qquit
, Qnil
);
3849 unbind_to (specpdl_count
, Qnil
);
3853 #endif /* HAVE_MENUS && !MSDOS */
3857 /***********************************************************************
3859 ***********************************************************************/
3861 /* Initialize the tty-dependent part of frame F. The frame must
3862 already have its device initialized. */
3865 create_tty_output (struct frame
*f
)
3867 struct tty_output
*t
= xzalloc (sizeof *t
);
3869 eassert (FRAME_TERMCAP_P (f
));
3871 t
->display_info
= FRAME_TERMINAL (f
)->display_info
.tty
;
3873 f
->output_data
.tty
= t
;
3876 /* Delete frame F's face cache, and its tty-dependent part. */
3879 tty_free_frame_resources (struct frame
*f
)
3881 eassert (FRAME_TERMCAP_P (f
));
3883 if (FRAME_FACE_CACHE (f
))
3884 free_frame_faces (f
);
3886 xfree (f
->output_data
.tty
);
3891 /* Delete frame F's face cache. */
3894 tty_free_frame_resources (struct frame
*f
)
3896 eassert (FRAME_TERMCAP_P (f
) || FRAME_MSDOS_P (f
));
3898 if (FRAME_FACE_CACHE (f
))
3899 free_frame_faces (f
);
3903 /* Reset the hooks in TERMINAL. */
3906 clear_tty_hooks (struct terminal
*terminal
)
3909 terminal
->cursor_to_hook
= 0;
3910 terminal
->raw_cursor_to_hook
= 0;
3911 terminal
->clear_to_end_hook
= 0;
3912 terminal
->clear_frame_hook
= 0;
3913 terminal
->clear_end_of_line_hook
= 0;
3914 terminal
->ins_del_lines_hook
= 0;
3915 terminal
->insert_glyphs_hook
= 0;
3916 terminal
->write_glyphs_hook
= 0;
3917 terminal
->delete_glyphs_hook
= 0;
3918 terminal
->ring_bell_hook
= 0;
3919 terminal
->reset_terminal_modes_hook
= 0;
3920 terminal
->set_terminal_modes_hook
= 0;
3921 terminal
->update_begin_hook
= 0;
3922 terminal
->update_end_hook
= 0;
3923 terminal
->set_terminal_window_hook
= 0;
3924 terminal
->mouse_position_hook
= 0;
3925 terminal
->frame_rehighlight_hook
= 0;
3926 terminal
->frame_raise_lower_hook
= 0;
3927 terminal
->fullscreen_hook
= 0;
3928 terminal
->set_vertical_scroll_bar_hook
= 0;
3929 terminal
->condemn_scroll_bars_hook
= 0;
3930 terminal
->redeem_scroll_bar_hook
= 0;
3931 terminal
->judge_scroll_bars_hook
= 0;
3932 terminal
->read_socket_hook
= 0;
3933 terminal
->frame_up_to_date_hook
= 0;
3935 /* Leave these two set, or suspended frames are not deleted
3937 terminal
->delete_frame_hook
= &tty_free_frame_resources
;
3938 terminal
->delete_terminal_hook
= &delete_tty
;
3941 /* Initialize hooks in TERMINAL with the values needed for a tty. */
3944 set_tty_hooks (struct terminal
*terminal
)
3946 terminal
->rif
= 0; /* ttys don't support window-based redisplay. */
3948 terminal
->cursor_to_hook
= &tty_cursor_to
;
3949 terminal
->raw_cursor_to_hook
= &tty_raw_cursor_to
;
3951 terminal
->clear_to_end_hook
= &tty_clear_to_end
;
3952 terminal
->clear_frame_hook
= &tty_clear_frame
;
3953 terminal
->clear_end_of_line_hook
= &tty_clear_end_of_line
;
3955 terminal
->ins_del_lines_hook
= &tty_ins_del_lines
;
3957 terminal
->insert_glyphs_hook
= &tty_insert_glyphs
;
3958 terminal
->write_glyphs_hook
= &tty_write_glyphs
;
3959 terminal
->delete_glyphs_hook
= &tty_delete_glyphs
;
3961 terminal
->ring_bell_hook
= &tty_ring_bell
;
3963 terminal
->reset_terminal_modes_hook
= &tty_reset_terminal_modes
;
3964 terminal
->set_terminal_modes_hook
= &tty_set_terminal_modes
;
3965 terminal
->update_begin_hook
= 0; /* Not needed. */
3966 terminal
->update_end_hook
= &tty_update_end
;
3967 terminal
->set_terminal_window_hook
= &tty_set_terminal_window
;
3969 terminal
->mouse_position_hook
= 0; /* Not needed. */
3970 terminal
->frame_rehighlight_hook
= 0; /* Not needed. */
3971 terminal
->frame_raise_lower_hook
= 0; /* Not needed. */
3973 terminal
->set_vertical_scroll_bar_hook
= 0; /* Not needed. */
3974 terminal
->condemn_scroll_bars_hook
= 0; /* Not needed. */
3975 terminal
->redeem_scroll_bar_hook
= 0; /* Not needed. */
3976 terminal
->judge_scroll_bars_hook
= 0; /* Not needed. */
3978 terminal
->read_socket_hook
= &tty_read_avail_input
; /* keyboard.c */
3979 terminal
->frame_up_to_date_hook
= 0; /* Not needed. */
3981 terminal
->delete_frame_hook
= &tty_free_frame_resources
;
3982 terminal
->delete_terminal_hook
= &delete_tty
;
3985 /* If FD is the controlling terminal, drop it. */
3987 dissociate_if_controlling_tty (int fd
)
3989 /* If tcgetpgrp succeeds, fd is the controlling terminal,
3990 so dissociate it by invoking setsid. */
3991 if (tcgetpgrp (fd
) >= 0 && setsid () < 0)
3994 /* setsid failed, presumably because Emacs is already a process
3995 group leader. Fall back on the obsolescent way to dissociate
3996 a controlling tty. */
3997 block_tty_out_signal ();
3998 ioctl (fd
, TIOCNOTTY
, 0);
3999 unblock_tty_out_signal ();
4004 /* Create a termcap display on the tty device with the given name and
4007 If NAME is NULL, then use the controlling tty, i.e., "/dev/tty".
4008 Otherwise NAME should be a path to the tty device file,
4011 TERMINAL_TYPE is the termcap type of the device, e.g. "vt100".
4013 If MUST_SUCCEED is true, then all errors are fatal. */
4016 init_tty (const char *name
, const char *terminal_type
, bool must_succeed
)
4019 char **address
= &area
;
4021 struct tty_display_info
*tty
= NULL
;
4022 struct terminal
*terminal
= NULL
;
4023 bool ctty
= false; /* True if asked to open controlling tty. */
4026 maybe_fatal (must_succeed
, 0,
4027 "Unknown terminal type",
4028 "Unknown terminal type");
4032 if (!strcmp (name
, DEV_TTY
))
4035 /* If we already have a terminal on the given device, use that. If
4036 all such terminals are suspended, create a new one instead. */
4037 /* XXX Perhaps this should be made explicit by having init_tty
4038 always create a new terminal and separating terminal and frame
4039 creation on Lisp level. */
4040 terminal
= get_named_tty (name
);
4044 terminal
= create_terminal ();
4047 maybe_fatal (0, 0, "Attempt to create another terminal %s", "",
4050 tty
= &the_only_display_info
;
4052 tty
= xzalloc (sizeof *tty
);
4054 tty
->top_frame
= Qnil
;
4055 tty
->next
= tty_list
;
4058 terminal
->type
= output_termcap
;
4059 terminal
->display_info
.tty
= tty
;
4060 tty
->terminal
= terminal
;
4062 tty
->Wcm
= xmalloc (sizeof *tty
->Wcm
);
4065 encode_terminal_src_size
= 0;
4066 encode_terminal_dst_size
= 0;
4070 set_tty_hooks (terminal
);
4073 /* Open the terminal device. */
4075 /* If !ctty, don't recognize it as our controlling terminal, and
4076 don't make it the controlling tty if we don't have one now.
4078 Alas, O_IGNORE_CTTY is a GNU extension that seems to be only
4079 defined on Hurd. On other systems, we need to explicitly
4080 dissociate ourselves from the controlling tty when we want to
4081 open a frame on the same terminal. */
4082 int flags
= O_RDWR
| O_NOCTTY
| (ctty
? 0 : O_IGNORE_CTTY
);
4083 int fd
= emacs_open (name
, flags
, 0);
4084 tty
->input
= tty
->output
= fd
< 0 || ! isatty (fd
) ? 0 : fdopen (fd
, "w+");
4088 char const *diagnostic
4089 = tty
->input
? "Not a tty device: %s" : "Could not open file: %s";
4091 maybe_fatal (must_succeed
, terminal
, diagnostic
, diagnostic
, name
);
4094 tty
->name
= xstrdup (name
);
4095 terminal
->name
= xstrdup (name
);
4097 if (!O_IGNORE_CTTY
&& !ctty
)
4098 dissociate_if_controlling_tty (fd
);
4101 tty
->type
= xstrdup (terminal_type
);
4103 add_keyboard_wait_descriptor (fileno (tty
->input
));
4107 /* On some systems, tgetent tries to access the controlling
4109 block_tty_out_signal ();
4110 status
= tgetent (tty
->termcap_term_buffer
, terminal_type
);
4111 if (tty
->termcap_term_buffer
[TERMCAP_BUFFER_SIZE
- 1])
4113 unblock_tty_out_signal ();
4118 maybe_fatal (must_succeed
, terminal
,
4119 "Cannot open terminfo database file",
4120 "Cannot open terminfo database file");
4122 maybe_fatal (must_succeed
, terminal
,
4123 "Cannot open termcap database file",
4124 "Cannot open termcap database file");
4129 maybe_fatal (must_succeed
, terminal
,
4130 "Terminal type %s is not defined",
4131 "Terminal type %s is not defined.\n\
4132 If that is not the actual type of terminal you have,\n\
4133 use the Bourne shell command `TERM=... export TERM' (C-shell:\n\
4134 `setenv TERM ...') to specify the correct type. It may be necessary\n"
4136 "to do `unset TERMINFO' (C-shell: `unsetenv TERMINFO') as well.",
4138 "to do `unset TERMCAP' (C-shell: `unsetenv TERMCAP') as well.",
4143 area
= tty
->termcap_strings_buffer
;
4144 tty
->TS_ins_line
= tgetstr ("al", address
);
4145 tty
->TS_ins_multi_lines
= tgetstr ("AL", address
);
4146 tty
->TS_bell
= tgetstr ("bl", address
);
4147 BackTab (tty
) = tgetstr ("bt", address
);
4148 tty
->TS_clr_to_bottom
= tgetstr ("cd", address
);
4149 tty
->TS_clr_line
= tgetstr ("ce", address
);
4150 tty
->TS_clr_frame
= tgetstr ("cl", address
);
4151 ColPosition (tty
) = NULL
; /* tgetstr ("ch", address); */
4152 AbsPosition (tty
) = tgetstr ("cm", address
);
4153 CR (tty
) = tgetstr ("cr", address
);
4154 tty
->TS_set_scroll_region
= tgetstr ("cs", address
);
4155 tty
->TS_set_scroll_region_1
= tgetstr ("cS", address
);
4156 RowPosition (tty
) = tgetstr ("cv", address
);
4157 tty
->TS_del_char
= tgetstr ("dc", address
);
4158 tty
->TS_del_multi_chars
= tgetstr ("DC", address
);
4159 tty
->TS_del_line
= tgetstr ("dl", address
);
4160 tty
->TS_del_multi_lines
= tgetstr ("DL", address
);
4161 tty
->TS_delete_mode
= tgetstr ("dm", address
);
4162 tty
->TS_end_delete_mode
= tgetstr ("ed", address
);
4163 tty
->TS_end_insert_mode
= tgetstr ("ei", address
);
4164 Home (tty
) = tgetstr ("ho", address
);
4165 tty
->TS_ins_char
= tgetstr ("ic", address
);
4166 tty
->TS_ins_multi_chars
= tgetstr ("IC", address
);
4167 tty
->TS_insert_mode
= tgetstr ("im", address
);
4168 tty
->TS_pad_inserted_char
= tgetstr ("ip", address
);
4169 tty
->TS_end_keypad_mode
= tgetstr ("ke", address
);
4170 tty
->TS_keypad_mode
= tgetstr ("ks", address
);
4171 LastLine (tty
) = tgetstr ("ll", address
);
4172 Right (tty
) = tgetstr ("nd", address
);
4173 Down (tty
) = tgetstr ("do", address
);
4175 Down (tty
) = tgetstr ("nl", address
); /* Obsolete name for "do". */
4176 if (tgetflag ("bs"))
4177 Left (tty
) = "\b"; /* Can't possibly be longer! */
4178 else /* (Actually, "bs" is obsolete...) */
4179 Left (tty
) = tgetstr ("le", address
);
4181 Left (tty
) = tgetstr ("bc", address
); /* Obsolete name for "le". */
4182 tty
->TS_pad_char
= tgetstr ("pc", address
);
4183 tty
->TS_repeat
= tgetstr ("rp", address
);
4184 tty
->TS_end_standout_mode
= tgetstr ("se", address
);
4185 tty
->TS_fwd_scroll
= tgetstr ("sf", address
);
4186 tty
->TS_standout_mode
= tgetstr ("so", address
);
4187 tty
->TS_rev_scroll
= tgetstr ("sr", address
);
4188 tty
->Wcm
->cm_tab
= tgetstr ("ta", address
);
4189 tty
->TS_end_termcap_modes
= tgetstr ("te", address
);
4190 tty
->TS_termcap_modes
= tgetstr ("ti", address
);
4191 Up (tty
) = tgetstr ("up", address
);
4192 tty
->TS_visible_bell
= tgetstr ("vb", address
);
4193 tty
->TS_cursor_normal
= tgetstr ("ve", address
);
4194 tty
->TS_cursor_visible
= tgetstr ("vs", address
);
4195 tty
->TS_cursor_invisible
= tgetstr ("vi", address
);
4196 tty
->TS_set_window
= tgetstr ("wi", address
);
4198 tty
->TS_enter_underline_mode
= tgetstr ("us", address
);
4199 tty
->TS_exit_underline_mode
= tgetstr ("ue", address
);
4200 tty
->TS_enter_bold_mode
= tgetstr ("md", address
);
4201 tty
->TS_enter_italic_mode
= tgetstr ("ZH", address
);
4202 tty
->TS_enter_dim_mode
= tgetstr ("mh", address
);
4203 tty
->TS_enter_reverse_mode
= tgetstr ("mr", address
);
4204 tty
->TS_enter_alt_charset_mode
= tgetstr ("as", address
);
4205 tty
->TS_exit_alt_charset_mode
= tgetstr ("ae", address
);
4206 tty
->TS_exit_attribute_mode
= tgetstr ("me", address
);
4208 MultiUp (tty
) = tgetstr ("UP", address
);
4209 MultiDown (tty
) = tgetstr ("DO", address
);
4210 MultiLeft (tty
) = tgetstr ("LE", address
);
4211 MultiRight (tty
) = tgetstr ("RI", address
);
4213 /* SVr4/ANSI color support. If "op" isn't available, don't support
4214 color because we can't switch back to the default foreground and
4216 tty
->TS_orig_pair
= tgetstr ("op", address
);
4217 if (tty
->TS_orig_pair
)
4219 tty
->TS_set_foreground
= tgetstr ("AF", address
);
4220 tty
->TS_set_background
= tgetstr ("AB", address
);
4221 if (!tty
->TS_set_foreground
)
4224 tty
->TS_set_foreground
= tgetstr ("Sf", address
);
4225 tty
->TS_set_background
= tgetstr ("Sb", address
);
4228 tty
->TN_max_colors
= tgetnum ("Co");
4229 tty
->TN_max_pairs
= tgetnum ("pa");
4231 tty
->TN_no_color_video
= tgetnum ("NC");
4232 if (tty
->TN_no_color_video
== -1)
4233 tty
->TN_no_color_video
= 0;
4236 tty_default_color_capabilities (tty
, 1);
4238 MagicWrap (tty
) = tgetflag ("xn");
4239 /* Since we make MagicWrap terminals look like AutoWrap, we need to have
4240 the former flag imply the latter. */
4241 AutoWrap (tty
) = MagicWrap (tty
) || tgetflag ("am");
4242 tty
->memory_below_frame
= tgetflag ("db");
4243 tty
->TF_hazeltine
= tgetflag ("hz");
4244 tty
->must_write_spaces
= tgetflag ("in");
4245 tty
->meta_key
= tgetflag ("km") || tgetflag ("MT");
4246 tty
->TF_insmode_motion
= tgetflag ("mi");
4247 tty
->TF_standout_motion
= tgetflag ("ms");
4248 tty
->TF_underscore
= tgetflag ("ul");
4249 tty
->TF_teleray
= tgetflag ("xt");
4254 struct frame
*f
= XFRAME (selected_frame
);
4257 initialize_w32_display (terminal
, &width
, &height
);
4259 FrameRows (tty
) = height
;
4260 FrameCols (tty
) = width
;
4261 tty
->specified_window
= height
;
4263 FRAME_VERTICAL_SCROLL_BAR_TYPE (f
) = vertical_scroll_bar_none
;
4264 tty
->char_ins_del_ok
= 1;
4270 if (strcmp (terminal_type
, "internal") == 0)
4271 terminal
->type
= output_msdos_raw
;
4272 initialize_msdos_display (terminal
);
4274 get_tty_size (fileno (tty
->input
), &width
, &height
);
4275 FrameCols (tty
) = width
;
4276 FrameRows (tty
) = height
;
4277 tty
->char_ins_del_ok
= 0;
4278 init_baud_rate (fileno (tty
->input
));
4281 tty
->output
= stdout
;
4283 /* The following two are inaccessible from w32console.c. */
4284 terminal
->delete_frame_hook
= &tty_free_frame_resources
;
4285 terminal
->delete_terminal_hook
= &delete_tty
;
4287 tty
->name
= xstrdup (name
);
4288 terminal
->name
= xstrdup (name
);
4289 tty
->type
= xstrdup (terminal_type
);
4291 add_keyboard_wait_descriptor (0);
4293 tty
->delete_in_insert_mode
= 1;
4296 tty
->scroll_region_ok
= 0;
4298 /* Seems to insert lines when it's not supposed to, messing up the
4299 display. In doing a trace, it didn't seem to be called much, so I
4300 don't think we're losing anything by turning it off. */
4301 tty
->line_ins_del_ok
= 0;
4303 tty
->TN_max_colors
= 16; /* Must be non-zero for tty-display-color-p. */
4307 terminal
->mouse_position_hook
= term_mouse_position
;
4308 tty
->mouse_highlight
.mouse_face_window
= Qnil
;
4311 terminal
->kboard
= allocate_kboard (Qnil
);
4312 terminal
->kboard
->reference_count
++;
4313 /* Don't let the initial kboard remain current longer than necessary.
4314 That would cause problems if a file loaded on startup tries to
4315 prompt in the mini-buffer. */
4316 if (current_kboard
== initial_kboard
)
4317 current_kboard
= terminal
->kboard
;
4319 term_get_fkeys (address
, terminal
->kboard
);
4321 /* Get frame size from system, or else from termcap. */
4324 get_tty_size (fileno (tty
->input
), &width
, &height
);
4325 FrameCols (tty
) = width
;
4326 FrameRows (tty
) = height
;
4329 if (FrameCols (tty
) <= 0)
4330 FrameCols (tty
) = tgetnum ("co");
4331 if (FrameRows (tty
) <= 0)
4332 FrameRows (tty
) = tgetnum ("li");
4334 if (FrameRows (tty
) < 3 || FrameCols (tty
) < 3)
4335 maybe_fatal (must_succeed
, terminal
,
4336 "Screen size %dx%d is too small",
4337 "Screen size %dx%d is too small",
4338 FrameCols (tty
), FrameRows (tty
));
4340 TabWidth (tty
) = tgetnum ("tw");
4343 tty
->TS_bell
= "\07";
4345 if (!tty
->TS_fwd_scroll
)
4346 tty
->TS_fwd_scroll
= Down (tty
);
4348 PC
= tty
->TS_pad_char
? *tty
->TS_pad_char
: 0;
4350 if (TabWidth (tty
) < 0)
4353 /* Turned off since /etc/termcap seems to have :ta= for most terminals
4354 and newer termcap doc does not seem to say there is a default.
4355 if (!tty->Wcm->cm_tab)
4356 tty->Wcm->cm_tab = "\t";
4359 /* We don't support standout modes that use `magic cookies', so
4360 turn off any that do. */
4361 if (tty
->TS_standout_mode
&& tgetnum ("sg") >= 0)
4363 tty
->TS_standout_mode
= 0;
4364 tty
->TS_end_standout_mode
= 0;
4366 if (tty
->TS_enter_underline_mode
&& tgetnum ("ug") >= 0)
4368 tty
->TS_enter_underline_mode
= 0;
4369 tty
->TS_exit_underline_mode
= 0;
4372 /* If there's no standout mode, try to use underlining instead. */
4373 if (tty
->TS_standout_mode
== 0)
4375 tty
->TS_standout_mode
= tty
->TS_enter_underline_mode
;
4376 tty
->TS_end_standout_mode
= tty
->TS_exit_underline_mode
;
4379 /* If no `se' string, try using a `me' string instead.
4380 If that fails, we can't use standout mode at all. */
4381 if (tty
->TS_end_standout_mode
== 0)
4383 char *s
= tgetstr ("me", address
);
4385 tty
->TS_end_standout_mode
= s
;
4387 tty
->TS_standout_mode
= 0;
4390 if (tty
->TF_teleray
)
4392 tty
->Wcm
->cm_tab
= 0;
4393 /* We can't support standout mode, because it uses magic cookies. */
4394 tty
->TS_standout_mode
= 0;
4395 /* But that means we cannot rely on ^M to go to column zero! */
4397 /* LF can't be trusted either -- can alter hpos. */
4398 /* If move at column 0 thru a line with TS_standout_mode. */
4402 tty
->specified_window
= FrameRows (tty
);
4404 if (Wcm_init (tty
) == -1) /* Can't do cursor motion. */
4406 maybe_fatal (must_succeed
, terminal
,
4407 "Terminal type \"%s\" is not powerful enough to run Emacs",
4408 "Terminal type \"%s\" is not powerful enough to run Emacs.\n\
4409 It lacks the ability to position the cursor.\n\
4410 If that is not the actual type of terminal you have,\n\
4411 use the Bourne shell command `TERM=... export TERM' (C-shell:\n\
4412 `setenv TERM ...') to specify the correct type. It may be necessary\n"
4414 "to do `unset TERMINFO' (C-shell: `unsetenv TERMINFO') as well.",
4415 # else /* TERMCAP */
4416 "to do `unset TERMCAP' (C-shell: `unsetenv TERMCAP') as well.",
4417 # endif /* TERMINFO */
4421 if (FrameRows (tty
) <= 0 || FrameCols (tty
) <= 0)
4422 maybe_fatal (must_succeed
, terminal
,
4423 "Could not determine the frame size",
4424 "Could not determine the frame size");
4426 tty
->delete_in_insert_mode
4427 = tty
->TS_delete_mode
&& tty
->TS_insert_mode
4428 && !strcmp (tty
->TS_delete_mode
, tty
->TS_insert_mode
);
4430 UseTabs (tty
) = tabs_safe_p (fileno (tty
->input
)) && TabWidth (tty
) == 8;
4432 tty
->scroll_region_ok
4434 && (tty
->TS_set_window
|| tty
->TS_set_scroll_region
|| tty
->TS_set_scroll_region_1
));
4436 tty
->line_ins_del_ok
4437 = (((tty
->TS_ins_line
|| tty
->TS_ins_multi_lines
)
4438 && (tty
->TS_del_line
|| tty
->TS_del_multi_lines
))
4439 || (tty
->scroll_region_ok
4440 && tty
->TS_fwd_scroll
&& tty
->TS_rev_scroll
));
4442 tty
->char_ins_del_ok
4443 = ((tty
->TS_ins_char
|| tty
->TS_insert_mode
4444 || tty
->TS_pad_inserted_char
|| tty
->TS_ins_multi_chars
)
4445 && (tty
->TS_del_char
|| tty
->TS_del_multi_chars
));
4447 init_baud_rate (fileno (tty
->input
));
4449 #endif /* not DOS_NT */
4451 /* Init system terminal modes (RAW or CBREAK, etc.). */
4452 init_sys_modes (tty
);
4459 vfatal (const char *str
, va_list ap
)
4461 fprintf (stderr
, "emacs: ");
4462 vfprintf (stderr
, str
, ap
);
4463 if (!(strlen (str
) > 0 && str
[strlen (str
) - 1] == '\n'))
4464 fprintf (stderr
, "\n");
4470 /* Auxiliary error-handling function for init_tty.
4471 Delete TERMINAL, then call error or fatal with str1 or str2,
4472 respectively, according to whether MUST_SUCCEED is true. */
4475 maybe_fatal (bool must_succeed
, struct terminal
*terminal
,
4476 const char *str1
, const char *str2
, ...)
4479 va_start (ap
, str2
);
4481 delete_tty (terminal
);
4490 fatal (const char *str
, ...)
4499 /* Delete the given tty terminal, closing all frames on it. */
4502 delete_tty (struct terminal
*terminal
)
4504 struct tty_display_info
*tty
;
4506 /* Protect against recursive calls. delete_frame in
4507 delete_terminal calls us back when it deletes our last frame. */
4508 if (!terminal
->name
)
4511 eassert (terminal
->type
== output_termcap
);
4513 tty
= terminal
->display_info
.tty
;
4515 if (tty
== tty_list
)
4516 tty_list
= tty
->next
;
4519 struct tty_display_info
*p
;
4520 for (p
= tty_list
; p
&& p
->next
!= tty
; p
= p
->next
)
4524 /* This should not happen. */
4527 p
->next
= tty
->next
;
4531 /* reset_sys_modes needs a valid device, so this call needs to be
4532 before delete_terminal. */
4533 reset_sys_modes (tty
);
4535 delete_terminal (terminal
);
4542 delete_keyboard_wait_descriptor (fileno (tty
->input
));
4543 if (tty
->input
!= stdin
)
4544 fclose (tty
->input
);
4546 if (tty
->output
&& tty
->output
!= stdout
&& tty
->output
!= tty
->input
)
4547 fclose (tty
->output
);
4548 if (tty
->termscript
)
4549 fclose (tty
->termscript
);
4551 xfree (tty
->old_tty
);
4559 DEFVAR_BOOL ("system-uses-terminfo", system_uses_terminfo
,
4560 doc
: /* Non-nil means the system uses terminfo rather than termcap.
4561 This variable can be used by terminal emulator packages. */);
4563 system_uses_terminfo
= 1;
4565 system_uses_terminfo
= 0;
4568 DEFVAR_LISP ("suspend-tty-functions", Vsuspend_tty_functions
,
4569 doc
: /* Functions run after suspending a tty.
4570 The functions are run with one argument, the terminal object to be suspended.
4571 See `suspend-tty'. */);
4572 Vsuspend_tty_functions
= Qnil
;
4575 DEFVAR_LISP ("resume-tty-functions", Vresume_tty_functions
,
4576 doc
: /* Functions run after resuming a tty.
4577 The functions are run with one argument, the terminal object that was revived.
4578 See `resume-tty'. */);
4579 Vresume_tty_functions
= Qnil
;
4581 DEFVAR_BOOL ("visible-cursor", visible_cursor
,
4582 doc
: /* Non-nil means to make the cursor very visible.
4583 This only has an effect when running in a text terminal.
4584 What means \"very visible\" is up to your terminal. It may make the cursor
4585 bigger, or it may make it blink, or it may do nothing at all. */);
4588 defsubr (&Stty_display_color_p
);
4589 defsubr (&Stty_display_color_cells
);
4590 defsubr (&Stty_no_underline
);
4591 defsubr (&Stty_type
);
4592 defsubr (&Scontrolling_tty_p
);
4593 defsubr (&Stty_top_frame
);
4594 defsubr (&Ssuspend_tty
);
4595 defsubr (&Sresume_tty
);
4597 defsubr (&Sgpm_mouse_start
);
4598 defsubr (&Sgpm_mouse_stop
);
4599 #endif /* HAVE_GPM */
4602 default_orig_pair
= NULL
;
4603 default_set_foreground
= NULL
;
4604 default_set_background
= NULL
;
4605 #endif /* !DOS_NT */
4607 encode_terminal_src
= NULL
;
4608 encode_terminal_dst
= NULL
;
4610 DEFSYM (Qtty_menu_next_item
, "tty-menu-next-item");
4611 DEFSYM (Qtty_menu_prev_item
, "tty-menu-prev-item");
4612 DEFSYM (Qtty_menu_next_menu
, "tty-menu-next-menu");
4613 DEFSYM (Qtty_menu_prev_menu
, "tty-menu-prev-menu");
4614 DEFSYM (Qtty_menu_select
, "tty-menu-select");
4615 DEFSYM (Qtty_menu_ignore
, "tty-menu-ignore");
4616 DEFSYM (Qtty_menu_exit
, "tty-menu-exit");
4617 DEFSYM (Qtty_menu_mouse_movement
, "tty-menu-mouse-movement");
4618 DEFSYM (Qtty_menu_navigation_map
, "tty-menu-navigation-map");