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 Free Software Foundation, Inc.
5 This file is part of GNU Emacs.
7 GNU Emacs is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
12 GNU Emacs is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU Emacs; see the file COPYING. If not, write to
19 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20 Boston, MA 02110-1301, USA. */
22 /* New redisplay, TTY faces by Gerd Moellmann <gerd@gnu.org>. */
30 #include <unistd.h> /* For isatty. */
33 #include <termios.h> /* For TIOCNOTTY. */
46 #include "termhooks.h"
47 #include "dispextern.h"
50 #include "syssignal.h"
53 /* For now, don't try to include termcap.h. On some systems,
54 configure finds a non-standard termcap.h that the main build
57 #if defined HAVE_TERMCAP_H && 0
60 extern void tputs
P_ ((const char *, int, int (*)(int)));
61 extern int tgetent
P_ ((char *, const char *));
62 extern int tgetflag
P_ ((char *id
));
63 extern int tgetnum
P_ ((char *id
));
82 static void tty_set_scroll_region
P_ ((struct frame
*f
, int start
, int stop
));
83 static void turn_on_face
P_ ((struct frame
*, int face_id
));
84 static void turn_off_face
P_ ((struct frame
*, int face_id
));
85 static void tty_show_cursor
P_ ((struct tty_display_info
*));
86 static void tty_hide_cursor
P_ ((struct tty_display_info
*));
87 static void tty_background_highlight
P_ ((struct tty_display_info
*tty
));
88 static void clear_tty_hooks
P_ ((struct terminal
*terminal
));
89 static void set_tty_hooks
P_ ((struct terminal
*terminal
));
90 static void dissociate_if_controlling_tty
P_ ((int fd
));
91 static void delete_tty
P_ ((struct terminal
*));
93 #define OUTPUT(tty, a) \
94 emacs_tputs ((tty), a, \
95 (int) (FRAME_LINES (XFRAME (selected_frame)) \
99 #define OUTPUT1(tty, a) emacs_tputs ((tty), a, 1, cmputc)
100 #define OUTPUTL(tty, a, lines) emacs_tputs ((tty), a, lines, cmputc)
102 #define OUTPUT_IF(tty, a) \
105 emacs_tputs ((tty), a, \
106 (int) (FRAME_LINES (XFRAME (selected_frame)) \
111 #define OUTPUT1_IF(tty, a) do { if (a) emacs_tputs ((tty), a, 1, cmputc); } while (0)
113 /* If true, use "vs", otherwise use "ve" to make the cursor visible. */
115 static int visible_cursor
;
117 /* Display space properties */
119 extern Lisp_Object Qspace
, QCalign_to
, QCwidth
;
121 /* Functions to call after suspending a tty. */
122 Lisp_Object Vsuspend_tty_functions
;
124 /* Functions to call after resuming a tty. */
125 Lisp_Object Vresume_tty_functions
;
127 /* Chain of all tty device parameters. */
128 struct tty_display_info
*tty_list
;
130 /* Nonzero means no need to redraw the entire frame on resuming a
131 suspended Emacs. This is useful on terminals with multiple
132 pages, where one page is used for Emacs and another for all
134 int no_redraw_on_reenter
;
136 /* Meaning of bits in no_color_video. Each bit set means that the
137 corresponding attribute cannot be combined with colors. */
141 NC_STANDOUT
= 1 << 0,
142 NC_UNDERLINE
= 1 << 1,
149 NC_ALT_CHARSET
= 1 << 8
154 /* The largest frame width in any call to calculate_costs. */
158 /* The largest frame height in any call to calculate_costs. */
162 /* Non-zero if we have dropped our controlling tty and therefore
163 should not open a frame on stdout. */
164 static int no_controlling_tty
;
166 /* Provided for lisp packages. */
168 static int system_uses_terminfo
;
172 extern char *tgetstr ();
176 /* We aren't X windows, but we aren't termcap either. This makes me
177 uncertain as to what value to use for frame.output_method. For
178 this file, we'll define FRAME_TERMCAP_P to be zero so that our
179 output hooks get called instead of the termcap functions. Probably
180 the best long-term solution is to define an output_windows_nt... */
182 #undef FRAME_TERMCAP_P
183 #define FRAME_TERMCAP_P(_f_) 0
184 #endif /* WINDOWSNT */
187 /* Ring the bell on a tty. */
190 tty_ring_bell (struct frame
*f
)
192 struct tty_display_info
*tty
= FRAME_TTY (f
);
196 OUTPUT (tty
, (tty
->TS_visible_bell
&& visible_bell
197 ? tty
->TS_visible_bell
199 fflush (tty
->output
);
203 /* Set up termcap modes for Emacs. */
206 tty_set_terminal_modes (struct terminal
*terminal
)
208 struct tty_display_info
*tty
= terminal
->display_info
.tty
;
212 if (tty
->TS_termcap_modes
)
213 OUTPUT (tty
, tty
->TS_termcap_modes
);
216 /* Output enough newlines to scroll all the old screen contents
217 off the screen, so it won't be overwritten and lost. */
220 for (i
= 0; i
< FRAME_LINES (XFRAME (selected_frame
)); i
++)
224 OUTPUT_IF (tty
, tty
->TS_termcap_modes
);
225 OUTPUT_IF (tty
, visible_cursor
? tty
->TS_cursor_visible
: tty
->TS_cursor_normal
);
226 OUTPUT_IF (tty
, tty
->TS_keypad_mode
);
228 fflush (tty
->output
);
232 /* Reset termcap modes before exiting Emacs. */
235 tty_reset_terminal_modes (struct terminal
*terminal
)
237 struct tty_display_info
*tty
= terminal
->display_info
.tty
;
241 tty_turn_off_highlight (tty
);
242 tty_turn_off_insert (tty
);
243 OUTPUT_IF (tty
, tty
->TS_end_keypad_mode
);
244 OUTPUT_IF (tty
, tty
->TS_cursor_normal
);
245 OUTPUT_IF (tty
, tty
->TS_end_termcap_modes
);
246 OUTPUT_IF (tty
, tty
->TS_orig_pair
);
247 /* Output raw CR so kernel can track the cursor hpos. */
250 fflush (tty
->output
);
254 /* Flag the end of a display update on a termcap terminal. */
257 tty_update_end (struct frame
*f
)
259 struct tty_display_info
*tty
= FRAME_TTY (f
);
261 if (!XWINDOW (selected_window
)->cursor_off_p
)
262 tty_show_cursor (tty
);
263 tty_turn_off_insert (tty
);
264 tty_background_highlight (tty
);
267 /* The implementation of set_terminal_window for termcap frames. */
270 tty_set_terminal_window (struct frame
*f
, int size
)
272 struct tty_display_info
*tty
= FRAME_TTY (f
);
274 tty
->specified_window
= size
? size
: FRAME_LINES (f
);
275 if (FRAME_SCROLL_REGION_OK (f
))
276 tty_set_scroll_region (f
, 0, tty
->specified_window
);
280 tty_set_scroll_region (struct frame
*f
, int start
, int stop
)
283 struct tty_display_info
*tty
= FRAME_TTY (f
);
285 if (tty
->TS_set_scroll_region
)
286 buf
= tparam (tty
->TS_set_scroll_region
, 0, 0, start
, stop
- 1);
287 else if (tty
->TS_set_scroll_region_1
)
288 buf
= tparam (tty
->TS_set_scroll_region_1
, 0, 0,
289 FRAME_LINES (f
), start
,
290 FRAME_LINES (f
) - stop
,
293 buf
= tparam (tty
->TS_set_window
, 0, 0, start
, 0, stop
, FRAME_COLS (f
));
302 tty_turn_on_insert (struct tty_display_info
*tty
)
304 if (!tty
->insert_mode
)
305 OUTPUT (tty
, tty
->TS_insert_mode
);
306 tty
->insert_mode
= 1;
310 tty_turn_off_insert (struct tty_display_info
*tty
)
312 if (tty
->insert_mode
)
313 OUTPUT (tty
, tty
->TS_end_insert_mode
);
314 tty
->insert_mode
= 0;
317 /* Handle highlighting. */
320 tty_turn_off_highlight (struct tty_display_info
*tty
)
322 if (tty
->standout_mode
)
323 OUTPUT_IF (tty
, tty
->TS_end_standout_mode
);
324 tty
->standout_mode
= 0;
328 tty_turn_on_highlight (struct tty_display_info
*tty
)
330 if (!tty
->standout_mode
)
331 OUTPUT_IF (tty
, tty
->TS_standout_mode
);
332 tty
->standout_mode
= 1;
336 tty_toggle_highlight (struct tty_display_info
*tty
)
338 if (tty
->standout_mode
)
339 tty_turn_off_highlight (tty
);
341 tty_turn_on_highlight (tty
);
345 /* Make cursor invisible. */
348 tty_hide_cursor (struct tty_display_info
*tty
)
350 if (tty
->cursor_hidden
== 0)
352 tty
->cursor_hidden
= 1;
353 OUTPUT_IF (tty
, tty
->TS_cursor_invisible
);
358 /* Ensure that cursor is visible. */
361 tty_show_cursor (struct tty_display_info
*tty
)
363 if (tty
->cursor_hidden
)
365 tty
->cursor_hidden
= 0;
366 OUTPUT_IF (tty
, tty
->TS_cursor_normal
);
368 OUTPUT_IF (tty
, tty
->TS_cursor_visible
);
373 /* Set standout mode to the state it should be in for
374 empty space inside windows. What this is,
375 depends on the user option inverse-video. */
378 tty_background_highlight (struct tty_display_info
*tty
)
381 tty_turn_on_highlight (tty
);
383 tty_turn_off_highlight (tty
);
386 /* Set standout mode to the mode specified for the text to be output. */
389 tty_highlight_if_desired (struct tty_display_info
*tty
)
392 tty_turn_on_highlight (tty
);
394 tty_turn_off_highlight (tty
);
398 /* Move cursor to row/column position VPOS/HPOS. HPOS/VPOS are
399 frame-relative coordinates. */
402 tty_cursor_to (struct frame
*f
, int vpos
, int hpos
)
404 struct tty_display_info
*tty
= FRAME_TTY (f
);
406 /* Detect the case where we are called from reset_sys_modes
407 and the costs have never been calculated. Do nothing. */
408 if (! tty
->costs_set
)
411 if (curY (tty
) == vpos
412 && curX (tty
) == hpos
)
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
, vpos
, hpos
);
421 /* Similar but don't take any account of the wasted characters. */
424 tty_raw_cursor_to (struct frame
*f
, int row
, int col
)
426 struct tty_display_info
*tty
= FRAME_TTY (f
);
428 if (curY (tty
) == row
429 && curX (tty
) == col
)
431 if (!tty
->TF_standout_motion
)
432 tty_background_highlight (tty
);
433 if (!tty
->TF_insmode_motion
)
434 tty_turn_off_insert (tty
);
435 cmgoto (tty
, row
, col
);
438 /* Erase operations */
440 /* Clear from cursor to end of frame on a termcap device. */
443 tty_clear_to_end (struct frame
*f
)
446 struct tty_display_info
*tty
= FRAME_TTY (f
);
448 if (tty
->TS_clr_to_bottom
)
450 tty_background_highlight (tty
);
451 OUTPUT (tty
, tty
->TS_clr_to_bottom
);
455 for (i
= curY (tty
); i
< FRAME_LINES (f
); i
++)
458 clear_end_of_line (f
, FRAME_COLS (f
));
463 /* Clear an entire termcap frame. */
466 tty_clear_frame (struct frame
*f
)
468 struct tty_display_info
*tty
= FRAME_TTY (f
);
470 if (tty
->TS_clr_frame
)
472 tty_background_highlight (tty
);
473 OUTPUT (tty
, tty
->TS_clr_frame
);
483 /* An implementation of clear_end_of_line for termcap frames.
485 Note that the cursor may be moved, on terminals lacking a `ce' string. */
488 tty_clear_end_of_line (struct frame
*f
, int first_unused_hpos
)
491 struct tty_display_info
*tty
= FRAME_TTY (f
);
493 /* Detect the case where we are called from reset_sys_modes
494 and the costs have never been calculated. Do nothing. */
495 if (! tty
->costs_set
)
498 if (curX (tty
) >= first_unused_hpos
)
500 tty_background_highlight (tty
);
501 if (tty
->TS_clr_line
)
503 OUTPUT1 (tty
, tty
->TS_clr_line
);
506 { /* have to do it the hard way */
507 tty_turn_off_insert (tty
);
509 /* Do not write in last row last col with Auto-wrap on. */
511 && curY (tty
) == FrameRows (tty
) - 1
512 && first_unused_hpos
== FrameCols (tty
))
515 for (i
= curX (tty
); i
< first_unused_hpos
; i
++)
518 fputc (' ', tty
->termscript
);
519 fputc (' ', tty
->output
);
521 cmplus (tty
, first_unused_hpos
- curX (tty
));
525 /* Buffer to store the source and result of code conversion for terminal. */
526 static unsigned char *encode_terminal_buf
;
527 /* Allocated size of the above buffer. */
528 static int encode_terminal_bufsize
;
530 /* Encode SRC_LEN glyphs starting at SRC to terminal output codes.
531 Set CODING->produced to the byte-length of the resulting byte
532 sequence, and return a pointer to that byte sequence. */
535 encode_terminal_code (src
, src_len
, coding
)
538 struct coding_system
*coding
;
540 struct glyph
*src_end
= src
+ src_len
;
543 int nchars
, nbytes
, required
;
544 register int tlen
= GLYPH_TABLE_LENGTH
;
545 register Lisp_Object
*tbase
= GLYPH_TABLE_BASE
;
547 /* Allocate sufficient size of buffer to store all characters in
548 multibyte-form. But, it may be enlarged on demand if
549 Vglyph_table contains a string. */
550 required
= MAX_MULTIBYTE_LENGTH
* src_len
;
551 if (encode_terminal_bufsize
< required
)
553 if (encode_terminal_bufsize
== 0)
554 encode_terminal_buf
= xmalloc (required
);
556 encode_terminal_buf
= xrealloc (encode_terminal_buf
, required
);
557 encode_terminal_bufsize
= required
;
560 buf
= encode_terminal_buf
;
562 while (src
< src_end
)
564 /* We must skip glyphs to be padded for a wide character. */
565 if (! CHAR_GLYPH_PADDING_P (*src
))
567 g
= GLYPH_FROM_CHAR_GLYPH (src
[0]);
569 if (g
< 0 || g
>= tlen
)
571 /* This glyph doesn't has an entry in Vglyph_table. */
572 if (CHAR_VALID_P (src
->u
.ch
, 0))
573 buf
+= CHAR_STRING (src
->u
.ch
, buf
);
580 /* This glyph has an entry in Vglyph_table,
581 so process any alias before testing for simpleness. */
582 GLYPH_FOLLOW_ALIASES (tbase
, tlen
, g
);
584 if (GLYPH_SIMPLE_P (tbase
, tlen
, g
))
586 int c
= FAST_GLYPH_CHAR (g
);
588 if (CHAR_VALID_P (c
, 0))
589 buf
+= CHAR_STRING (c
, buf
);
596 /* We have a string in Vglyph_table. */
600 if (! STRING_MULTIBYTE (string
))
601 string
= string_to_multibyte (string
);
602 nbytes
= buf
- encode_terminal_buf
;
603 if (encode_terminal_bufsize
< nbytes
+ SBYTES (string
))
605 encode_terminal_bufsize
= nbytes
+ SBYTES (string
);
606 encode_terminal_buf
= xrealloc (encode_terminal_buf
,
607 encode_terminal_bufsize
);
608 buf
= encode_terminal_buf
+ nbytes
;
610 bcopy (SDATA (string
), buf
, SBYTES (string
));
611 buf
+= SBYTES (string
);
612 nchars
+= SCHARS (string
);
619 nbytes
= buf
- encode_terminal_buf
;
620 coding
->src_multibyte
= 1;
621 coding
->dst_multibyte
= 0;
622 if (SYMBOLP (coding
->pre_write_conversion
)
623 && ! NILP (Ffboundp (coding
->pre_write_conversion
)))
625 run_pre_write_conversin_on_c_str (&encode_terminal_buf
,
626 &encode_terminal_bufsize
,
627 nchars
, nbytes
, coding
);
628 nchars
= coding
->produced_char
;
629 nbytes
= coding
->produced
;
631 required
= nbytes
+ encoding_buffer_size (coding
, nbytes
);
632 if (encode_terminal_bufsize
< required
)
634 encode_terminal_bufsize
= required
;
635 encode_terminal_buf
= xrealloc (encode_terminal_buf
, required
);
638 encode_coding (coding
, encode_terminal_buf
, encode_terminal_buf
+ nbytes
,
639 nbytes
, encode_terminal_bufsize
- nbytes
);
640 return encode_terminal_buf
+ nbytes
;
644 /* An implementation of write_glyphs for termcap frames. */
647 tty_write_glyphs (struct frame
*f
, struct glyph
*string
, int len
)
649 unsigned char *conversion_buffer
;
650 struct coding_system
*coding
;
652 struct tty_display_info
*tty
= FRAME_TTY (f
);
654 tty_turn_off_insert (tty
);
655 tty_hide_cursor (tty
);
657 /* Don't dare write in last column of bottom line, if Auto-Wrap,
658 since that would scroll the whole frame on some terminals. */
661 && curY (tty
) + 1 == FRAME_LINES (f
)
662 && (curX (tty
) + len
) == FRAME_COLS (f
))
669 /* If terminal_coding does any conversion, use it, otherwise use
670 safe_terminal_coding. We can't use CODING_REQUIRE_ENCODING here
671 because it always return 1 if the member src_multibyte is 1. */
672 coding
= (FRAME_TERMINAL_CODING (f
)->common_flags
& CODING_REQUIRE_ENCODING_MASK
673 ? FRAME_TERMINAL_CODING (f
) : &safe_terminal_coding
);
674 /* The mode bit CODING_MODE_LAST_BLOCK should be set to 1 only at
676 coding
->mode
&= ~CODING_MODE_LAST_BLOCK
;
680 /* Identify a run of glyphs with the same face. */
681 int face_id
= string
->face_id
;
684 for (n
= 1; n
< len
; ++n
)
685 if (string
[n
].face_id
!= face_id
)
688 /* Turn appearance modes of the face of the run on. */
689 tty_highlight_if_desired (tty
);
690 turn_on_face (f
, face_id
);
693 /* This is the last run. */
694 coding
->mode
|= CODING_MODE_LAST_BLOCK
;
695 conversion_buffer
= encode_terminal_code (string
, n
, coding
);
696 if (coding
->produced
> 0)
698 fwrite (conversion_buffer
, 1, coding
->produced
, tty
->output
);
699 if (ferror (tty
->output
))
700 clearerr (tty
->output
);
702 fwrite (conversion_buffer
, 1, coding
->produced
, tty
->termscript
);
707 /* Turn appearance modes off. */
708 turn_off_face (f
, face_id
);
709 tty_turn_off_highlight (tty
);
715 /* An implementation of insert_glyphs for termcap frames. */
718 tty_insert_glyphs (struct frame
*f
, struct glyph
*start
, int len
)
721 struct glyph
*glyph
= NULL
;
722 unsigned char *conversion_buffer
;
723 unsigned char space
[1];
724 struct coding_system
*coding
;
726 struct tty_display_info
*tty
= FRAME_TTY (f
);
728 if (tty
->TS_ins_multi_chars
)
730 buf
= tparam (tty
->TS_ins_multi_chars
, 0, 0, len
);
734 write_glyphs (f
, start
, len
);
738 tty_turn_on_insert (tty
);
742 space
[0] = SPACEGLYPH
;
744 /* If terminal_coding does any conversion, use it, otherwise use
745 safe_terminal_coding. We can't use CODING_REQUIRE_ENCODING here
746 because it always return 1 if the member src_multibyte is 1. */
747 coding
= (FRAME_TERMINAL_CODING (f
)->common_flags
& CODING_REQUIRE_ENCODING_MASK
748 ? FRAME_TERMINAL_CODING (f
) : &safe_terminal_coding
);
749 /* The mode bit CODING_MODE_LAST_BLOCK should be set to 1 only at
751 coding
->mode
&= ~CODING_MODE_LAST_BLOCK
;
755 OUTPUT1_IF (tty
, tty
->TS_ins_char
);
758 conversion_buffer
= space
;
759 coding
->produced
= 1;
763 tty_highlight_if_desired (tty
);
764 turn_on_face (f
, start
->face_id
);
767 /* We must open sufficient space for a character which
768 occupies more than one column. */
769 while (len
&& CHAR_GLYPH_PADDING_P (*start
))
771 OUTPUT1_IF (tty
, tty
->TS_ins_char
);
776 /* This is the last glyph. */
777 coding
->mode
|= CODING_MODE_LAST_BLOCK
;
779 conversion_buffer
= encode_terminal_code (glyph
, 1, coding
);
782 if (coding
->produced
> 0)
784 fwrite (conversion_buffer
, 1, coding
->produced
, tty
->output
);
785 if (ferror (tty
->output
))
786 clearerr (tty
->output
);
788 fwrite (conversion_buffer
, 1, coding
->produced
, tty
->termscript
);
791 OUTPUT1_IF (tty
, tty
->TS_pad_inserted_char
);
794 turn_off_face (f
, glyph
->face_id
);
795 tty_turn_off_highlight (tty
);
802 /* An implementation of delete_glyphs for termcap frames. */
805 tty_delete_glyphs (struct frame
*f
, int n
)
810 struct tty_display_info
*tty
= FRAME_TTY (f
);
812 if (tty
->delete_in_insert_mode
)
814 tty_turn_on_insert (tty
);
818 tty_turn_off_insert (tty
);
819 OUTPUT_IF (tty
, tty
->TS_delete_mode
);
822 if (tty
->TS_del_multi_chars
)
824 buf
= tparam (tty
->TS_del_multi_chars
, 0, 0, n
);
829 for (i
= 0; i
< n
; i
++)
830 OUTPUT1 (tty
, tty
->TS_del_char
);
831 if (!tty
->delete_in_insert_mode
)
832 OUTPUT_IF (tty
, tty
->TS_end_delete_mode
);
835 /* An implementation of ins_del_lines for termcap frames. */
838 tty_ins_del_lines (struct frame
*f
, int vpos
, int n
)
840 struct tty_display_info
*tty
= FRAME_TTY (f
);
841 char *multi
= n
> 0 ? tty
->TS_ins_multi_lines
: tty
->TS_del_multi_lines
;
842 char *single
= n
> 0 ? tty
->TS_ins_line
: tty
->TS_del_line
;
843 char *scroll
= n
> 0 ? tty
->TS_rev_scroll
: tty
->TS_fwd_scroll
;
845 register int i
= n
> 0 ? n
: -n
;
848 /* If the lines below the insertion are being pushed
849 into the end of the window, this is the same as clearing;
850 and we know the lines are already clear, since the matching
851 deletion has already been done. So can ignore this. */
852 /* If the lines below the deletion are blank lines coming
853 out of the end of the window, don't bother,
854 as there will be a matching inslines later that will flush them. */
855 if (FRAME_SCROLL_REGION_OK (f
)
856 && vpos
+ i
>= tty
->specified_window
)
858 if (!FRAME_MEMORY_BELOW_FRAME (f
)
859 && vpos
+ i
>= FRAME_LINES (f
))
864 raw_cursor_to (f
, vpos
, 0);
865 tty_background_highlight (tty
);
866 buf
= tparam (multi
, 0, 0, i
);
872 raw_cursor_to (f
, vpos
, 0);
873 tty_background_highlight (tty
);
875 OUTPUT (tty
, single
);
881 tty_set_scroll_region (f
, vpos
, tty
->specified_window
);
883 raw_cursor_to (f
, tty
->specified_window
- 1, 0);
885 raw_cursor_to (f
, vpos
, 0);
886 tty_background_highlight (tty
);
888 OUTPUTL (tty
, scroll
, tty
->specified_window
- vpos
);
889 tty_set_scroll_region (f
, 0, tty
->specified_window
);
892 if (!FRAME_SCROLL_REGION_OK (f
)
893 && FRAME_MEMORY_BELOW_FRAME (f
)
896 cursor_to (f
, FRAME_LINES (f
) + n
, 0);
901 /* Compute cost of sending "str", in characters,
902 not counting any line-dependent padding. */
905 string_cost (char *str
)
909 tputs (str
, 0, evalcost
);
913 /* Compute cost of sending "str", in characters,
914 counting any line-dependent padding at one line. */
917 string_cost_one_line (char *str
)
921 tputs (str
, 1, evalcost
);
925 /* Compute per line amount of line-dependent padding,
926 in tenths of characters. */
929 per_line_cost (char *str
)
933 tputs (str
, 0, evalcost
);
936 tputs (str
, 10, evalcost
);
941 /* char_ins_del_cost[n] is cost of inserting N characters.
942 char_ins_del_cost[-n] is cost of deleting N characters.
943 The length of this vector is based on max_frame_cols. */
945 int *char_ins_del_vector
;
947 #define char_ins_del_cost(f) (&char_ins_del_vector[FRAME_COLS ((f))])
952 calculate_ins_del_char_costs (struct frame
*f
)
954 struct tty_display_info
*tty
= FRAME_TTY (f
);
955 int ins_startup_cost
, del_startup_cost
;
956 int ins_cost_per_char
, del_cost_per_char
;
960 if (tty
->TS_ins_multi_chars
)
962 ins_cost_per_char
= 0;
963 ins_startup_cost
= string_cost_one_line (tty
->TS_ins_multi_chars
);
965 else if (tty
->TS_ins_char
|| tty
->TS_pad_inserted_char
966 || (tty
->TS_insert_mode
&& tty
->TS_end_insert_mode
))
968 ins_startup_cost
= (30 * (string_cost (tty
->TS_insert_mode
)
969 + string_cost (tty
->TS_end_insert_mode
))) / 100;
970 ins_cost_per_char
= (string_cost_one_line (tty
->TS_ins_char
)
971 + string_cost_one_line (tty
->TS_pad_inserted_char
));
975 ins_startup_cost
= 9999;
976 ins_cost_per_char
= 0;
979 if (tty
->TS_del_multi_chars
)
981 del_cost_per_char
= 0;
982 del_startup_cost
= string_cost_one_line (tty
->TS_del_multi_chars
);
984 else if (tty
->TS_del_char
)
986 del_startup_cost
= (string_cost (tty
->TS_delete_mode
)
987 + string_cost (tty
->TS_end_delete_mode
));
988 if (tty
->delete_in_insert_mode
)
989 del_startup_cost
/= 2;
990 del_cost_per_char
= string_cost_one_line (tty
->TS_del_char
);
994 del_startup_cost
= 9999;
995 del_cost_per_char
= 0;
998 /* Delete costs are at negative offsets */
999 p
= &char_ins_del_cost (f
)[0];
1000 for (i
= FRAME_COLS (f
); --i
>= 0;)
1001 *--p
= (del_startup_cost
+= del_cost_per_char
);
1003 /* Doing nothing is free */
1004 p
= &char_ins_del_cost (f
)[0];
1007 /* Insert costs are at positive offsets */
1008 for (i
= FRAME_COLS (f
); --i
>= 0;)
1009 *p
++ = (ins_startup_cost
+= ins_cost_per_char
);
1013 calculate_costs (struct frame
*frame
)
1015 FRAME_COST_BAUD_RATE (frame
) = baud_rate
;
1017 if (FRAME_TERMCAP_P (frame
))
1019 struct tty_display_info
*tty
= FRAME_TTY (frame
);
1020 register char *f
= (tty
->TS_set_scroll_region
1021 ? tty
->TS_set_scroll_region
1022 : tty
->TS_set_scroll_region_1
);
1024 FRAME_SCROLL_REGION_COST (frame
) = string_cost (f
);
1028 /* These variables are only used for terminal stuff. They are
1029 allocated once for the terminal frame of X-windows emacs, but not
1032 char_ins_del_vector (i.e., char_ins_del_cost) isn't used because
1033 X turns off char_ins_del_ok. */
1035 max_frame_lines
= max (max_frame_lines
, FRAME_LINES (frame
));
1036 max_frame_cols
= max (max_frame_cols
, FRAME_COLS (frame
));
1038 if (char_ins_del_vector
!= 0)
1040 = (int *) xrealloc (char_ins_del_vector
,
1042 + 2 * max_frame_cols
* sizeof (int)));
1045 = (int *) xmalloc (sizeof (int)
1046 + 2 * max_frame_cols
* sizeof (int));
1048 bzero (char_ins_del_vector
, (sizeof (int)
1049 + 2 * max_frame_cols
* sizeof (int)));
1052 if (f
&& (!tty
->TS_ins_line
&& !tty
->TS_del_line
))
1053 do_line_insertion_deletion_costs (frame
,
1054 tty
->TS_rev_scroll
, tty
->TS_ins_multi_lines
,
1055 tty
->TS_fwd_scroll
, tty
->TS_del_multi_lines
,
1058 do_line_insertion_deletion_costs (frame
,
1059 tty
->TS_ins_line
, tty
->TS_ins_multi_lines
,
1060 tty
->TS_del_line
, tty
->TS_del_multi_lines
,
1063 calculate_ins_del_char_costs (frame
);
1065 /* Don't use TS_repeat if its padding is worse than sending the chars */
1066 if (tty
->TS_repeat
&& per_line_cost (tty
->TS_repeat
) * baud_rate
< 9000)
1067 tty
->RPov
= string_cost (tty
->TS_repeat
);
1069 tty
->RPov
= FRAME_COLS (frame
) * 2;
1071 cmcostinit (FRAME_TTY (frame
)); /* set up cursor motion costs */
1079 /* Termcap capability names that correspond directly to X keysyms.
1080 Some of these (marked "terminfo") aren't supplied by old-style
1081 (Berkeley) termcap entries. They're listed in X keysym order;
1082 except we put the keypad keys first, so that if they clash with
1083 other keys (as on the IBM PC keyboard) they get overridden.
1086 static struct fkey_table keys
[] =
1088 {"kh", "home"}, /* termcap */
1089 {"kl", "left"}, /* termcap */
1090 {"ku", "up"}, /* termcap */
1091 {"kr", "right"}, /* termcap */
1092 {"kd", "down"}, /* termcap */
1093 {"%8", "prior"}, /* terminfo */
1094 {"%5", "next"}, /* terminfo */
1095 {"@7", "end"}, /* terminfo */
1096 {"@1", "begin"}, /* terminfo */
1097 {"*6", "select"}, /* terminfo */
1098 {"%9", "print"}, /* terminfo */
1099 {"@4", "execute"}, /* terminfo --- actually the `command' key */
1101 * "insert" --- see below
1103 {"&8", "undo"}, /* terminfo */
1104 {"%0", "redo"}, /* terminfo */
1105 {"%7", "menu"}, /* terminfo --- actually the `options' key */
1106 {"@0", "find"}, /* terminfo */
1107 {"@2", "cancel"}, /* terminfo */
1108 {"%1", "help"}, /* terminfo */
1110 * "break" goes here, but can't be reliably intercepted with termcap
1112 {"&4", "reset"}, /* terminfo --- actually `restart' */
1114 * "system" and "user" --- no termcaps
1116 {"kE", "clearline"}, /* terminfo */
1117 {"kA", "insertline"}, /* terminfo */
1118 {"kL", "deleteline"}, /* terminfo */
1119 {"kI", "insertchar"}, /* terminfo */
1120 {"kD", "deletechar"}, /* terminfo */
1121 {"kB", "backtab"}, /* terminfo */
1123 * "kp_backtab", "kp-space", "kp-tab" --- no termcaps
1125 {"@8", "kp-enter"}, /* terminfo */
1127 * "kp-f1", "kp-f2", "kp-f3" "kp-f4",
1128 * "kp-multiply", "kp-add", "kp-separator",
1129 * "kp-subtract", "kp-decimal", "kp-divide", "kp-0";
1130 * --- no termcaps for any of these.
1132 {"K4", "kp-1"}, /* terminfo */
1134 * "kp-2" --- no termcap
1136 {"K5", "kp-3"}, /* terminfo */
1138 * "kp-4" --- no termcap
1140 {"K2", "kp-5"}, /* terminfo */
1142 * "kp-6" --- no termcap
1144 {"K1", "kp-7"}, /* terminfo */
1146 * "kp-8" --- no termcap
1148 {"K3", "kp-9"}, /* terminfo */
1150 * "kp-equal" --- no termcap
1162 {"&0", "S-cancel"}, /*shifted cancel key*/
1163 {"&9", "S-begin"}, /*shifted begin key*/
1164 {"*0", "S-find"}, /*shifted find key*/
1165 {"*1", "S-execute"}, /*shifted execute? actually shifted command key*/
1166 {"*4", "S-delete"}, /*shifted delete-character key*/
1167 {"*7", "S-end"}, /*shifted end key*/
1168 {"*8", "S-clearline"}, /*shifted clear-to end-of-line key*/
1169 {"#1", "S-help"}, /*shifted help key*/
1170 {"#2", "S-home"}, /*shifted home key*/
1171 {"#3", "S-insert"}, /*shifted insert-character key*/
1172 {"#4", "S-left"}, /*shifted left-arrow key*/
1173 {"%d", "S-menu"}, /*shifted menu? actually shifted options key*/
1174 {"%c", "S-next"}, /*shifted next key*/
1175 {"%e", "S-prior"}, /*shifted previous key*/
1176 {"%f", "S-print"}, /*shifted print key*/
1177 {"%g", "S-redo"}, /*shifted redo key*/
1178 {"%i", "S-right"}, /*shifted right-arrow key*/
1179 {"!3", "S-undo"} /*shifted undo key*/
1182 static char **term_get_fkeys_address
;
1183 static KBOARD
*term_get_fkeys_kboard
;
1184 static Lisp_Object
term_get_fkeys_1 ();
1186 /* Find the escape codes sent by the function keys for Vfunction_key_map.
1187 This function scans the termcap function key sequence entries, and
1188 adds entries to Vfunction_key_map for each function key it finds. */
1191 term_get_fkeys (address
, kboard
)
1195 /* We run the body of the function (term_get_fkeys_1) and ignore all Lisp
1196 errors during the call. The only errors should be from Fdefine_key
1197 when given a key sequence containing an invalid prefix key. If the
1198 termcap defines function keys which use a prefix that is already bound
1199 to a command by the default bindings, we should silently ignore that
1200 function key specification, rather than giving the user an error and
1201 refusing to run at all on such a terminal. */
1203 extern Lisp_Object
Fidentity ();
1204 term_get_fkeys_address
= address
;
1205 term_get_fkeys_kboard
= kboard
;
1206 internal_condition_case (term_get_fkeys_1
, Qerror
, Fidentity
);
1214 char **address
= term_get_fkeys_address
;
1215 KBOARD
*kboard
= term_get_fkeys_kboard
;
1217 /* This can happen if CANNOT_DUMP or with strange options. */
1219 kboard
->Vlocal_function_key_map
= Fmake_sparse_keymap (Qnil
);
1221 for (i
= 0; i
< (sizeof (keys
)/sizeof (keys
[0])); i
++)
1223 char *sequence
= tgetstr (keys
[i
].cap
, address
);
1225 Fdefine_key (kboard
->Vlocal_function_key_map
, build_string (sequence
),
1226 Fmake_vector (make_number (1),
1227 intern (keys
[i
].name
)));
1230 /* The uses of the "k0" capability are inconsistent; sometimes it
1231 describes F10, whereas othertimes it describes F0 and "k;" describes F10.
1232 We will attempt to politely accommodate both systems by testing for
1233 "k;", and if it is present, assuming that "k0" denotes F0, otherwise F10.
1236 char *k_semi
= tgetstr ("k;", address
);
1237 char *k0
= tgetstr ("k0", address
);
1238 char *k0_name
= "f10";
1243 /* Define f0 first, so that f10 takes precedence in case the
1244 key sequences happens to be the same. */
1245 Fdefine_key (kboard
->Vlocal_function_key_map
, build_string (k0
),
1246 Fmake_vector (make_number (1), intern ("f0")));
1247 Fdefine_key (kboard
->Vlocal_function_key_map
, build_string (k_semi
),
1248 Fmake_vector (make_number (1), intern ("f10")));
1251 Fdefine_key (kboard
->Vlocal_function_key_map
, build_string (k0
),
1252 Fmake_vector (make_number (1), intern (k0_name
)));
1255 /* Set up cookies for numbered function keys above f10. */
1257 char fcap
[3], fkey
[4];
1259 fcap
[0] = 'F'; fcap
[2] = '\0';
1260 for (i
= 11; i
< 64; i
++)
1263 fcap
[1] = '1' + i
- 11;
1265 fcap
[1] = 'A' + i
- 20;
1267 fcap
[1] = 'a' + i
- 46;
1270 char *sequence
= tgetstr (fcap
, address
);
1273 sprintf (fkey
, "f%d", i
);
1274 Fdefine_key (kboard
->Vlocal_function_key_map
, build_string (sequence
),
1275 Fmake_vector (make_number (1),
1283 * Various mappings to try and get a better fit.
1286 #define CONDITIONAL_REASSIGN(cap1, cap2, sym) \
1287 if (!tgetstr (cap1, address)) \
1289 char *sequence = tgetstr (cap2, address); \
1291 Fdefine_key (kboard->Vlocal_function_key_map, build_string (sequence), \
1292 Fmake_vector (make_number (1), \
1296 /* if there's no key_next keycap, map key_npage to `next' keysym */
1297 CONDITIONAL_REASSIGN ("%5", "kN", "next");
1298 /* if there's no key_prev keycap, map key_ppage to `previous' keysym */
1299 CONDITIONAL_REASSIGN ("%8", "kP", "prior");
1300 /* if there's no key_dc keycap, map key_ic to `insert' keysym */
1301 CONDITIONAL_REASSIGN ("kD", "kI", "insert");
1302 /* if there's no key_end keycap, map key_ll to 'end' keysym */
1303 CONDITIONAL_REASSIGN ("@7", "kH", "end");
1305 /* IBM has their own non-standard dialect of terminfo.
1306 If the standard name isn't found, try the IBM name. */
1307 CONDITIONAL_REASSIGN ("kB", "KO", "backtab");
1308 CONDITIONAL_REASSIGN ("@4", "kJ", "execute"); /* actually "action" */
1309 CONDITIONAL_REASSIGN ("@4", "kc", "execute"); /* actually "command" */
1310 CONDITIONAL_REASSIGN ("%7", "ki", "menu");
1311 CONDITIONAL_REASSIGN ("@7", "kw", "end");
1312 CONDITIONAL_REASSIGN ("F1", "k<", "f11");
1313 CONDITIONAL_REASSIGN ("F2", "k>", "f12");
1314 CONDITIONAL_REASSIGN ("%1", "kq", "help");
1315 CONDITIONAL_REASSIGN ("*6", "kU", "select");
1316 #undef CONDITIONAL_REASSIGN
1323 /***********************************************************************
1324 Character Display Information
1325 ***********************************************************************/
1327 /* Avoid name clash with functions defined in xterm.c */
1329 #define append_glyph append_glyph_term
1330 #define produce_stretch_glyph produce_stretch_glyph_term
1333 static void append_glyph
P_ ((struct it
*));
1334 static void produce_stretch_glyph
P_ ((struct it
*));
1337 /* Append glyphs to IT's glyph_row. Called from produce_glyphs for
1338 terminal frames if IT->glyph_row != NULL. IT->char_to_display is
1339 the character for which to produce glyphs; IT->face_id contains the
1340 character's face. Padding glyphs are appended if IT->c has a
1341 IT->pixel_width > 1. */
1347 struct glyph
*glyph
, *end
;
1350 xassert (it
->glyph_row
);
1351 glyph
= (it
->glyph_row
->glyphs
[it
->area
]
1352 + it
->glyph_row
->used
[it
->area
]);
1353 end
= it
->glyph_row
->glyphs
[1 + it
->area
];
1356 i
< it
->pixel_width
&& glyph
< end
;
1359 glyph
->type
= CHAR_GLYPH
;
1360 glyph
->pixel_width
= 1;
1361 glyph
->u
.ch
= it
->char_to_display
;
1362 glyph
->face_id
= it
->face_id
;
1363 glyph
->padding_p
= i
> 0;
1364 glyph
->charpos
= CHARPOS (it
->position
);
1365 glyph
->object
= it
->object
;
1367 ++it
->glyph_row
->used
[it
->area
];
1373 /* Produce glyphs for the display element described by IT. *IT
1374 specifies what we want to produce a glyph for (character, image, ...),
1375 and where in the glyph matrix we currently are (glyph row and hpos).
1376 produce_glyphs fills in output fields of *IT with information such as the
1377 pixel width and height of a character, and maybe output actual glyphs at
1378 the same time if IT->glyph_row is non-null. See the explanation of
1379 struct display_iterator in dispextern.h for an overview.
1381 produce_glyphs also stores the result of glyph width, ascent
1382 etc. computations in *IT.
1384 IT->glyph_row may be null, in which case produce_glyphs does not
1385 actually fill in the glyphs. This is used in the move_* functions
1386 in xdisp.c for text width and height computations.
1388 Callers usually don't call produce_glyphs directly;
1389 instead they use the macro PRODUCE_GLYPHS. */
1395 /* If a hook is installed, let it do the work. */
1396 xassert (it
->what
== IT_CHARACTER
1397 || it
->what
== IT_COMPOSITION
1398 || it
->what
== IT_STRETCH
);
1400 if (it
->what
== IT_STRETCH
)
1402 produce_stretch_glyph (it
);
1406 /* Nothing but characters are supported on terminal frames. For a
1407 composition sequence, it->c is the first character of the
1409 xassert (it
->what
== IT_CHARACTER
1410 || it
->what
== IT_COMPOSITION
);
1412 /* Maybe translate single-byte characters to multibyte. */
1413 it
->char_to_display
= it
->c
;
1415 if (it
->c
>= 040 && it
->c
< 0177)
1417 it
->pixel_width
= it
->nglyphs
= 1;
1421 else if (it
->c
== '\n')
1422 it
->pixel_width
= it
->nglyphs
= 0;
1423 else if (it
->c
== '\t')
1425 int absolute_x
= (it
->current_x
1426 + it
->continuation_lines_width
);
1428 = (((1 + absolute_x
+ it
->tab_width
- 1)
1433 /* If part of the TAB has been displayed on the previous line
1434 which is continued now, continuation_lines_width will have
1435 been incremented already by the part that fitted on the
1436 continued line. So, we will get the right number of spaces
1438 nspaces
= next_tab_x
- absolute_x
;
1444 it
->char_to_display
= ' ';
1445 it
->pixel_width
= it
->len
= 1;
1451 it
->pixel_width
= nspaces
;
1452 it
->nglyphs
= nspaces
;
1454 else if (SINGLE_BYTE_CHAR_P (it
->c
))
1456 if (unibyte_display_via_language_environment
1458 || !NILP (Vnonascii_translation_table
)))
1462 it
->char_to_display
= unibyte_char_to_multibyte (it
->c
);
1463 charset
= CHAR_CHARSET (it
->char_to_display
);
1464 it
->pixel_width
= CHARSET_WIDTH (charset
);
1465 it
->nglyphs
= it
->pixel_width
;
1471 /* Coming here means that it->c is from display table, thus we
1472 must send the code as is to the terminal. Although there's
1473 no way to know how many columns it occupies on a screen, it
1474 is a good assumption that a single byte code has 1-column
1476 it
->pixel_width
= it
->nglyphs
= 1;
1483 /* A multi-byte character. The display width is fixed for all
1484 characters of the set. Some of the glyphs may have to be
1485 ignored because they are already displayed in a continued
1487 int charset
= CHAR_CHARSET (it
->c
);
1489 it
->pixel_width
= CHARSET_WIDTH (charset
);
1490 it
->nglyphs
= it
->pixel_width
;
1497 /* Advance current_x by the pixel width as a convenience for
1499 if (it
->area
== TEXT_AREA
)
1500 it
->current_x
+= it
->pixel_width
;
1501 it
->ascent
= it
->max_ascent
= it
->phys_ascent
= it
->max_phys_ascent
= 0;
1502 it
->descent
= it
->max_descent
= it
->phys_descent
= it
->max_phys_descent
= 1;
1506 /* Produce a stretch glyph for iterator IT. IT->object is the value
1507 of the glyph property displayed. The value must be a list
1508 `(space KEYWORD VALUE ...)' with the following KEYWORD/VALUE pairs
1511 1. `:width WIDTH' specifies that the space should be WIDTH *
1512 canonical char width wide. WIDTH may be an integer or floating
1515 2. `:align-to HPOS' specifies that the space should be wide enough
1516 to reach HPOS, a value in canonical character units. */
1519 produce_stretch_glyph (it
)
1522 /* (space :width WIDTH ...) */
1523 Lisp_Object prop
, plist
;
1524 int width
= 0, align_to
= -1;
1525 int zero_width_ok_p
= 0;
1528 /* List should start with `space'. */
1529 xassert (CONSP (it
->object
) && EQ (XCAR (it
->object
), Qspace
));
1530 plist
= XCDR (it
->object
);
1532 /* Compute the width of the stretch. */
1533 if ((prop
= Fplist_get (plist
, QCwidth
), !NILP (prop
))
1534 && calc_pixel_width_or_height (&tem
, it
, prop
, 0, 1, 0))
1536 /* Absolute width `:width WIDTH' specified and valid. */
1537 zero_width_ok_p
= 1;
1538 width
= (int)(tem
+ 0.5);
1540 else if ((prop
= Fplist_get (plist
, QCalign_to
), !NILP (prop
))
1541 && calc_pixel_width_or_height (&tem
, it
, prop
, 0, 1, &align_to
))
1543 if (it
->glyph_row
== NULL
|| !it
->glyph_row
->mode_line_p
)
1544 align_to
= (align_to
< 0
1546 : align_to
- window_box_left_offset (it
->w
, TEXT_AREA
));
1547 else if (align_to
< 0)
1548 align_to
= window_box_left_offset (it
->w
, TEXT_AREA
);
1549 width
= max (0, (int)(tem
+ 0.5) + align_to
- it
->current_x
);
1550 zero_width_ok_p
= 1;
1553 /* Nothing specified -> width defaults to canonical char width. */
1554 width
= FRAME_COLUMN_WIDTH (it
->f
);
1556 if (width
<= 0 && (width
< 0 || !zero_width_ok_p
))
1559 if (width
> 0 && it
->glyph_row
)
1561 Lisp_Object o_object
= it
->object
;
1562 Lisp_Object object
= it
->stack
[it
->sp
- 1].string
;
1565 if (!STRINGP (object
))
1566 object
= it
->w
->buffer
;
1567 it
->object
= object
;
1568 it
->char_to_display
= ' ';
1569 it
->pixel_width
= it
->len
= 1;
1572 it
->object
= o_object
;
1574 it
->pixel_width
= width
;
1575 it
->nglyphs
= width
;
1579 /* Get information about special display element WHAT in an
1580 environment described by IT. WHAT is one of IT_TRUNCATION or
1581 IT_CONTINUATION. Maybe produce glyphs for WHAT if IT has a
1582 non-null glyph_row member. This function ensures that fields like
1583 face_id, c, len of IT are left untouched. */
1586 produce_special_glyphs (it
, what
)
1588 enum display_element_type what
;
1595 temp_it
.what
= IT_CHARACTER
;
1597 temp_it
.object
= make_number (0);
1598 bzero (&temp_it
.current
, sizeof temp_it
.current
);
1600 if (what
== IT_CONTINUATION
)
1602 /* Continuation glyph. */
1604 && INTEGERP (DISP_CONTINUE_GLYPH (it
->dp
))
1605 && GLYPH_CHAR_VALID_P (XINT (DISP_CONTINUE_GLYPH (it
->dp
))))
1607 glyph
= XINT (DISP_CONTINUE_GLYPH (it
->dp
));
1608 glyph
= spec_glyph_lookup_face (XWINDOW (it
->window
), glyph
);
1613 else if (what
== IT_TRUNCATION
)
1615 /* Truncation glyph. */
1617 && INTEGERP (DISP_TRUNC_GLYPH (it
->dp
))
1618 && GLYPH_CHAR_VALID_P (XINT (DISP_TRUNC_GLYPH (it
->dp
))))
1620 glyph
= XINT (DISP_TRUNC_GLYPH (it
->dp
));
1621 glyph
= spec_glyph_lookup_face (XWINDOW (it
->window
), glyph
);
1629 temp_it
.c
= FAST_GLYPH_CHAR (glyph
);
1630 temp_it
.face_id
= FAST_GLYPH_FACE (glyph
);
1631 temp_it
.len
= CHAR_BYTES (temp_it
.c
);
1633 produce_glyphs (&temp_it
);
1634 it
->pixel_width
= temp_it
.pixel_width
;
1635 it
->nglyphs
= temp_it
.pixel_width
;
1640 /***********************************************************************
1642 ***********************************************************************/
1644 /* Value is non-zero if attribute ATTR may be used. ATTR should be
1645 one of the enumerators from enum no_color_bit, or a bit set built
1646 from them. Some display attributes may not be used together with
1647 color; the termcap capability `NC' specifies which ones. */
1649 #define MAY_USE_WITH_COLORS_P(tty, ATTR) \
1650 (tty->TN_max_colors > 0 \
1651 ? (tty->TN_no_color_video & (ATTR)) == 0 \
1654 /* Turn appearances of face FACE_ID on tty frame F on.
1655 FACE_ID is a realized face ID number, in the face cache. */
1658 turn_on_face (f
, face_id
)
1662 struct face
*face
= FACE_FROM_ID (f
, face_id
);
1663 long fg
= face
->foreground
;
1664 long bg
= face
->background
;
1665 struct tty_display_info
*tty
= FRAME_TTY (f
);
1667 /* Do this first because TS_end_standout_mode may be the same
1668 as TS_exit_attribute_mode, which turns all appearances off. */
1669 if (MAY_USE_WITH_COLORS_P (tty
, NC_REVERSE
))
1671 if (tty
->TN_max_colors
> 0)
1673 if (fg
>= 0 && bg
>= 0)
1675 /* If the terminal supports colors, we can set them
1676 below without using reverse video. The face's fg
1677 and bg colors are set as they should appear on
1678 the screen, i.e. they take the inverse-video'ness
1679 of the face already into account. */
1681 else if (inverse_video
)
1683 if (fg
== FACE_TTY_DEFAULT_FG_COLOR
1684 || bg
== FACE_TTY_DEFAULT_BG_COLOR
)
1685 tty_toggle_highlight (tty
);
1689 if (fg
== FACE_TTY_DEFAULT_BG_COLOR
1690 || bg
== FACE_TTY_DEFAULT_FG_COLOR
)
1691 tty_toggle_highlight (tty
);
1696 /* If we can't display colors, use reverse video
1697 if the face specifies that. */
1700 if (fg
== FACE_TTY_DEFAULT_FG_COLOR
1701 || bg
== FACE_TTY_DEFAULT_BG_COLOR
)
1702 tty_toggle_highlight (tty
);
1706 if (fg
== FACE_TTY_DEFAULT_BG_COLOR
1707 || bg
== FACE_TTY_DEFAULT_FG_COLOR
)
1708 tty_toggle_highlight (tty
);
1713 if (face
->tty_bold_p
)
1715 if (MAY_USE_WITH_COLORS_P (tty
, NC_BOLD
))
1716 OUTPUT1_IF (tty
, tty
->TS_enter_bold_mode
);
1718 else if (face
->tty_dim_p
)
1719 if (MAY_USE_WITH_COLORS_P (tty
, NC_DIM
))
1720 OUTPUT1_IF (tty
, tty
->TS_enter_dim_mode
);
1722 /* Alternate charset and blinking not yet used. */
1723 if (face
->tty_alt_charset_p
1724 && MAY_USE_WITH_COLORS_P (tty
, NC_ALT_CHARSET
))
1725 OUTPUT1_IF (tty
, tty
->TS_enter_alt_charset_mode
);
1727 if (face
->tty_blinking_p
1728 && MAY_USE_WITH_COLORS_P (tty
, NC_BLINK
))
1729 OUTPUT1_IF (tty
, tty
->TS_enter_blink_mode
);
1731 if (face
->tty_underline_p
&& MAY_USE_WITH_COLORS_P (tty
, NC_UNDERLINE
))
1732 OUTPUT1_IF (tty
, tty
->TS_enter_underline_mode
);
1734 if (tty
->TN_max_colors
> 0)
1738 ts
= tty
->standout_mode
? tty
->TS_set_background
: tty
->TS_set_foreground
;
1741 p
= tparam (ts
, NULL
, 0, (int) fg
);
1746 ts
= tty
->standout_mode
? tty
->TS_set_foreground
: tty
->TS_set_background
;
1749 p
= tparam (ts
, NULL
, 0, (int) bg
);
1757 /* Turn off appearances of face FACE_ID on tty frame F. */
1760 turn_off_face (f
, face_id
)
1764 struct face
*face
= FACE_FROM_ID (f
, face_id
);
1765 struct tty_display_info
*tty
= FRAME_TTY (f
);
1767 xassert (face
!= NULL
);
1769 if (tty
->TS_exit_attribute_mode
)
1771 /* Capability "me" will turn off appearance modes double-bright,
1772 half-bright, reverse-video, standout, underline. It may or
1773 may not turn off alt-char-mode. */
1774 if (face
->tty_bold_p
1776 || face
->tty_reverse_p
1777 || face
->tty_alt_charset_p
1778 || face
->tty_blinking_p
1779 || face
->tty_underline_p
)
1781 OUTPUT1_IF (tty
, tty
->TS_exit_attribute_mode
);
1782 if (strcmp (tty
->TS_exit_attribute_mode
, tty
->TS_end_standout_mode
) == 0)
1783 tty
->standout_mode
= 0;
1786 if (face
->tty_alt_charset_p
)
1787 OUTPUT_IF (tty
, tty
->TS_exit_alt_charset_mode
);
1791 /* If we don't have "me" we can only have those appearances
1792 that have exit sequences defined. */
1793 if (face
->tty_alt_charset_p
)
1794 OUTPUT_IF (tty
, tty
->TS_exit_alt_charset_mode
);
1796 if (face
->tty_underline_p
)
1797 OUTPUT_IF (tty
, tty
->TS_exit_underline_mode
);
1800 /* Switch back to default colors. */
1801 if (tty
->TN_max_colors
> 0
1802 && ((face
->foreground
!= FACE_TTY_DEFAULT_COLOR
1803 && face
->foreground
!= FACE_TTY_DEFAULT_FG_COLOR
)
1804 || (face
->background
!= FACE_TTY_DEFAULT_COLOR
1805 && face
->background
!= FACE_TTY_DEFAULT_BG_COLOR
)))
1806 OUTPUT1_IF (tty
, tty
->TS_orig_pair
);
1810 /* Return non-zero if the terminal on frame F supports all of the
1811 capabilities in CAPS simultaneously, with foreground and background
1812 colors FG and BG. */
1815 tty_capable_p (tty
, caps
, fg
, bg
)
1816 struct tty_display_info
*tty
;
1818 unsigned long fg
, bg
;
1820 #define TTY_CAPABLE_P_TRY(tty, cap, TS, NC_bit) \
1821 if ((caps & (cap)) && (!(TS) || !MAY_USE_WITH_COLORS_P(tty, NC_bit))) \
1824 TTY_CAPABLE_P_TRY (tty
, TTY_CAP_INVERSE
, tty
->TS_standout_mode
, NC_REVERSE
);
1825 TTY_CAPABLE_P_TRY (tty
, TTY_CAP_UNDERLINE
, tty
->TS_enter_underline_mode
, NC_UNDERLINE
);
1826 TTY_CAPABLE_P_TRY (tty
, TTY_CAP_BOLD
, tty
->TS_enter_bold_mode
, NC_BOLD
);
1827 TTY_CAPABLE_P_TRY (tty
, TTY_CAP_DIM
, tty
->TS_enter_dim_mode
, NC_DIM
);
1828 TTY_CAPABLE_P_TRY (tty
, TTY_CAP_BLINK
, tty
->TS_enter_blink_mode
, NC_BLINK
);
1829 TTY_CAPABLE_P_TRY (tty
, TTY_CAP_ALT_CHARSET
, tty
->TS_enter_alt_charset_mode
, NC_ALT_CHARSET
);
1835 /* Return non-zero if the terminal is capable to display colors. */
1837 DEFUN ("tty-display-color-p", Ftty_display_color_p
, Stty_display_color_p
,
1839 doc
: /* Return non-nil if the tty device TERMINAL can display colors.
1841 TERMINAL can be a terminal id, a frame or nil (meaning the selected
1842 frame's terminal). This function always returns nil if TERMINAL
1843 is not on a tty device. */)
1845 Lisp_Object terminal
;
1847 struct terminal
*t
= get_tty_terminal (terminal
, 0);
1851 return t
->display_info
.tty
->TN_max_colors
> 0 ? Qt
: Qnil
;
1854 /* Return the number of supported colors. */
1855 DEFUN ("tty-display-color-cells", Ftty_display_color_cells
,
1856 Stty_display_color_cells
, 0, 1, 0,
1857 doc
: /* Return the number of colors supported by the tty device TERMINAL.
1859 TERMINAL can be a terminal id, a frame or nil (meaning the selected
1860 frame's terminal). This function always returns 0 if TERMINAL
1861 is not on a tty device. */)
1863 Lisp_Object terminal
;
1865 struct terminal
*t
= get_tty_terminal (terminal
, 0);
1867 return make_number (0);
1869 return make_number (t
->display_info
.tty
->TN_max_colors
);
1874 /* Save or restore the default color-related capabilities of this
1877 tty_default_color_capabilities (struct tty_display_info
*tty
, int save
)
1880 *default_orig_pair
, *default_set_foreground
, *default_set_background
;
1881 static int default_max_colors
, default_max_pairs
, default_no_color_video
;
1885 if (default_orig_pair
)
1886 xfree (default_orig_pair
);
1887 default_orig_pair
= tty
->TS_orig_pair
? xstrdup (tty
->TS_orig_pair
) : NULL
;
1889 if (default_set_foreground
)
1890 xfree (default_set_foreground
);
1891 default_set_foreground
= tty
->TS_set_foreground
? xstrdup (tty
->TS_set_foreground
)
1894 if (default_set_background
)
1895 xfree (default_set_background
);
1896 default_set_background
= tty
->TS_set_background
? xstrdup (tty
->TS_set_background
)
1899 default_max_colors
= tty
->TN_max_colors
;
1900 default_max_pairs
= tty
->TN_max_pairs
;
1901 default_no_color_video
= tty
->TN_no_color_video
;
1905 tty
->TS_orig_pair
= default_orig_pair
;
1906 tty
->TS_set_foreground
= default_set_foreground
;
1907 tty
->TS_set_background
= default_set_background
;
1908 tty
->TN_max_colors
= default_max_colors
;
1909 tty
->TN_max_pairs
= default_max_pairs
;
1910 tty
->TN_no_color_video
= default_no_color_video
;
1914 /* Setup one of the standard tty color schemes according to MODE.
1915 MODE's value is generally the number of colors which we want to
1916 support; zero means set up for the default capabilities, the ones
1917 we saw at init_tty time; -1 means turn off color support. */
1919 tty_setup_colors (struct tty_display_info
*tty
, int mode
)
1921 /* Canonicalize all negative values of MODE. */
1927 case -1: /* no colors at all */
1928 tty
->TN_max_colors
= 0;
1929 tty
->TN_max_pairs
= 0;
1930 tty
->TN_no_color_video
= 0;
1931 tty
->TS_set_foreground
= tty
->TS_set_background
= tty
->TS_orig_pair
= NULL
;
1933 case 0: /* default colors, if any */
1935 tty_default_color_capabilities (tty
, 0);
1937 case 8: /* 8 standard ANSI colors */
1938 tty
->TS_orig_pair
= "\033[0m";
1940 tty
->TS_set_foreground
= "\033[3%p1%dm";
1941 tty
->TS_set_background
= "\033[4%p1%dm";
1943 tty
->TS_set_foreground
= "\033[3%dm";
1944 tty
->TS_set_background
= "\033[4%dm";
1946 tty
->TN_max_colors
= 8;
1947 tty
->TN_max_pairs
= 64;
1948 tty
->TN_no_color_video
= 0;
1954 set_tty_color_mode (f
, val
)
1958 Lisp_Object color_mode_spec
, current_mode_spec
;
1959 Lisp_Object color_mode
, current_mode
;
1961 extern Lisp_Object Qtty_color_mode
;
1962 Lisp_Object tty_color_mode_alist
;
1964 tty_color_mode_alist
= Fintern_soft (build_string ("tty-color-mode-alist"),
1971 if (NILP (tty_color_mode_alist
))
1972 color_mode_spec
= Qnil
;
1974 color_mode_spec
= Fassq (val
, XSYMBOL (tty_color_mode_alist
)->value
);
1976 if (CONSP (color_mode_spec
))
1977 color_mode
= XCDR (color_mode_spec
);
1982 current_mode_spec
= assq_no_quit (Qtty_color_mode
, f
->param_alist
);
1984 if (CONSP (current_mode_spec
))
1985 current_mode
= XCDR (current_mode_spec
);
1987 current_mode
= Qnil
;
1988 if (INTEGERP (color_mode
))
1989 mode
= XINT (color_mode
);
1991 mode
= 0; /* meaning default */
1992 if (INTEGERP (current_mode
))
1993 old_mode
= XINT (current_mode
);
1997 if (mode
!= old_mode
)
1999 tty_setup_colors (FRAME_TTY (f
), mode
);
2000 /* This recomputes all the faces given the new color
2002 call0 (intern ("tty-set-up-initial-frame-faces"));
2007 #endif /* !WINDOWSNT */
2011 /* Return the tty display object specified by TERMINAL. */
2014 get_tty_terminal (Lisp_Object terminal
, int throw)
2016 struct terminal
*t
= get_terminal (terminal
, throw);
2018 if (t
&& t
->type
== output_initial
)
2021 if (t
&& t
->type
!= output_termcap
)
2024 error ("Device %d is not a termcap terminal device", t
->id
);
2032 /* Return an active termcap device that uses the tty device with the
2035 This function ignores suspended devices.
2037 Returns NULL if the named terminal device is not opened. */
2040 get_named_tty (name
)
2048 for (t
= terminal_list
; t
; t
= t
->next_terminal
)
2050 if (t
->type
== output_termcap
2051 && !strcmp (t
->display_info
.tty
->name
, name
)
2052 && TERMINAL_ACTIVE_P (t
))
2060 DEFUN ("tty-type", Ftty_type
, Stty_type
, 0, 1, 0,
2061 doc
: /* Return the type of the tty device that TERMINAL uses.
2062 Returns nil if TERMINAL is not on a tty device.
2064 TERMINAL can be a terminal id, a frame or nil (meaning the selected
2065 frame's terminal). */)
2067 Lisp_Object terminal
;
2069 struct terminal
*t
= get_terminal (terminal
, 1);
2071 if (t
->type
!= output_termcap
)
2074 if (t
->display_info
.tty
->type
)
2075 return build_string (t
->display_info
.tty
->type
);
2080 DEFUN ("controlling-tty-p", Fcontrolling_tty_p
, Scontrolling_tty_p
, 0, 1, 0,
2081 doc
: /* Return non-nil if TERMINAL is on the controlling tty of the Emacs process.
2083 TERMINAL can be a terminal id, a frame or nil (meaning the selected
2084 frame's terminal). This function always returns nil if TERMINAL
2085 is not on a tty device. */)
2087 Lisp_Object terminal
;
2089 struct terminal
*t
= get_terminal (terminal
, 1);
2091 if (t
->type
!= output_termcap
|| strcmp (t
->display_info
.tty
->name
, "/dev/tty"))
2097 DEFUN ("tty-no-underline", Ftty_no_underline
, Stty_no_underline
, 0, 1, 0,
2098 doc
: /* Declare that the tty used by TERMINAL does not handle underlining.
2099 This is used to override the terminfo data, for certain terminals that
2100 do not really do underlining, but say that they do. This function has
2101 no effect if used on a non-tty terminal.
2103 TERMINAL can be a terminal id, a frame or nil (meaning the selected
2104 frame's terminal). This function always returns nil if TERMINAL
2105 is not on a tty device. */)
2107 Lisp_Object terminal
;
2109 struct terminal
*t
= get_terminal (terminal
, 1);
2111 if (t
->type
== output_termcap
)
2112 t
->display_info
.tty
->TS_enter_underline_mode
= 0;
2118 DEFUN ("suspend-tty", Fsuspend_tty
, Ssuspend_tty
, 0, 1, 0,
2119 doc
: /* Suspend the terminal device TTY.
2121 The device is restored to its default state, and Emacs ceases all
2122 access to the tty device. Frames that use the device are not deleted,
2123 but input is not read from them and if they change, their display is
2126 TTY may be a terminal id, a frame, or nil for the terminal device of
2127 the currently selected frame.
2129 This function runs `suspend-tty-functions' after suspending the
2130 device. The functions are run with one arg, the id of the suspended
2133 `suspend-tty' does nothing if it is called on a device that is already
2136 A suspended tty may be resumed by calling `resume-tty' on it. */)
2140 struct terminal
*t
= get_tty_terminal (tty
, 1);
2144 error ("Unknown tty device");
2146 f
= t
->display_info
.tty
->input
;
2150 reset_sys_modes (t
->display_info
.tty
);
2152 delete_keyboard_wait_descriptor (fileno (f
));
2155 if (f
!= t
->display_info
.tty
->output
)
2156 fclose (t
->display_info
.tty
->output
);
2158 t
->display_info
.tty
->input
= 0;
2159 t
->display_info
.tty
->output
= 0;
2161 if (FRAMEP (t
->display_info
.tty
->top_frame
))
2162 FRAME_SET_VISIBLE (XFRAME (t
->display_info
.tty
->top_frame
), 0);
2164 /* Run `suspend-tty-functions'. */
2165 if (!NILP (Vrun_hooks
))
2167 Lisp_Object args
[2];
2168 args
[0] = intern ("suspend-tty-functions");
2169 args
[1] = make_number (t
->id
);
2170 Frun_hook_with_args (2, args
);
2174 /* Clear display hooks to prevent further output. */
2175 clear_tty_hooks (t
);
2180 DEFUN ("resume-tty", Fresume_tty
, Sresume_tty
, 0, 1, 0,
2181 doc
: /* Resume the previously suspended terminal device TTY.
2182 The terminal is opened and reinitialized. Frames that are on the
2183 suspended terminal are revived.
2185 It is an error to resume a terminal while another terminal is active
2188 This function runs `resume-tty-functions' after resuming the terminal.
2189 The functions are run with one arg, the id of the resumed terminal
2192 `resume-tty' does nothing if it is called on a device that is not
2195 TTY may be a terminal id, a frame, or nil for the terminal device of
2196 the currently selected frame. */)
2200 struct terminal
*t
= get_tty_terminal (tty
, 1);
2204 error ("Unknown tty device");
2206 if (!t
->display_info
.tty
->input
)
2208 if (get_named_tty (t
->display_info
.tty
->name
))
2209 error ("Cannot resume display while another display is active on the same device");
2211 fd
= emacs_open (t
->display_info
.tty
->name
, O_RDWR
| O_NOCTTY
, 0);
2214 error ("Can not reopen tty device %s: %s", t
->display_info
.tty
->name
, strerror (errno
));
2216 if (strcmp (t
->display_info
.tty
->name
, "/dev/tty"))
2217 dissociate_if_controlling_tty (fd
);
2219 t
->display_info
.tty
->output
= fdopen (fd
, "w+");
2220 t
->display_info
.tty
->input
= t
->display_info
.tty
->output
;
2222 add_keyboard_wait_descriptor (fd
);
2224 if (FRAMEP (t
->display_info
.tty
->top_frame
))
2225 FRAME_SET_VISIBLE (XFRAME (t
->display_info
.tty
->top_frame
), 1);
2227 init_sys_modes (t
->display_info
.tty
);
2229 /* Run `suspend-tty-functions'. */
2230 if (!NILP (Vrun_hooks
))
2232 Lisp_Object args
[2];
2233 args
[0] = intern ("resume-tty-functions");
2234 args
[1] = make_number (t
->id
);
2235 Frun_hook_with_args (2, args
);
2245 /***********************************************************************
2247 ***********************************************************************/
2249 /* Initialize the tty-dependent part of frame F. The frame must
2250 already have its device initialized. */
2253 create_tty_output (struct frame
*f
)
2255 struct tty_output
*t
;
2257 if (! FRAME_TERMCAP_P (f
))
2260 t
= xmalloc (sizeof (struct tty_output
));
2261 bzero (t
, sizeof (struct tty_output
));
2263 t
->display_info
= FRAME_TERMINAL (f
)->display_info
.tty
;
2265 f
->output_data
.tty
= t
;
2268 /* Delete the tty-dependent part of frame F. */
2271 delete_tty_output (struct frame
*f
)
2273 if (! FRAME_TERMCAP_P (f
))
2276 xfree (f
->output_data
.tty
);
2282 clear_tty_hooks (struct terminal
*terminal
)
2285 terminal
->cursor_to_hook
= 0;
2286 terminal
->raw_cursor_to_hook
= 0;
2287 terminal
->clear_to_end_hook
= 0;
2288 terminal
->clear_frame_hook
= 0;
2289 terminal
->clear_end_of_line_hook
= 0;
2290 terminal
->ins_del_lines_hook
= 0;
2291 terminal
->insert_glyphs_hook
= 0;
2292 terminal
->write_glyphs_hook
= 0;
2293 terminal
->delete_glyphs_hook
= 0;
2294 terminal
->ring_bell_hook
= 0;
2295 terminal
->reset_terminal_modes_hook
= 0;
2296 terminal
->set_terminal_modes_hook
= 0;
2297 terminal
->update_begin_hook
= 0;
2298 terminal
->update_end_hook
= 0;
2299 terminal
->set_terminal_window_hook
= 0;
2300 terminal
->mouse_position_hook
= 0;
2301 terminal
->frame_rehighlight_hook
= 0;
2302 terminal
->frame_raise_lower_hook
= 0;
2303 terminal
->fullscreen_hook
= 0;
2304 terminal
->set_vertical_scroll_bar_hook
= 0;
2305 terminal
->condemn_scroll_bars_hook
= 0;
2306 terminal
->redeem_scroll_bar_hook
= 0;
2307 terminal
->judge_scroll_bars_hook
= 0;
2308 terminal
->read_socket_hook
= 0;
2309 terminal
->frame_up_to_date_hook
= 0;
2311 /* Leave these two set, or suspended frames are not deleted
2313 terminal
->delete_frame_hook
= &delete_tty_output
;
2314 terminal
->delete_terminal_hook
= &delete_tty
;
2318 set_tty_hooks (struct terminal
*terminal
)
2320 terminal
->rif
= 0; /* ttys don't support window-based redisplay. */
2322 terminal
->cursor_to_hook
= &tty_cursor_to
;
2323 terminal
->raw_cursor_to_hook
= &tty_raw_cursor_to
;
2325 terminal
->clear_to_end_hook
= &tty_clear_to_end
;
2326 terminal
->clear_frame_hook
= &tty_clear_frame
;
2327 terminal
->clear_end_of_line_hook
= &tty_clear_end_of_line
;
2329 terminal
->ins_del_lines_hook
= &tty_ins_del_lines
;
2331 terminal
->insert_glyphs_hook
= &tty_insert_glyphs
;
2332 terminal
->write_glyphs_hook
= &tty_write_glyphs
;
2333 terminal
->delete_glyphs_hook
= &tty_delete_glyphs
;
2335 terminal
->ring_bell_hook
= &tty_ring_bell
;
2337 terminal
->reset_terminal_modes_hook
= &tty_reset_terminal_modes
;
2338 terminal
->set_terminal_modes_hook
= &tty_set_terminal_modes
;
2339 terminal
->update_begin_hook
= 0; /* Not needed. */
2340 terminal
->update_end_hook
= &tty_update_end
;
2341 terminal
->set_terminal_window_hook
= &tty_set_terminal_window
;
2343 terminal
->mouse_position_hook
= 0; /* Not needed. */
2344 terminal
->frame_rehighlight_hook
= 0; /* Not needed. */
2345 terminal
->frame_raise_lower_hook
= 0; /* Not needed. */
2347 terminal
->set_vertical_scroll_bar_hook
= 0; /* Not needed. */
2348 terminal
->condemn_scroll_bars_hook
= 0; /* Not needed. */
2349 terminal
->redeem_scroll_bar_hook
= 0; /* Not needed. */
2350 terminal
->judge_scroll_bars_hook
= 0; /* Not needed. */
2352 terminal
->read_socket_hook
= &tty_read_avail_input
; /* keyboard.c */
2353 terminal
->frame_up_to_date_hook
= 0; /* Not needed. */
2355 terminal
->delete_frame_hook
= &delete_tty_output
;
2356 terminal
->delete_terminal_hook
= &delete_tty
;
2359 /* Drop the controlling terminal if fd is the same device. */
2361 dissociate_if_controlling_tty (int fd
)
2364 EMACS_GET_TTY_PGRP (fd
, &pgid
); /* If tcgetpgrp succeeds, fd is the ctty. */
2367 #if defined (USG) && !defined (BSD_PGRPS)
2369 no_controlling_tty
= 1;
2371 #ifdef TIOCNOTTY /* Try BSD ioctls. */
2372 sigblock (sigmask (SIGTTOU
));
2373 fd
= emacs_open ("/dev/tty", O_RDWR
, 0);
2374 if (fd
!= -1 && ioctl (fd
, TIOCNOTTY
, 0) != -1)
2376 no_controlling_tty
= 1;
2380 sigunblock (sigmask (SIGTTOU
));
2382 /* Unknown system. */
2384 #endif /* ! TIOCNOTTY */
2389 static void maybe_fatal();
2391 /* Create a termcap display on the tty device with the given name and
2394 If NAME is NULL, then use the controlling tty, i.e., "/dev/tty".
2395 Otherwise NAME should be a path to the tty device file,
2398 TERMINAL_TYPE is the termcap type of the device, e.g. "vt100".
2400 If MUST_SUCCEED is true, then all errors are fatal. */
2403 init_tty (char *name
, char *terminal_type
, int must_succeed
)
2406 char **address
= &area
;
2407 char *buffer
= NULL
;
2408 int buffer_size
= 4096;
2409 register char *p
= NULL
;
2411 struct tty_display_info
*tty
= NULL
;
2412 struct terminal
*terminal
= NULL
;
2413 int ctty
= 0; /* 1 if asked to open controlling tty. */
2416 maybe_fatal (must_succeed
, 0, 0,
2417 "Unknown terminal type",
2418 "Unknown terminal type");
2422 if (!strcmp (name
, "/dev/tty"))
2425 /* If we already have a terminal on the given device, use that. If
2426 all such terminals are suspended, create a new one instead. */
2427 /* XXX Perhaps this should be made explicit by having init_tty
2428 always create a new terminal and separating terminal and frame
2429 creation on Lisp level. */
2430 terminal
= get_named_tty (name
);
2434 terminal
= create_terminal ();
2435 tty
= (struct tty_display_info
*) xmalloc (sizeof (struct tty_display_info
));
2436 bzero (tty
, sizeof (struct tty_display_info
));
2437 tty
->next
= tty_list
;
2440 terminal
->type
= output_termcap
;
2441 terminal
->display_info
.tty
= tty
;
2442 tty
->terminal
= terminal
;
2444 tty
->Wcm
= (struct cm
*) xmalloc (sizeof (struct cm
));
2447 set_tty_hooks (terminal
);
2453 #ifdef O_IGNORE_CTTY
2455 /* Open the terminal device. Don't recognize it as our
2456 controlling terminal, and don't make it the controlling tty
2457 if we don't have one at the moment. */
2458 fd
= emacs_open (name
, O_RDWR
| O_IGNORE_CTTY
| O_NOCTTY
, 0);
2461 /* Alas, O_IGNORE_CTTY is a GNU extension that seems to be only
2462 defined on Hurd. On other systems, we need to explicitly
2463 dissociate ourselves from the controlling tty when we want to
2464 open a frame on the same terminal. */
2465 fd
= emacs_open (name
, O_RDWR
| O_NOCTTY
, 0);
2466 #endif /* O_IGNORE_CTTY */
2469 maybe_fatal (must_succeed
, buffer
, terminal
,
2470 "Could not open file: %s",
2471 "Could not open file: %s",
2476 maybe_fatal (must_succeed
, buffer
, terminal
,
2477 "Not a tty device: %s",
2478 "Not a tty device: %s",
2482 #ifndef O_IGNORE_CTTY
2484 dissociate_if_controlling_tty (fd
);
2487 file
= fdopen (fd
, "w+");
2488 tty
->name
= xstrdup (name
);
2489 terminal
->name
= xstrdup (name
);
2494 tty
->type
= xstrdup (terminal_type
);
2496 add_keyboard_wait_descriptor (fileno (tty
->input
));
2498 encode_terminal_bufsize
= 0;
2501 initialize_w32_display ();
2505 area
= (char *) xmalloc (2044);
2507 FrameRows (tty
) = FRAME_LINES (f
); /* XXX */
2508 FrameCols (tty
) = FRAME_COLS (f
); /* XXX */
2509 tty
->specified_window
= FRAME_LINES (f
); /* XXX */
2511 tty
->terminal
->delete_in_insert_mode
= 1;
2514 terminal
->scroll_region_ok
= 0;
2516 /* Seems to insert lines when it's not supposed to, messing up the
2517 display. In doing a trace, it didn't seem to be called much, so I
2518 don't think we're losing anything by turning it off. */
2519 terminal
->line_ins_del_ok
= 0;
2520 terminal
->char_ins_del_ok
= 1;
2524 FRAME_CAN_HAVE_SCROLL_BARS (f
) = 0; /* XXX */
2525 FRAME_VERTICAL_SCROLL_BAR_TYPE (f
) = vertical_scroll_bar_none
; /* XXX */
2526 TN_max_colors
= 16; /* Required to be non-zero for tty-display-color-p */
2529 #else /* not WINDOWSNT */
2533 buffer
= (char *) xmalloc (buffer_size
);
2535 /* On some systems, tgetent tries to access the controlling
2537 sigblock (sigmask (SIGTTOU
));
2538 status
= tgetent (buffer
, terminal_type
);
2539 sigunblock (sigmask (SIGTTOU
));
2544 maybe_fatal (must_succeed
, buffer
, terminal
,
2545 "Cannot open terminfo database file",
2546 "Cannot open terminfo database file");
2548 maybe_fatal (must_succeed
, buffer
, terminal
,
2549 "Cannot open termcap database file",
2550 "Cannot open termcap database file");
2556 maybe_fatal (must_succeed
, buffer
, terminal
,
2557 "Terminal type %s is not defined",
2558 "Terminal type %s is not defined.\n\
2559 If that is not the actual type of terminal you have,\n\
2560 use the Bourne shell command `TERM=... export TERM' (C-shell:\n\
2561 `setenv TERM ...') to specify the correct type. It may be necessary\n\
2562 to do `unset TERMINFO' (C-shell: `unsetenv TERMINFO') as well.",
2565 maybe_fatal (must_succeed
, buffer
, terminal
,
2566 "Terminal type %s is not defined",
2567 "Terminal type %s is not defined.\n\
2568 If that is not the actual type of terminal you have,\n\
2569 use the Bourne shell command `TERM=... export TERM' (C-shell:\n\
2570 `setenv TERM ...') to specify the correct type. It may be necessary\n\
2571 to do `unset TERMCAP' (C-shell: `unsetenv TERMCAP') as well.",
2577 if (strlen (buffer
) >= buffer_size
)
2579 buffer_size
= strlen (buffer
);
2581 area
= (char *) xmalloc (buffer_size
);
2583 tty
->TS_ins_line
= tgetstr ("al", address
);
2584 tty
->TS_ins_multi_lines
= tgetstr ("AL", address
);
2585 tty
->TS_bell
= tgetstr ("bl", address
);
2586 BackTab (tty
) = tgetstr ("bt", address
);
2587 tty
->TS_clr_to_bottom
= tgetstr ("cd", address
);
2588 tty
->TS_clr_line
= tgetstr ("ce", address
);
2589 tty
->TS_clr_frame
= tgetstr ("cl", address
);
2590 ColPosition (tty
) = NULL
; /* tgetstr ("ch", address); */
2591 AbsPosition (tty
) = tgetstr ("cm", address
);
2592 CR (tty
) = tgetstr ("cr", address
);
2593 tty
->TS_set_scroll_region
= tgetstr ("cs", address
);
2594 tty
->TS_set_scroll_region_1
= tgetstr ("cS", address
);
2595 RowPosition (tty
) = tgetstr ("cv", address
);
2596 tty
->TS_del_char
= tgetstr ("dc", address
);
2597 tty
->TS_del_multi_chars
= tgetstr ("DC", address
);
2598 tty
->TS_del_line
= tgetstr ("dl", address
);
2599 tty
->TS_del_multi_lines
= tgetstr ("DL", address
);
2600 tty
->TS_delete_mode
= tgetstr ("dm", address
);
2601 tty
->TS_end_delete_mode
= tgetstr ("ed", address
);
2602 tty
->TS_end_insert_mode
= tgetstr ("ei", address
);
2603 Home (tty
) = tgetstr ("ho", address
);
2604 tty
->TS_ins_char
= tgetstr ("ic", address
);
2605 tty
->TS_ins_multi_chars
= tgetstr ("IC", address
);
2606 tty
->TS_insert_mode
= tgetstr ("im", address
);
2607 tty
->TS_pad_inserted_char
= tgetstr ("ip", address
);
2608 tty
->TS_end_keypad_mode
= tgetstr ("ke", address
);
2609 tty
->TS_keypad_mode
= tgetstr ("ks", address
);
2610 LastLine (tty
) = tgetstr ("ll", address
);
2611 Right (tty
) = tgetstr ("nd", address
);
2612 Down (tty
) = tgetstr ("do", address
);
2614 Down (tty
) = tgetstr ("nl", address
); /* Obsolete name for "do" */
2616 /* VMS puts a carriage return before each linefeed,
2617 so it is not safe to use linefeeds. */
2618 if (Down (tty
) && Down (tty
)[0] == '\n' && Down (tty
)[1] == '\0')
2621 if (tgetflag ("bs"))
2622 Left (tty
) = "\b"; /* can't possibly be longer! */
2623 else /* (Actually, "bs" is obsolete...) */
2624 Left (tty
) = tgetstr ("le", address
);
2626 Left (tty
) = tgetstr ("bc", address
); /* Obsolete name for "le" */
2627 tty
->TS_pad_char
= tgetstr ("pc", address
);
2628 tty
->TS_repeat
= tgetstr ("rp", address
);
2629 tty
->TS_end_standout_mode
= tgetstr ("se", address
);
2630 tty
->TS_fwd_scroll
= tgetstr ("sf", address
);
2631 tty
->TS_standout_mode
= tgetstr ("so", address
);
2632 tty
->TS_rev_scroll
= tgetstr ("sr", address
);
2633 tty
->Wcm
->cm_tab
= tgetstr ("ta", address
);
2634 tty
->TS_end_termcap_modes
= tgetstr ("te", address
);
2635 tty
->TS_termcap_modes
= tgetstr ("ti", address
);
2636 Up (tty
) = tgetstr ("up", address
);
2637 tty
->TS_visible_bell
= tgetstr ("vb", address
);
2638 tty
->TS_cursor_normal
= tgetstr ("ve", address
);
2639 tty
->TS_cursor_visible
= tgetstr ("vs", address
);
2640 tty
->TS_cursor_invisible
= tgetstr ("vi", address
);
2641 tty
->TS_set_window
= tgetstr ("wi", address
);
2643 tty
->TS_enter_underline_mode
= tgetstr ("us", address
);
2644 tty
->TS_exit_underline_mode
= tgetstr ("ue", address
);
2645 tty
->TS_enter_bold_mode
= tgetstr ("md", address
);
2646 tty
->TS_enter_dim_mode
= tgetstr ("mh", address
);
2647 tty
->TS_enter_blink_mode
= tgetstr ("mb", address
);
2648 tty
->TS_enter_reverse_mode
= tgetstr ("mr", address
);
2649 tty
->TS_enter_alt_charset_mode
= tgetstr ("as", address
);
2650 tty
->TS_exit_alt_charset_mode
= tgetstr ("ae", address
);
2651 tty
->TS_exit_attribute_mode
= tgetstr ("me", address
);
2653 MultiUp (tty
) = tgetstr ("UP", address
);
2654 MultiDown (tty
) = tgetstr ("DO", address
);
2655 MultiLeft (tty
) = tgetstr ("LE", address
);
2656 MultiRight (tty
) = tgetstr ("RI", address
);
2658 /* SVr4/ANSI color suppert. If "op" isn't available, don't support
2659 color because we can't switch back to the default foreground and
2661 tty
->TS_orig_pair
= tgetstr ("op", address
);
2662 if (tty
->TS_orig_pair
)
2664 tty
->TS_set_foreground
= tgetstr ("AF", address
);
2665 tty
->TS_set_background
= tgetstr ("AB", address
);
2666 if (!tty
->TS_set_foreground
)
2669 tty
->TS_set_foreground
= tgetstr ("Sf", address
);
2670 tty
->TS_set_background
= tgetstr ("Sb", address
);
2673 tty
->TN_max_colors
= tgetnum ("Co");
2674 tty
->TN_max_pairs
= tgetnum ("pa");
2676 tty
->TN_no_color_video
= tgetnum ("NC");
2677 if (tty
->TN_no_color_video
== -1)
2678 tty
->TN_no_color_video
= 0;
2681 tty_default_color_capabilities (tty
, 1);
2683 MagicWrap (tty
) = tgetflag ("xn");
2684 /* Since we make MagicWrap terminals look like AutoWrap, we need to have
2685 the former flag imply the latter. */
2686 AutoWrap (tty
) = MagicWrap (tty
) || tgetflag ("am");
2687 terminal
->memory_below_frame
= tgetflag ("db");
2688 tty
->TF_hazeltine
= tgetflag ("hz");
2689 terminal
->must_write_spaces
= tgetflag ("in");
2690 tty
->meta_key
= tgetflag ("km") || tgetflag ("MT");
2691 tty
->TF_insmode_motion
= tgetflag ("mi");
2692 tty
->TF_standout_motion
= tgetflag ("ms");
2693 tty
->TF_underscore
= tgetflag ("ul");
2694 tty
->TF_teleray
= tgetflag ("xt");
2697 terminal
->kboard
= (KBOARD
*) xmalloc (sizeof (KBOARD
));
2698 init_kboard (terminal
->kboard
);
2699 terminal
->kboard
->next_kboard
= all_kboards
;
2700 all_kboards
= terminal
->kboard
;
2701 terminal
->kboard
->reference_count
++;
2702 /* Don't let the initial kboard remain current longer than necessary.
2703 That would cause problems if a file loaded on startup tries to
2704 prompt in the mini-buffer. */
2705 if (current_kboard
== initial_kboard
)
2706 current_kboard
= terminal
->kboard
;
2709 term_get_fkeys (address
, terminal
->kboard
);
2711 /* Get frame size from system, or else from termcap. */
2714 get_tty_size (fileno (tty
->input
), &width
, &height
);
2715 FrameCols (tty
) = width
;
2716 FrameRows (tty
) = height
;
2719 if (FrameCols (tty
) <= 0)
2720 FrameCols (tty
) = tgetnum ("co");
2721 if (FrameRows (tty
) <= 0)
2722 FrameRows (tty
) = tgetnum ("li");
2724 if (FrameRows (tty
) < 3 || FrameCols (tty
) < 3)
2725 maybe_fatal (must_succeed
, NULL
, terminal
,
2726 "Screen size %dx%d is too small"
2727 "Screen size %dx%d is too small",
2728 FrameCols (tty
), FrameRows (tty
));
2730 #if 0 /* This is not used anywhere. */
2731 tty
->terminal
->min_padding_speed
= tgetnum ("pb");
2734 TabWidth (tty
) = tgetnum ("tw");
2737 /* These capabilities commonly use ^J.
2738 I don't know why, but sending them on VMS does not work;
2739 it causes following spaces to be lost, sometimes.
2740 For now, the simplest fix is to avoid using these capabilities ever. */
2741 if (Down (tty
) && Down (tty
)[0] == '\n')
2746 tty
->TS_bell
= "\07";
2748 if (!tty
->TS_fwd_scroll
)
2749 tty
->TS_fwd_scroll
= Down (tty
);
2751 PC
= tty
->TS_pad_char
? *tty
->TS_pad_char
: 0;
2753 if (TabWidth (tty
) < 0)
2756 /* Turned off since /etc/termcap seems to have :ta= for most terminals
2757 and newer termcap doc does not seem to say there is a default.
2758 if (!tty->Wcm->cm_tab)
2759 tty->Wcm->cm_tab = "\t";
2762 /* We don't support standout modes that use `magic cookies', so
2763 turn off any that do. */
2764 if (tty
->TS_standout_mode
&& tgetnum ("sg") >= 0)
2766 tty
->TS_standout_mode
= 0;
2767 tty
->TS_end_standout_mode
= 0;
2769 if (tty
->TS_enter_underline_mode
&& tgetnum ("ug") >= 0)
2771 tty
->TS_enter_underline_mode
= 0;
2772 tty
->TS_exit_underline_mode
= 0;
2775 /* If there's no standout mode, try to use underlining instead. */
2776 if (tty
->TS_standout_mode
== 0)
2778 tty
->TS_standout_mode
= tty
->TS_enter_underline_mode
;
2779 tty
->TS_end_standout_mode
= tty
->TS_exit_underline_mode
;
2782 /* If no `se' string, try using a `me' string instead.
2783 If that fails, we can't use standout mode at all. */
2784 if (tty
->TS_end_standout_mode
== 0)
2786 char *s
= tgetstr ("me", address
);
2788 tty
->TS_end_standout_mode
= s
;
2790 tty
->TS_standout_mode
= 0;
2793 if (tty
->TF_teleray
)
2795 tty
->Wcm
->cm_tab
= 0;
2796 /* We can't support standout mode, because it uses magic cookies. */
2797 tty
->TS_standout_mode
= 0;
2798 /* But that means we cannot rely on ^M to go to column zero! */
2800 /* LF can't be trusted either -- can alter hpos */
2801 /* if move at column 0 thru a line with TS_standout_mode */
2805 /* Special handling for certain terminal types known to need it */
2807 if (!strcmp (terminal_type
, "supdup"))
2809 terminal
->memory_below_frame
= 1;
2810 tty
->Wcm
->cm_losewrap
= 1;
2812 if (!strncmp (terminal_type
, "c10", 3)
2813 || !strcmp (terminal_type
, "perq"))
2815 /* Supply a makeshift :wi string.
2816 This string is not valid in general since it works only
2817 for windows starting at the upper left corner;
2818 but that is all Emacs uses.
2820 This string works only if the frame is using
2821 the top of the video memory, because addressing is memory-relative.
2822 So first check the :ti string to see if that is true.
2824 It would be simpler if the :wi string could go in the termcap
2825 entry, but it can't because it is not fully valid.
2826 If it were in the termcap entry, it would confuse other programs. */
2827 if (!tty
->TS_set_window
)
2829 p
= tty
->TS_termcap_modes
;
2830 while (*p
&& strcmp (p
, "\033v "))
2833 tty
->TS_set_window
= "\033v%C %C %C %C ";
2835 /* Termcap entry often fails to have :in: flag */
2836 terminal
->must_write_spaces
= 1;
2837 /* :ti string typically fails to have \E^G! in it */
2838 /* This limits scope of insert-char to one line. */
2839 strcpy (area
, tty
->TS_termcap_modes
);
2840 strcat (area
, "\033\007!");
2841 tty
->TS_termcap_modes
= area
;
2842 area
+= strlen (area
) + 1;
2843 p
= AbsPosition (tty
);
2844 /* Change all %+ parameters to %C, to handle
2845 values above 96 correctly for the C100. */
2848 if (p
[0] == '%' && p
[1] == '+')
2854 tty
->specified_window
= FrameRows (tty
);
2856 if (Wcm_init (tty
) == -1) /* can't do cursor motion */
2858 maybe_fatal (must_succeed
, NULL
, terminal
,
2859 "Terminal type \"%s\" is not powerful enough to run Emacs",
2861 "Terminal type \"%s\" is not powerful enough to run Emacs.\n\
2862 It lacks the ability to position the cursor.\n\
2863 If that is not the actual type of terminal you have, use either the\n\
2864 DCL command `SET TERMINAL/DEVICE= ...' for DEC-compatible terminals,\n\
2865 or `define EMACS_TERM \"terminal type\"' for non-DEC terminals.",
2868 "Terminal type \"%s\" is not powerful enough to run Emacs.\n\
2869 It lacks the ability to position the cursor.\n\
2870 If that is not the actual type of terminal you have,\n\
2871 use the Bourne shell command `TERM=... export TERM' (C-shell:\n\
2872 `setenv TERM ...') to specify the correct type. It may be necessary\n\
2873 to do `unset TERMINFO' (C-shell: `unsetenv TERMINFO') as well.",
2874 # else /* TERMCAP */
2875 "Terminal type \"%s\" is not powerful enough to run Emacs.\n\
2876 It lacks the ability to position the cursor.\n\
2877 If that is not the actual type of terminal you have,\n\
2878 use the Bourne shell command `TERM=... export TERM' (C-shell:\n\
2879 `setenv TERM ...') to specify the correct type. It may be necessary\n\
2880 to do `unset TERMCAP' (C-shell: `unsetenv TERMCAP') as well.",
2881 # endif /* TERMINFO */
2886 if (FrameRows (tty
) <= 0 || FrameCols (tty
) <= 0)
2887 maybe_fatal (must_succeed
, NULL
, terminal
,
2888 "Could not determine the frame size",
2889 "Could not determine the frame size");
2891 tty
->delete_in_insert_mode
2892 = tty
->TS_delete_mode
&& tty
->TS_insert_mode
2893 && !strcmp (tty
->TS_delete_mode
, tty
->TS_insert_mode
);
2895 tty
->se_is_so
= (tty
->TS_standout_mode
2896 && tty
->TS_end_standout_mode
2897 && !strcmp (tty
->TS_standout_mode
, tty
->TS_end_standout_mode
));
2899 UseTabs (tty
) = tabs_safe_p (fileno (tty
->input
)) && TabWidth (tty
) == 8;
2901 terminal
->scroll_region_ok
2903 && (tty
->TS_set_window
|| tty
->TS_set_scroll_region
|| tty
->TS_set_scroll_region_1
));
2905 terminal
->line_ins_del_ok
2906 = (((tty
->TS_ins_line
|| tty
->TS_ins_multi_lines
)
2907 && (tty
->TS_del_line
|| tty
->TS_del_multi_lines
))
2908 || (terminal
->scroll_region_ok
2909 && tty
->TS_fwd_scroll
&& tty
->TS_rev_scroll
));
2911 terminal
->char_ins_del_ok
2912 = ((tty
->TS_ins_char
|| tty
->TS_insert_mode
2913 || tty
->TS_pad_inserted_char
|| tty
->TS_ins_multi_chars
)
2914 && (tty
->TS_del_char
|| tty
->TS_del_multi_chars
));
2916 terminal
->fast_clear_end_of_line
= tty
->TS_clr_line
!= 0;
2918 init_baud_rate (fileno (tty
->input
));
2921 /* The HFT system on AIX doesn't optimize for scrolling, so it's
2922 really ugly at times. */
2923 terminal
->line_ins_del_ok
= 0;
2924 terminal
->char_ins_del_ok
= 0;
2927 /* Don't do this. I think termcap may still need the buffer. */
2928 /* xfree (buffer); */
2930 /* Init system terminal modes (RAW or CBREAK, etc.). */
2931 init_sys_modes (tty
);
2934 #endif /* not WINDOWSNT */
2937 /* Auxiliary error-handling function for init_tty.
2938 Free BUFFER and delete TERMINAL, then call error or fatal
2939 with str1 or str2, respectively, according to MUST_SUCCEED. */
2942 maybe_fatal (must_succeed
, buffer
, terminal
, str1
, str2
, arg1
, arg2
)
2945 struct terminal
*terminal
;
2946 char *str1
, *str2
, *arg1
, *arg2
;
2952 delete_tty (terminal
);
2955 fatal (str2
, arg1
, arg2
);
2957 error (str1
, arg1
, arg2
);
2964 fatal (str
, arg1
, arg2
)
2965 char *str
, *arg1
, *arg2
;
2967 fprintf (stderr
, "emacs: ");
2968 fprintf (stderr
, str
, arg1
, arg2
);
2969 fprintf (stderr
, "\n");
2976 /* Delete the given tty terminal, closing all frames on it. */
2979 delete_tty (struct terminal
*terminal
)
2981 struct tty_display_info
*tty
;
2982 Lisp_Object tail
, frame
;
2985 /* Protect against recursive calls. Fdelete_frame in
2986 delete_terminal calls us back when it deletes our last frame. */
2987 if (terminal
->deleted
)
2990 if (terminal
->type
!= output_termcap
)
2993 tty
= terminal
->display_info
.tty
;
2996 FOR_EACH_FRAME (tail
, frame
)
2998 struct frame
*f
= XFRAME (frame
);
2999 if (FRAME_LIVE_P (f
) && (!FRAME_TERMCAP_P (f
) || FRAME_TTY (f
) != tty
))
3006 error ("Attempt to delete the sole terminal device with live frames");
3008 if (tty
== tty_list
)
3009 tty_list
= tty
->next
;
3012 struct tty_display_info
*p
;
3013 for (p
= tty_list
; p
&& p
->next
!= tty
; p
= p
->next
)
3017 /* This should not happen. */
3020 p
->next
= tty
->next
;
3024 /* reset_sys_modes needs a valid device, so this call needs to be
3025 before delete_terminal. */
3026 reset_sys_modes (tty
);
3028 delete_terminal (terminal
);
3038 delete_keyboard_wait_descriptor (fileno (tty
->input
));
3039 if (tty
->input
!= stdin
)
3040 fclose (tty
->input
);
3042 if (tty
->output
&& tty
->output
!= stdout
&& tty
->output
!= tty
->input
)
3043 fclose (tty
->output
);
3044 if (tty
->termscript
)
3045 fclose (tty
->termscript
);
3048 xfree (tty
->old_tty
);
3053 bzero (tty
, sizeof (struct tty_display_info
));
3059 /* Mark the pointers in the tty_display_info objects.
3060 Called by the Fgarbage_collector. */
3065 struct tty_display_info
*tty
;
3067 for (tty
= tty_list
; tty
; tty
= tty
->next
)
3070 mark_object (tty
->top_frame
);
3079 DEFVAR_BOOL ("system-uses-terminfo", &system_uses_terminfo
,
3080 doc
: /* Non-nil means the system uses terminfo rather than termcap.
3081 This variable can be used by terminal emulator packages. */);
3083 system_uses_terminfo
= 1;
3085 system_uses_terminfo
= 0;
3088 DEFVAR_LISP ("suspend-tty-functions", &Vsuspend_tty_functions
,
3089 doc
: /* Functions to be run after suspending a tty.
3090 The functions are run with one argument, the terminal id to be suspended.
3091 See `suspend-tty'. */);
3092 Vsuspend_tty_functions
= Qnil
;
3095 DEFVAR_LISP ("resume-tty-functions", &Vresume_tty_functions
,
3096 doc
: /* Functions to be run after resuming a tty.
3097 The functions are run with one argument, the terminal id that was revived.
3098 See `resume-tty'. */);
3099 Vresume_tty_functions
= Qnil
;
3101 DEFVAR_BOOL ("visible-cursor", &visible_cursor
,
3102 doc
: /* Non-nil means to make the cursor very visible.
3103 This only has an effect when running in a text terminal.
3104 What means \"very visible\" is up to your terminal. It may make the cursor
3105 bigger, or it may make it blink, or it may do nothing at all. */);
3108 defsubr (&Stty_display_color_p
);
3109 defsubr (&Stty_display_color_cells
);
3110 defsubr (&Stty_no_underline
);
3111 defsubr (&Stty_type
);
3112 defsubr (&Scontrolling_tty_p
);
3113 defsubr (&Ssuspend_tty
);
3114 defsubr (&Sresume_tty
);
3119 /* arch-tag: 498e7449-6f2e-45e2-91dd-b7d4ca488193
3120 (do not change this comment) */