1 /* Terminal control module for terminals described by TERMCAP
2 Copyright (C) 1985, 1986, 1987, 1993, 1994, 1995, 1998, 2000, 2001,
3 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011
4 Free Software Foundation, Inc.
6 This file is part of GNU Emacs.
8 GNU Emacs is free software: you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation, either version 3 of the License, or
11 (at your option) any later version.
13 GNU Emacs is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
21 /* New redisplay, TTY faces by Gerd Moellmann <gerd@gnu.org>. */
37 #include "character.h"
40 #include "composite.h"
44 #include "termhooks.h"
45 #include "dispextern.h"
48 #include "blockinput.h"
49 #include "syssignal.h"
51 #include "intervals.h"
54 static int been_here
= -1;
57 /* For now, don't try to include termcap.h. On some systems,
58 configure finds a non-standard termcap.h that the main build
60 extern void tputs (const char *, int, int (*)(int));
61 extern int tgetent (char *, const char *);
62 extern int tgetflag (char *id
);
63 extern int tgetnum (char *id
);
65 char *tparam (char *, char *, int, int, ...);
67 extern char *tgetstr (char *, char **);
82 /* The name of the default console device. */
84 #define DEV_TTY "CONOUT$"
86 #define DEV_TTY "/dev/tty"
89 static void tty_set_scroll_region (struct frame
*f
, int start
, int stop
);
90 static void turn_on_face (struct frame
*, int face_id
);
91 static void turn_off_face (struct frame
*, int face_id
);
92 static void tty_show_cursor (struct tty_display_info
*);
93 static void tty_hide_cursor (struct tty_display_info
*);
94 static void tty_background_highlight (struct tty_display_info
*tty
);
95 static void clear_tty_hooks (struct terminal
*terminal
);
96 static void set_tty_hooks (struct terminal
*terminal
);
97 static void dissociate_if_controlling_tty (int fd
);
98 static void delete_tty (struct terminal
*);
99 static void maybe_fatal (int must_succeed
, struct terminal
*terminal
,
100 const char *str1
, const char *str2
, ...) NO_RETURN
;
101 static void vfatal (const char *str
, va_list ap
) NO_RETURN
;
104 #define OUTPUT(tty, a) \
105 emacs_tputs ((tty), a, \
106 (int) (FRAME_LINES (XFRAME (selected_frame)) \
110 #define OUTPUT1(tty, a) emacs_tputs ((tty), a, 1, cmputc)
111 #define OUTPUTL(tty, a, lines) emacs_tputs ((tty), a, lines, cmputc)
113 #define OUTPUT_IF(tty, a) \
116 emacs_tputs ((tty), a, \
117 (int) (FRAME_LINES (XFRAME (selected_frame)) \
122 #define OUTPUT1_IF(tty, a) do { if (a) emacs_tputs ((tty), a, 1, cmputc); } while (0)
124 /* Display space properties */
126 /* Chain of all tty device parameters. */
127 struct tty_display_info
*tty_list
;
129 /* Meaning of bits in no_color_video. Each bit set means that the
130 corresponding attribute cannot be combined with colors. */
134 NC_STANDOUT
= 1 << 0,
135 NC_UNDERLINE
= 1 << 1,
142 NC_ALT_CHARSET
= 1 << 8
147 /* The largest frame width in any call to calculate_costs. */
151 /* The largest frame height in any call to calculate_costs. */
155 /* Non-zero if we have dropped our controlling tty and therefore
156 should not open a frame on stdout. */
157 static int no_controlling_tty
;
162 #include <sys/fcntl.h>
164 /* The device for which we have enabled gpm support (or NULL). */
165 struct tty_display_info
*gpm_tty
= NULL
;
167 /* Last recorded mouse coordinates. */
168 static int last_mouse_x
, last_mouse_y
;
169 #endif /* HAVE_GPM */
171 /* Ring the bell on a tty. */
174 tty_ring_bell (struct frame
*f
)
176 struct tty_display_info
*tty
= FRAME_TTY (f
);
180 OUTPUT (tty
, (tty
->TS_visible_bell
&& visible_bell
181 ? tty
->TS_visible_bell
183 fflush (tty
->output
);
187 /* Set up termcap modes for Emacs. */
190 tty_set_terminal_modes (struct terminal
*terminal
)
192 struct tty_display_info
*tty
= terminal
->display_info
.tty
;
196 if (tty
->TS_termcap_modes
)
197 OUTPUT (tty
, tty
->TS_termcap_modes
);
200 /* Output enough newlines to scroll all the old screen contents
201 off the screen, so it won't be overwritten and lost. */
204 for (i
= 0; i
< FRAME_LINES (XFRAME (selected_frame
)); i
++)
208 OUTPUT_IF (tty
, visible_cursor
? tty
->TS_cursor_visible
: tty
->TS_cursor_normal
);
209 OUTPUT_IF (tty
, tty
->TS_keypad_mode
);
211 fflush (tty
->output
);
215 /* Reset termcap modes before exiting Emacs. */
218 tty_reset_terminal_modes (struct terminal
*terminal
)
220 struct tty_display_info
*tty
= terminal
->display_info
.tty
;
224 tty_turn_off_highlight (tty
);
225 tty_turn_off_insert (tty
);
226 OUTPUT_IF (tty
, tty
->TS_end_keypad_mode
);
227 OUTPUT_IF (tty
, tty
->TS_cursor_normal
);
228 OUTPUT_IF (tty
, tty
->TS_end_termcap_modes
);
229 OUTPUT_IF (tty
, tty
->TS_orig_pair
);
230 /* Output raw CR so kernel can track the cursor hpos. */
233 fflush (tty
->output
);
237 /* Flag the end of a display update on a termcap terminal. */
240 tty_update_end (struct frame
*f
)
242 struct tty_display_info
*tty
= FRAME_TTY (f
);
244 if (!XWINDOW (selected_window
)->cursor_off_p
)
245 tty_show_cursor (tty
);
246 tty_turn_off_insert (tty
);
247 tty_background_highlight (tty
);
250 /* The implementation of set_terminal_window for termcap frames. */
253 tty_set_terminal_window (struct frame
*f
, int size
)
255 struct tty_display_info
*tty
= FRAME_TTY (f
);
257 tty
->specified_window
= size
? size
: FRAME_LINES (f
);
258 if (FRAME_SCROLL_REGION_OK (f
))
259 tty_set_scroll_region (f
, 0, tty
->specified_window
);
263 tty_set_scroll_region (struct frame
*f
, int start
, int stop
)
266 struct tty_display_info
*tty
= FRAME_TTY (f
);
268 if (tty
->TS_set_scroll_region
)
269 buf
= tparam (tty
->TS_set_scroll_region
, 0, 0, start
, stop
- 1);
270 else if (tty
->TS_set_scroll_region_1
)
271 buf
= tparam (tty
->TS_set_scroll_region_1
, 0, 0,
272 FRAME_LINES (f
), start
,
273 FRAME_LINES (f
) - stop
,
276 buf
= tparam (tty
->TS_set_window
, 0, 0, start
, 0, stop
, FRAME_COLS (f
));
285 tty_turn_on_insert (struct tty_display_info
*tty
)
287 if (!tty
->insert_mode
)
288 OUTPUT (tty
, tty
->TS_insert_mode
);
289 tty
->insert_mode
= 1;
293 tty_turn_off_insert (struct tty_display_info
*tty
)
295 if (tty
->insert_mode
)
296 OUTPUT (tty
, tty
->TS_end_insert_mode
);
297 tty
->insert_mode
= 0;
300 /* Handle highlighting. */
303 tty_turn_off_highlight (struct tty_display_info
*tty
)
305 if (tty
->standout_mode
)
306 OUTPUT_IF (tty
, tty
->TS_end_standout_mode
);
307 tty
->standout_mode
= 0;
311 tty_turn_on_highlight (struct tty_display_info
*tty
)
313 if (!tty
->standout_mode
)
314 OUTPUT_IF (tty
, tty
->TS_standout_mode
);
315 tty
->standout_mode
= 1;
319 tty_toggle_highlight (struct tty_display_info
*tty
)
321 if (tty
->standout_mode
)
322 tty_turn_off_highlight (tty
);
324 tty_turn_on_highlight (tty
);
328 /* Make cursor invisible. */
331 tty_hide_cursor (struct tty_display_info
*tty
)
333 if (tty
->cursor_hidden
== 0)
335 tty
->cursor_hidden
= 1;
336 OUTPUT_IF (tty
, tty
->TS_cursor_invisible
);
341 /* Ensure that cursor is visible. */
344 tty_show_cursor (struct tty_display_info
*tty
)
346 if (tty
->cursor_hidden
)
348 tty
->cursor_hidden
= 0;
349 OUTPUT_IF (tty
, tty
->TS_cursor_normal
);
351 OUTPUT_IF (tty
, tty
->TS_cursor_visible
);
356 /* Set standout mode to the state it should be in for
357 empty space inside windows. What this is,
358 depends on the user option inverse-video. */
361 tty_background_highlight (struct tty_display_info
*tty
)
364 tty_turn_on_highlight (tty
);
366 tty_turn_off_highlight (tty
);
369 /* Set standout mode to the mode specified for the text to be output. */
372 tty_highlight_if_desired (struct tty_display_info
*tty
)
375 tty_turn_on_highlight (tty
);
377 tty_turn_off_highlight (tty
);
381 /* Move cursor to row/column position VPOS/HPOS. HPOS/VPOS are
382 frame-relative coordinates. */
385 tty_cursor_to (struct frame
*f
, int vpos
, int hpos
)
387 struct tty_display_info
*tty
= FRAME_TTY (f
);
389 /* Detect the case where we are called from reset_sys_modes
390 and the costs have never been calculated. Do nothing. */
391 if (! tty
->costs_set
)
394 if (curY (tty
) == vpos
395 && curX (tty
) == hpos
)
397 if (!tty
->TF_standout_motion
)
398 tty_background_highlight (tty
);
399 if (!tty
->TF_insmode_motion
)
400 tty_turn_off_insert (tty
);
401 cmgoto (tty
, vpos
, hpos
);
404 /* Similar but don't take any account of the wasted characters. */
407 tty_raw_cursor_to (struct frame
*f
, int row
, int col
)
409 struct tty_display_info
*tty
= FRAME_TTY (f
);
411 if (curY (tty
) == row
412 && curX (tty
) == col
)
414 if (!tty
->TF_standout_motion
)
415 tty_background_highlight (tty
);
416 if (!tty
->TF_insmode_motion
)
417 tty_turn_off_insert (tty
);
418 cmgoto (tty
, row
, col
);
421 /* Erase operations */
423 /* Clear from cursor to end of frame on a termcap device. */
426 tty_clear_to_end (struct frame
*f
)
429 struct tty_display_info
*tty
= FRAME_TTY (f
);
431 if (tty
->TS_clr_to_bottom
)
433 tty_background_highlight (tty
);
434 OUTPUT (tty
, tty
->TS_clr_to_bottom
);
438 for (i
= curY (tty
); i
< FRAME_LINES (f
); i
++)
441 clear_end_of_line (f
, FRAME_COLS (f
));
446 /* Clear an entire termcap frame. */
449 tty_clear_frame (struct frame
*f
)
451 struct tty_display_info
*tty
= FRAME_TTY (f
);
453 if (tty
->TS_clr_frame
)
455 tty_background_highlight (tty
);
456 OUTPUT (tty
, tty
->TS_clr_frame
);
466 /* An implementation of clear_end_of_line for termcap frames.
468 Note that the cursor may be moved, on terminals lacking a `ce' string. */
471 tty_clear_end_of_line (struct frame
*f
, int first_unused_hpos
)
474 struct tty_display_info
*tty
= FRAME_TTY (f
);
476 /* Detect the case where we are called from reset_sys_modes
477 and the costs have never been calculated. Do nothing. */
478 if (! tty
->costs_set
)
481 if (curX (tty
) >= first_unused_hpos
)
483 tty_background_highlight (tty
);
484 if (tty
->TS_clr_line
)
486 OUTPUT1 (tty
, tty
->TS_clr_line
);
489 { /* have to do it the hard way */
490 tty_turn_off_insert (tty
);
492 /* Do not write in last row last col with Auto-wrap on. */
494 && curY (tty
) == FrameRows (tty
) - 1
495 && first_unused_hpos
== FrameCols (tty
))
498 for (i
= curX (tty
); i
< first_unused_hpos
; i
++)
501 fputc (' ', tty
->termscript
);
502 fputc (' ', tty
->output
);
504 cmplus (tty
, first_unused_hpos
- curX (tty
));
508 /* Buffers to store the source and result of code conversion for terminal. */
509 static unsigned char *encode_terminal_src
;
510 static unsigned char *encode_terminal_dst
;
511 /* Allocated sizes of the above buffers. */
512 static int encode_terminal_src_size
;
513 static int encode_terminal_dst_size
;
515 /* Encode SRC_LEN glyphs starting at SRC to terminal output codes.
516 Set CODING->produced to the byte-length of the resulting byte
517 sequence, and return a pointer to that byte sequence. */
520 encode_terminal_code (struct glyph
*src
, int src_len
, struct coding_system
*coding
)
522 struct glyph
*src_end
= src
+ src_len
;
524 int nchars
, nbytes
, required
;
525 register int tlen
= GLYPH_TABLE_LENGTH
;
526 register Lisp_Object
*tbase
= GLYPH_TABLE_BASE
;
527 Lisp_Object charset_list
;
529 /* Allocate sufficient size of buffer to store all characters in
530 multibyte-form. But, it may be enlarged on demand if
531 Vglyph_table contains a string or a composite glyph is
533 required
= MAX_MULTIBYTE_LENGTH
* src_len
;
534 if (encode_terminal_src_size
< required
)
536 if (encode_terminal_src
)
537 encode_terminal_src
= xrealloc (encode_terminal_src
, required
);
539 encode_terminal_src
= xmalloc (required
);
540 encode_terminal_src_size
= required
;
543 charset_list
= coding_charset_list (coding
);
545 buf
= encode_terminal_src
;
547 while (src
< src_end
)
549 if (src
->type
== COMPOSITE_GLYPH
)
551 struct composition
*cmp
;
555 nbytes
= buf
- encode_terminal_src
;
556 if (src
->u
.cmp
.automatic
)
558 gstring
= composition_gstring_from_id (src
->u
.cmp
.id
);
559 required
= src
->slice
.cmp
.to
+ 1 - src
->slice
.cmp
.from
;
563 cmp
= composition_table
[src
->u
.cmp
.id
];
564 required
= MAX_MULTIBYTE_LENGTH
* cmp
->glyph_len
;
567 if (encode_terminal_src_size
< nbytes
+ required
)
569 encode_terminal_src_size
= nbytes
+ required
;
570 encode_terminal_src
= xrealloc (encode_terminal_src
,
571 encode_terminal_src_size
);
572 buf
= encode_terminal_src
+ nbytes
;
575 if (src
->u
.cmp
.automatic
)
576 for (i
= src
->slice
.cmp
.from
; i
<= src
->slice
.cmp
.to
; i
++)
578 Lisp_Object g
= LGSTRING_GLYPH (gstring
, i
);
579 int c
= LGLYPH_CHAR (g
);
581 if (! char_charset (c
, charset_list
, NULL
))
583 buf
+= CHAR_STRING (c
, buf
);
587 for (i
= 0; i
< cmp
->glyph_len
; i
++)
589 int c
= COMPOSITION_GLYPH (cmp
, i
);
593 if (char_charset (c
, charset_list
, NULL
))
595 if (CHAR_WIDTH (c
) == 0
596 && i
> 0 && COMPOSITION_GLYPH (cmp
, i
- 1) == '\t')
597 /* Should be left-padded */
599 buf
+= CHAR_STRING (' ', buf
);
605 buf
+= CHAR_STRING (c
, buf
);
609 /* We must skip glyphs to be padded for a wide character. */
610 else if (! CHAR_GLYPH_PADDING_P (*src
))
617 SET_GLYPH_FROM_CHAR_GLYPH (g
, src
[0]);
619 if (GLYPH_INVALID_P (g
) || GLYPH_SIMPLE_P (tbase
, tlen
, g
))
621 /* This glyph doesn't have an entry in Vglyph_table. */
626 /* This glyph has an entry in Vglyph_table,
627 so process any alias before testing for simpleness. */
628 GLYPH_FOLLOW_ALIASES (tbase
, tlen
, g
);
630 if (GLYPH_SIMPLE_P (tbase
, tlen
, g
))
631 /* We set the multi-byte form of a character in G
632 (that should be an ASCII character) at WORKBUF. */
635 /* We have a string in Vglyph_table. */
636 string
= tbase
[GLYPH_CHAR (g
)];
641 nbytes
= buf
- encode_terminal_src
;
642 if (encode_terminal_src_size
< nbytes
+ MAX_MULTIBYTE_LENGTH
)
644 encode_terminal_src_size
= nbytes
+ MAX_MULTIBYTE_LENGTH
;
645 encode_terminal_src
= xrealloc (encode_terminal_src
,
646 encode_terminal_src_size
);
647 buf
= encode_terminal_src
+ nbytes
;
650 || char_charset (c
, charset_list
, NULL
))
652 /* Store the multibyte form of C at BUF. */
653 buf
+= CHAR_STRING (c
, buf
);
658 /* C is not encodable. */
661 while (src
+ 1 < src_end
&& CHAR_GLYPH_PADDING_P (src
[1]))
671 unsigned char *p
= SDATA (string
);
673 if (! STRING_MULTIBYTE (string
))
674 string
= string_to_multibyte (string
);
675 nbytes
= buf
- encode_terminal_src
;
676 if (encode_terminal_src_size
< nbytes
+ SBYTES (string
))
678 encode_terminal_src_size
= nbytes
+ SBYTES (string
);
679 encode_terminal_src
= xrealloc (encode_terminal_src
,
680 encode_terminal_src_size
);
681 buf
= encode_terminal_src
+ nbytes
;
683 memcpy (buf
, SDATA (string
), SBYTES (string
));
684 buf
+= SBYTES (string
);
685 nchars
+= SCHARS (string
);
693 coding
->produced
= 0;
697 nbytes
= buf
- encode_terminal_src
;
698 coding
->source
= encode_terminal_src
;
699 if (encode_terminal_dst_size
== 0)
701 encode_terminal_dst_size
= encode_terminal_src_size
;
702 if (encode_terminal_dst
)
703 encode_terminal_dst
= xrealloc (encode_terminal_dst
,
704 encode_terminal_dst_size
);
706 encode_terminal_dst
= xmalloc (encode_terminal_dst_size
);
708 coding
->destination
= encode_terminal_dst
;
709 coding
->dst_bytes
= encode_terminal_dst_size
;
710 encode_coding_object (coding
, Qnil
, 0, 0, nchars
, nbytes
, Qnil
);
711 /* coding->destination may have been reallocated. */
712 encode_terminal_dst
= coding
->destination
;
713 encode_terminal_dst_size
= coding
->dst_bytes
;
715 return (encode_terminal_dst
);
720 /* An implementation of write_glyphs for termcap frames. */
723 tty_write_glyphs (struct frame
*f
, struct glyph
*string
, int len
)
725 unsigned char *conversion_buffer
;
726 struct coding_system
*coding
;
728 struct tty_display_info
*tty
= FRAME_TTY (f
);
730 tty_turn_off_insert (tty
);
731 tty_hide_cursor (tty
);
733 /* Don't dare write in last column of bottom line, if Auto-Wrap,
734 since that would scroll the whole frame on some terminals. */
737 && curY (tty
) + 1 == FRAME_LINES (f
)
738 && (curX (tty
) + len
) == FRAME_COLS (f
))
745 /* If terminal_coding does any conversion, use it, otherwise use
746 safe_terminal_coding. We can't use CODING_REQUIRE_ENCODING here
747 because it always return 1 if the member src_multibyte is 1. */
748 coding
= (FRAME_TERMINAL_CODING (f
)->common_flags
& CODING_REQUIRE_ENCODING_MASK
749 ? FRAME_TERMINAL_CODING (f
) : &safe_terminal_coding
);
750 /* The mode bit CODING_MODE_LAST_BLOCK should be set to 1 only at
752 coding
->mode
&= ~CODING_MODE_LAST_BLOCK
;
756 /* Identify a run of glyphs with the same face. */
757 int face_id
= string
->face_id
;
760 for (n
= 1; n
< len
; ++n
)
761 if (string
[n
].face_id
!= face_id
)
764 /* Turn appearance modes of the face of the run on. */
765 tty_highlight_if_desired (tty
);
766 turn_on_face (f
, face_id
);
769 /* This is the last run. */
770 coding
->mode
|= CODING_MODE_LAST_BLOCK
;
771 conversion_buffer
= encode_terminal_code (string
, n
, coding
);
772 if (coding
->produced
> 0)
775 fwrite (conversion_buffer
, 1, coding
->produced
, tty
->output
);
776 if (ferror (tty
->output
))
777 clearerr (tty
->output
);
779 fwrite (conversion_buffer
, 1, coding
->produced
, tty
->termscript
);
785 /* Turn appearance modes off. */
786 turn_off_face (f
, face_id
);
787 tty_turn_off_highlight (tty
);
793 #ifdef HAVE_GPM /* Only used by GPM code. */
796 tty_write_glyphs_with_face (register struct frame
*f
, register struct glyph
*string
,
797 register int len
, register int face_id
)
799 unsigned char *conversion_buffer
;
800 struct coding_system
*coding
;
802 struct tty_display_info
*tty
= FRAME_TTY (f
);
804 tty_turn_off_insert (tty
);
805 tty_hide_cursor (tty
);
807 /* Don't dare write in last column of bottom line, if Auto-Wrap,
808 since that would scroll the whole frame on some terminals. */
811 && curY (tty
) + 1 == FRAME_LINES (f
)
812 && (curX (tty
) + len
) == FRAME_COLS (f
))
819 /* If terminal_coding does any conversion, use it, otherwise use
820 safe_terminal_coding. We can't use CODING_REQUIRE_ENCODING here
821 because it always return 1 if the member src_multibyte is 1. */
822 coding
= (FRAME_TERMINAL_CODING (f
)->common_flags
& CODING_REQUIRE_ENCODING_MASK
823 ? FRAME_TERMINAL_CODING (f
) : &safe_terminal_coding
);
824 /* The mode bit CODING_MODE_LAST_BLOCK should be set to 1 only at
826 coding
->mode
&= ~CODING_MODE_LAST_BLOCK
;
828 /* Turn appearance modes of the face. */
829 tty_highlight_if_desired (tty
);
830 turn_on_face (f
, face_id
);
832 coding
->mode
|= CODING_MODE_LAST_BLOCK
;
833 conversion_buffer
= encode_terminal_code (string
, len
, coding
);
834 if (coding
->produced
> 0)
837 fwrite (conversion_buffer
, 1, coding
->produced
, tty
->output
);
838 if (ferror (tty
->output
))
839 clearerr (tty
->output
);
841 fwrite (conversion_buffer
, 1, coding
->produced
, tty
->termscript
);
845 /* Turn appearance modes off. */
846 turn_off_face (f
, face_id
);
847 tty_turn_off_highlight (tty
);
853 /* An implementation of insert_glyphs for termcap frames. */
856 tty_insert_glyphs (struct frame
*f
, struct glyph
*start
, int len
)
859 struct glyph
*glyph
= NULL
;
860 unsigned char *conversion_buffer
;
861 unsigned char space
[1];
862 struct coding_system
*coding
;
864 struct tty_display_info
*tty
= FRAME_TTY (f
);
866 if (tty
->TS_ins_multi_chars
)
868 buf
= tparam (tty
->TS_ins_multi_chars
, 0, 0, len
);
872 write_glyphs (f
, start
, len
);
876 tty_turn_on_insert (tty
);
880 space
[0] = SPACEGLYPH
;
882 /* If terminal_coding does any conversion, use it, otherwise use
883 safe_terminal_coding. We can't use CODING_REQUIRE_ENCODING here
884 because it always return 1 if the member src_multibyte is 1. */
885 coding
= (FRAME_TERMINAL_CODING (f
)->common_flags
& CODING_REQUIRE_ENCODING_MASK
886 ? FRAME_TERMINAL_CODING (f
) : &safe_terminal_coding
);
887 /* The mode bit CODING_MODE_LAST_BLOCK should be set to 1 only at
889 coding
->mode
&= ~CODING_MODE_LAST_BLOCK
;
893 OUTPUT1_IF (tty
, tty
->TS_ins_char
);
896 conversion_buffer
= space
;
897 coding
->produced
= 1;
901 tty_highlight_if_desired (tty
);
902 turn_on_face (f
, start
->face_id
);
905 /* We must open sufficient space for a character which
906 occupies more than one column. */
907 while (len
&& CHAR_GLYPH_PADDING_P (*start
))
909 OUTPUT1_IF (tty
, tty
->TS_ins_char
);
914 /* This is the last glyph. */
915 coding
->mode
|= CODING_MODE_LAST_BLOCK
;
917 conversion_buffer
= encode_terminal_code (glyph
, 1, coding
);
920 if (coding
->produced
> 0)
923 fwrite (conversion_buffer
, 1, coding
->produced
, tty
->output
);
924 if (ferror (tty
->output
))
925 clearerr (tty
->output
);
927 fwrite (conversion_buffer
, 1, coding
->produced
, tty
->termscript
);
931 OUTPUT1_IF (tty
, tty
->TS_pad_inserted_char
);
934 turn_off_face (f
, glyph
->face_id
);
935 tty_turn_off_highlight (tty
);
942 /* An implementation of delete_glyphs for termcap frames. */
945 tty_delete_glyphs (struct frame
*f
, int n
)
950 struct tty_display_info
*tty
= FRAME_TTY (f
);
952 if (tty
->delete_in_insert_mode
)
954 tty_turn_on_insert (tty
);
958 tty_turn_off_insert (tty
);
959 OUTPUT_IF (tty
, tty
->TS_delete_mode
);
962 if (tty
->TS_del_multi_chars
)
964 buf
= tparam (tty
->TS_del_multi_chars
, 0, 0, n
);
969 for (i
= 0; i
< n
; i
++)
970 OUTPUT1 (tty
, tty
->TS_del_char
);
971 if (!tty
->delete_in_insert_mode
)
972 OUTPUT_IF (tty
, tty
->TS_end_delete_mode
);
975 /* An implementation of ins_del_lines for termcap frames. */
978 tty_ins_del_lines (struct frame
*f
, int vpos
, int n
)
980 struct tty_display_info
*tty
= FRAME_TTY (f
);
981 char *multi
= n
> 0 ? tty
->TS_ins_multi_lines
: tty
->TS_del_multi_lines
;
982 char *single
= n
> 0 ? tty
->TS_ins_line
: tty
->TS_del_line
;
983 char *scroll
= n
> 0 ? tty
->TS_rev_scroll
: tty
->TS_fwd_scroll
;
985 register int i
= n
> 0 ? n
: -n
;
988 /* If the lines below the insertion are being pushed
989 into the end of the window, this is the same as clearing;
990 and we know the lines are already clear, since the matching
991 deletion has already been done. So can ignore this. */
992 /* If the lines below the deletion are blank lines coming
993 out of the end of the window, don't bother,
994 as there will be a matching inslines later that will flush them. */
995 if (FRAME_SCROLL_REGION_OK (f
)
996 && vpos
+ i
>= tty
->specified_window
)
998 if (!FRAME_MEMORY_BELOW_FRAME (f
)
999 && vpos
+ i
>= FRAME_LINES (f
))
1004 raw_cursor_to (f
, vpos
, 0);
1005 tty_background_highlight (tty
);
1006 buf
= tparam (multi
, 0, 0, i
);
1012 raw_cursor_to (f
, vpos
, 0);
1013 tty_background_highlight (tty
);
1015 OUTPUT (tty
, single
);
1016 if (tty
->TF_teleray
)
1021 tty_set_scroll_region (f
, vpos
, tty
->specified_window
);
1023 raw_cursor_to (f
, tty
->specified_window
- 1, 0);
1025 raw_cursor_to (f
, vpos
, 0);
1026 tty_background_highlight (tty
);
1028 OUTPUTL (tty
, scroll
, tty
->specified_window
- vpos
);
1029 tty_set_scroll_region (f
, 0, tty
->specified_window
);
1032 if (!FRAME_SCROLL_REGION_OK (f
)
1033 && FRAME_MEMORY_BELOW_FRAME (f
)
1036 cursor_to (f
, FRAME_LINES (f
) + n
, 0);
1041 /* Compute cost of sending "str", in characters,
1042 not counting any line-dependent padding. */
1045 string_cost (const char *str
)
1049 tputs (str
, 0, evalcost
);
1053 /* Compute cost of sending "str", in characters,
1054 counting any line-dependent padding at one line. */
1057 string_cost_one_line (const char *str
)
1061 tputs (str
, 1, evalcost
);
1065 /* Compute per line amount of line-dependent padding,
1066 in tenths of characters. */
1069 per_line_cost (const char *str
)
1073 tputs (str
, 0, evalcost
);
1076 tputs (str
, 10, evalcost
);
1080 /* char_ins_del_cost[n] is cost of inserting N characters.
1081 char_ins_del_cost[-n] is cost of deleting N characters.
1082 The length of this vector is based on max_frame_cols. */
1084 int *char_ins_del_vector
;
1086 #define char_ins_del_cost(f) (&char_ins_del_vector[FRAME_COLS ((f))])
1090 calculate_ins_del_char_costs (struct frame
*f
)
1092 struct tty_display_info
*tty
= FRAME_TTY (f
);
1093 int ins_startup_cost
, del_startup_cost
;
1094 int ins_cost_per_char
, del_cost_per_char
;
1098 if (tty
->TS_ins_multi_chars
)
1100 ins_cost_per_char
= 0;
1101 ins_startup_cost
= string_cost_one_line (tty
->TS_ins_multi_chars
);
1103 else if (tty
->TS_ins_char
|| tty
->TS_pad_inserted_char
1104 || (tty
->TS_insert_mode
&& tty
->TS_end_insert_mode
))
1106 ins_startup_cost
= (30 * (string_cost (tty
->TS_insert_mode
)
1107 + string_cost (tty
->TS_end_insert_mode
))) / 100;
1108 ins_cost_per_char
= (string_cost_one_line (tty
->TS_ins_char
)
1109 + string_cost_one_line (tty
->TS_pad_inserted_char
));
1113 ins_startup_cost
= 9999;
1114 ins_cost_per_char
= 0;
1117 if (tty
->TS_del_multi_chars
)
1119 del_cost_per_char
= 0;
1120 del_startup_cost
= string_cost_one_line (tty
->TS_del_multi_chars
);
1122 else if (tty
->TS_del_char
)
1124 del_startup_cost
= (string_cost (tty
->TS_delete_mode
)
1125 + string_cost (tty
->TS_end_delete_mode
));
1126 if (tty
->delete_in_insert_mode
)
1127 del_startup_cost
/= 2;
1128 del_cost_per_char
= string_cost_one_line (tty
->TS_del_char
);
1132 del_startup_cost
= 9999;
1133 del_cost_per_char
= 0;
1136 /* Delete costs are at negative offsets */
1137 p
= &char_ins_del_cost (f
)[0];
1138 for (i
= FRAME_COLS (f
); --i
>= 0;)
1139 *--p
= (del_startup_cost
+= del_cost_per_char
);
1141 /* Doing nothing is free */
1142 p
= &char_ins_del_cost (f
)[0];
1145 /* Insert costs are at positive offsets */
1146 for (i
= FRAME_COLS (f
); --i
>= 0;)
1147 *p
++ = (ins_startup_cost
+= ins_cost_per_char
);
1151 calculate_costs (struct frame
*frame
)
1153 FRAME_COST_BAUD_RATE (frame
) = baud_rate
;
1155 if (FRAME_TERMCAP_P (frame
))
1157 struct tty_display_info
*tty
= FRAME_TTY (frame
);
1158 register char *f
= (tty
->TS_set_scroll_region
1159 ? tty
->TS_set_scroll_region
1160 : tty
->TS_set_scroll_region_1
);
1162 FRAME_SCROLL_REGION_COST (frame
) = string_cost (f
);
1166 /* These variables are only used for terminal stuff. They are
1167 allocated once for the terminal frame of X-windows emacs, but not
1170 char_ins_del_vector (i.e., char_ins_del_cost) isn't used because
1171 X turns off char_ins_del_ok. */
1173 max_frame_lines
= max (max_frame_lines
, FRAME_LINES (frame
));
1174 max_frame_cols
= max (max_frame_cols
, FRAME_COLS (frame
));
1176 if (char_ins_del_vector
!= 0)
1178 = (int *) xrealloc (char_ins_del_vector
,
1180 + 2 * max_frame_cols
* sizeof (int)));
1183 = (int *) xmalloc (sizeof (int)
1184 + 2 * max_frame_cols
* sizeof (int));
1186 memset (char_ins_del_vector
, 0,
1187 (sizeof (int) + 2 * max_frame_cols
* sizeof (int)));
1190 if (f
&& (!tty
->TS_ins_line
&& !tty
->TS_del_line
))
1191 do_line_insertion_deletion_costs (frame
,
1192 tty
->TS_rev_scroll
, tty
->TS_ins_multi_lines
,
1193 tty
->TS_fwd_scroll
, tty
->TS_del_multi_lines
,
1196 do_line_insertion_deletion_costs (frame
,
1197 tty
->TS_ins_line
, tty
->TS_ins_multi_lines
,
1198 tty
->TS_del_line
, tty
->TS_del_multi_lines
,
1201 calculate_ins_del_char_costs (frame
);
1203 /* Don't use TS_repeat if its padding is worse than sending the chars */
1204 if (tty
->TS_repeat
&& per_line_cost (tty
->TS_repeat
) * baud_rate
< 9000)
1205 tty
->RPov
= string_cost (tty
->TS_repeat
);
1207 tty
->RPov
= FRAME_COLS (frame
) * 2;
1209 cmcostinit (FRAME_TTY (frame
)); /* set up cursor motion costs */
1217 /* Termcap capability names that correspond directly to X keysyms.
1218 Some of these (marked "terminfo") aren't supplied by old-style
1219 (Berkeley) termcap entries. They're listed in X keysym order;
1220 except we put the keypad keys first, so that if they clash with
1221 other keys (as on the IBM PC keyboard) they get overridden.
1224 static const struct fkey_table keys
[] =
1226 {"kh", "home"}, /* termcap */
1227 {"kl", "left"}, /* termcap */
1228 {"ku", "up"}, /* termcap */
1229 {"kr", "right"}, /* termcap */
1230 {"kd", "down"}, /* termcap */
1231 {"%8", "prior"}, /* terminfo */
1232 {"%5", "next"}, /* terminfo */
1233 {"@7", "end"}, /* terminfo */
1234 {"@1", "begin"}, /* terminfo */
1235 {"*6", "select"}, /* terminfo */
1236 {"%9", "print"}, /* terminfo */
1237 {"@4", "execute"}, /* terminfo --- actually the `command' key */
1239 * "insert" --- see below
1241 {"&8", "undo"}, /* terminfo */
1242 {"%0", "redo"}, /* terminfo */
1243 {"%7", "menu"}, /* terminfo --- actually the `options' key */
1244 {"@0", "find"}, /* terminfo */
1245 {"@2", "cancel"}, /* terminfo */
1246 {"%1", "help"}, /* terminfo */
1248 * "break" goes here, but can't be reliably intercepted with termcap
1250 {"&4", "reset"}, /* terminfo --- actually `restart' */
1252 * "system" and "user" --- no termcaps
1254 {"kE", "clearline"}, /* terminfo */
1255 {"kA", "insertline"}, /* terminfo */
1256 {"kL", "deleteline"}, /* terminfo */
1257 {"kI", "insertchar"}, /* terminfo */
1258 {"kD", "deletechar"}, /* terminfo */
1259 {"kB", "backtab"}, /* terminfo */
1261 * "kp_backtab", "kp-space", "kp-tab" --- no termcaps
1263 {"@8", "kp-enter"}, /* terminfo */
1265 * "kp-f1", "kp-f2", "kp-f3" "kp-f4",
1266 * "kp-multiply", "kp-add", "kp-separator",
1267 * "kp-subtract", "kp-decimal", "kp-divide", "kp-0";
1268 * --- no termcaps for any of these.
1270 {"K4", "kp-1"}, /* terminfo */
1272 * "kp-2" --- no termcap
1274 {"K5", "kp-3"}, /* terminfo */
1276 * "kp-4" --- no termcap
1278 {"K2", "kp-5"}, /* terminfo */
1280 * "kp-6" --- no termcap
1282 {"K1", "kp-7"}, /* terminfo */
1284 * "kp-8" --- no termcap
1286 {"K3", "kp-9"}, /* terminfo */
1288 * "kp-equal" --- no termcap
1300 {"&0", "S-cancel"}, /*shifted cancel key*/
1301 {"&9", "S-begin"}, /*shifted begin key*/
1302 {"*0", "S-find"}, /*shifted find key*/
1303 {"*1", "S-execute"}, /*shifted execute? actually shifted command key*/
1304 {"*4", "S-delete"}, /*shifted delete-character key*/
1305 {"*7", "S-end"}, /*shifted end key*/
1306 {"*8", "S-clearline"}, /*shifted clear-to end-of-line key*/
1307 {"#1", "S-help"}, /*shifted help key*/
1308 {"#2", "S-home"}, /*shifted home key*/
1309 {"#3", "S-insert"}, /*shifted insert-character key*/
1310 {"#4", "S-left"}, /*shifted left-arrow key*/
1311 {"%d", "S-menu"}, /*shifted menu? actually shifted options key*/
1312 {"%c", "S-next"}, /*shifted next key*/
1313 {"%e", "S-prior"}, /*shifted previous key*/
1314 {"%f", "S-print"}, /*shifted print key*/
1315 {"%g", "S-redo"}, /*shifted redo key*/
1316 {"%i", "S-right"}, /*shifted right-arrow key*/
1317 {"!3", "S-undo"} /*shifted undo key*/
1321 static char **term_get_fkeys_address
;
1322 static KBOARD
*term_get_fkeys_kboard
;
1323 static Lisp_Object
term_get_fkeys_1 (void);
1325 /* Find the escape codes sent by the function keys for Vinput_decode_map.
1326 This function scans the termcap function key sequence entries, and
1327 adds entries to Vinput_decode_map for each function key it finds. */
1330 term_get_fkeys (char **address
, KBOARD
*kboard
)
1332 /* We run the body of the function (term_get_fkeys_1) and ignore all Lisp
1333 errors during the call. The only errors should be from Fdefine_key
1334 when given a key sequence containing an invalid prefix key. If the
1335 termcap defines function keys which use a prefix that is already bound
1336 to a command by the default bindings, we should silently ignore that
1337 function key specification, rather than giving the user an error and
1338 refusing to run at all on such a terminal. */
1340 term_get_fkeys_address
= address
;
1341 term_get_fkeys_kboard
= kboard
;
1342 internal_condition_case (term_get_fkeys_1
, Qerror
, Fidentity
);
1346 term_get_fkeys_1 (void)
1350 char **address
= term_get_fkeys_address
;
1351 KBOARD
*kboard
= term_get_fkeys_kboard
;
1353 /* This can happen if CANNOT_DUMP or with strange options. */
1354 if (!KEYMAPP (kboard
->Vinput_decode_map
))
1355 kboard
->Vinput_decode_map
= Fmake_sparse_keymap (Qnil
);
1357 for (i
= 0; i
< (sizeof (keys
)/sizeof (keys
[0])); i
++)
1359 char *sequence
= tgetstr (keys
[i
].cap
, address
);
1361 Fdefine_key (kboard
->Vinput_decode_map
, build_string (sequence
),
1362 Fmake_vector (make_number (1),
1363 intern (keys
[i
].name
)));
1366 /* The uses of the "k0" capability are inconsistent; sometimes it
1367 describes F10, whereas othertimes it describes F0 and "k;" describes F10.
1368 We will attempt to politely accommodate both systems by testing for
1369 "k;", and if it is present, assuming that "k0" denotes F0, otherwise F10.
1372 char *k_semi
= tgetstr ("k;", address
);
1373 char *k0
= tgetstr ("k0", address
);
1374 char *k0_name
= "f10";
1379 /* Define f0 first, so that f10 takes precedence in case the
1380 key sequences happens to be the same. */
1381 Fdefine_key (kboard
->Vinput_decode_map
, build_string (k0
),
1382 Fmake_vector (make_number (1), intern ("f0")));
1383 Fdefine_key (kboard
->Vinput_decode_map
, build_string (k_semi
),
1384 Fmake_vector (make_number (1), intern ("f10")));
1387 Fdefine_key (kboard
->Vinput_decode_map
, build_string (k0
),
1388 Fmake_vector (make_number (1), intern (k0_name
)));
1391 /* Set up cookies for numbered function keys above f10. */
1393 char fcap
[3], fkey
[4];
1395 fcap
[0] = 'F'; fcap
[2] = '\0';
1396 for (i
= 11; i
< 64; i
++)
1399 fcap
[1] = '1' + i
- 11;
1401 fcap
[1] = 'A' + i
- 20;
1403 fcap
[1] = 'a' + i
- 46;
1406 char *sequence
= tgetstr (fcap
, address
);
1409 sprintf (fkey
, "f%d", i
);
1410 Fdefine_key (kboard
->Vinput_decode_map
, build_string (sequence
),
1411 Fmake_vector (make_number (1),
1419 * Various mappings to try and get a better fit.
1422 #define CONDITIONAL_REASSIGN(cap1, cap2, sym) \
1423 if (!tgetstr (cap1, address)) \
1425 char *sequence = tgetstr (cap2, address); \
1427 Fdefine_key (kboard->Vinput_decode_map, build_string (sequence), \
1428 Fmake_vector (make_number (1), \
1432 /* if there's no key_next keycap, map key_npage to `next' keysym */
1433 CONDITIONAL_REASSIGN ("%5", "kN", "next");
1434 /* if there's no key_prev keycap, map key_ppage to `previous' keysym */
1435 CONDITIONAL_REASSIGN ("%8", "kP", "prior");
1436 /* if there's no key_dc keycap, map key_ic to `insert' keysym */
1437 CONDITIONAL_REASSIGN ("kD", "kI", "insert");
1438 /* if there's no key_end keycap, map key_ll to 'end' keysym */
1439 CONDITIONAL_REASSIGN ("@7", "kH", "end");
1441 /* IBM has their own non-standard dialect of terminfo.
1442 If the standard name isn't found, try the IBM name. */
1443 CONDITIONAL_REASSIGN ("kB", "KO", "backtab");
1444 CONDITIONAL_REASSIGN ("@4", "kJ", "execute"); /* actually "action" */
1445 CONDITIONAL_REASSIGN ("@4", "kc", "execute"); /* actually "command" */
1446 CONDITIONAL_REASSIGN ("%7", "ki", "menu");
1447 CONDITIONAL_REASSIGN ("@7", "kw", "end");
1448 CONDITIONAL_REASSIGN ("F1", "k<", "f11");
1449 CONDITIONAL_REASSIGN ("F2", "k>", "f12");
1450 CONDITIONAL_REASSIGN ("%1", "kq", "help");
1451 CONDITIONAL_REASSIGN ("*6", "kU", "select");
1452 #undef CONDITIONAL_REASSIGN
1457 #endif /* not DOS_NT */
1460 /***********************************************************************
1461 Character Display Information
1462 ***********************************************************************/
1463 static void append_glyph (struct it
*);
1464 static void produce_stretch_glyph (struct it
*);
1465 static void append_composite_glyph (struct it
*);
1466 static void produce_composite_glyph (struct it
*);
1467 static void append_glyphless_glyph (struct it
*, int, char *);
1468 static void produce_glyphless_glyph (struct it
*, int, Lisp_Object
);
1470 /* Append glyphs to IT's glyph_row. Called from produce_glyphs for
1471 terminal frames if IT->glyph_row != NULL. IT->char_to_display is
1472 the character for which to produce glyphs; IT->face_id contains the
1473 character's face. Padding glyphs are appended if IT->c has a
1474 IT->pixel_width > 1. */
1477 append_glyph (struct it
*it
)
1479 struct glyph
*glyph
, *end
;
1482 xassert (it
->glyph_row
);
1483 glyph
= (it
->glyph_row
->glyphs
[it
->area
]
1484 + it
->glyph_row
->used
[it
->area
]);
1485 end
= it
->glyph_row
->glyphs
[1 + it
->area
];
1487 /* If the glyph row is reversed, we need to prepend the glyph rather
1489 if (it
->glyph_row
->reversed_p
&& it
->area
== TEXT_AREA
)
1492 int move_by
= it
->pixel_width
;
1494 /* Make room for the new glyphs. */
1495 if (move_by
> end
- glyph
) /* don't overstep end of this area */
1496 move_by
= end
- glyph
;
1497 for (g
= glyph
- 1; g
>= it
->glyph_row
->glyphs
[it
->area
]; g
--)
1499 glyph
= it
->glyph_row
->glyphs
[it
->area
];
1500 end
= glyph
+ move_by
;
1503 /* BIDI Note: we put the glyphs of a "multi-pixel" character left to
1504 right, even in the REVERSED_P case, since (a) all of its u.ch are
1505 identical, and (b) the PADDING_P flag needs to be set for the
1506 leftmost one, because we write to the terminal left-to-right. */
1508 i
< it
->pixel_width
&& glyph
< end
;
1511 glyph
->type
= CHAR_GLYPH
;
1512 glyph
->pixel_width
= 1;
1513 glyph
->u
.ch
= it
->char_to_display
;
1514 glyph
->face_id
= it
->face_id
;
1515 glyph
->padding_p
= i
> 0;
1516 glyph
->charpos
= CHARPOS (it
->position
);
1517 glyph
->object
= it
->object
;
1520 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
1521 if ((it
->bidi_it
.type
& 7) != it
->bidi_it
.type
)
1523 glyph
->bidi_type
= it
->bidi_it
.type
;
1527 glyph
->resolved_level
= 0;
1528 glyph
->bidi_type
= UNKNOWN_BT
;
1531 ++it
->glyph_row
->used
[it
->area
];
1536 /* Produce glyphs for the display element described by IT. *IT
1537 specifies what we want to produce a glyph for (character, image, ...),
1538 and where in the glyph matrix we currently are (glyph row and hpos).
1539 produce_glyphs fills in output fields of *IT with information such as the
1540 pixel width and height of a character, and maybe output actual glyphs at
1541 the same time if IT->glyph_row is non-null. For an overview, see
1542 the explanation in dispextern.h, before the definition of the
1543 display_element_type enumeration.
1545 produce_glyphs also stores the result of glyph width, ascent
1546 etc. computations in *IT.
1548 IT->glyph_row may be null, in which case produce_glyphs does not
1549 actually fill in the glyphs. This is used in the move_* functions
1550 in xdisp.c for text width and height computations.
1552 Callers usually don't call produce_glyphs directly;
1553 instead they use the macro PRODUCE_GLYPHS. */
1556 produce_glyphs (struct it
*it
)
1558 /* If a hook is installed, let it do the work. */
1560 /* Nothing but characters are supported on terminal frames. */
1561 xassert (it
->what
== IT_CHARACTER
1562 || it
->what
== IT_COMPOSITION
1563 || it
->what
== IT_STRETCH
);
1565 if (it
->what
== IT_STRETCH
)
1567 produce_stretch_glyph (it
);
1571 if (it
->what
== IT_COMPOSITION
)
1573 produce_composite_glyph (it
);
1577 if (it
->what
== IT_GLYPHLESS
)
1579 produce_glyphless_glyph (it
, 0, Qnil
);
1583 if (it
->char_to_display
>= 040 && it
->char_to_display
< 0177)
1585 it
->pixel_width
= it
->nglyphs
= 1;
1589 else if (it
->char_to_display
== '\n')
1590 it
->pixel_width
= it
->nglyphs
= 0;
1591 else if (it
->char_to_display
== '\t')
1593 int absolute_x
= (it
->current_x
1594 + it
->continuation_lines_width
);
1596 = (((1 + absolute_x
+ it
->tab_width
- 1)
1601 /* If part of the TAB has been displayed on the previous line
1602 which is continued now, continuation_lines_width will have
1603 been incremented already by the part that fitted on the
1604 continued line. So, we will get the right number of spaces
1606 nspaces
= next_tab_x
- absolute_x
;
1612 it
->char_to_display
= ' ';
1613 it
->pixel_width
= it
->len
= 1;
1619 it
->pixel_width
= nspaces
;
1620 it
->nglyphs
= nspaces
;
1622 else if (CHAR_BYTE8_P (it
->char_to_display
))
1624 /* Coming here means that we must send the raw 8-bit byte as is
1625 to the terminal. Although there's no way to know how many
1626 columns it occupies on a screen, it is a good assumption that
1627 a single byte code has 1-column width. */
1628 it
->pixel_width
= it
->nglyphs
= 1;
1634 Lisp_Object charset_list
= FRAME_TERMINAL (it
->f
)->charset_list
;
1636 if (char_charset (it
->char_to_display
, charset_list
, NULL
))
1638 it
->pixel_width
= CHAR_WIDTH (it
->char_to_display
);
1639 it
->nglyphs
= it
->pixel_width
;
1645 Lisp_Object acronym
= lookup_glyphless_char_display (-1, it
);
1647 xassert (it
->what
== IT_GLYPHLESS
);
1648 produce_glyphless_glyph (it
, 1, acronym
);
1653 /* Advance current_x by the pixel width as a convenience for
1655 if (it
->area
== TEXT_AREA
)
1656 it
->current_x
+= it
->pixel_width
;
1657 it
->ascent
= it
->max_ascent
= it
->phys_ascent
= it
->max_phys_ascent
= 0;
1658 it
->descent
= it
->max_descent
= it
->phys_descent
= it
->max_phys_descent
= 1;
1662 /* Produce a stretch glyph for iterator IT. IT->object is the value
1663 of the glyph property displayed. The value must be a list
1664 `(space KEYWORD VALUE ...)' with the following KEYWORD/VALUE pairs
1667 1. `:width WIDTH' specifies that the space should be WIDTH *
1668 canonical char width wide. WIDTH may be an integer or floating
1671 2. `:align-to HPOS' specifies that the space should be wide enough
1672 to reach HPOS, a value in canonical character units. */
1675 produce_stretch_glyph (struct it
*it
)
1677 /* (space :width WIDTH ...) */
1678 Lisp_Object prop
, plist
;
1679 int width
= 0, align_to
= -1;
1680 int zero_width_ok_p
= 0;
1683 /* List should start with `space'. */
1684 xassert (CONSP (it
->object
) && EQ (XCAR (it
->object
), Qspace
));
1685 plist
= XCDR (it
->object
);
1687 /* Compute the width of the stretch. */
1688 if ((prop
= Fplist_get (plist
, QCwidth
), !NILP (prop
))
1689 && calc_pixel_width_or_height (&tem
, it
, prop
, 0, 1, 0))
1691 /* Absolute width `:width WIDTH' specified and valid. */
1692 zero_width_ok_p
= 1;
1693 width
= (int)(tem
+ 0.5);
1695 else if ((prop
= Fplist_get (plist
, QCalign_to
), !NILP (prop
))
1696 && calc_pixel_width_or_height (&tem
, it
, prop
, 0, 1, &align_to
))
1698 if (it
->glyph_row
== NULL
|| !it
->glyph_row
->mode_line_p
)
1699 align_to
= (align_to
< 0
1701 : align_to
- window_box_left_offset (it
->w
, TEXT_AREA
));
1702 else if (align_to
< 0)
1703 align_to
= window_box_left_offset (it
->w
, TEXT_AREA
);
1704 width
= max (0, (int)(tem
+ 0.5) + align_to
- it
->current_x
);
1705 zero_width_ok_p
= 1;
1708 /* Nothing specified -> width defaults to canonical char width. */
1709 width
= FRAME_COLUMN_WIDTH (it
->f
);
1711 if (width
<= 0 && (width
< 0 || !zero_width_ok_p
))
1714 if (width
> 0 && it
->line_wrap
!= TRUNCATE
1715 && it
->current_x
+ width
> it
->last_visible_x
)
1716 width
= it
->last_visible_x
- it
->current_x
- 1;
1718 if (width
> 0 && it
->glyph_row
)
1720 Lisp_Object o_object
= it
->object
;
1721 Lisp_Object object
= it
->stack
[it
->sp
- 1].string
;
1724 if (!STRINGP (object
))
1725 object
= it
->w
->buffer
;
1726 it
->object
= object
;
1727 it
->char_to_display
= ' ';
1728 it
->pixel_width
= it
->len
= 1;
1731 it
->object
= o_object
;
1733 it
->pixel_width
= width
;
1734 it
->nglyphs
= width
;
1738 /* Append glyphs to IT's glyph_row for the composition IT->cmp_id.
1739 Called from produce_composite_glyph for terminal frames if
1740 IT->glyph_row != NULL. IT->face_id contains the character's
1744 append_composite_glyph (struct it
*it
)
1746 struct glyph
*glyph
;
1748 xassert (it
->glyph_row
);
1749 glyph
= it
->glyph_row
->glyphs
[it
->area
] + it
->glyph_row
->used
[it
->area
];
1750 if (glyph
< it
->glyph_row
->glyphs
[1 + it
->area
])
1752 /* If the glyph row is reversed, we need to prepend the glyph
1753 rather than append it. */
1754 if (it
->glyph_row
->reversed_p
&& it
->area
== TEXT_AREA
)
1758 /* Make room for the new glyph. */
1759 for (g
= glyph
- 1; g
>= it
->glyph_row
->glyphs
[it
->area
]; g
--)
1761 glyph
= it
->glyph_row
->glyphs
[it
->area
];
1763 glyph
->type
= COMPOSITE_GLYPH
;
1764 glyph
->pixel_width
= it
->pixel_width
;
1765 glyph
->u
.cmp
.id
= it
->cmp_it
.id
;
1766 if (it
->cmp_it
.ch
< 0)
1768 glyph
->u
.cmp
.automatic
= 0;
1769 glyph
->u
.cmp
.id
= it
->cmp_it
.id
;
1773 glyph
->u
.cmp
.automatic
= 1;
1774 glyph
->u
.cmp
.id
= it
->cmp_it
.id
;
1775 glyph
->slice
.cmp
.from
= it
->cmp_it
.from
;
1776 glyph
->slice
.cmp
.to
= it
->cmp_it
.to
- 1;
1779 glyph
->face_id
= it
->face_id
;
1780 glyph
->padding_p
= 0;
1781 glyph
->charpos
= CHARPOS (it
->position
);
1782 glyph
->object
= it
->object
;
1785 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
1786 if ((it
->bidi_it
.type
& 7) != it
->bidi_it
.type
)
1788 glyph
->bidi_type
= it
->bidi_it
.type
;
1792 glyph
->resolved_level
= 0;
1793 glyph
->bidi_type
= UNKNOWN_BT
;
1796 ++it
->glyph_row
->used
[it
->area
];
1802 /* Produce a composite glyph for iterator IT. IT->cmp_id is the ID of
1803 the composition. We simply produces components of the composition
1804 assuming that the terminal has a capability to layout/render it
1808 produce_composite_glyph (struct it
*it
)
1810 if (it
->cmp_it
.ch
< 0)
1812 struct composition
*cmp
= composition_table
[it
->cmp_it
.id
];
1814 it
->pixel_width
= cmp
->width
;
1818 Lisp_Object gstring
= composition_gstring_from_id (it
->cmp_it
.id
);
1820 it
->pixel_width
= composition_gstring_width (gstring
, it
->cmp_it
.from
,
1821 it
->cmp_it
.to
, NULL
);
1825 append_composite_glyph (it
);
1829 /* Append a glyph for a glyphless character to IT->glyph_row. FACE_ID
1830 is a face ID to be used for the glyph. What is actually appended
1831 are glyphs of type CHAR_GLYPH whose characters are in STR (which
1832 comes from it->nglyphs bytes). */
1835 append_glyphless_glyph (struct it
*it
, int face_id
, char *str
)
1837 struct glyph
*glyph
, *end
;
1840 xassert (it
->glyph_row
);
1841 glyph
= it
->glyph_row
->glyphs
[it
->area
] + it
->glyph_row
->used
[it
->area
];
1842 end
= it
->glyph_row
->glyphs
[1 + it
->area
];
1844 /* If the glyph row is reversed, we need to prepend the glyph rather
1846 if (it
->glyph_row
->reversed_p
&& it
->area
== TEXT_AREA
)
1849 int move_by
= it
->pixel_width
;
1851 /* Make room for the new glyphs. */
1852 if (move_by
> end
- glyph
) /* don't overstep end of this area */
1853 move_by
= end
- glyph
;
1854 for (g
= glyph
- 1; g
>= it
->glyph_row
->glyphs
[it
->area
]; g
--)
1856 glyph
= it
->glyph_row
->glyphs
[it
->area
];
1857 end
= glyph
+ move_by
;
1862 glyph
->type
= CHAR_GLYPH
;
1863 glyph
->pixel_width
= 1;
1864 glyph
->face_id
= face_id
;
1865 glyph
->padding_p
= 0;
1866 glyph
->charpos
= CHARPOS (it
->position
);
1867 glyph
->object
= it
->object
;
1870 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
1871 if ((it
->bidi_it
.type
& 7) != it
->bidi_it
.type
)
1873 glyph
->bidi_type
= it
->bidi_it
.type
;
1877 glyph
->resolved_level
= 0;
1878 glyph
->bidi_type
= UNKNOWN_BT
;
1881 /* BIDI Note: we put the glyphs of characters left to right, even in
1882 the REVERSED_P case because we write to the terminal
1884 for (i
= 0; i
< it
->nglyphs
&& glyph
< end
; ++i
)
1887 glyph
[0] = glyph
[-1];
1888 glyph
->u
.ch
= str
[i
];
1889 ++it
->glyph_row
->used
[it
->area
];
1894 /* Produce glyphs for a glyphless character for iterator IT.
1895 IT->glyphless_method specifies which method to use for displaying
1896 the character. See the description of enum
1897 glyphless_display_method in dispextern.h for the details.
1899 FOR_NO_FONT is nonzero if and only if this is for a character that
1900 is not supproted by the coding system of the terminal. ACRONYM, if
1901 non-nil, is an acronym string for the character.
1903 The glyphs actually produced are of type CHAR_GLYPH. */
1906 produce_glyphless_glyph (struct it
*it
, int for_no_font
, Lisp_Object acronym
)
1910 char buf
[9], *str
= " ";
1912 /* Get a face ID for the glyph by utilizing a cache (the same way as
1913 done for `escape-glyph' in get_next_display_element). */
1914 if (it
->f
== last_glyphless_glyph_frame
1915 && it
->face_id
== last_glyphless_glyph_face_id
)
1917 face_id
= last_glyphless_glyph_merged_face_id
;
1921 /* Merge the `glyphless-char' face into the current face. */
1922 face_id
= merge_faces (it
->f
, Qglyphless_char
, 0, it
->face_id
);
1923 last_glyphless_glyph_frame
= it
->f
;
1924 last_glyphless_glyph_face_id
= it
->face_id
;
1925 last_glyphless_glyph_merged_face_id
= face_id
;
1928 if (it
->glyphless_method
== GLYPHLESS_DISPLAY_THIN_SPACE
)
1930 /* As there's no way to produce a thin space, we produce a space
1931 of canonical width. */
1934 else if (it
->glyphless_method
== GLYPHLESS_DISPLAY_EMPTY_BOX
)
1936 len
= CHAR_WIDTH (it
->c
);
1941 sprintf (buf
, "[%.*s]", len
, str
);
1947 if (it
->glyphless_method
== GLYPHLESS_DISPLAY_ACRONYM
)
1949 if (! STRINGP (acronym
) && CHAR_TABLE_P (Vglyphless_char_display
))
1950 acronym
= CHAR_TABLE_REF (Vglyphless_char_display
, it
->c
);
1952 str
= STRINGP (acronym
) ? SSDATA (acronym
) : "";
1953 for (len
= 0; len
< 6 && str
[len
] && ASCII_BYTE_P (str
[len
]); len
++)
1954 buf
[1 + len
] = str
[len
];
1960 xassert (it
->glyphless_method
== GLYPHLESS_DISPLAY_HEX_CODE
);
1961 len
= (it
->c
< 0x10000 ? sprintf (buf
, "\\u%04X", it
->c
)
1962 : it
->c
<= MAX_UNICODE_CHAR
? sprintf (buf
, "\\U%06X", it
->c
)
1963 : sprintf (buf
, "\\x%06X", it
->c
));
1968 it
->pixel_width
= len
;
1970 if (len
> 0 && it
->glyph_row
)
1971 append_glyphless_glyph (it
, face_id
, str
);
1975 /* Get information about special display element WHAT in an
1976 environment described by IT. WHAT is one of IT_TRUNCATION or
1977 IT_CONTINUATION. Maybe produce glyphs for WHAT if IT has a
1978 non-null glyph_row member. This function ensures that fields like
1979 face_id, c, len of IT are left untouched. */
1982 produce_special_glyphs (struct it
*it
, enum display_element_type what
)
1990 temp_it
.what
= IT_CHARACTER
;
1992 temp_it
.object
= make_number (0);
1993 memset (&temp_it
.current
, 0, sizeof temp_it
.current
);
1995 if (what
== IT_CONTINUATION
)
1997 /* Continuation glyph. For R2L lines, we mirror it by hand. */
1998 if (it
->bidi_it
.paragraph_dir
== R2L
)
1999 SET_GLYPH_FROM_CHAR (glyph
, '/');
2001 SET_GLYPH_FROM_CHAR (glyph
, '\\');
2003 && (gc
= DISP_CONTINUE_GLYPH (it
->dp
), GLYPH_CODE_P (gc
))
2004 && GLYPH_CODE_CHAR_VALID_P (gc
))
2006 /* FIXME: Should we mirror GC for R2L lines? */
2007 SET_GLYPH_FROM_GLYPH_CODE (glyph
, gc
);
2008 spec_glyph_lookup_face (XWINDOW (it
->window
), &glyph
);
2011 else if (what
== IT_TRUNCATION
)
2013 /* Truncation glyph. */
2014 SET_GLYPH_FROM_CHAR (glyph
, '$');
2016 && (gc
= DISP_TRUNC_GLYPH (it
->dp
), GLYPH_CODE_P (gc
))
2017 && GLYPH_CODE_CHAR_VALID_P (gc
))
2019 /* FIXME: Should we mirror GC for R2L lines? */
2020 SET_GLYPH_FROM_GLYPH_CODE (glyph
, gc
);
2021 spec_glyph_lookup_face (XWINDOW (it
->window
), &glyph
);
2027 temp_it
.c
= temp_it
.char_to_display
= GLYPH_CHAR (glyph
);
2028 temp_it
.face_id
= GLYPH_FACE (glyph
);
2029 temp_it
.len
= CHAR_BYTES (temp_it
.c
);
2031 produce_glyphs (&temp_it
);
2032 it
->pixel_width
= temp_it
.pixel_width
;
2033 it
->nglyphs
= temp_it
.pixel_width
;
2038 /***********************************************************************
2040 ***********************************************************************/
2042 /* Value is non-zero if attribute ATTR may be used. ATTR should be
2043 one of the enumerators from enum no_color_bit, or a bit set built
2044 from them. Some display attributes may not be used together with
2045 color; the termcap capability `NC' specifies which ones. */
2047 #define MAY_USE_WITH_COLORS_P(tty, ATTR) \
2048 (tty->TN_max_colors > 0 \
2049 ? (tty->TN_no_color_video & (ATTR)) == 0 \
2052 /* Turn appearances of face FACE_ID on tty frame F on.
2053 FACE_ID is a realized face ID number, in the face cache. */
2056 turn_on_face (struct frame
*f
, int face_id
)
2058 struct face
*face
= FACE_FROM_ID (f
, face_id
);
2059 long fg
= face
->foreground
;
2060 long bg
= face
->background
;
2061 struct tty_display_info
*tty
= FRAME_TTY (f
);
2063 /* Do this first because TS_end_standout_mode may be the same
2064 as TS_exit_attribute_mode, which turns all appearances off. */
2065 if (MAY_USE_WITH_COLORS_P (tty
, NC_REVERSE
))
2067 if (tty
->TN_max_colors
> 0)
2069 if (fg
>= 0 && bg
>= 0)
2071 /* If the terminal supports colors, we can set them
2072 below without using reverse video. The face's fg
2073 and bg colors are set as they should appear on
2074 the screen, i.e. they take the inverse-video'ness
2075 of the face already into account. */
2077 else if (inverse_video
)
2079 if (fg
== FACE_TTY_DEFAULT_FG_COLOR
2080 || bg
== FACE_TTY_DEFAULT_BG_COLOR
)
2081 tty_toggle_highlight (tty
);
2085 if (fg
== FACE_TTY_DEFAULT_BG_COLOR
2086 || bg
== FACE_TTY_DEFAULT_FG_COLOR
)
2087 tty_toggle_highlight (tty
);
2092 /* If we can't display colors, use reverse video
2093 if the face specifies that. */
2096 if (fg
== FACE_TTY_DEFAULT_FG_COLOR
2097 || bg
== FACE_TTY_DEFAULT_BG_COLOR
)
2098 tty_toggle_highlight (tty
);
2102 if (fg
== FACE_TTY_DEFAULT_BG_COLOR
2103 || bg
== FACE_TTY_DEFAULT_FG_COLOR
)
2104 tty_toggle_highlight (tty
);
2109 if (face
->tty_bold_p
&& MAY_USE_WITH_COLORS_P (tty
, NC_BOLD
))
2110 OUTPUT1_IF (tty
, tty
->TS_enter_bold_mode
);
2112 if (face
->tty_dim_p
&& MAY_USE_WITH_COLORS_P (tty
, NC_DIM
))
2113 OUTPUT1_IF (tty
, tty
->TS_enter_dim_mode
);
2115 /* Alternate charset and blinking not yet used. */
2116 if (face
->tty_alt_charset_p
2117 && MAY_USE_WITH_COLORS_P (tty
, NC_ALT_CHARSET
))
2118 OUTPUT1_IF (tty
, tty
->TS_enter_alt_charset_mode
);
2120 if (face
->tty_blinking_p
2121 && MAY_USE_WITH_COLORS_P (tty
, NC_BLINK
))
2122 OUTPUT1_IF (tty
, tty
->TS_enter_blink_mode
);
2124 if (face
->tty_underline_p
&& MAY_USE_WITH_COLORS_P (tty
, NC_UNDERLINE
))
2125 OUTPUT1_IF (tty
, tty
->TS_enter_underline_mode
);
2127 if (tty
->TN_max_colors
> 0)
2131 ts
= tty
->standout_mode
? tty
->TS_set_background
: tty
->TS_set_foreground
;
2134 p
= tparam (ts
, NULL
, 0, (int) fg
);
2139 ts
= tty
->standout_mode
? tty
->TS_set_foreground
: tty
->TS_set_background
;
2142 p
= tparam (ts
, NULL
, 0, (int) bg
);
2150 /* Turn off appearances of face FACE_ID on tty frame F. */
2153 turn_off_face (struct frame
*f
, int face_id
)
2155 struct face
*face
= FACE_FROM_ID (f
, face_id
);
2156 struct tty_display_info
*tty
= FRAME_TTY (f
);
2158 xassert (face
!= NULL
);
2160 if (tty
->TS_exit_attribute_mode
)
2162 /* Capability "me" will turn off appearance modes double-bright,
2163 half-bright, reverse-video, standout, underline. It may or
2164 may not turn off alt-char-mode. */
2165 if (face
->tty_bold_p
2167 || face
->tty_reverse_p
2168 || face
->tty_alt_charset_p
2169 || face
->tty_blinking_p
2170 || face
->tty_underline_p
)
2172 OUTPUT1_IF (tty
, tty
->TS_exit_attribute_mode
);
2173 if (strcmp (tty
->TS_exit_attribute_mode
, tty
->TS_end_standout_mode
) == 0)
2174 tty
->standout_mode
= 0;
2177 if (face
->tty_alt_charset_p
)
2178 OUTPUT_IF (tty
, tty
->TS_exit_alt_charset_mode
);
2182 /* If we don't have "me" we can only have those appearances
2183 that have exit sequences defined. */
2184 if (face
->tty_alt_charset_p
)
2185 OUTPUT_IF (tty
, tty
->TS_exit_alt_charset_mode
);
2187 if (face
->tty_underline_p
)
2188 OUTPUT_IF (tty
, tty
->TS_exit_underline_mode
);
2191 /* Switch back to default colors. */
2192 if (tty
->TN_max_colors
> 0
2193 && ((face
->foreground
!= FACE_TTY_DEFAULT_COLOR
2194 && face
->foreground
!= FACE_TTY_DEFAULT_FG_COLOR
)
2195 || (face
->background
!= FACE_TTY_DEFAULT_COLOR
2196 && face
->background
!= FACE_TTY_DEFAULT_BG_COLOR
)))
2197 OUTPUT1_IF (tty
, tty
->TS_orig_pair
);
2201 /* Return non-zero if the terminal on frame F supports all of the
2202 capabilities in CAPS simultaneously, with foreground and background
2203 colors FG and BG. */
2206 tty_capable_p (struct tty_display_info
*tty
, unsigned int caps
,
2207 unsigned long fg
, unsigned long bg
)
2209 #define TTY_CAPABLE_P_TRY(tty, cap, TS, NC_bit) \
2210 if ((caps & (cap)) && (!(TS) || !MAY_USE_WITH_COLORS_P(tty, NC_bit))) \
2213 TTY_CAPABLE_P_TRY (tty
, TTY_CAP_INVERSE
, tty
->TS_standout_mode
, NC_REVERSE
);
2214 TTY_CAPABLE_P_TRY (tty
, TTY_CAP_UNDERLINE
, tty
->TS_enter_underline_mode
, NC_UNDERLINE
);
2215 TTY_CAPABLE_P_TRY (tty
, TTY_CAP_BOLD
, tty
->TS_enter_bold_mode
, NC_BOLD
);
2216 TTY_CAPABLE_P_TRY (tty
, TTY_CAP_DIM
, tty
->TS_enter_dim_mode
, NC_DIM
);
2217 TTY_CAPABLE_P_TRY (tty
, TTY_CAP_BLINK
, tty
->TS_enter_blink_mode
, NC_BLINK
);
2218 TTY_CAPABLE_P_TRY (tty
, TTY_CAP_ALT_CHARSET
, tty
->TS_enter_alt_charset_mode
, NC_ALT_CHARSET
);
2224 /* Return non-zero if the terminal is capable to display colors. */
2226 DEFUN ("tty-display-color-p", Ftty_display_color_p
, Stty_display_color_p
,
2228 doc
: /* Return non-nil if the tty device TERMINAL can display colors.
2230 TERMINAL can be a terminal object, a frame, or nil (meaning the
2231 selected frame's terminal). This function always returns nil if
2232 TERMINAL does not refer to a text-only terminal. */)
2233 (Lisp_Object terminal
)
2235 struct terminal
*t
= get_tty_terminal (terminal
, 0);
2239 return t
->display_info
.tty
->TN_max_colors
> 0 ? Qt
: Qnil
;
2242 /* Return the number of supported colors. */
2243 DEFUN ("tty-display-color-cells", Ftty_display_color_cells
,
2244 Stty_display_color_cells
, 0, 1, 0,
2245 doc
: /* Return the number of colors supported by the tty device TERMINAL.
2247 TERMINAL can be a terminal object, a frame, or nil (meaning the
2248 selected frame's terminal). This function always returns 0 if
2249 TERMINAL does not refer to a text-only terminal. */)
2250 (Lisp_Object terminal
)
2252 struct terminal
*t
= get_tty_terminal (terminal
, 0);
2254 return make_number (0);
2256 return make_number (t
->display_info
.tty
->TN_max_colors
);
2261 /* Declare here rather than in the function, as in the rest of Emacs,
2262 to work around an HPUX compiler bug (?). See
2263 http://lists.gnu.org/archive/html/emacs-devel/2007-08/msg00410.html */
2264 static int default_max_colors
;
2265 static int default_max_pairs
;
2266 static int default_no_color_video
;
2267 static char *default_orig_pair
;
2268 static char *default_set_foreground
;
2269 static char *default_set_background
;
2271 /* Save or restore the default color-related capabilities of this
2274 tty_default_color_capabilities (struct tty_display_info
*tty
, int save
)
2279 xfree (default_orig_pair
);
2280 default_orig_pair
= tty
->TS_orig_pair
? xstrdup (tty
->TS_orig_pair
) : NULL
;
2282 xfree (default_set_foreground
);
2283 default_set_foreground
= tty
->TS_set_foreground
? xstrdup (tty
->TS_set_foreground
)
2286 xfree (default_set_background
);
2287 default_set_background
= tty
->TS_set_background
? xstrdup (tty
->TS_set_background
)
2290 default_max_colors
= tty
->TN_max_colors
;
2291 default_max_pairs
= tty
->TN_max_pairs
;
2292 default_no_color_video
= tty
->TN_no_color_video
;
2296 tty
->TS_orig_pair
= default_orig_pair
;
2297 tty
->TS_set_foreground
= default_set_foreground
;
2298 tty
->TS_set_background
= default_set_background
;
2299 tty
->TN_max_colors
= default_max_colors
;
2300 tty
->TN_max_pairs
= default_max_pairs
;
2301 tty
->TN_no_color_video
= default_no_color_video
;
2305 /* Setup one of the standard tty color schemes according to MODE.
2306 MODE's value is generally the number of colors which we want to
2307 support; zero means set up for the default capabilities, the ones
2308 we saw at init_tty time; -1 means turn off color support. */
2310 tty_setup_colors (struct tty_display_info
*tty
, int mode
)
2312 /* Canonicalize all negative values of MODE. */
2318 case -1: /* no colors at all */
2319 tty
->TN_max_colors
= 0;
2320 tty
->TN_max_pairs
= 0;
2321 tty
->TN_no_color_video
= 0;
2322 tty
->TS_set_foreground
= tty
->TS_set_background
= tty
->TS_orig_pair
= NULL
;
2324 case 0: /* default colors, if any */
2326 tty_default_color_capabilities (tty
, 0);
2328 case 8: /* 8 standard ANSI colors */
2329 tty
->TS_orig_pair
= "\033[0m";
2331 tty
->TS_set_foreground
= "\033[3%p1%dm";
2332 tty
->TS_set_background
= "\033[4%p1%dm";
2334 tty
->TS_set_foreground
= "\033[3%dm";
2335 tty
->TS_set_background
= "\033[4%dm";
2337 tty
->TN_max_colors
= 8;
2338 tty
->TN_max_pairs
= 64;
2339 tty
->TN_no_color_video
= 0;
2345 set_tty_color_mode (struct tty_display_info
*tty
, struct frame
*f
)
2347 Lisp_Object tem
, val
;
2348 Lisp_Object color_mode
;
2350 Lisp_Object tty_color_mode_alist
2351 = Fintern_soft (build_string ("tty-color-mode-alist"), Qnil
);
2353 tem
= assq_no_quit (Qtty_color_mode
, f
->param_alist
);
2354 val
= CONSP (tem
) ? XCDR (tem
) : Qnil
;
2358 else if (SYMBOLP (tty_color_mode_alist
))
2360 tem
= Fassq (val
, Fsymbol_value (tty_color_mode_alist
));
2361 color_mode
= CONSP (tem
) ? XCDR (tem
) : Qnil
;
2366 mode
= INTEGERP (color_mode
) ? XINT (color_mode
) : 0;
2368 if (mode
!= tty
->previous_color_mode
)
2370 Lisp_Object funsym
= intern ("tty-set-up-initial-frame-faces");
2371 tty
->previous_color_mode
= mode
;
2372 tty_setup_colors (tty
, mode
);
2373 /* This recomputes all the faces given the new color definitions. */
2374 safe_call (1, &funsym
);
2378 #endif /* !DOS_NT */
2382 /* Return the tty display object specified by TERMINAL. */
2385 get_tty_terminal (Lisp_Object terminal
, int throw)
2387 struct terminal
*t
= get_terminal (terminal
, throw);
2389 if (t
&& t
->type
!= output_termcap
&& t
->type
!= output_msdos_raw
)
2392 error ("Device %d is not a termcap terminal device", t
->id
);
2400 /* Return an active termcap device that uses the tty device with the
2403 This function ignores suspended devices.
2405 Returns NULL if the named terminal device is not opened. */
2408 get_named_tty (const char *name
)
2415 for (t
= terminal_list
; t
; t
= t
->next_terminal
)
2417 if ((t
->type
== output_termcap
|| t
->type
== output_msdos_raw
)
2418 && !strcmp (t
->display_info
.tty
->name
, name
)
2419 && TERMINAL_ACTIVE_P (t
))
2427 DEFUN ("tty-type", Ftty_type
, Stty_type
, 0, 1, 0,
2428 doc
: /* Return the type of the tty device that TERMINAL uses.
2429 Returns nil if TERMINAL is not on a tty device.
2431 TERMINAL can be a terminal object, a frame, or nil (meaning the
2432 selected frame's terminal). */)
2433 (Lisp_Object terminal
)
2435 struct terminal
*t
= get_terminal (terminal
, 1);
2437 if (t
->type
!= output_termcap
&& t
->type
!= output_msdos_raw
)
2440 if (t
->display_info
.tty
->type
)
2441 return build_string (t
->display_info
.tty
->type
);
2446 DEFUN ("controlling-tty-p", Fcontrolling_tty_p
, Scontrolling_tty_p
, 0, 1, 0,
2447 doc
: /* Return non-nil if TERMINAL is the controlling tty of the Emacs process.
2449 TERMINAL can be a terminal object, a frame, or nil (meaning the
2450 selected frame's terminal). This function always returns nil if
2451 TERMINAL is not on a tty device. */)
2452 (Lisp_Object terminal
)
2454 struct terminal
*t
= get_terminal (terminal
, 1);
2456 if ((t
->type
!= output_termcap
&& t
->type
!= output_msdos_raw
)
2457 || strcmp (t
->display_info
.tty
->name
, DEV_TTY
) != 0)
2463 DEFUN ("tty-no-underline", Ftty_no_underline
, Stty_no_underline
, 0, 1, 0,
2464 doc
: /* Declare that the tty used by TERMINAL does not handle underlining.
2465 This is used to override the terminfo data, for certain terminals that
2466 do not really do underlining, but say that they do. This function has
2467 no effect if used on a non-tty terminal.
2469 TERMINAL can be a terminal object, a frame or nil (meaning the
2470 selected frame's terminal). This function always returns nil if
2471 TERMINAL does not refer to a text-only terminal. */)
2472 (Lisp_Object terminal
)
2474 struct terminal
*t
= get_terminal (terminal
, 1);
2476 if (t
->type
== output_termcap
)
2477 t
->display_info
.tty
->TS_enter_underline_mode
= 0;
2483 DEFUN ("suspend-tty", Fsuspend_tty
, Ssuspend_tty
, 0, 1, 0,
2484 doc
: /* Suspend the terminal device TTY.
2486 The device is restored to its default state, and Emacs ceases all
2487 access to the tty device. Frames that use the device are not deleted,
2488 but input is not read from them and if they change, their display is
2491 TTY may be a terminal object, a frame, or nil for the terminal device
2492 of the currently selected frame.
2494 This function runs `suspend-tty-functions' after suspending the
2495 device. The functions are run with one arg, the id of the suspended
2498 `suspend-tty' does nothing if it is called on a device that is already
2501 A suspended tty may be resumed by calling `resume-tty' on it. */)
2504 struct terminal
*t
= get_tty_terminal (tty
, 1);
2508 error ("Unknown tty device");
2510 f
= t
->display_info
.tty
->input
;
2514 /* First run `suspend-tty-functions' and then clean up the tty
2515 state because `suspend-tty-functions' might need to change
2517 if (!NILP (Vrun_hooks
))
2519 Lisp_Object args
[2];
2520 args
[0] = intern ("suspend-tty-functions");
2521 XSETTERMINAL (args
[1], t
);
2522 Frun_hook_with_args (2, args
);
2525 reset_sys_modes (t
->display_info
.tty
);
2526 delete_keyboard_wait_descriptor (fileno (f
));
2530 if (f
!= t
->display_info
.tty
->output
)
2531 fclose (t
->display_info
.tty
->output
);
2534 t
->display_info
.tty
->input
= 0;
2535 t
->display_info
.tty
->output
= 0;
2537 if (FRAMEP (t
->display_info
.tty
->top_frame
))
2538 FRAME_SET_VISIBLE (XFRAME (t
->display_info
.tty
->top_frame
), 0);
2542 /* Clear display hooks to prevent further output. */
2543 clear_tty_hooks (t
);
2548 DEFUN ("resume-tty", Fresume_tty
, Sresume_tty
, 0, 1, 0,
2549 doc
: /* Resume the previously suspended terminal device TTY.
2550 The terminal is opened and reinitialized. Frames that are on the
2551 suspended terminal are revived.
2553 It is an error to resume a terminal while another terminal is active
2556 This function runs `resume-tty-functions' after resuming the terminal.
2557 The functions are run with one arg, the id of the resumed terminal
2560 `resume-tty' does nothing if it is called on a device that is not
2563 TTY may be a terminal object, a frame, or nil (meaning the selected
2564 frame's terminal). */)
2567 struct terminal
*t
= get_tty_terminal (tty
, 1);
2571 error ("Unknown tty device");
2573 if (!t
->display_info
.tty
->input
)
2575 if (get_named_tty (t
->display_info
.tty
->name
))
2576 error ("Cannot resume display while another display is active on the same device");
2579 t
->display_info
.tty
->output
= stdout
;
2580 t
->display_info
.tty
->input
= stdin
;
2582 fd
= emacs_open (t
->display_info
.tty
->name
, O_RDWR
| O_NOCTTY
, 0);
2585 error ("Can not reopen tty device %s: %s", t
->display_info
.tty
->name
, strerror (errno
));
2587 if (strcmp (t
->display_info
.tty
->name
, DEV_TTY
))
2588 dissociate_if_controlling_tty (fd
);
2590 t
->display_info
.tty
->output
= fdopen (fd
, "w+");
2591 t
->display_info
.tty
->input
= t
->display_info
.tty
->output
;
2594 add_keyboard_wait_descriptor (fd
);
2596 if (FRAMEP (t
->display_info
.tty
->top_frame
))
2598 struct frame
*f
= XFRAME (t
->display_info
.tty
->top_frame
);
2600 int old_height
= FRAME_COLS (f
);
2601 int old_width
= FRAME_LINES (f
);
2603 /* Check if terminal/window size has changed while the frame
2605 get_tty_size (fileno (t
->display_info
.tty
->input
), &width
, &height
);
2606 if (width
!= old_width
|| height
!= old_height
)
2607 change_frame_size (f
, height
, width
, 0, 0, 0);
2608 FRAME_SET_VISIBLE (XFRAME (t
->display_info
.tty
->top_frame
), 1);
2611 init_sys_modes (t
->display_info
.tty
);
2613 /* Run `resume-tty-functions'. */
2614 if (!NILP (Vrun_hooks
))
2616 Lisp_Object args
[2];
2617 args
[0] = intern ("resume-tty-functions");
2618 XSETTERMINAL (args
[1], t
);
2619 Frun_hook_with_args (2, args
);
2629 /***********************************************************************
2631 ***********************************************************************/
2635 term_mouse_moveto (int x
, int y
)
2637 /* TODO: how to set mouse position?
2640 name = (const char *) ttyname (0);
2641 fd = open (name, O_WRONLY);
2642 SOME_FUNCTION (x, y, fd);
2645 last_mouse_y = y; */
2648 /* Implementation of draw_row_with_mouse_face for TTY/GPM. */
2650 tty_draw_row_with_mouse_face (struct window
*w
, struct glyph_row
*row
,
2651 int start_hpos
, int end_hpos
,
2652 enum draw_glyphs_face draw
)
2654 int nglyphs
= end_hpos
- start_hpos
;
2655 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
2656 struct tty_display_info
*tty
= FRAME_TTY (f
);
2657 int face_id
= tty
->mouse_highlight
.mouse_face_face_id
;
2658 int save_x
, save_y
, pos_x
, pos_y
;
2660 if (end_hpos
>= row
->used
[TEXT_AREA
])
2661 nglyphs
= row
->used
[TEXT_AREA
] - start_hpos
;
2663 pos_y
= row
->y
+ WINDOW_TOP_EDGE_Y (w
);
2664 pos_x
= row
->used
[LEFT_MARGIN_AREA
] + start_hpos
+ WINDOW_LEFT_EDGE_X (w
);
2666 /* Save current cursor co-ordinates. */
2667 save_y
= curY (tty
);
2668 save_x
= curX (tty
);
2669 cursor_to (f
, pos_y
, pos_x
);
2671 if (draw
== DRAW_MOUSE_FACE
)
2672 tty_write_glyphs_with_face (f
, row
->glyphs
[TEXT_AREA
] + start_hpos
,
2674 else if (draw
== DRAW_NORMAL_TEXT
)
2675 write_glyphs (f
, row
->glyphs
[TEXT_AREA
] + start_hpos
, nglyphs
);
2677 cursor_to (f
, save_y
, save_x
);
2681 term_mouse_movement (FRAME_PTR frame
, Gpm_Event
*event
)
2683 /* Has the mouse moved off the glyph it was on at the last sighting? */
2684 if (event
->x
!= last_mouse_x
|| event
->y
!= last_mouse_y
)
2686 frame
->mouse_moved
= 1;
2687 note_mouse_highlight (frame
, event
->x
, event
->y
);
2688 /* Remember which glyph we're now on. */
2689 last_mouse_x
= event
->x
;
2690 last_mouse_y
= event
->y
;
2696 /* Return the current position of the mouse.
2698 Set *f to the frame the mouse is in, or zero if the mouse is in no
2699 Emacs frame. If it is set to zero, all the other arguments are
2702 Set *bar_window to Qnil, and *x and *y to the column and
2703 row of the character cell the mouse is over.
2705 Set *time to the time the mouse was at the returned position.
2707 This clears mouse_moved until the next motion
2710 term_mouse_position (FRAME_PTR
*fp
, int insist
, Lisp_Object
*bar_window
,
2711 enum scroll_bar_part
*part
, Lisp_Object
*x
,
2712 Lisp_Object
*y
, unsigned long *time
)
2716 *fp
= SELECTED_FRAME ();
2717 (*fp
)->mouse_moved
= 0;
2722 XSETINT (*x
, last_mouse_x
);
2723 XSETINT (*y
, last_mouse_y
);
2724 gettimeofday(&now
, 0);
2725 *time
= (now
.tv_sec
* 1000) + (now
.tv_usec
/ 1000);
2728 /* Prepare a mouse-event in *RESULT for placement in the input queue.
2730 If the event is a button press, then note that we have grabbed
2734 term_mouse_click (struct input_event
*result
, Gpm_Event
*event
,
2740 result
->kind
= GPM_CLICK_EVENT
;
2741 for (i
= 0, j
= GPM_B_LEFT
; i
< 3; i
++, j
>>= 1 )
2743 if (event
->buttons
& j
) {
2744 result
->code
= i
; /* button number */
2748 gettimeofday(&now
, 0);
2749 result
->timestamp
= (now
.tv_sec
* 1000) + (now
.tv_usec
/ 1000);
2751 if (event
->type
& GPM_UP
)
2752 result
->modifiers
= up_modifier
;
2753 else if (event
->type
& GPM_DOWN
)
2754 result
->modifiers
= down_modifier
;
2756 result
->modifiers
= 0;
2758 if (event
->type
& GPM_SINGLE
)
2759 result
->modifiers
|= click_modifier
;
2761 if (event
->type
& GPM_DOUBLE
)
2762 result
->modifiers
|= double_modifier
;
2764 if (event
->type
& GPM_TRIPLE
)
2765 result
->modifiers
|= triple_modifier
;
2767 if (event
->type
& GPM_DRAG
)
2768 result
->modifiers
|= drag_modifier
;
2770 if (!(event
->type
& (GPM_MOVE
| GPM_DRAG
))) {
2773 if (event
->modifiers
& (1 << 0))
2774 result
->modifiers
|= shift_modifier
;
2777 if (event
->modifiers
& (1 << 2))
2778 result
->modifiers
|= ctrl_modifier
;
2780 /* 1 << KG_ALT || KG_ALTGR */
2781 if (event
->modifiers
& (1 << 3)
2782 || event
->modifiers
& (1 << 1))
2783 result
->modifiers
|= meta_modifier
;
2786 XSETINT (result
->x
, event
->x
);
2787 XSETINT (result
->y
, event
->y
);
2788 XSETFRAME (result
->frame_or_window
, f
);
2794 handle_one_term_event (struct tty_display_info
*tty
, Gpm_Event
*event
, struct input_event
* hold_quit
)
2796 struct frame
*f
= XFRAME (tty
->top_frame
);
2797 struct input_event ie
;
2805 if (event
->type
& (GPM_MOVE
| GPM_DRAG
)) {
2806 previous_help_echo_string
= help_echo_string
;
2807 help_echo_string
= Qnil
;
2809 Gpm_DrawPointer (event
->x
, event
->y
, fileno (tty
->output
));
2811 if (!term_mouse_movement (f
, event
))
2812 help_echo_string
= previous_help_echo_string
;
2814 /* If the contents of the global variable help_echo_string
2815 has changed, generate a HELP_EVENT. */
2816 if (!NILP (help_echo_string
)
2817 || !NILP (previous_help_echo_string
))
2824 term_mouse_click (&ie
, event
, f
);
2828 if (ie
.kind
!= NO_EVENT
)
2830 kbd_buffer_store_event_hold (&ie
, hold_quit
);
2835 && !(hold_quit
&& hold_quit
->kind
!= NO_EVENT
))
2840 XSETFRAME (frame
, f
);
2844 gen_help_event (help_echo_string
, frame
, help_echo_window
,
2845 help_echo_object
, help_echo_pos
);
2852 DEFUN ("gpm-mouse-start", Fgpm_mouse_start
, Sgpm_mouse_start
,
2854 doc
: /* Open a connection to Gpm.
2855 Gpm-mouse can only be activated for one tty at a time. */)
2858 struct frame
*f
= SELECTED_FRAME ();
2859 struct tty_display_info
*tty
2860 = ((f
)->output_method
== output_termcap
2861 ? (f
)->terminal
->display_info
.tty
: NULL
);
2862 Gpm_Connect connection
;
2865 error ("Gpm-mouse only works in the GNU/Linux console");
2867 return Qnil
; /* Already activated, nothing to do. */
2869 error ("Gpm-mouse can only be activated for one tty at a time");
2871 connection
.eventMask
= ~0;
2872 connection
.defaultMask
= ~GPM_HARD
;
2873 connection
.maxMod
= ~0;
2874 connection
.minMod
= 0;
2877 if (Gpm_Open (&connection
, 0) < 0)
2878 error ("Gpm-mouse failed to connect to the gpm daemon");
2882 /* `init_sys_modes' arranges for mouse movements sent through gpm_fd
2883 to generate SIGIOs. Apparently we need to call reset_sys_modes
2884 before calling init_sys_modes. */
2885 reset_sys_modes (tty
);
2886 init_sys_modes (tty
);
2887 add_gpm_wait_descriptor (gpm_fd
);
2896 delete_gpm_wait_descriptor (fd
);
2897 while (Gpm_Close()); /* close all the stack */
2901 DEFUN ("gpm-mouse-stop", Fgpm_mouse_stop
, Sgpm_mouse_stop
,
2903 doc
: /* Close a connection to Gpm. */)
2906 struct frame
*f
= SELECTED_FRAME ();
2907 struct tty_display_info
*tty
2908 = ((f
)->output_method
== output_termcap
2909 ? (f
)->terminal
->display_info
.tty
: NULL
);
2911 if (!tty
|| gpm_tty
!= tty
)
2912 return Qnil
; /* Not activated on this terminal, nothing to do. */
2917 #endif /* HAVE_GPM */
2921 /***********************************************************************
2923 ***********************************************************************/
2925 /* Initialize the tty-dependent part of frame F. The frame must
2926 already have its device initialized. */
2929 create_tty_output (struct frame
*f
)
2931 struct tty_output
*t
;
2933 if (! FRAME_TERMCAP_P (f
))
2936 t
= xmalloc (sizeof (struct tty_output
));
2937 memset (t
, 0, sizeof (struct tty_output
));
2939 t
->display_info
= FRAME_TERMINAL (f
)->display_info
.tty
;
2941 f
->output_data
.tty
= t
;
2944 /* Delete frame F's face cache, and its tty-dependent part. */
2947 tty_free_frame_resources (struct frame
*f
)
2949 if (! FRAME_TERMCAP_P (f
))
2952 if (FRAME_FACE_CACHE (f
))
2953 free_frame_faces (f
);
2955 xfree (f
->output_data
.tty
);
2960 /* Delete frame F's face cache. */
2963 tty_free_frame_resources (struct frame
*f
)
2965 if (! FRAME_TERMCAP_P (f
) && ! FRAME_MSDOS_P (f
))
2968 if (FRAME_FACE_CACHE (f
))
2969 free_frame_faces (f
);
2973 /* Reset the hooks in TERMINAL. */
2976 clear_tty_hooks (struct terminal
*terminal
)
2979 terminal
->cursor_to_hook
= 0;
2980 terminal
->raw_cursor_to_hook
= 0;
2981 terminal
->clear_to_end_hook
= 0;
2982 terminal
->clear_frame_hook
= 0;
2983 terminal
->clear_end_of_line_hook
= 0;
2984 terminal
->ins_del_lines_hook
= 0;
2985 terminal
->insert_glyphs_hook
= 0;
2986 terminal
->write_glyphs_hook
= 0;
2987 terminal
->delete_glyphs_hook
= 0;
2988 terminal
->ring_bell_hook
= 0;
2989 terminal
->reset_terminal_modes_hook
= 0;
2990 terminal
->set_terminal_modes_hook
= 0;
2991 terminal
->update_begin_hook
= 0;
2992 terminal
->update_end_hook
= 0;
2993 terminal
->set_terminal_window_hook
= 0;
2994 terminal
->mouse_position_hook
= 0;
2995 terminal
->frame_rehighlight_hook
= 0;
2996 terminal
->frame_raise_lower_hook
= 0;
2997 terminal
->fullscreen_hook
= 0;
2998 terminal
->set_vertical_scroll_bar_hook
= 0;
2999 terminal
->condemn_scroll_bars_hook
= 0;
3000 terminal
->redeem_scroll_bar_hook
= 0;
3001 terminal
->judge_scroll_bars_hook
= 0;
3002 terminal
->read_socket_hook
= 0;
3003 terminal
->frame_up_to_date_hook
= 0;
3005 /* Leave these two set, or suspended frames are not deleted
3007 terminal
->delete_frame_hook
= &tty_free_frame_resources
;
3008 terminal
->delete_terminal_hook
= &delete_tty
;
3011 /* Initialize hooks in TERMINAL with the values needed for a tty. */
3014 set_tty_hooks (struct terminal
*terminal
)
3016 terminal
->rif
= 0; /* ttys don't support window-based redisplay. */
3018 terminal
->cursor_to_hook
= &tty_cursor_to
;
3019 terminal
->raw_cursor_to_hook
= &tty_raw_cursor_to
;
3021 terminal
->clear_to_end_hook
= &tty_clear_to_end
;
3022 terminal
->clear_frame_hook
= &tty_clear_frame
;
3023 terminal
->clear_end_of_line_hook
= &tty_clear_end_of_line
;
3025 terminal
->ins_del_lines_hook
= &tty_ins_del_lines
;
3027 terminal
->insert_glyphs_hook
= &tty_insert_glyphs
;
3028 terminal
->write_glyphs_hook
= &tty_write_glyphs
;
3029 terminal
->delete_glyphs_hook
= &tty_delete_glyphs
;
3031 terminal
->ring_bell_hook
= &tty_ring_bell
;
3033 terminal
->reset_terminal_modes_hook
= &tty_reset_terminal_modes
;
3034 terminal
->set_terminal_modes_hook
= &tty_set_terminal_modes
;
3035 terminal
->update_begin_hook
= 0; /* Not needed. */
3036 terminal
->update_end_hook
= &tty_update_end
;
3037 terminal
->set_terminal_window_hook
= &tty_set_terminal_window
;
3039 terminal
->mouse_position_hook
= 0; /* Not needed. */
3040 terminal
->frame_rehighlight_hook
= 0; /* Not needed. */
3041 terminal
->frame_raise_lower_hook
= 0; /* Not needed. */
3043 terminal
->set_vertical_scroll_bar_hook
= 0; /* Not needed. */
3044 terminal
->condemn_scroll_bars_hook
= 0; /* Not needed. */
3045 terminal
->redeem_scroll_bar_hook
= 0; /* Not needed. */
3046 terminal
->judge_scroll_bars_hook
= 0; /* Not needed. */
3048 terminal
->read_socket_hook
= &tty_read_avail_input
; /* keyboard.c */
3049 terminal
->frame_up_to_date_hook
= 0; /* Not needed. */
3051 terminal
->delete_frame_hook
= &tty_free_frame_resources
;
3052 terminal
->delete_terminal_hook
= &delete_tty
;
3055 /* Drop the controlling terminal if fd is the same device. */
3057 dissociate_if_controlling_tty (int fd
)
3060 int pgid
= tcgetpgrp (fd
); /* If tcgetpgrp succeeds, fd is the ctty. */
3065 no_controlling_tty
= 1;
3066 #elif defined (CYGWIN)
3068 no_controlling_tty
= 1;
3070 #ifdef TIOCNOTTY /* Try BSD ioctls. */
3071 sigblock (sigmask (SIGTTOU
));
3072 fd
= emacs_open (DEV_TTY
, O_RDWR
, 0);
3073 if (fd
!= -1 && ioctl (fd
, TIOCNOTTY
, 0) != -1)
3075 no_controlling_tty
= 1;
3079 sigunblock (sigmask (SIGTTOU
));
3081 /* Unknown system. */
3083 #endif /* ! TIOCNOTTY */
3086 #endif /* !DOS_NT */
3089 /* Create a termcap display on the tty device with the given name and
3092 If NAME is NULL, then use the controlling tty, i.e., "/dev/tty".
3093 Otherwise NAME should be a path to the tty device file,
3096 TERMINAL_TYPE is the termcap type of the device, e.g. "vt100".
3098 If MUST_SUCCEED is true, then all errors are fatal. */
3101 init_tty (const char *name
, const char *terminal_type
, int must_succeed
)
3104 char **address
= &area
;
3105 int buffer_size
= 4096;
3106 register char *p
= NULL
;
3108 struct tty_display_info
*tty
= NULL
;
3109 struct terminal
*terminal
= NULL
;
3110 int ctty
= 0; /* 1 if asked to open controlling tty. */
3113 maybe_fatal (must_succeed
, 0,
3114 "Unknown terminal type",
3115 "Unknown terminal type");
3119 if (!strcmp (name
, DEV_TTY
))
3122 /* If we already have a terminal on the given device, use that. If
3123 all such terminals are suspended, create a new one instead. */
3124 /* XXX Perhaps this should be made explicit by having init_tty
3125 always create a new terminal and separating terminal and frame
3126 creation on Lisp level. */
3127 terminal
= get_named_tty (name
);
3131 terminal
= create_terminal ();
3134 maybe_fatal (1, 0, "Attempt to create another terminal %s", "",
3137 tty
= &the_only_display_info
;
3139 tty
= (struct tty_display_info
*) xmalloc (sizeof (struct tty_display_info
));
3141 memset (tty
, 0, sizeof (struct tty_display_info
));
3142 tty
->next
= tty_list
;
3145 terminal
->type
= output_termcap
;
3146 terminal
->display_info
.tty
= tty
;
3147 tty
->terminal
= terminal
;
3149 tty
->Wcm
= (struct cm
*) xmalloc (sizeof (struct cm
));
3152 encode_terminal_src_size
= 0;
3153 encode_terminal_dst_size
= 0;
3156 terminal
->mouse_position_hook
= term_mouse_position
;
3157 tty
->mouse_highlight
.mouse_face_window
= Qnil
;
3162 set_tty_hooks (terminal
);
3168 #ifdef O_IGNORE_CTTY
3170 /* Open the terminal device. Don't recognize it as our
3171 controlling terminal, and don't make it the controlling tty
3172 if we don't have one at the moment. */
3173 fd
= emacs_open (name
, O_RDWR
| O_IGNORE_CTTY
| O_NOCTTY
, 0);
3176 /* Alas, O_IGNORE_CTTY is a GNU extension that seems to be only
3177 defined on Hurd. On other systems, we need to explicitly
3178 dissociate ourselves from the controlling tty when we want to
3179 open a frame on the same terminal. */
3180 fd
= emacs_open (name
, O_RDWR
| O_NOCTTY
, 0);
3181 #endif /* O_IGNORE_CTTY */
3183 tty
->name
= xstrdup (name
);
3184 terminal
->name
= xstrdup (name
);
3187 maybe_fatal (must_succeed
, terminal
,
3188 "Could not open file: %s",
3189 "Could not open file: %s",
3194 maybe_fatal (must_succeed
, terminal
,
3195 "Not a tty device: %s",
3196 "Not a tty device: %s",
3200 #ifndef O_IGNORE_CTTY
3202 dissociate_if_controlling_tty (fd
);
3205 file
= fdopen (fd
, "w+");
3210 tty
->type
= xstrdup (terminal_type
);
3212 add_keyboard_wait_descriptor (fileno (tty
->input
));
3216 tty
->termcap_term_buffer
= (char *) xmalloc (buffer_size
);
3218 /* On some systems, tgetent tries to access the controlling
3220 sigblock (sigmask (SIGTTOU
));
3221 status
= tgetent (tty
->termcap_term_buffer
, terminal_type
);
3222 sigunblock (sigmask (SIGTTOU
));
3227 maybe_fatal (must_succeed
, terminal
,
3228 "Cannot open terminfo database file",
3229 "Cannot open terminfo database file");
3231 maybe_fatal (must_succeed
, terminal
,
3232 "Cannot open termcap database file",
3233 "Cannot open termcap database file");
3238 maybe_fatal (must_succeed
, terminal
,
3239 "Terminal type %s is not defined",
3240 "Terminal type %s is not defined.\n\
3241 If that is not the actual type of terminal you have,\n\
3242 use the Bourne shell command `TERM=... export TERM' (C-shell:\n\
3243 `setenv TERM ...') to specify the correct type. It may be necessary\n"
3245 "to do `unset TERMINFO' (C-shell: `unsetenv TERMINFO') as well.",
3247 "to do `unset TERMCAP' (C-shell: `unsetenv TERMCAP') as well.",
3253 if (strlen (tty
->termcap_term_buffer
) >= buffer_size
)
3255 buffer_size
= strlen (tty
->termcap_term_buffer
);
3257 tty
->termcap_strings_buffer
= area
= (char *) xmalloc (buffer_size
);
3258 tty
->TS_ins_line
= tgetstr ("al", address
);
3259 tty
->TS_ins_multi_lines
= tgetstr ("AL", address
);
3260 tty
->TS_bell
= tgetstr ("bl", address
);
3261 BackTab (tty
) = tgetstr ("bt", address
);
3262 tty
->TS_clr_to_bottom
= tgetstr ("cd", address
);
3263 tty
->TS_clr_line
= tgetstr ("ce", address
);
3264 tty
->TS_clr_frame
= tgetstr ("cl", address
);
3265 ColPosition (tty
) = NULL
; /* tgetstr ("ch", address); */
3266 AbsPosition (tty
) = tgetstr ("cm", address
);
3267 CR (tty
) = tgetstr ("cr", address
);
3268 tty
->TS_set_scroll_region
= tgetstr ("cs", address
);
3269 tty
->TS_set_scroll_region_1
= tgetstr ("cS", address
);
3270 RowPosition (tty
) = tgetstr ("cv", address
);
3271 tty
->TS_del_char
= tgetstr ("dc", address
);
3272 tty
->TS_del_multi_chars
= tgetstr ("DC", address
);
3273 tty
->TS_del_line
= tgetstr ("dl", address
);
3274 tty
->TS_del_multi_lines
= tgetstr ("DL", address
);
3275 tty
->TS_delete_mode
= tgetstr ("dm", address
);
3276 tty
->TS_end_delete_mode
= tgetstr ("ed", address
);
3277 tty
->TS_end_insert_mode
= tgetstr ("ei", address
);
3278 Home (tty
) = tgetstr ("ho", address
);
3279 tty
->TS_ins_char
= tgetstr ("ic", address
);
3280 tty
->TS_ins_multi_chars
= tgetstr ("IC", address
);
3281 tty
->TS_insert_mode
= tgetstr ("im", address
);
3282 tty
->TS_pad_inserted_char
= tgetstr ("ip", address
);
3283 tty
->TS_end_keypad_mode
= tgetstr ("ke", address
);
3284 tty
->TS_keypad_mode
= tgetstr ("ks", address
);
3285 LastLine (tty
) = tgetstr ("ll", address
);
3286 Right (tty
) = tgetstr ("nd", address
);
3287 Down (tty
) = tgetstr ("do", address
);
3289 Down (tty
) = tgetstr ("nl", address
); /* Obsolete name for "do" */
3290 if (tgetflag ("bs"))
3291 Left (tty
) = "\b"; /* can't possibly be longer! */
3292 else /* (Actually, "bs" is obsolete...) */
3293 Left (tty
) = tgetstr ("le", address
);
3295 Left (tty
) = tgetstr ("bc", address
); /* Obsolete name for "le" */
3296 tty
->TS_pad_char
= tgetstr ("pc", address
);
3297 tty
->TS_repeat
= tgetstr ("rp", address
);
3298 tty
->TS_end_standout_mode
= tgetstr ("se", address
);
3299 tty
->TS_fwd_scroll
= tgetstr ("sf", address
);
3300 tty
->TS_standout_mode
= tgetstr ("so", address
);
3301 tty
->TS_rev_scroll
= tgetstr ("sr", address
);
3302 tty
->Wcm
->cm_tab
= tgetstr ("ta", address
);
3303 tty
->TS_end_termcap_modes
= tgetstr ("te", address
);
3304 tty
->TS_termcap_modes
= tgetstr ("ti", address
);
3305 Up (tty
) = tgetstr ("up", address
);
3306 tty
->TS_visible_bell
= tgetstr ("vb", address
);
3307 tty
->TS_cursor_normal
= tgetstr ("ve", address
);
3308 tty
->TS_cursor_visible
= tgetstr ("vs", address
);
3309 tty
->TS_cursor_invisible
= tgetstr ("vi", address
);
3310 tty
->TS_set_window
= tgetstr ("wi", address
);
3312 tty
->TS_enter_underline_mode
= tgetstr ("us", address
);
3313 tty
->TS_exit_underline_mode
= tgetstr ("ue", address
);
3314 tty
->TS_enter_bold_mode
= tgetstr ("md", address
);
3315 tty
->TS_enter_dim_mode
= tgetstr ("mh", address
);
3316 tty
->TS_enter_blink_mode
= tgetstr ("mb", address
);
3317 tty
->TS_enter_reverse_mode
= tgetstr ("mr", address
);
3318 tty
->TS_enter_alt_charset_mode
= tgetstr ("as", address
);
3319 tty
->TS_exit_alt_charset_mode
= tgetstr ("ae", address
);
3320 tty
->TS_exit_attribute_mode
= tgetstr ("me", address
);
3322 MultiUp (tty
) = tgetstr ("UP", address
);
3323 MultiDown (tty
) = tgetstr ("DO", address
);
3324 MultiLeft (tty
) = tgetstr ("LE", address
);
3325 MultiRight (tty
) = tgetstr ("RI", address
);
3327 /* SVr4/ANSI color suppert. If "op" isn't available, don't support
3328 color because we can't switch back to the default foreground and
3330 tty
->TS_orig_pair
= tgetstr ("op", address
);
3331 if (tty
->TS_orig_pair
)
3333 tty
->TS_set_foreground
= tgetstr ("AF", address
);
3334 tty
->TS_set_background
= tgetstr ("AB", address
);
3335 if (!tty
->TS_set_foreground
)
3338 tty
->TS_set_foreground
= tgetstr ("Sf", address
);
3339 tty
->TS_set_background
= tgetstr ("Sb", address
);
3342 tty
->TN_max_colors
= tgetnum ("Co");
3343 tty
->TN_max_pairs
= tgetnum ("pa");
3345 tty
->TN_no_color_video
= tgetnum ("NC");
3346 if (tty
->TN_no_color_video
== -1)
3347 tty
->TN_no_color_video
= 0;
3350 tty_default_color_capabilities (tty
, 1);
3352 MagicWrap (tty
) = tgetflag ("xn");
3353 /* Since we make MagicWrap terminals look like AutoWrap, we need to have
3354 the former flag imply the latter. */
3355 AutoWrap (tty
) = MagicWrap (tty
) || tgetflag ("am");
3356 terminal
->memory_below_frame
= tgetflag ("db");
3357 tty
->TF_hazeltine
= tgetflag ("hz");
3358 terminal
->must_write_spaces
= tgetflag ("in");
3359 tty
->meta_key
= tgetflag ("km") || tgetflag ("MT");
3360 tty
->TF_insmode_motion
= tgetflag ("mi");
3361 tty
->TF_standout_motion
= tgetflag ("ms");
3362 tty
->TF_underscore
= tgetflag ("ul");
3363 tty
->TF_teleray
= tgetflag ("xt");
3368 struct frame
*f
= XFRAME (selected_frame
);
3370 initialize_w32_display (terminal
);
3372 FrameRows (tty
) = FRAME_LINES (f
);
3373 FrameCols (tty
) = FRAME_COLS (f
);
3374 tty
->specified_window
= FRAME_LINES (f
);
3376 FRAME_CAN_HAVE_SCROLL_BARS (f
) = 0;
3377 FRAME_VERTICAL_SCROLL_BAR_TYPE (f
) = vertical_scroll_bar_none
;
3378 terminal
->char_ins_del_ok
= 1;
3384 if (strcmp (terminal_type
, "internal") == 0)
3385 terminal
->type
= output_msdos_raw
;
3386 initialize_msdos_display (terminal
);
3388 get_tty_size (fileno (tty
->input
), &width
, &height
);
3389 FrameCols (tty
) = width
;
3390 FrameRows (tty
) = height
;
3391 terminal
->char_ins_del_ok
= 0;
3392 init_baud_rate (fileno (tty
->input
));
3395 tty
->output
= stdout
;
3397 /* The following two are inaccessible from w32console.c. */
3398 terminal
->delete_frame_hook
= &tty_free_frame_resources
;
3399 terminal
->delete_terminal_hook
= &delete_tty
;
3401 tty
->name
= xstrdup (name
);
3402 terminal
->name
= xstrdup (name
);
3403 tty
->type
= xstrdup (terminal_type
);
3405 add_keyboard_wait_descriptor (0);
3407 tty
->delete_in_insert_mode
= 1;
3410 terminal
->scroll_region_ok
= 0;
3412 /* Seems to insert lines when it's not supposed to, messing up the
3413 display. In doing a trace, it didn't seem to be called much, so I
3414 don't think we're losing anything by turning it off. */
3415 terminal
->line_ins_del_ok
= 0;
3417 tty
->TN_max_colors
= 16; /* Required to be non-zero for tty-display-color-p */
3420 terminal
->kboard
= (KBOARD
*) xmalloc (sizeof (KBOARD
));
3421 init_kboard (terminal
->kboard
);
3422 terminal
->kboard
->Vwindow_system
= Qnil
;
3423 terminal
->kboard
->next_kboard
= all_kboards
;
3424 all_kboards
= terminal
->kboard
;
3425 terminal
->kboard
->reference_count
++;
3426 /* Don't let the initial kboard remain current longer than necessary.
3427 That would cause problems if a file loaded on startup tries to
3428 prompt in the mini-buffer. */
3429 if (current_kboard
== initial_kboard
)
3430 current_kboard
= terminal
->kboard
;
3432 term_get_fkeys (address
, terminal
->kboard
);
3434 /* Get frame size from system, or else from termcap. */
3437 get_tty_size (fileno (tty
->input
), &width
, &height
);
3438 FrameCols (tty
) = width
;
3439 FrameRows (tty
) = height
;
3442 if (FrameCols (tty
) <= 0)
3443 FrameCols (tty
) = tgetnum ("co");
3444 if (FrameRows (tty
) <= 0)
3445 FrameRows (tty
) = tgetnum ("li");
3447 if (FrameRows (tty
) < 3 || FrameCols (tty
) < 3)
3448 maybe_fatal (must_succeed
, terminal
,
3449 "Screen size %dx%d is too small",
3450 "Screen size %dx%d is too small",
3451 FrameCols (tty
), FrameRows (tty
));
3453 TabWidth (tty
) = tgetnum ("tw");
3456 tty
->TS_bell
= "\07";
3458 if (!tty
->TS_fwd_scroll
)
3459 tty
->TS_fwd_scroll
= Down (tty
);
3461 PC
= tty
->TS_pad_char
? *tty
->TS_pad_char
: 0;
3463 if (TabWidth (tty
) < 0)
3466 /* Turned off since /etc/termcap seems to have :ta= for most terminals
3467 and newer termcap doc does not seem to say there is a default.
3468 if (!tty->Wcm->cm_tab)
3469 tty->Wcm->cm_tab = "\t";
3472 /* We don't support standout modes that use `magic cookies', so
3473 turn off any that do. */
3474 if (tty
->TS_standout_mode
&& tgetnum ("sg") >= 0)
3476 tty
->TS_standout_mode
= 0;
3477 tty
->TS_end_standout_mode
= 0;
3479 if (tty
->TS_enter_underline_mode
&& tgetnum ("ug") >= 0)
3481 tty
->TS_enter_underline_mode
= 0;
3482 tty
->TS_exit_underline_mode
= 0;
3485 /* If there's no standout mode, try to use underlining instead. */
3486 if (tty
->TS_standout_mode
== 0)
3488 tty
->TS_standout_mode
= tty
->TS_enter_underline_mode
;
3489 tty
->TS_end_standout_mode
= tty
->TS_exit_underline_mode
;
3492 /* If no `se' string, try using a `me' string instead.
3493 If that fails, we can't use standout mode at all. */
3494 if (tty
->TS_end_standout_mode
== 0)
3496 char *s
= tgetstr ("me", address
);
3498 tty
->TS_end_standout_mode
= s
;
3500 tty
->TS_standout_mode
= 0;
3503 if (tty
->TF_teleray
)
3505 tty
->Wcm
->cm_tab
= 0;
3506 /* We can't support standout mode, because it uses magic cookies. */
3507 tty
->TS_standout_mode
= 0;
3508 /* But that means we cannot rely on ^M to go to column zero! */
3510 /* LF can't be trusted either -- can alter hpos */
3511 /* if move at column 0 thru a line with TS_standout_mode */
3515 /* Special handling for certain terminal types known to need it */
3517 if (!strcmp (terminal_type
, "supdup"))
3519 terminal
->memory_below_frame
= 1;
3520 tty
->Wcm
->cm_losewrap
= 1;
3522 if (!strncmp (terminal_type
, "c10", 3)
3523 || !strcmp (terminal_type
, "perq"))
3525 /* Supply a makeshift :wi string.
3526 This string is not valid in general since it works only
3527 for windows starting at the upper left corner;
3528 but that is all Emacs uses.
3530 This string works only if the frame is using
3531 the top of the video memory, because addressing is memory-relative.
3532 So first check the :ti string to see if that is true.
3534 It would be simpler if the :wi string could go in the termcap
3535 entry, but it can't because it is not fully valid.
3536 If it were in the termcap entry, it would confuse other programs. */
3537 if (!tty
->TS_set_window
)
3539 p
= tty
->TS_termcap_modes
;
3540 while (*p
&& strcmp (p
, "\033v "))
3543 tty
->TS_set_window
= "\033v%C %C %C %C ";
3545 /* Termcap entry often fails to have :in: flag */
3546 terminal
->must_write_spaces
= 1;
3547 /* :ti string typically fails to have \E^G! in it */
3548 /* This limits scope of insert-char to one line. */
3549 strcpy (area
, tty
->TS_termcap_modes
);
3550 strcat (area
, "\033\007!");
3551 tty
->TS_termcap_modes
= area
;
3552 area
+= strlen (area
) + 1;
3553 p
= AbsPosition (tty
);
3554 /* Change all %+ parameters to %C, to handle
3555 values above 96 correctly for the C100. */
3558 if (p
[0] == '%' && p
[1] == '+')
3564 tty
->specified_window
= FrameRows (tty
);
3566 if (Wcm_init (tty
) == -1) /* can't do cursor motion */
3568 maybe_fatal (must_succeed
, terminal
,
3569 "Terminal type \"%s\" is not powerful enough to run Emacs",
3570 "Terminal type \"%s\" is not powerful enough to run Emacs.\n\
3571 It lacks the ability to position the cursor.\n\
3572 If that is not the actual type of terminal you have,\n\
3573 use the Bourne shell command `TERM=... export TERM' (C-shell:\n\
3574 `setenv TERM ...') to specify the correct type. It may be necessary\n"
3576 "to do `unset TERMINFO' (C-shell: `unsetenv TERMINFO') as well.",
3577 # else /* TERMCAP */
3578 "to do `unset TERMCAP' (C-shell: `unsetenv TERMCAP') as well.",
3579 # endif /* TERMINFO */
3583 if (FrameRows (tty
) <= 0 || FrameCols (tty
) <= 0)
3584 maybe_fatal (must_succeed
, terminal
,
3585 "Could not determine the frame size",
3586 "Could not determine the frame size");
3588 tty
->delete_in_insert_mode
3589 = tty
->TS_delete_mode
&& tty
->TS_insert_mode
3590 && !strcmp (tty
->TS_delete_mode
, tty
->TS_insert_mode
);
3592 tty
->se_is_so
= (tty
->TS_standout_mode
3593 && tty
->TS_end_standout_mode
3594 && !strcmp (tty
->TS_standout_mode
, tty
->TS_end_standout_mode
));
3596 UseTabs (tty
) = tabs_safe_p (fileno (tty
->input
)) && TabWidth (tty
) == 8;
3598 terminal
->scroll_region_ok
3600 && (tty
->TS_set_window
|| tty
->TS_set_scroll_region
|| tty
->TS_set_scroll_region_1
));
3602 terminal
->line_ins_del_ok
3603 = (((tty
->TS_ins_line
|| tty
->TS_ins_multi_lines
)
3604 && (tty
->TS_del_line
|| tty
->TS_del_multi_lines
))
3605 || (terminal
->scroll_region_ok
3606 && tty
->TS_fwd_scroll
&& tty
->TS_rev_scroll
));
3608 terminal
->char_ins_del_ok
3609 = ((tty
->TS_ins_char
|| tty
->TS_insert_mode
3610 || tty
->TS_pad_inserted_char
|| tty
->TS_ins_multi_chars
)
3611 && (tty
->TS_del_char
|| tty
->TS_del_multi_chars
));
3613 terminal
->fast_clear_end_of_line
= tty
->TS_clr_line
!= 0;
3615 init_baud_rate (fileno (tty
->input
));
3617 #endif /* not DOS_NT */
3619 /* Init system terminal modes (RAW or CBREAK, etc.). */
3620 init_sys_modes (tty
);
3627 vfatal (const char *str
, va_list ap
)
3629 fprintf (stderr
, "emacs: ");
3630 vfprintf (stderr
, str
, ap
);
3631 if (!(strlen (str
) > 0 && str
[strlen (str
) - 1] == '\n'))
3632 fprintf (stderr
, "\n");
3639 /* Auxiliary error-handling function for init_tty.
3640 Delete TERMINAL, then call error or fatal with str1 or str2,
3641 respectively, according to MUST_SUCCEED. */
3644 maybe_fatal (int must_succeed
, struct terminal
*terminal
,
3645 const char *str1
, const char *str2
, ...)
3648 va_start (ap
, str2
);
3650 delete_tty (terminal
);
3662 fatal (const char *str
, ...)
3672 /* Delete the given tty terminal, closing all frames on it. */
3675 delete_tty (struct terminal
*terminal
)
3677 struct tty_display_info
*tty
;
3679 /* Protect against recursive calls. delete_frame in
3680 delete_terminal calls us back when it deletes our last frame. */
3681 if (!terminal
->name
)
3684 if (terminal
->type
!= output_termcap
)
3687 tty
= terminal
->display_info
.tty
;
3689 if (tty
== tty_list
)
3690 tty_list
= tty
->next
;
3693 struct tty_display_info
*p
;
3694 for (p
= tty_list
; p
&& p
->next
!= tty
; p
= p
->next
)
3698 /* This should not happen. */
3701 p
->next
= tty
->next
;
3705 /* reset_sys_modes needs a valid device, so this call needs to be
3706 before delete_terminal. */
3707 reset_sys_modes (tty
);
3709 delete_terminal (terminal
);
3716 delete_keyboard_wait_descriptor (fileno (tty
->input
));
3717 if (tty
->input
!= stdin
)
3718 fclose (tty
->input
);
3720 if (tty
->output
&& tty
->output
!= stdout
&& tty
->output
!= tty
->input
)
3721 fclose (tty
->output
);
3722 if (tty
->termscript
)
3723 fclose (tty
->termscript
);
3725 xfree (tty
->old_tty
);
3727 xfree (tty
->termcap_strings_buffer
);
3728 xfree (tty
->termcap_term_buffer
);
3730 memset (tty
, 0, sizeof (struct tty_display_info
));
3736 /* Mark the pointers in the tty_display_info objects.
3737 Called by the Fgarbage_collector. */
3742 struct tty_display_info
*tty
;
3744 for (tty
= tty_list
; tty
; tty
= tty
->next
)
3745 mark_object (tty
->top_frame
);
3753 DEFVAR_BOOL ("system-uses-terminfo", system_uses_terminfo
,
3754 doc
: /* Non-nil means the system uses terminfo rather than termcap.
3755 This variable can be used by terminal emulator packages. */);
3757 system_uses_terminfo
= 1;
3759 system_uses_terminfo
= 0;
3762 DEFVAR_LISP ("suspend-tty-functions", Vsuspend_tty_functions
,
3763 doc
: /* Functions to be run after suspending a tty.
3764 The functions are run with one argument, the terminal object to be suspended.
3765 See `suspend-tty'. */);
3766 Vsuspend_tty_functions
= Qnil
;
3769 DEFVAR_LISP ("resume-tty-functions", Vresume_tty_functions
,
3770 doc
: /* Functions to be run after resuming a tty.
3771 The functions are run with one argument, the terminal object that was revived.
3772 See `resume-tty'. */);
3773 Vresume_tty_functions
= Qnil
;
3775 DEFVAR_BOOL ("visible-cursor", visible_cursor
,
3776 doc
: /* Non-nil means to make the cursor very visible.
3777 This only has an effect when running in a text terminal.
3778 What means \"very visible\" is up to your terminal. It may make the cursor
3779 bigger, or it may make it blink, or it may do nothing at all. */);
3782 defsubr (&Stty_display_color_p
);
3783 defsubr (&Stty_display_color_cells
);
3784 defsubr (&Stty_no_underline
);
3785 defsubr (&Stty_type
);
3786 defsubr (&Scontrolling_tty_p
);
3787 defsubr (&Ssuspend_tty
);
3788 defsubr (&Sresume_tty
);
3790 defsubr (&Sgpm_mouse_start
);
3791 defsubr (&Sgpm_mouse_stop
);
3792 #endif /* HAVE_GPM */
3795 default_orig_pair
= NULL
;
3796 default_set_foreground
= NULL
;
3797 default_set_background
= NULL
;
3798 #endif /* !DOS_NT */
3800 encode_terminal_src
= NULL
;
3801 encode_terminal_dst
= NULL
;