1 /* Terminal control module for terminals described by TERMCAP
2 Copyright (C) 1985-1987, 1993-1995, 1998, 2000-2011
3 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 3 of the License, or
10 (at your option) any later version.
12 GNU Emacs is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
20 /* New redisplay, TTY faces by Gerd Moellmann <gerd@gnu.org>. */
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;
70 /* The name of the default console device. */
72 #define DEV_TTY "CONOUT$"
74 #define DEV_TTY "/dev/tty"
77 static void tty_set_scroll_region (struct frame
*f
, int start
, int stop
);
78 static void turn_on_face (struct frame
*, int face_id
);
79 static void turn_off_face (struct frame
*, int face_id
);
80 static void tty_show_cursor (struct tty_display_info
*);
81 static void tty_hide_cursor (struct tty_display_info
*);
82 static void tty_background_highlight (struct tty_display_info
*tty
);
83 static void clear_tty_hooks (struct terminal
*terminal
);
84 static void set_tty_hooks (struct terminal
*terminal
);
85 static void dissociate_if_controlling_tty (int fd
);
86 static void delete_tty (struct terminal
*);
87 static void maybe_fatal (int must_succeed
, struct terminal
*terminal
,
88 const char *str1
, const char *str2
, ...) NO_RETURN
;
89 static void vfatal (const char *str
, va_list ap
) NO_RETURN
;
92 #define OUTPUT(tty, a) \
93 emacs_tputs ((tty), a, \
94 (int) (FRAME_LINES (XFRAME (selected_frame)) \
98 #define OUTPUT1(tty, a) emacs_tputs ((tty), a, 1, cmputc)
99 #define OUTPUTL(tty, a, lines) emacs_tputs ((tty), a, lines, cmputc)
101 #define OUTPUT_IF(tty, a) \
107 #define OUTPUT1_IF(tty, a) do { if (a) emacs_tputs ((tty), a, 1, cmputc); } while (0)
109 /* Display space properties */
111 /* Chain of all tty device parameters. */
112 struct tty_display_info
*tty_list
;
114 /* Meaning of bits in no_color_video. Each bit set means that the
115 corresponding attribute cannot be combined with colors. */
119 NC_STANDOUT
= 1 << 0,
120 NC_UNDERLINE
= 1 << 1,
127 NC_ALT_CHARSET
= 1 << 8
132 /* The largest frame width in any call to calculate_costs. */
136 /* The largest frame height in any call to calculate_costs. */
140 /* Non-zero if we have dropped our controlling tty and therefore
141 should not open a frame on stdout. */
142 static int no_controlling_tty
;
147 #include <sys/fcntl.h>
149 /* The device for which we have enabled gpm support (or NULL). */
150 struct tty_display_info
*gpm_tty
= NULL
;
152 /* Last recorded mouse coordinates. */
153 static int last_mouse_x
, last_mouse_y
;
154 #endif /* HAVE_GPM */
156 /* Ring the bell on a tty. */
159 tty_ring_bell (struct frame
*f
)
161 struct tty_display_info
*tty
= FRAME_TTY (f
);
165 OUTPUT (tty
, (tty
->TS_visible_bell
&& visible_bell
166 ? tty
->TS_visible_bell
168 fflush (tty
->output
);
172 /* Set up termcap modes for Emacs. */
175 tty_set_terminal_modes (struct terminal
*terminal
)
177 struct tty_display_info
*tty
= terminal
->display_info
.tty
;
181 if (tty
->TS_termcap_modes
)
182 OUTPUT (tty
, tty
->TS_termcap_modes
);
185 /* Output enough newlines to scroll all the old screen contents
186 off the screen, so it won't be overwritten and lost. */
189 for (i
= 0; i
< FRAME_LINES (XFRAME (selected_frame
)); i
++)
193 OUTPUT_IF (tty
, visible_cursor
? tty
->TS_cursor_visible
: tty
->TS_cursor_normal
);
194 OUTPUT_IF (tty
, tty
->TS_keypad_mode
);
196 fflush (tty
->output
);
200 /* Reset termcap modes before exiting Emacs. */
203 tty_reset_terminal_modes (struct terminal
*terminal
)
205 struct tty_display_info
*tty
= terminal
->display_info
.tty
;
209 tty_turn_off_highlight (tty
);
210 tty_turn_off_insert (tty
);
211 OUTPUT_IF (tty
, tty
->TS_end_keypad_mode
);
212 OUTPUT_IF (tty
, tty
->TS_cursor_normal
);
213 OUTPUT_IF (tty
, tty
->TS_end_termcap_modes
);
214 OUTPUT_IF (tty
, tty
->TS_orig_pair
);
215 /* Output raw CR so kernel can track the cursor hpos. */
218 fflush (tty
->output
);
222 /* Flag the end of a display update on a termcap terminal. */
225 tty_update_end (struct frame
*f
)
227 struct tty_display_info
*tty
= FRAME_TTY (f
);
229 if (!XWINDOW (selected_window
)->cursor_off_p
)
230 tty_show_cursor (tty
);
231 tty_turn_off_insert (tty
);
232 tty_background_highlight (tty
);
235 /* The implementation of set_terminal_window for termcap frames. */
238 tty_set_terminal_window (struct frame
*f
, int size
)
240 struct tty_display_info
*tty
= FRAME_TTY (f
);
242 tty
->specified_window
= size
? size
: FRAME_LINES (f
);
243 if (FRAME_SCROLL_REGION_OK (f
))
244 tty_set_scroll_region (f
, 0, tty
->specified_window
);
248 tty_set_scroll_region (struct frame
*f
, int start
, int stop
)
251 struct tty_display_info
*tty
= FRAME_TTY (f
);
253 if (tty
->TS_set_scroll_region
)
254 buf
= tparam (tty
->TS_set_scroll_region
, 0, 0, start
, stop
- 1, 0, 0);
255 else if (tty
->TS_set_scroll_region_1
)
256 buf
= tparam (tty
->TS_set_scroll_region_1
, 0, 0,
257 FRAME_LINES (f
), start
,
258 FRAME_LINES (f
) - stop
,
261 buf
= tparam (tty
->TS_set_window
, 0, 0, start
, 0, stop
, FRAME_COLS (f
));
270 tty_turn_on_insert (struct tty_display_info
*tty
)
272 if (!tty
->insert_mode
)
273 OUTPUT (tty
, tty
->TS_insert_mode
);
274 tty
->insert_mode
= 1;
278 tty_turn_off_insert (struct tty_display_info
*tty
)
280 if (tty
->insert_mode
)
281 OUTPUT (tty
, tty
->TS_end_insert_mode
);
282 tty
->insert_mode
= 0;
285 /* Handle highlighting. */
288 tty_turn_off_highlight (struct tty_display_info
*tty
)
290 if (tty
->standout_mode
)
291 OUTPUT_IF (tty
, tty
->TS_end_standout_mode
);
292 tty
->standout_mode
= 0;
296 tty_turn_on_highlight (struct tty_display_info
*tty
)
298 if (!tty
->standout_mode
)
299 OUTPUT_IF (tty
, tty
->TS_standout_mode
);
300 tty
->standout_mode
= 1;
304 tty_toggle_highlight (struct tty_display_info
*tty
)
306 if (tty
->standout_mode
)
307 tty_turn_off_highlight (tty
);
309 tty_turn_on_highlight (tty
);
313 /* Make cursor invisible. */
316 tty_hide_cursor (struct tty_display_info
*tty
)
318 if (tty
->cursor_hidden
== 0)
320 tty
->cursor_hidden
= 1;
321 OUTPUT_IF (tty
, tty
->TS_cursor_invisible
);
326 /* Ensure that cursor is visible. */
329 tty_show_cursor (struct tty_display_info
*tty
)
331 if (tty
->cursor_hidden
)
333 tty
->cursor_hidden
= 0;
334 OUTPUT_IF (tty
, tty
->TS_cursor_normal
);
336 OUTPUT_IF (tty
, tty
->TS_cursor_visible
);
341 /* Set standout mode to the state it should be in for
342 empty space inside windows. What this is,
343 depends on the user option inverse-video. */
346 tty_background_highlight (struct tty_display_info
*tty
)
349 tty_turn_on_highlight (tty
);
351 tty_turn_off_highlight (tty
);
354 /* Set standout mode to the mode specified for the text to be output. */
357 tty_highlight_if_desired (struct tty_display_info
*tty
)
360 tty_turn_on_highlight (tty
);
362 tty_turn_off_highlight (tty
);
366 /* Move cursor to row/column position VPOS/HPOS. HPOS/VPOS are
367 frame-relative coordinates. */
370 tty_cursor_to (struct frame
*f
, int vpos
, int hpos
)
372 struct tty_display_info
*tty
= FRAME_TTY (f
);
374 /* Detect the case where we are called from reset_sys_modes
375 and the costs have never been calculated. Do nothing. */
376 if (! tty
->costs_set
)
379 if (curY (tty
) == vpos
380 && curX (tty
) == hpos
)
382 if (!tty
->TF_standout_motion
)
383 tty_background_highlight (tty
);
384 if (!tty
->TF_insmode_motion
)
385 tty_turn_off_insert (tty
);
386 cmgoto (tty
, vpos
, hpos
);
389 /* Similar but don't take any account of the wasted characters. */
392 tty_raw_cursor_to (struct frame
*f
, int row
, int col
)
394 struct tty_display_info
*tty
= FRAME_TTY (f
);
396 if (curY (tty
) == row
397 && curX (tty
) == col
)
399 if (!tty
->TF_standout_motion
)
400 tty_background_highlight (tty
);
401 if (!tty
->TF_insmode_motion
)
402 tty_turn_off_insert (tty
);
403 cmgoto (tty
, row
, col
);
406 /* Erase operations */
408 /* Clear from cursor to end of frame on a termcap device. */
411 tty_clear_to_end (struct frame
*f
)
414 struct tty_display_info
*tty
= FRAME_TTY (f
);
416 if (tty
->TS_clr_to_bottom
)
418 tty_background_highlight (tty
);
419 OUTPUT (tty
, tty
->TS_clr_to_bottom
);
423 for (i
= curY (tty
); i
< FRAME_LINES (f
); i
++)
426 clear_end_of_line (f
, FRAME_COLS (f
));
431 /* Clear an entire termcap frame. */
434 tty_clear_frame (struct frame
*f
)
436 struct tty_display_info
*tty
= FRAME_TTY (f
);
438 if (tty
->TS_clr_frame
)
440 tty_background_highlight (tty
);
441 OUTPUT (tty
, tty
->TS_clr_frame
);
451 /* An implementation of clear_end_of_line for termcap frames.
453 Note that the cursor may be moved, on terminals lacking a `ce' string. */
456 tty_clear_end_of_line (struct frame
*f
, int first_unused_hpos
)
459 struct tty_display_info
*tty
= FRAME_TTY (f
);
461 /* Detect the case where we are called from reset_sys_modes
462 and the costs have never been calculated. Do nothing. */
463 if (! tty
->costs_set
)
466 if (curX (tty
) >= first_unused_hpos
)
468 tty_background_highlight (tty
);
469 if (tty
->TS_clr_line
)
471 OUTPUT1 (tty
, tty
->TS_clr_line
);
474 { /* have to do it the hard way */
475 tty_turn_off_insert (tty
);
477 /* Do not write in last row last col with Auto-wrap on. */
479 && curY (tty
) == FrameRows (tty
) - 1
480 && first_unused_hpos
== FrameCols (tty
))
483 for (i
= curX (tty
); i
< first_unused_hpos
; i
++)
486 fputc (' ', tty
->termscript
);
487 fputc (' ', tty
->output
);
489 cmplus (tty
, first_unused_hpos
- curX (tty
));
493 /* Buffers to store the source and result of code conversion for terminal. */
494 static unsigned char *encode_terminal_src
;
495 static unsigned char *encode_terminal_dst
;
496 /* Allocated sizes of the above buffers. */
497 static int encode_terminal_src_size
;
498 static int encode_terminal_dst_size
;
500 /* Encode SRC_LEN glyphs starting at SRC to terminal output codes.
501 Set CODING->produced to the byte-length of the resulting byte
502 sequence, and return a pointer to that byte sequence. */
505 encode_terminal_code (struct glyph
*src
, int src_len
, struct coding_system
*coding
)
507 struct glyph
*src_end
= src
+ src_len
;
509 int nchars
, nbytes
, required
;
510 register int tlen
= GLYPH_TABLE_LENGTH
;
511 register Lisp_Object
*tbase
= GLYPH_TABLE_BASE
;
512 Lisp_Object charset_list
;
514 /* Allocate sufficient size of buffer to store all characters in
515 multibyte-form. But, it may be enlarged on demand if
516 Vglyph_table contains a string or a composite glyph is
518 required
= MAX_MULTIBYTE_LENGTH
* src_len
;
519 if (encode_terminal_src_size
< required
)
521 if (encode_terminal_src
)
522 encode_terminal_src
= xrealloc (encode_terminal_src
, required
);
524 encode_terminal_src
= xmalloc (required
);
525 encode_terminal_src_size
= required
;
528 charset_list
= coding_charset_list (coding
);
530 buf
= encode_terminal_src
;
532 while (src
< src_end
)
534 if (src
->type
== COMPOSITE_GLYPH
)
536 struct composition
*cmp
IF_LINT (= NULL
);
537 Lisp_Object gstring
IF_LINT (= Qnil
);
540 nbytes
= buf
- encode_terminal_src
;
541 if (src
->u
.cmp
.automatic
)
543 gstring
= composition_gstring_from_id (src
->u
.cmp
.id
);
544 required
= src
->slice
.cmp
.to
+ 1 - src
->slice
.cmp
.from
;
548 cmp
= composition_table
[src
->u
.cmp
.id
];
549 required
= MAX_MULTIBYTE_LENGTH
* cmp
->glyph_len
;
552 if (encode_terminal_src_size
< nbytes
+ required
)
554 encode_terminal_src_size
= nbytes
+ required
;
555 encode_terminal_src
= xrealloc (encode_terminal_src
,
556 encode_terminal_src_size
);
557 buf
= encode_terminal_src
+ nbytes
;
560 if (src
->u
.cmp
.automatic
)
561 for (i
= src
->slice
.cmp
.from
; i
<= src
->slice
.cmp
.to
; i
++)
563 Lisp_Object g
= LGSTRING_GLYPH (gstring
, i
);
564 int c
= LGLYPH_CHAR (g
);
566 if (! char_charset (c
, charset_list
, NULL
))
568 buf
+= CHAR_STRING (c
, buf
);
572 for (i
= 0; i
< cmp
->glyph_len
; i
++)
574 int c
= COMPOSITION_GLYPH (cmp
, i
);
578 if (char_charset (c
, charset_list
, NULL
))
580 if (CHAR_WIDTH (c
) == 0
581 && i
> 0 && COMPOSITION_GLYPH (cmp
, i
- 1) == '\t')
582 /* Should be left-padded */
584 buf
+= CHAR_STRING (' ', buf
);
590 buf
+= CHAR_STRING (c
, buf
);
594 /* We must skip glyphs to be padded for a wide character. */
595 else if (! CHAR_GLYPH_PADDING_P (*src
))
602 SET_GLYPH_FROM_CHAR_GLYPH (g
, src
[0]);
604 if (GLYPH_INVALID_P (g
) || GLYPH_SIMPLE_P (tbase
, tlen
, g
))
606 /* This glyph doesn't have an entry in Vglyph_table. */
611 /* This glyph has an entry in Vglyph_table,
612 so process any alias before testing for simpleness. */
613 GLYPH_FOLLOW_ALIASES (tbase
, tlen
, g
);
615 if (GLYPH_SIMPLE_P (tbase
, tlen
, g
))
616 /* We set the multi-byte form of a character in G
617 (that should be an ASCII character) at WORKBUF. */
620 /* We have a string in Vglyph_table. */
621 string
= tbase
[GLYPH_CHAR (g
)];
626 nbytes
= buf
- encode_terminal_src
;
627 if (encode_terminal_src_size
< nbytes
+ MAX_MULTIBYTE_LENGTH
)
629 encode_terminal_src_size
= nbytes
+ MAX_MULTIBYTE_LENGTH
;
630 encode_terminal_src
= xrealloc (encode_terminal_src
,
631 encode_terminal_src_size
);
632 buf
= encode_terminal_src
+ nbytes
;
635 || char_charset (c
, charset_list
, NULL
))
637 /* Store the multibyte form of C at BUF. */
638 buf
+= CHAR_STRING (c
, buf
);
643 /* C is not encodable. */
646 while (src
+ 1 < src_end
&& CHAR_GLYPH_PADDING_P (src
[1]))
656 if (! STRING_MULTIBYTE (string
))
657 string
= string_to_multibyte (string
);
658 nbytes
= buf
- encode_terminal_src
;
659 if (encode_terminal_src_size
< nbytes
+ SBYTES (string
))
661 encode_terminal_src_size
= nbytes
+ SBYTES (string
);
662 encode_terminal_src
= xrealloc (encode_terminal_src
,
663 encode_terminal_src_size
);
664 buf
= encode_terminal_src
+ nbytes
;
666 memcpy (buf
, SDATA (string
), SBYTES (string
));
667 buf
+= SBYTES (string
);
668 nchars
+= SCHARS (string
);
676 coding
->produced
= 0;
680 nbytes
= buf
- encode_terminal_src
;
681 coding
->source
= encode_terminal_src
;
682 if (encode_terminal_dst_size
== 0)
684 encode_terminal_dst_size
= encode_terminal_src_size
;
685 if (encode_terminal_dst
)
686 encode_terminal_dst
= xrealloc (encode_terminal_dst
,
687 encode_terminal_dst_size
);
689 encode_terminal_dst
= xmalloc (encode_terminal_dst_size
);
691 coding
->destination
= encode_terminal_dst
;
692 coding
->dst_bytes
= encode_terminal_dst_size
;
693 encode_coding_object (coding
, Qnil
, 0, 0, nchars
, nbytes
, Qnil
);
694 /* coding->destination may have been reallocated. */
695 encode_terminal_dst
= coding
->destination
;
696 encode_terminal_dst_size
= coding
->dst_bytes
;
698 return (encode_terminal_dst
);
703 /* An implementation of write_glyphs for termcap frames. */
706 tty_write_glyphs (struct frame
*f
, struct glyph
*string
, int len
)
708 unsigned char *conversion_buffer
;
709 struct coding_system
*coding
;
712 struct tty_display_info
*tty
= FRAME_TTY (f
);
714 tty_turn_off_insert (tty
);
715 tty_hide_cursor (tty
);
717 /* Don't dare write in last column of bottom line, if Auto-Wrap,
718 since that would scroll the whole frame on some terminals. */
721 && curY (tty
) + 1 == FRAME_LINES (f
)
722 && (curX (tty
) + len
) == FRAME_COLS (f
))
729 /* If terminal_coding does any conversion, use it, otherwise use
730 safe_terminal_coding. We can't use CODING_REQUIRE_ENCODING here
731 because it always return 1 if the member src_multibyte is 1. */
732 coding
= (FRAME_TERMINAL_CODING (f
)->common_flags
& CODING_REQUIRE_ENCODING_MASK
733 ? FRAME_TERMINAL_CODING (f
) : &safe_terminal_coding
);
734 /* The mode bit CODING_MODE_LAST_BLOCK should be set to 1 only at
736 coding
->mode
&= ~CODING_MODE_LAST_BLOCK
;
738 for (stringlen
= len
; stringlen
!= 0; stringlen
-= n
)
740 /* Identify a run of glyphs with the same face. */
741 int face_id
= string
->face_id
;
743 for (n
= 1; n
< stringlen
; ++n
)
744 if (string
[n
].face_id
!= face_id
)
747 /* Turn appearance modes of the face of the run on. */
748 tty_highlight_if_desired (tty
);
749 turn_on_face (f
, face_id
);
752 /* This is the last run. */
753 coding
->mode
|= CODING_MODE_LAST_BLOCK
;
754 conversion_buffer
= encode_terminal_code (string
, n
, coding
);
755 if (coding
->produced
> 0)
758 fwrite (conversion_buffer
, 1, coding
->produced
, tty
->output
);
759 if (ferror (tty
->output
))
760 clearerr (tty
->output
);
762 fwrite (conversion_buffer
, 1, coding
->produced
, tty
->termscript
);
767 /* Turn appearance modes off. */
768 turn_off_face (f
, face_id
);
769 tty_turn_off_highlight (tty
);
775 #ifdef HAVE_GPM /* Only used by GPM code. */
778 tty_write_glyphs_with_face (register struct frame
*f
, register struct glyph
*string
,
779 register int len
, register int face_id
)
781 unsigned char *conversion_buffer
;
782 struct coding_system
*coding
;
784 struct tty_display_info
*tty
= FRAME_TTY (f
);
786 tty_turn_off_insert (tty
);
787 tty_hide_cursor (tty
);
789 /* Don't dare write in last column of bottom line, if Auto-Wrap,
790 since that would scroll the whole frame on some terminals. */
793 && curY (tty
) + 1 == FRAME_LINES (f
)
794 && (curX (tty
) + len
) == FRAME_COLS (f
))
801 /* If terminal_coding does any conversion, use it, otherwise use
802 safe_terminal_coding. We can't use CODING_REQUIRE_ENCODING here
803 because it always return 1 if the member src_multibyte is 1. */
804 coding
= (FRAME_TERMINAL_CODING (f
)->common_flags
& CODING_REQUIRE_ENCODING_MASK
805 ? FRAME_TERMINAL_CODING (f
) : &safe_terminal_coding
);
806 /* The mode bit CODING_MODE_LAST_BLOCK should be set to 1 only at
808 coding
->mode
&= ~CODING_MODE_LAST_BLOCK
;
810 /* Turn appearance modes of the face. */
811 tty_highlight_if_desired (tty
);
812 turn_on_face (f
, face_id
);
814 coding
->mode
|= CODING_MODE_LAST_BLOCK
;
815 conversion_buffer
= encode_terminal_code (string
, len
, coding
);
816 if (coding
->produced
> 0)
819 fwrite (conversion_buffer
, 1, coding
->produced
, tty
->output
);
820 if (ferror (tty
->output
))
821 clearerr (tty
->output
);
823 fwrite (conversion_buffer
, 1, coding
->produced
, tty
->termscript
);
827 /* Turn appearance modes off. */
828 turn_off_face (f
, face_id
);
829 tty_turn_off_highlight (tty
);
835 /* An implementation of insert_glyphs for termcap frames. */
838 tty_insert_glyphs (struct frame
*f
, struct glyph
*start
, int len
)
841 struct glyph
*glyph
= NULL
;
842 unsigned char *conversion_buffer
;
843 unsigned char space
[1];
844 struct coding_system
*coding
;
846 struct tty_display_info
*tty
= FRAME_TTY (f
);
848 if (tty
->TS_ins_multi_chars
)
850 buf
= tparam (tty
->TS_ins_multi_chars
, 0, 0, len
, 0, 0, 0);
854 write_glyphs (f
, start
, len
);
858 tty_turn_on_insert (tty
);
862 space
[0] = SPACEGLYPH
;
864 /* If terminal_coding does any conversion, use it, otherwise use
865 safe_terminal_coding. We can't use CODING_REQUIRE_ENCODING here
866 because it always return 1 if the member src_multibyte is 1. */
867 coding
= (FRAME_TERMINAL_CODING (f
)->common_flags
& CODING_REQUIRE_ENCODING_MASK
868 ? FRAME_TERMINAL_CODING (f
) : &safe_terminal_coding
);
869 /* The mode bit CODING_MODE_LAST_BLOCK should be set to 1 only at
871 coding
->mode
&= ~CODING_MODE_LAST_BLOCK
;
875 OUTPUT1_IF (tty
, tty
->TS_ins_char
);
878 conversion_buffer
= space
;
879 coding
->produced
= 1;
883 tty_highlight_if_desired (tty
);
884 turn_on_face (f
, start
->face_id
);
887 /* We must open sufficient space for a character which
888 occupies more than one column. */
889 while (len
&& CHAR_GLYPH_PADDING_P (*start
))
891 OUTPUT1_IF (tty
, tty
->TS_ins_char
);
896 /* This is the last glyph. */
897 coding
->mode
|= CODING_MODE_LAST_BLOCK
;
899 conversion_buffer
= encode_terminal_code (glyph
, 1, coding
);
902 if (coding
->produced
> 0)
905 fwrite (conversion_buffer
, 1, coding
->produced
, tty
->output
);
906 if (ferror (tty
->output
))
907 clearerr (tty
->output
);
909 fwrite (conversion_buffer
, 1, coding
->produced
, tty
->termscript
);
913 OUTPUT1_IF (tty
, tty
->TS_pad_inserted_char
);
916 turn_off_face (f
, glyph
->face_id
);
917 tty_turn_off_highlight (tty
);
924 /* An implementation of delete_glyphs for termcap frames. */
927 tty_delete_glyphs (struct frame
*f
, int n
)
932 struct tty_display_info
*tty
= FRAME_TTY (f
);
934 if (tty
->delete_in_insert_mode
)
936 tty_turn_on_insert (tty
);
940 tty_turn_off_insert (tty
);
941 OUTPUT_IF (tty
, tty
->TS_delete_mode
);
944 if (tty
->TS_del_multi_chars
)
946 buf
= tparam (tty
->TS_del_multi_chars
, 0, 0, n
, 0, 0, 0);
951 for (i
= 0; i
< n
; i
++)
952 OUTPUT1 (tty
, tty
->TS_del_char
);
953 if (!tty
->delete_in_insert_mode
)
954 OUTPUT_IF (tty
, tty
->TS_end_delete_mode
);
957 /* An implementation of ins_del_lines for termcap frames. */
960 tty_ins_del_lines (struct frame
*f
, int vpos
, int n
)
962 struct tty_display_info
*tty
= FRAME_TTY (f
);
964 n
> 0 ? tty
->TS_ins_multi_lines
: tty
->TS_del_multi_lines
;
965 const char *single
= n
> 0 ? tty
->TS_ins_line
: tty
->TS_del_line
;
966 const char *scroll
= n
> 0 ? tty
->TS_rev_scroll
: tty
->TS_fwd_scroll
;
968 register int i
= n
> 0 ? n
: -n
;
971 /* If the lines below the insertion are being pushed
972 into the end of the window, this is the same as clearing;
973 and we know the lines are already clear, since the matching
974 deletion has already been done. So can ignore this. */
975 /* If the lines below the deletion are blank lines coming
976 out of the end of the window, don't bother,
977 as there will be a matching inslines later that will flush them. */
978 if (FRAME_SCROLL_REGION_OK (f
)
979 && vpos
+ i
>= tty
->specified_window
)
981 if (!FRAME_MEMORY_BELOW_FRAME (f
)
982 && vpos
+ i
>= FRAME_LINES (f
))
987 raw_cursor_to (f
, vpos
, 0);
988 tty_background_highlight (tty
);
989 buf
= tparam (multi
, 0, 0, i
, 0, 0, 0);
995 raw_cursor_to (f
, vpos
, 0);
996 tty_background_highlight (tty
);
998 OUTPUT (tty
, single
);
1004 tty_set_scroll_region (f
, vpos
, tty
->specified_window
);
1006 raw_cursor_to (f
, tty
->specified_window
- 1, 0);
1008 raw_cursor_to (f
, vpos
, 0);
1009 tty_background_highlight (tty
);
1011 OUTPUTL (tty
, scroll
, tty
->specified_window
- vpos
);
1012 tty_set_scroll_region (f
, 0, tty
->specified_window
);
1015 if (!FRAME_SCROLL_REGION_OK (f
)
1016 && FRAME_MEMORY_BELOW_FRAME (f
)
1019 cursor_to (f
, FRAME_LINES (f
) + n
, 0);
1024 /* Compute cost of sending "str", in characters,
1025 not counting any line-dependent padding. */
1028 string_cost (const char *str
)
1032 tputs (str
, 0, evalcost
);
1036 /* Compute cost of sending "str", in characters,
1037 counting any line-dependent padding at one line. */
1040 string_cost_one_line (const char *str
)
1044 tputs (str
, 1, evalcost
);
1048 /* Compute per line amount of line-dependent padding,
1049 in tenths of characters. */
1052 per_line_cost (const char *str
)
1056 tputs (str
, 0, evalcost
);
1059 tputs (str
, 10, evalcost
);
1063 /* char_ins_del_cost[n] is cost of inserting N characters.
1064 char_ins_del_cost[-n] is cost of deleting N characters.
1065 The length of this vector is based on max_frame_cols. */
1067 int *char_ins_del_vector
;
1069 #define char_ins_del_cost(f) (&char_ins_del_vector[FRAME_COLS ((f))])
1073 calculate_ins_del_char_costs (struct frame
*f
)
1075 struct tty_display_info
*tty
= FRAME_TTY (f
);
1076 int ins_startup_cost
, del_startup_cost
;
1077 int ins_cost_per_char
, del_cost_per_char
;
1081 if (tty
->TS_ins_multi_chars
)
1083 ins_cost_per_char
= 0;
1084 ins_startup_cost
= string_cost_one_line (tty
->TS_ins_multi_chars
);
1086 else if (tty
->TS_ins_char
|| tty
->TS_pad_inserted_char
1087 || (tty
->TS_insert_mode
&& tty
->TS_end_insert_mode
))
1089 ins_startup_cost
= (30 * (string_cost (tty
->TS_insert_mode
)
1090 + string_cost (tty
->TS_end_insert_mode
))) / 100;
1091 ins_cost_per_char
= (string_cost_one_line (tty
->TS_ins_char
)
1092 + string_cost_one_line (tty
->TS_pad_inserted_char
));
1096 ins_startup_cost
= 9999;
1097 ins_cost_per_char
= 0;
1100 if (tty
->TS_del_multi_chars
)
1102 del_cost_per_char
= 0;
1103 del_startup_cost
= string_cost_one_line (tty
->TS_del_multi_chars
);
1105 else if (tty
->TS_del_char
)
1107 del_startup_cost
= (string_cost (tty
->TS_delete_mode
)
1108 + string_cost (tty
->TS_end_delete_mode
));
1109 if (tty
->delete_in_insert_mode
)
1110 del_startup_cost
/= 2;
1111 del_cost_per_char
= string_cost_one_line (tty
->TS_del_char
);
1115 del_startup_cost
= 9999;
1116 del_cost_per_char
= 0;
1119 /* Delete costs are at negative offsets */
1120 p
= &char_ins_del_cost (f
)[0];
1121 for (i
= FRAME_COLS (f
); --i
>= 0;)
1122 *--p
= (del_startup_cost
+= del_cost_per_char
);
1124 /* Doing nothing is free */
1125 p
= &char_ins_del_cost (f
)[0];
1128 /* Insert costs are at positive offsets */
1129 for (i
= FRAME_COLS (f
); --i
>= 0;)
1130 *p
++ = (ins_startup_cost
+= ins_cost_per_char
);
1134 calculate_costs (struct frame
*frame
)
1136 FRAME_COST_BAUD_RATE (frame
) = baud_rate
;
1138 if (FRAME_TERMCAP_P (frame
))
1140 struct tty_display_info
*tty
= FRAME_TTY (frame
);
1141 register const char *f
= (tty
->TS_set_scroll_region
1142 ? tty
->TS_set_scroll_region
1143 : tty
->TS_set_scroll_region_1
);
1145 FRAME_SCROLL_REGION_COST (frame
) = string_cost (f
);
1149 /* These variables are only used for terminal stuff. They are
1150 allocated once for the terminal frame of X-windows emacs, but not
1153 char_ins_del_vector (i.e., char_ins_del_cost) isn't used because
1154 X turns off char_ins_del_ok. */
1156 max_frame_lines
= max (max_frame_lines
, FRAME_LINES (frame
));
1157 max_frame_cols
= max (max_frame_cols
, FRAME_COLS (frame
));
1159 if (char_ins_del_vector
!= 0)
1161 = (int *) xrealloc (char_ins_del_vector
,
1163 + 2 * max_frame_cols
* sizeof (int)));
1166 = (int *) xmalloc (sizeof (int)
1167 + 2 * max_frame_cols
* sizeof (int));
1169 memset (char_ins_del_vector
, 0,
1170 (sizeof (int) + 2 * max_frame_cols
* sizeof (int)));
1173 if (f
&& (!tty
->TS_ins_line
&& !tty
->TS_del_line
))
1174 do_line_insertion_deletion_costs (frame
,
1175 tty
->TS_rev_scroll
, tty
->TS_ins_multi_lines
,
1176 tty
->TS_fwd_scroll
, tty
->TS_del_multi_lines
,
1179 do_line_insertion_deletion_costs (frame
,
1180 tty
->TS_ins_line
, tty
->TS_ins_multi_lines
,
1181 tty
->TS_del_line
, tty
->TS_del_multi_lines
,
1184 calculate_ins_del_char_costs (frame
);
1186 /* Don't use TS_repeat if its padding is worse than sending the chars */
1187 if (tty
->TS_repeat
&& per_line_cost (tty
->TS_repeat
) * baud_rate
< 9000)
1188 tty
->RPov
= string_cost (tty
->TS_repeat
);
1190 tty
->RPov
= FRAME_COLS (frame
) * 2;
1192 cmcostinit (FRAME_TTY (frame
)); /* set up cursor motion costs */
1197 const char *cap
, *name
;
1200 /* Termcap capability names that correspond directly to X keysyms.
1201 Some of these (marked "terminfo") aren't supplied by old-style
1202 (Berkeley) termcap entries. They're listed in X keysym order;
1203 except we put the keypad keys first, so that if they clash with
1204 other keys (as on the IBM PC keyboard) they get overridden.
1207 static const struct fkey_table keys
[] =
1209 {"kh", "home"}, /* termcap */
1210 {"kl", "left"}, /* termcap */
1211 {"ku", "up"}, /* termcap */
1212 {"kr", "right"}, /* termcap */
1213 {"kd", "down"}, /* termcap */
1214 {"%8", "prior"}, /* terminfo */
1215 {"%5", "next"}, /* terminfo */
1216 {"@7", "end"}, /* terminfo */
1217 {"@1", "begin"}, /* terminfo */
1218 {"*6", "select"}, /* terminfo */
1219 {"%9", "print"}, /* terminfo */
1220 {"@4", "execute"}, /* terminfo --- actually the `command' key */
1222 * "insert" --- see below
1224 {"&8", "undo"}, /* terminfo */
1225 {"%0", "redo"}, /* terminfo */
1226 {"%7", "menu"}, /* terminfo --- actually the `options' key */
1227 {"@0", "find"}, /* terminfo */
1228 {"@2", "cancel"}, /* terminfo */
1229 {"%1", "help"}, /* terminfo */
1231 * "break" goes here, but can't be reliably intercepted with termcap
1233 {"&4", "reset"}, /* terminfo --- actually `restart' */
1235 * "system" and "user" --- no termcaps
1237 {"kE", "clearline"}, /* terminfo */
1238 {"kA", "insertline"}, /* terminfo */
1239 {"kL", "deleteline"}, /* terminfo */
1240 {"kI", "insertchar"}, /* terminfo */
1241 {"kD", "deletechar"}, /* terminfo */
1242 {"kB", "backtab"}, /* terminfo */
1244 * "kp_backtab", "kp-space", "kp-tab" --- no termcaps
1246 {"@8", "kp-enter"}, /* terminfo */
1248 * "kp-f1", "kp-f2", "kp-f3" "kp-f4",
1249 * "kp-multiply", "kp-add", "kp-separator",
1250 * "kp-subtract", "kp-decimal", "kp-divide", "kp-0";
1251 * --- no termcaps for any of these.
1253 {"K4", "kp-1"}, /* terminfo */
1255 * "kp-2" --- no termcap
1257 {"K5", "kp-3"}, /* terminfo */
1259 * "kp-4" --- no termcap
1261 {"K2", "kp-5"}, /* terminfo */
1263 * "kp-6" --- no termcap
1265 {"K1", "kp-7"}, /* terminfo */
1267 * "kp-8" --- no termcap
1269 {"K3", "kp-9"}, /* terminfo */
1271 * "kp-equal" --- no termcap
1283 {"&0", "S-cancel"}, /*shifted cancel key*/
1284 {"&9", "S-begin"}, /*shifted begin key*/
1285 {"*0", "S-find"}, /*shifted find key*/
1286 {"*1", "S-execute"}, /*shifted execute? actually shifted command key*/
1287 {"*4", "S-delete"}, /*shifted delete-character key*/
1288 {"*7", "S-end"}, /*shifted end key*/
1289 {"*8", "S-clearline"}, /*shifted clear-to end-of-line key*/
1290 {"#1", "S-help"}, /*shifted help key*/
1291 {"#2", "S-home"}, /*shifted home key*/
1292 {"#3", "S-insert"}, /*shifted insert-character key*/
1293 {"#4", "S-left"}, /*shifted left-arrow key*/
1294 {"%d", "S-menu"}, /*shifted menu? actually shifted options key*/
1295 {"%c", "S-next"}, /*shifted next key*/
1296 {"%e", "S-prior"}, /*shifted previous key*/
1297 {"%f", "S-print"}, /*shifted print key*/
1298 {"%g", "S-redo"}, /*shifted redo key*/
1299 {"%i", "S-right"}, /*shifted right-arrow key*/
1300 {"!3", "S-undo"} /*shifted undo key*/
1304 static char **term_get_fkeys_address
;
1305 static KBOARD
*term_get_fkeys_kboard
;
1306 static Lisp_Object
term_get_fkeys_1 (void);
1308 /* Find the escape codes sent by the function keys for Vinput_decode_map.
1309 This function scans the termcap function key sequence entries, and
1310 adds entries to Vinput_decode_map for each function key it finds. */
1313 term_get_fkeys (char **address
, KBOARD
*kboard
)
1315 /* We run the body of the function (term_get_fkeys_1) and ignore all Lisp
1316 errors during the call. The only errors should be from Fdefine_key
1317 when given a key sequence containing an invalid prefix key. If the
1318 termcap defines function keys which use a prefix that is already bound
1319 to a command by the default bindings, we should silently ignore that
1320 function key specification, rather than giving the user an error and
1321 refusing to run at all on such a terminal. */
1323 term_get_fkeys_address
= address
;
1324 term_get_fkeys_kboard
= kboard
;
1325 internal_condition_case (term_get_fkeys_1
, Qerror
, Fidentity
);
1329 term_get_fkeys_1 (void)
1333 char **address
= term_get_fkeys_address
;
1334 KBOARD
*kboard
= term_get_fkeys_kboard
;
1336 /* This can happen if CANNOT_DUMP or with strange options. */
1337 if (!KEYMAPP (KVAR (kboard
, Vinput_decode_map
)))
1338 KVAR (kboard
, Vinput_decode_map
) = Fmake_sparse_keymap (Qnil
);
1340 for (i
= 0; i
< (sizeof (keys
)/sizeof (keys
[0])); i
++)
1342 char *sequence
= tgetstr (keys
[i
].cap
, address
);
1344 Fdefine_key (KVAR (kboard
, Vinput_decode_map
), build_string (sequence
),
1345 Fmake_vector (make_number (1),
1346 intern (keys
[i
].name
)));
1349 /* The uses of the "k0" capability are inconsistent; sometimes it
1350 describes F10, whereas othertimes it describes F0 and "k;" describes F10.
1351 We will attempt to politely accommodate both systems by testing for
1352 "k;", and if it is present, assuming that "k0" denotes F0, otherwise F10.
1355 const char *k_semi
= tgetstr ("k;", address
);
1356 const char *k0
= tgetstr ("k0", address
);
1357 const char *k0_name
= "f10";
1362 /* Define f0 first, so that f10 takes precedence in case the
1363 key sequences happens to be the same. */
1364 Fdefine_key (KVAR (kboard
, Vinput_decode_map
), build_string (k0
),
1365 Fmake_vector (make_number (1), intern ("f0")));
1366 Fdefine_key (KVAR (kboard
, Vinput_decode_map
), build_string (k_semi
),
1367 Fmake_vector (make_number (1), intern ("f10")));
1370 Fdefine_key (KVAR (kboard
, Vinput_decode_map
), build_string (k0
),
1371 Fmake_vector (make_number (1), intern (k0_name
)));
1374 /* Set up cookies for numbered function keys above f10. */
1376 char fcap
[3], fkey
[4];
1378 fcap
[0] = 'F'; fcap
[2] = '\0';
1379 for (i
= 11; i
< 64; i
++)
1382 fcap
[1] = '1' + i
- 11;
1384 fcap
[1] = 'A' + i
- 20;
1386 fcap
[1] = 'a' + i
- 46;
1389 char *sequence
= tgetstr (fcap
, address
);
1392 sprintf (fkey
, "f%d", i
);
1393 Fdefine_key (KVAR (kboard
, Vinput_decode_map
), build_string (sequence
),
1394 Fmake_vector (make_number (1),
1402 * Various mappings to try and get a better fit.
1405 #define CONDITIONAL_REASSIGN(cap1, cap2, sym) \
1406 if (!tgetstr (cap1, address)) \
1408 char *sequence = tgetstr (cap2, address); \
1410 Fdefine_key (KVAR (kboard, Vinput_decode_map), build_string (sequence), \
1411 Fmake_vector (make_number (1), \
1415 /* if there's no key_next keycap, map key_npage to `next' keysym */
1416 CONDITIONAL_REASSIGN ("%5", "kN", "next");
1417 /* if there's no key_prev keycap, map key_ppage to `previous' keysym */
1418 CONDITIONAL_REASSIGN ("%8", "kP", "prior");
1419 /* if there's no key_dc keycap, map key_ic to `insert' keysym */
1420 CONDITIONAL_REASSIGN ("kD", "kI", "insert");
1421 /* if there's no key_end keycap, map key_ll to 'end' keysym */
1422 CONDITIONAL_REASSIGN ("@7", "kH", "end");
1424 /* IBM has their own non-standard dialect of terminfo.
1425 If the standard name isn't found, try the IBM name. */
1426 CONDITIONAL_REASSIGN ("kB", "KO", "backtab");
1427 CONDITIONAL_REASSIGN ("@4", "kJ", "execute"); /* actually "action" */
1428 CONDITIONAL_REASSIGN ("@4", "kc", "execute"); /* actually "command" */
1429 CONDITIONAL_REASSIGN ("%7", "ki", "menu");
1430 CONDITIONAL_REASSIGN ("@7", "kw", "end");
1431 CONDITIONAL_REASSIGN ("F1", "k<", "f11");
1432 CONDITIONAL_REASSIGN ("F2", "k>", "f12");
1433 CONDITIONAL_REASSIGN ("%1", "kq", "help");
1434 CONDITIONAL_REASSIGN ("*6", "kU", "select");
1435 #undef CONDITIONAL_REASSIGN
1440 #endif /* not DOS_NT */
1443 /***********************************************************************
1444 Character Display Information
1445 ***********************************************************************/
1446 static void append_glyph (struct it
*);
1447 static void produce_stretch_glyph (struct it
*);
1448 static void append_composite_glyph (struct it
*);
1449 static void produce_composite_glyph (struct it
*);
1450 static void append_glyphless_glyph (struct it
*, int, const char *);
1451 static void produce_glyphless_glyph (struct it
*, int, Lisp_Object
);
1453 /* Append glyphs to IT's glyph_row. Called from produce_glyphs for
1454 terminal frames if IT->glyph_row != NULL. IT->char_to_display is
1455 the character for which to produce glyphs; IT->face_id contains the
1456 character's face. Padding glyphs are appended if IT->c has a
1457 IT->pixel_width > 1. */
1460 append_glyph (struct it
*it
)
1462 struct glyph
*glyph
, *end
;
1465 xassert (it
->glyph_row
);
1466 glyph
= (it
->glyph_row
->glyphs
[it
->area
]
1467 + it
->glyph_row
->used
[it
->area
]);
1468 end
= it
->glyph_row
->glyphs
[1 + it
->area
];
1470 /* If the glyph row is reversed, we need to prepend the glyph rather
1472 if (it
->glyph_row
->reversed_p
&& it
->area
== TEXT_AREA
)
1475 int move_by
= it
->pixel_width
;
1477 /* Make room for the new glyphs. */
1478 if (move_by
> end
- glyph
) /* don't overstep end of this area */
1479 move_by
= end
- glyph
;
1480 for (g
= glyph
- 1; g
>= it
->glyph_row
->glyphs
[it
->area
]; g
--)
1482 glyph
= it
->glyph_row
->glyphs
[it
->area
];
1483 end
= glyph
+ move_by
;
1486 /* BIDI Note: we put the glyphs of a "multi-pixel" character left to
1487 right, even in the REVERSED_P case, since (a) all of its u.ch are
1488 identical, and (b) the PADDING_P flag needs to be set for the
1489 leftmost one, because we write to the terminal left-to-right. */
1491 i
< it
->pixel_width
&& glyph
< end
;
1494 glyph
->type
= CHAR_GLYPH
;
1495 glyph
->pixel_width
= 1;
1496 glyph
->u
.ch
= it
->char_to_display
;
1497 glyph
->face_id
= it
->face_id
;
1498 glyph
->padding_p
= i
> 0;
1499 glyph
->charpos
= CHARPOS (it
->position
);
1500 glyph
->object
= it
->object
;
1503 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
1504 if ((it
->bidi_it
.type
& 7) != it
->bidi_it
.type
)
1506 glyph
->bidi_type
= it
->bidi_it
.type
;
1510 glyph
->resolved_level
= 0;
1511 glyph
->bidi_type
= UNKNOWN_BT
;
1514 ++it
->glyph_row
->used
[it
->area
];
1519 /* Produce glyphs for the display element described by IT. *IT
1520 specifies what we want to produce a glyph for (character, image, ...),
1521 and where in the glyph matrix we currently are (glyph row and hpos).
1522 produce_glyphs fills in output fields of *IT with information such as the
1523 pixel width and height of a character, and maybe output actual glyphs at
1524 the same time if IT->glyph_row is non-null. For an overview, see
1525 the explanation in dispextern.h, before the definition of the
1526 display_element_type enumeration.
1528 produce_glyphs also stores the result of glyph width, ascent
1529 etc. computations in *IT.
1531 IT->glyph_row may be null, in which case produce_glyphs does not
1532 actually fill in the glyphs. This is used in the move_* functions
1533 in xdisp.c for text width and height computations.
1535 Callers usually don't call produce_glyphs directly;
1536 instead they use the macro PRODUCE_GLYPHS. */
1539 produce_glyphs (struct it
*it
)
1541 /* If a hook is installed, let it do the work. */
1543 /* Nothing but characters are supported on terminal frames. */
1544 xassert (it
->what
== IT_CHARACTER
1545 || it
->what
== IT_COMPOSITION
1546 || it
->what
== IT_STRETCH
);
1548 if (it
->what
== IT_STRETCH
)
1550 produce_stretch_glyph (it
);
1554 if (it
->what
== IT_COMPOSITION
)
1556 produce_composite_glyph (it
);
1560 if (it
->what
== IT_GLYPHLESS
)
1562 produce_glyphless_glyph (it
, 0, Qnil
);
1566 if (it
->char_to_display
>= 040 && it
->char_to_display
< 0177)
1568 it
->pixel_width
= it
->nglyphs
= 1;
1572 else if (it
->char_to_display
== '\n')
1573 it
->pixel_width
= it
->nglyphs
= 0;
1574 else if (it
->char_to_display
== '\t')
1576 int absolute_x
= (it
->current_x
1577 + it
->continuation_lines_width
);
1579 = (((1 + absolute_x
+ it
->tab_width
- 1)
1584 /* If part of the TAB has been displayed on the previous line
1585 which is continued now, continuation_lines_width will have
1586 been incremented already by the part that fitted on the
1587 continued line. So, we will get the right number of spaces
1589 nspaces
= next_tab_x
- absolute_x
;
1595 it
->char_to_display
= ' ';
1596 it
->pixel_width
= it
->len
= 1;
1602 it
->pixel_width
= nspaces
;
1603 it
->nglyphs
= nspaces
;
1605 else if (CHAR_BYTE8_P (it
->char_to_display
))
1607 /* Coming here means that we must send the raw 8-bit byte as is
1608 to the terminal. Although there's no way to know how many
1609 columns it occupies on a screen, it is a good assumption that
1610 a single byte code has 1-column width. */
1611 it
->pixel_width
= it
->nglyphs
= 1;
1617 Lisp_Object charset_list
= FRAME_TERMINAL (it
->f
)->charset_list
;
1619 if (char_charset (it
->char_to_display
, charset_list
, NULL
))
1621 it
->pixel_width
= CHAR_WIDTH (it
->char_to_display
);
1622 it
->nglyphs
= it
->pixel_width
;
1628 Lisp_Object acronym
= lookup_glyphless_char_display (-1, it
);
1630 xassert (it
->what
== IT_GLYPHLESS
);
1631 produce_glyphless_glyph (it
, 1, acronym
);
1636 /* Advance current_x by the pixel width as a convenience for
1638 if (it
->area
== TEXT_AREA
)
1639 it
->current_x
+= it
->pixel_width
;
1640 it
->ascent
= it
->max_ascent
= it
->phys_ascent
= it
->max_phys_ascent
= 0;
1641 it
->descent
= it
->max_descent
= it
->phys_descent
= it
->max_phys_descent
= 1;
1645 /* Produce a stretch glyph for iterator IT. IT->object is the value
1646 of the glyph property displayed. The value must be a list
1647 `(space KEYWORD VALUE ...)' with the following KEYWORD/VALUE pairs
1650 1. `:width WIDTH' specifies that the space should be WIDTH *
1651 canonical char width wide. WIDTH may be an integer or floating
1654 2. `:align-to HPOS' specifies that the space should be wide enough
1655 to reach HPOS, a value in canonical character units. */
1658 produce_stretch_glyph (struct it
*it
)
1660 /* (space :width WIDTH ...) */
1661 Lisp_Object prop
, plist
;
1662 int width
= 0, align_to
= -1;
1663 int zero_width_ok_p
= 0;
1666 /* List should start with `space'. */
1667 xassert (CONSP (it
->object
) && EQ (XCAR (it
->object
), Qspace
));
1668 plist
= XCDR (it
->object
);
1670 /* Compute the width of the stretch. */
1671 if ((prop
= Fplist_get (plist
, QCwidth
), !NILP (prop
))
1672 && calc_pixel_width_or_height (&tem
, it
, prop
, 0, 1, 0))
1674 /* Absolute width `:width WIDTH' specified and valid. */
1675 zero_width_ok_p
= 1;
1676 width
= (int)(tem
+ 0.5);
1678 else if ((prop
= Fplist_get (plist
, QCalign_to
), !NILP (prop
))
1679 && calc_pixel_width_or_height (&tem
, it
, prop
, 0, 1, &align_to
))
1681 if (it
->glyph_row
== NULL
|| !it
->glyph_row
->mode_line_p
)
1682 align_to
= (align_to
< 0
1684 : align_to
- window_box_left_offset (it
->w
, TEXT_AREA
));
1685 else if (align_to
< 0)
1686 align_to
= window_box_left_offset (it
->w
, TEXT_AREA
);
1687 width
= max (0, (int)(tem
+ 0.5) + align_to
- it
->current_x
);
1688 zero_width_ok_p
= 1;
1691 /* Nothing specified -> width defaults to canonical char width. */
1692 width
= FRAME_COLUMN_WIDTH (it
->f
);
1694 if (width
<= 0 && (width
< 0 || !zero_width_ok_p
))
1697 if (width
> 0 && it
->line_wrap
!= TRUNCATE
1698 && it
->current_x
+ width
> it
->last_visible_x
)
1699 width
= it
->last_visible_x
- it
->current_x
- 1;
1701 if (width
> 0 && it
->glyph_row
)
1703 Lisp_Object o_object
= it
->object
;
1704 Lisp_Object object
= it
->stack
[it
->sp
- 1].string
;
1707 if (!STRINGP (object
))
1708 object
= it
->w
->buffer
;
1709 it
->object
= object
;
1710 it
->char_to_display
= ' ';
1711 it
->pixel_width
= it
->len
= 1;
1714 it
->object
= o_object
;
1716 it
->pixel_width
= width
;
1717 it
->nglyphs
= width
;
1721 /* Append glyphs to IT's glyph_row for the composition IT->cmp_id.
1722 Called from produce_composite_glyph for terminal frames if
1723 IT->glyph_row != NULL. IT->face_id contains the character's
1727 append_composite_glyph (struct it
*it
)
1729 struct glyph
*glyph
;
1731 xassert (it
->glyph_row
);
1732 glyph
= it
->glyph_row
->glyphs
[it
->area
] + it
->glyph_row
->used
[it
->area
];
1733 if (glyph
< it
->glyph_row
->glyphs
[1 + it
->area
])
1735 /* If the glyph row is reversed, we need to prepend the glyph
1736 rather than append it. */
1737 if (it
->glyph_row
->reversed_p
&& it
->area
== TEXT_AREA
)
1741 /* Make room for the new glyph. */
1742 for (g
= glyph
- 1; g
>= it
->glyph_row
->glyphs
[it
->area
]; g
--)
1744 glyph
= it
->glyph_row
->glyphs
[it
->area
];
1746 glyph
->type
= COMPOSITE_GLYPH
;
1747 glyph
->pixel_width
= it
->pixel_width
;
1748 glyph
->u
.cmp
.id
= it
->cmp_it
.id
;
1749 if (it
->cmp_it
.ch
< 0)
1751 glyph
->u
.cmp
.automatic
= 0;
1752 glyph
->u
.cmp
.id
= it
->cmp_it
.id
;
1756 glyph
->u
.cmp
.automatic
= 1;
1757 glyph
->u
.cmp
.id
= it
->cmp_it
.id
;
1758 glyph
->slice
.cmp
.from
= it
->cmp_it
.from
;
1759 glyph
->slice
.cmp
.to
= it
->cmp_it
.to
- 1;
1762 glyph
->face_id
= it
->face_id
;
1763 glyph
->padding_p
= 0;
1764 glyph
->charpos
= CHARPOS (it
->position
);
1765 glyph
->object
= it
->object
;
1768 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
1769 if ((it
->bidi_it
.type
& 7) != it
->bidi_it
.type
)
1771 glyph
->bidi_type
= it
->bidi_it
.type
;
1775 glyph
->resolved_level
= 0;
1776 glyph
->bidi_type
= UNKNOWN_BT
;
1779 ++it
->glyph_row
->used
[it
->area
];
1785 /* Produce a composite glyph for iterator IT. IT->cmp_id is the ID of
1786 the composition. We simply produces components of the composition
1787 assuming that the terminal has a capability to layout/render it
1791 produce_composite_glyph (struct it
*it
)
1793 if (it
->cmp_it
.ch
< 0)
1795 struct composition
*cmp
= composition_table
[it
->cmp_it
.id
];
1797 it
->pixel_width
= cmp
->width
;
1801 Lisp_Object gstring
= composition_gstring_from_id (it
->cmp_it
.id
);
1803 it
->pixel_width
= composition_gstring_width (gstring
, it
->cmp_it
.from
,
1804 it
->cmp_it
.to
, NULL
);
1808 append_composite_glyph (it
);
1812 /* Append a glyph for a glyphless character to IT->glyph_row. FACE_ID
1813 is a face ID to be used for the glyph. What is actually appended
1814 are glyphs of type CHAR_GLYPH whose characters are in STR (which
1815 comes from it->nglyphs bytes). */
1818 append_glyphless_glyph (struct it
*it
, int face_id
, const char *str
)
1820 struct glyph
*glyph
, *end
;
1823 xassert (it
->glyph_row
);
1824 glyph
= it
->glyph_row
->glyphs
[it
->area
] + it
->glyph_row
->used
[it
->area
];
1825 end
= it
->glyph_row
->glyphs
[1 + it
->area
];
1827 /* If the glyph row is reversed, we need to prepend the glyph rather
1829 if (it
->glyph_row
->reversed_p
&& it
->area
== TEXT_AREA
)
1832 int move_by
= it
->pixel_width
;
1834 /* Make room for the new glyphs. */
1835 if (move_by
> end
- glyph
) /* don't overstep end of this area */
1836 move_by
= end
- glyph
;
1837 for (g
= glyph
- 1; g
>= it
->glyph_row
->glyphs
[it
->area
]; g
--)
1839 glyph
= it
->glyph_row
->glyphs
[it
->area
];
1840 end
= glyph
+ move_by
;
1845 glyph
->type
= CHAR_GLYPH
;
1846 glyph
->pixel_width
= 1;
1847 glyph
->face_id
= face_id
;
1848 glyph
->padding_p
= 0;
1849 glyph
->charpos
= CHARPOS (it
->position
);
1850 glyph
->object
= it
->object
;
1853 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
1854 if ((it
->bidi_it
.type
& 7) != it
->bidi_it
.type
)
1856 glyph
->bidi_type
= it
->bidi_it
.type
;
1860 glyph
->resolved_level
= 0;
1861 glyph
->bidi_type
= UNKNOWN_BT
;
1864 /* BIDI Note: we put the glyphs of characters left to right, even in
1865 the REVERSED_P case because we write to the terminal
1867 for (i
= 0; i
< it
->nglyphs
&& glyph
< end
; ++i
)
1870 glyph
[0] = glyph
[-1];
1871 glyph
->u
.ch
= str
[i
];
1872 ++it
->glyph_row
->used
[it
->area
];
1877 /* Produce glyphs for a glyphless character for iterator IT.
1878 IT->glyphless_method specifies which method to use for displaying
1879 the character. See the description of enum
1880 glyphless_display_method in dispextern.h for the details.
1882 FOR_NO_FONT is nonzero if and only if this is for a character that
1883 is not supproted by the coding system of the terminal. ACRONYM, if
1884 non-nil, is an acronym string for the character.
1886 The glyphs actually produced are of type CHAR_GLYPH. */
1889 produce_glyphless_glyph (struct it
*it
, int for_no_font
, Lisp_Object acronym
)
1894 char const *str
= " ";
1896 /* Get a face ID for the glyph by utilizing a cache (the same way as
1897 done for `escape-glyph' in get_next_display_element). */
1898 if (it
->f
== last_glyphless_glyph_frame
1899 && it
->face_id
== last_glyphless_glyph_face_id
)
1901 face_id
= last_glyphless_glyph_merged_face_id
;
1905 /* Merge the `glyphless-char' face into the current face. */
1906 face_id
= merge_faces (it
->f
, Qglyphless_char
, 0, it
->face_id
);
1907 last_glyphless_glyph_frame
= it
->f
;
1908 last_glyphless_glyph_face_id
= it
->face_id
;
1909 last_glyphless_glyph_merged_face_id
= face_id
;
1912 if (it
->glyphless_method
== GLYPHLESS_DISPLAY_THIN_SPACE
)
1914 /* As there's no way to produce a thin space, we produce a space
1915 of canonical width. */
1918 else if (it
->glyphless_method
== GLYPHLESS_DISPLAY_EMPTY_BOX
)
1920 len
= CHAR_WIDTH (it
->c
);
1925 sprintf (buf
, "[%.*s]", len
, str
);
1931 if (it
->glyphless_method
== GLYPHLESS_DISPLAY_ACRONYM
)
1933 if (! STRINGP (acronym
) && CHAR_TABLE_P (Vglyphless_char_display
))
1934 acronym
= CHAR_TABLE_REF (Vglyphless_char_display
, it
->c
);
1936 str
= STRINGP (acronym
) ? SSDATA (acronym
) : "";
1937 for (len
= 0; len
< 6 && str
[len
] && ASCII_BYTE_P (str
[len
]); len
++)
1938 buf
[1 + len
] = str
[len
];
1944 xassert (it
->glyphless_method
== GLYPHLESS_DISPLAY_HEX_CODE
);
1945 len
= (it
->c
< 0x10000 ? sprintf (buf
, "\\u%04X", it
->c
)
1946 : it
->c
<= MAX_UNICODE_CHAR
? sprintf (buf
, "\\U%06X", it
->c
)
1947 : sprintf (buf
, "\\x%06X", it
->c
));
1952 it
->pixel_width
= len
;
1955 append_glyphless_glyph (it
, face_id
, str
);
1959 /* Get information about special display element WHAT in an
1960 environment described by IT. WHAT is one of IT_TRUNCATION or
1961 IT_CONTINUATION. Maybe produce glyphs for WHAT if IT has a
1962 non-null glyph_row member. This function ensures that fields like
1963 face_id, c, len of IT are left untouched. */
1966 produce_special_glyphs (struct it
*it
, enum display_element_type what
)
1974 temp_it
.what
= IT_CHARACTER
;
1976 temp_it
.object
= make_number (0);
1977 memset (&temp_it
.current
, 0, sizeof temp_it
.current
);
1979 if (what
== IT_CONTINUATION
)
1981 /* Continuation glyph. For R2L lines, we mirror it by hand. */
1982 if (it
->bidi_it
.paragraph_dir
== R2L
)
1983 SET_GLYPH_FROM_CHAR (glyph
, '/');
1985 SET_GLYPH_FROM_CHAR (glyph
, '\\');
1987 && (gc
= DISP_CONTINUE_GLYPH (it
->dp
), GLYPH_CODE_P (gc
))
1988 && GLYPH_CODE_CHAR_VALID_P (gc
))
1990 /* FIXME: Should we mirror GC for R2L lines? */
1991 SET_GLYPH_FROM_GLYPH_CODE (glyph
, gc
);
1992 spec_glyph_lookup_face (XWINDOW (it
->window
), &glyph
);
1995 else if (what
== IT_TRUNCATION
)
1997 /* Truncation glyph. */
1998 SET_GLYPH_FROM_CHAR (glyph
, '$');
2000 && (gc
= DISP_TRUNC_GLYPH (it
->dp
), GLYPH_CODE_P (gc
))
2001 && GLYPH_CODE_CHAR_VALID_P (gc
))
2003 /* FIXME: Should we mirror GC for R2L lines? */
2004 SET_GLYPH_FROM_GLYPH_CODE (glyph
, gc
);
2005 spec_glyph_lookup_face (XWINDOW (it
->window
), &glyph
);
2011 temp_it
.c
= temp_it
.char_to_display
= GLYPH_CHAR (glyph
);
2012 temp_it
.face_id
= GLYPH_FACE (glyph
);
2013 temp_it
.len
= CHAR_BYTES (temp_it
.c
);
2015 produce_glyphs (&temp_it
);
2016 it
->pixel_width
= temp_it
.pixel_width
;
2017 it
->nglyphs
= temp_it
.pixel_width
;
2022 /***********************************************************************
2024 ***********************************************************************/
2026 /* Value is non-zero if attribute ATTR may be used. ATTR should be
2027 one of the enumerators from enum no_color_bit, or a bit set built
2028 from them. Some display attributes may not be used together with
2029 color; the termcap capability `NC' specifies which ones. */
2031 #define MAY_USE_WITH_COLORS_P(tty, ATTR) \
2032 (tty->TN_max_colors > 0 \
2033 ? (tty->TN_no_color_video & (ATTR)) == 0 \
2036 /* Turn appearances of face FACE_ID on tty frame F on.
2037 FACE_ID is a realized face ID number, in the face cache. */
2040 turn_on_face (struct frame
*f
, int face_id
)
2042 struct face
*face
= FACE_FROM_ID (f
, face_id
);
2043 long fg
= face
->foreground
;
2044 long bg
= face
->background
;
2045 struct tty_display_info
*tty
= FRAME_TTY (f
);
2047 /* Do this first because TS_end_standout_mode may be the same
2048 as TS_exit_attribute_mode, which turns all appearances off. */
2049 if (MAY_USE_WITH_COLORS_P (tty
, NC_REVERSE
))
2051 if (tty
->TN_max_colors
> 0)
2053 if (fg
>= 0 && bg
>= 0)
2055 /* If the terminal supports colors, we can set them
2056 below without using reverse video. The face's fg
2057 and bg colors are set as they should appear on
2058 the screen, i.e. they take the inverse-video'ness
2059 of the face already into account. */
2061 else if (inverse_video
)
2063 if (fg
== FACE_TTY_DEFAULT_FG_COLOR
2064 || bg
== FACE_TTY_DEFAULT_BG_COLOR
)
2065 tty_toggle_highlight (tty
);
2069 if (fg
== FACE_TTY_DEFAULT_BG_COLOR
2070 || bg
== FACE_TTY_DEFAULT_FG_COLOR
)
2071 tty_toggle_highlight (tty
);
2076 /* If we can't display colors, use reverse video
2077 if the face specifies that. */
2080 if (fg
== FACE_TTY_DEFAULT_FG_COLOR
2081 || bg
== FACE_TTY_DEFAULT_BG_COLOR
)
2082 tty_toggle_highlight (tty
);
2086 if (fg
== FACE_TTY_DEFAULT_BG_COLOR
2087 || bg
== FACE_TTY_DEFAULT_FG_COLOR
)
2088 tty_toggle_highlight (tty
);
2093 if (face
->tty_bold_p
&& MAY_USE_WITH_COLORS_P (tty
, NC_BOLD
))
2094 OUTPUT1_IF (tty
, tty
->TS_enter_bold_mode
);
2096 if (face
->tty_dim_p
&& MAY_USE_WITH_COLORS_P (tty
, NC_DIM
))
2097 OUTPUT1_IF (tty
, tty
->TS_enter_dim_mode
);
2099 /* Alternate charset and blinking not yet used. */
2100 if (face
->tty_alt_charset_p
2101 && MAY_USE_WITH_COLORS_P (tty
, NC_ALT_CHARSET
))
2102 OUTPUT1_IF (tty
, tty
->TS_enter_alt_charset_mode
);
2104 if (face
->tty_blinking_p
2105 && MAY_USE_WITH_COLORS_P (tty
, NC_BLINK
))
2106 OUTPUT1_IF (tty
, tty
->TS_enter_blink_mode
);
2108 if (face
->tty_underline_p
&& MAY_USE_WITH_COLORS_P (tty
, NC_UNDERLINE
))
2109 OUTPUT1_IF (tty
, tty
->TS_enter_underline_mode
);
2111 if (tty
->TN_max_colors
> 0)
2116 ts
= tty
->standout_mode
? tty
->TS_set_background
: tty
->TS_set_foreground
;
2119 p
= tparam (ts
, NULL
, 0, (int) fg
, 0, 0, 0);
2124 ts
= tty
->standout_mode
? tty
->TS_set_foreground
: tty
->TS_set_background
;
2127 p
= tparam (ts
, NULL
, 0, (int) bg
, 0, 0, 0);
2135 /* Turn off appearances of face FACE_ID on tty frame F. */
2138 turn_off_face (struct frame
*f
, int face_id
)
2140 struct face
*face
= FACE_FROM_ID (f
, face_id
);
2141 struct tty_display_info
*tty
= FRAME_TTY (f
);
2143 xassert (face
!= NULL
);
2145 if (tty
->TS_exit_attribute_mode
)
2147 /* Capability "me" will turn off appearance modes double-bright,
2148 half-bright, reverse-video, standout, underline. It may or
2149 may not turn off alt-char-mode. */
2150 if (face
->tty_bold_p
2152 || face
->tty_reverse_p
2153 || face
->tty_alt_charset_p
2154 || face
->tty_blinking_p
2155 || face
->tty_underline_p
)
2157 OUTPUT1_IF (tty
, tty
->TS_exit_attribute_mode
);
2158 if (strcmp (tty
->TS_exit_attribute_mode
, tty
->TS_end_standout_mode
) == 0)
2159 tty
->standout_mode
= 0;
2162 if (face
->tty_alt_charset_p
)
2163 OUTPUT_IF (tty
, tty
->TS_exit_alt_charset_mode
);
2167 /* If we don't have "me" we can only have those appearances
2168 that have exit sequences defined. */
2169 if (face
->tty_alt_charset_p
)
2170 OUTPUT_IF (tty
, tty
->TS_exit_alt_charset_mode
);
2172 if (face
->tty_underline_p
)
2173 OUTPUT_IF (tty
, tty
->TS_exit_underline_mode
);
2176 /* Switch back to default colors. */
2177 if (tty
->TN_max_colors
> 0
2178 && ((face
->foreground
!= FACE_TTY_DEFAULT_COLOR
2179 && face
->foreground
!= FACE_TTY_DEFAULT_FG_COLOR
)
2180 || (face
->background
!= FACE_TTY_DEFAULT_COLOR
2181 && face
->background
!= FACE_TTY_DEFAULT_BG_COLOR
)))
2182 OUTPUT1_IF (tty
, tty
->TS_orig_pair
);
2186 /* Return non-zero if the terminal on frame F supports all of the
2187 capabilities in CAPS simultaneously, with foreground and background
2188 colors FG and BG. */
2191 tty_capable_p (struct tty_display_info
*tty
, unsigned int caps
,
2192 unsigned long fg
, unsigned long bg
)
2194 #define TTY_CAPABLE_P_TRY(tty, cap, TS, NC_bit) \
2195 if ((caps & (cap)) && (!(TS) || !MAY_USE_WITH_COLORS_P(tty, NC_bit))) \
2198 TTY_CAPABLE_P_TRY (tty
, TTY_CAP_INVERSE
, tty
->TS_standout_mode
, NC_REVERSE
);
2199 TTY_CAPABLE_P_TRY (tty
, TTY_CAP_UNDERLINE
, tty
->TS_enter_underline_mode
, NC_UNDERLINE
);
2200 TTY_CAPABLE_P_TRY (tty
, TTY_CAP_BOLD
, tty
->TS_enter_bold_mode
, NC_BOLD
);
2201 TTY_CAPABLE_P_TRY (tty
, TTY_CAP_DIM
, tty
->TS_enter_dim_mode
, NC_DIM
);
2202 TTY_CAPABLE_P_TRY (tty
, TTY_CAP_BLINK
, tty
->TS_enter_blink_mode
, NC_BLINK
);
2203 TTY_CAPABLE_P_TRY (tty
, TTY_CAP_ALT_CHARSET
, tty
->TS_enter_alt_charset_mode
, NC_ALT_CHARSET
);
2209 /* Return non-zero if the terminal is capable to display colors. */
2211 DEFUN ("tty-display-color-p", Ftty_display_color_p
, Stty_display_color_p
,
2213 doc
: /* Return non-nil if the tty device TERMINAL can display colors.
2215 TERMINAL can be a terminal object, a frame, or nil (meaning the
2216 selected frame's terminal). This function always returns nil if
2217 TERMINAL does not refer to a text-only terminal. */)
2218 (Lisp_Object terminal
)
2220 struct terminal
*t
= get_tty_terminal (terminal
, 0);
2224 return t
->display_info
.tty
->TN_max_colors
> 0 ? Qt
: Qnil
;
2227 /* Return the number of supported colors. */
2228 DEFUN ("tty-display-color-cells", Ftty_display_color_cells
,
2229 Stty_display_color_cells
, 0, 1, 0,
2230 doc
: /* Return the number of colors supported by the tty device TERMINAL.
2232 TERMINAL can be a terminal object, a frame, or nil (meaning the
2233 selected frame's terminal). This function always returns 0 if
2234 TERMINAL does not refer to a text-only terminal. */)
2235 (Lisp_Object terminal
)
2237 struct terminal
*t
= get_tty_terminal (terminal
, 0);
2239 return make_number (0);
2241 return make_number (t
->display_info
.tty
->TN_max_colors
);
2246 /* Declare here rather than in the function, as in the rest of Emacs,
2247 to work around an HPUX compiler bug (?). See
2248 http://lists.gnu.org/archive/html/emacs-devel/2007-08/msg00410.html */
2249 static int default_max_colors
;
2250 static int default_max_pairs
;
2251 static int default_no_color_video
;
2252 static char *default_orig_pair
;
2253 static char *default_set_foreground
;
2254 static char *default_set_background
;
2256 /* Save or restore the default color-related capabilities of this
2259 tty_default_color_capabilities (struct tty_display_info
*tty
, int save
)
2264 xfree (default_orig_pair
);
2265 default_orig_pair
= tty
->TS_orig_pair
? xstrdup (tty
->TS_orig_pair
) : NULL
;
2267 xfree (default_set_foreground
);
2268 default_set_foreground
= tty
->TS_set_foreground
? xstrdup (tty
->TS_set_foreground
)
2271 xfree (default_set_background
);
2272 default_set_background
= tty
->TS_set_background
? xstrdup (tty
->TS_set_background
)
2275 default_max_colors
= tty
->TN_max_colors
;
2276 default_max_pairs
= tty
->TN_max_pairs
;
2277 default_no_color_video
= tty
->TN_no_color_video
;
2281 tty
->TS_orig_pair
= default_orig_pair
;
2282 tty
->TS_set_foreground
= default_set_foreground
;
2283 tty
->TS_set_background
= default_set_background
;
2284 tty
->TN_max_colors
= default_max_colors
;
2285 tty
->TN_max_pairs
= default_max_pairs
;
2286 tty
->TN_no_color_video
= default_no_color_video
;
2290 /* Setup one of the standard tty color schemes according to MODE.
2291 MODE's value is generally the number of colors which we want to
2292 support; zero means set up for the default capabilities, the ones
2293 we saw at init_tty time; -1 means turn off color support. */
2295 tty_setup_colors (struct tty_display_info
*tty
, int mode
)
2297 /* Canonicalize all negative values of MODE. */
2303 case -1: /* no colors at all */
2304 tty
->TN_max_colors
= 0;
2305 tty
->TN_max_pairs
= 0;
2306 tty
->TN_no_color_video
= 0;
2307 tty
->TS_set_foreground
= tty
->TS_set_background
= tty
->TS_orig_pair
= NULL
;
2309 case 0: /* default colors, if any */
2311 tty_default_color_capabilities (tty
, 0);
2313 case 8: /* 8 standard ANSI colors */
2314 tty
->TS_orig_pair
= "\033[0m";
2316 tty
->TS_set_foreground
= "\033[3%p1%dm";
2317 tty
->TS_set_background
= "\033[4%p1%dm";
2319 tty
->TS_set_foreground
= "\033[3%dm";
2320 tty
->TS_set_background
= "\033[4%dm";
2322 tty
->TN_max_colors
= 8;
2323 tty
->TN_max_pairs
= 64;
2324 tty
->TN_no_color_video
= 0;
2330 set_tty_color_mode (struct tty_display_info
*tty
, struct frame
*f
)
2332 Lisp_Object tem
, val
;
2333 Lisp_Object color_mode
;
2335 Lisp_Object tty_color_mode_alist
2336 = Fintern_soft (build_string ("tty-color-mode-alist"), Qnil
);
2338 tem
= assq_no_quit (Qtty_color_mode
, f
->param_alist
);
2339 val
= CONSP (tem
) ? XCDR (tem
) : Qnil
;
2343 else if (SYMBOLP (tty_color_mode_alist
))
2345 tem
= Fassq (val
, Fsymbol_value (tty_color_mode_alist
));
2346 color_mode
= CONSP (tem
) ? XCDR (tem
) : Qnil
;
2351 mode
= INTEGERP (color_mode
) ? XINT (color_mode
) : 0;
2353 if (mode
!= tty
->previous_color_mode
)
2355 Lisp_Object funsym
= intern ("tty-set-up-initial-frame-faces");
2356 tty
->previous_color_mode
= mode
;
2357 tty_setup_colors (tty
, mode
);
2358 /* This recomputes all the faces given the new color definitions. */
2359 safe_call (1, &funsym
);
2363 #endif /* !DOS_NT */
2367 /* Return the tty display object specified by TERMINAL. */
2370 get_tty_terminal (Lisp_Object terminal
, int throw)
2372 struct terminal
*t
= get_terminal (terminal
, throw);
2374 if (t
&& t
->type
!= output_termcap
&& t
->type
!= output_msdos_raw
)
2377 error ("Device %d is not a termcap terminal device", t
->id
);
2385 /* Return an active termcap device that uses the tty device with the
2388 This function ignores suspended devices.
2390 Returns NULL if the named terminal device is not opened. */
2393 get_named_tty (const char *name
)
2400 for (t
= terminal_list
; t
; t
= t
->next_terminal
)
2402 if ((t
->type
== output_termcap
|| t
->type
== output_msdos_raw
)
2403 && !strcmp (t
->display_info
.tty
->name
, name
)
2404 && TERMINAL_ACTIVE_P (t
))
2412 DEFUN ("tty-type", Ftty_type
, Stty_type
, 0, 1, 0,
2413 doc
: /* Return the type of the tty device that TERMINAL uses.
2414 Returns nil if TERMINAL is not on a tty device.
2416 TERMINAL can be a terminal object, a frame, or nil (meaning the
2417 selected frame's terminal). */)
2418 (Lisp_Object terminal
)
2420 struct terminal
*t
= get_terminal (terminal
, 1);
2422 if (t
->type
!= output_termcap
&& t
->type
!= output_msdos_raw
)
2425 if (t
->display_info
.tty
->type
)
2426 return build_string (t
->display_info
.tty
->type
);
2431 DEFUN ("controlling-tty-p", Fcontrolling_tty_p
, Scontrolling_tty_p
, 0, 1, 0,
2432 doc
: /* Return non-nil if TERMINAL is the controlling tty of the Emacs process.
2434 TERMINAL can be a terminal object, a frame, or nil (meaning the
2435 selected frame's terminal). This function always returns nil if
2436 TERMINAL is not on a tty device. */)
2437 (Lisp_Object terminal
)
2439 struct terminal
*t
= get_terminal (terminal
, 1);
2441 if ((t
->type
!= output_termcap
&& t
->type
!= output_msdos_raw
)
2442 || strcmp (t
->display_info
.tty
->name
, DEV_TTY
) != 0)
2448 DEFUN ("tty-no-underline", Ftty_no_underline
, Stty_no_underline
, 0, 1, 0,
2449 doc
: /* Declare that the tty used by TERMINAL does not handle underlining.
2450 This is used to override the terminfo data, for certain terminals that
2451 do not really do underlining, but say that they do. This function has
2452 no effect if used on a non-tty terminal.
2454 TERMINAL can be a terminal object, a frame or nil (meaning the
2455 selected frame's terminal). This function always returns nil if
2456 TERMINAL does not refer to a text-only terminal. */)
2457 (Lisp_Object terminal
)
2459 struct terminal
*t
= get_terminal (terminal
, 1);
2461 if (t
->type
== output_termcap
)
2462 t
->display_info
.tty
->TS_enter_underline_mode
= 0;
2468 DEFUN ("suspend-tty", Fsuspend_tty
, Ssuspend_tty
, 0, 1, 0,
2469 doc
: /* Suspend the terminal device TTY.
2471 The device is restored to its default state, and Emacs ceases all
2472 access to the tty device. Frames that use the device are not deleted,
2473 but input is not read from them and if they change, their display is
2476 TTY may be a terminal object, a frame, or nil for the terminal device
2477 of the currently selected frame.
2479 This function runs `suspend-tty-functions' after suspending the
2480 device. The functions are run with one arg, the id of the suspended
2483 `suspend-tty' does nothing if it is called on a device that is already
2486 A suspended tty may be resumed by calling `resume-tty' on it. */)
2489 struct terminal
*t
= get_tty_terminal (tty
, 1);
2493 error ("Unknown tty device");
2495 f
= t
->display_info
.tty
->input
;
2499 /* First run `suspend-tty-functions' and then clean up the tty
2500 state because `suspend-tty-functions' might need to change
2502 Lisp_Object args
[2];
2503 args
[0] = intern ("suspend-tty-functions");
2504 XSETTERMINAL (args
[1], t
);
2505 Frun_hook_with_args (2, args
);
2507 reset_sys_modes (t
->display_info
.tty
);
2508 delete_keyboard_wait_descriptor (fileno (f
));
2512 if (f
!= t
->display_info
.tty
->output
)
2513 fclose (t
->display_info
.tty
->output
);
2516 t
->display_info
.tty
->input
= 0;
2517 t
->display_info
.tty
->output
= 0;
2519 if (FRAMEP (t
->display_info
.tty
->top_frame
))
2520 FRAME_SET_VISIBLE (XFRAME (t
->display_info
.tty
->top_frame
), 0);
2524 /* Clear display hooks to prevent further output. */
2525 clear_tty_hooks (t
);
2530 DEFUN ("resume-tty", Fresume_tty
, Sresume_tty
, 0, 1, 0,
2531 doc
: /* Resume the previously suspended terminal device TTY.
2532 The terminal is opened and reinitialized. Frames that are on the
2533 suspended terminal are revived.
2535 It is an error to resume a terminal while another terminal is active
2538 This function runs `resume-tty-functions' after resuming the terminal.
2539 The functions are run with one arg, the id of the resumed terminal
2542 `resume-tty' does nothing if it is called on a device that is not
2545 TTY may be a terminal object, a frame, or nil (meaning the selected
2546 frame's terminal). */)
2549 struct terminal
*t
= get_tty_terminal (tty
, 1);
2553 error ("Unknown tty device");
2555 if (!t
->display_info
.tty
->input
)
2557 if (get_named_tty (t
->display_info
.tty
->name
))
2558 error ("Cannot resume display while another display is active on the same device");
2561 t
->display_info
.tty
->output
= stdout
;
2562 t
->display_info
.tty
->input
= stdin
;
2564 fd
= emacs_open (t
->display_info
.tty
->name
, O_RDWR
| O_NOCTTY
, 0);
2567 error ("Can not reopen tty device %s: %s", t
->display_info
.tty
->name
, strerror (errno
));
2569 if (strcmp (t
->display_info
.tty
->name
, DEV_TTY
))
2570 dissociate_if_controlling_tty (fd
);
2572 t
->display_info
.tty
->output
= fdopen (fd
, "w+");
2573 t
->display_info
.tty
->input
= t
->display_info
.tty
->output
;
2576 add_keyboard_wait_descriptor (fd
);
2578 if (FRAMEP (t
->display_info
.tty
->top_frame
))
2580 struct frame
*f
= XFRAME (t
->display_info
.tty
->top_frame
);
2582 int old_height
= FRAME_COLS (f
);
2583 int old_width
= FRAME_LINES (f
);
2585 /* Check if terminal/window size has changed while the frame
2587 get_tty_size (fileno (t
->display_info
.tty
->input
), &width
, &height
);
2588 if (width
!= old_width
|| height
!= old_height
)
2589 change_frame_size (f
, height
, width
, 0, 0, 0);
2590 FRAME_SET_VISIBLE (XFRAME (t
->display_info
.tty
->top_frame
), 1);
2593 init_sys_modes (t
->display_info
.tty
);
2596 /* Run `resume-tty-functions'. */
2597 Lisp_Object args
[2];
2598 args
[0] = intern ("resume-tty-functions");
2599 XSETTERMINAL (args
[1], t
);
2600 Frun_hook_with_args (2, args
);
2610 /***********************************************************************
2612 ***********************************************************************/
2616 term_mouse_moveto (int x
, int y
)
2618 /* TODO: how to set mouse position?
2621 name = (const char *) ttyname (0);
2622 fd = open (name, O_WRONLY);
2623 SOME_FUNCTION (x, y, fd);
2626 last_mouse_y = y; */
2629 /* Implementation of draw_row_with_mouse_face for TTY/GPM. */
2631 tty_draw_row_with_mouse_face (struct window
*w
, struct glyph_row
*row
,
2632 int start_hpos
, int end_hpos
,
2633 enum draw_glyphs_face draw
)
2635 int nglyphs
= end_hpos
- start_hpos
;
2636 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
2637 struct tty_display_info
*tty
= FRAME_TTY (f
);
2638 int face_id
= tty
->mouse_highlight
.mouse_face_face_id
;
2639 int save_x
, save_y
, pos_x
, pos_y
;
2641 if (end_hpos
>= row
->used
[TEXT_AREA
])
2642 nglyphs
= row
->used
[TEXT_AREA
] - start_hpos
;
2644 pos_y
= row
->y
+ WINDOW_TOP_EDGE_Y (w
);
2645 pos_x
= row
->used
[LEFT_MARGIN_AREA
] + start_hpos
+ WINDOW_LEFT_EDGE_X (w
);
2647 /* Save current cursor co-ordinates. */
2648 save_y
= curY (tty
);
2649 save_x
= curX (tty
);
2650 cursor_to (f
, pos_y
, pos_x
);
2652 if (draw
== DRAW_MOUSE_FACE
)
2653 tty_write_glyphs_with_face (f
, row
->glyphs
[TEXT_AREA
] + start_hpos
,
2655 else if (draw
== DRAW_NORMAL_TEXT
)
2656 write_glyphs (f
, row
->glyphs
[TEXT_AREA
] + start_hpos
, nglyphs
);
2658 cursor_to (f
, save_y
, save_x
);
2662 term_mouse_movement (FRAME_PTR frame
, Gpm_Event
*event
)
2664 /* Has the mouse moved off the glyph it was on at the last sighting? */
2665 if (event
->x
!= last_mouse_x
|| event
->y
!= last_mouse_y
)
2667 frame
->mouse_moved
= 1;
2668 note_mouse_highlight (frame
, event
->x
, event
->y
);
2669 /* Remember which glyph we're now on. */
2670 last_mouse_x
= event
->x
;
2671 last_mouse_y
= event
->y
;
2677 /* Return the current position of the mouse.
2679 Set *f to the frame the mouse is in, or zero if the mouse is in no
2680 Emacs frame. If it is set to zero, all the other arguments are
2683 Set *bar_window to Qnil, and *x and *y to the column and
2684 row of the character cell the mouse is over.
2686 Set *timeptr to the time the mouse was at the returned position.
2688 This clears mouse_moved until the next motion
2691 term_mouse_position (FRAME_PTR
*fp
, int insist
, Lisp_Object
*bar_window
,
2692 enum scroll_bar_part
*part
, Lisp_Object
*x
,
2693 Lisp_Object
*y
, unsigned long *timeptr
)
2697 *fp
= SELECTED_FRAME ();
2698 (*fp
)->mouse_moved
= 0;
2703 XSETINT (*x
, last_mouse_x
);
2704 XSETINT (*y
, last_mouse_y
);
2705 gettimeofday(&now
, 0);
2706 *timeptr
= (now
.tv_sec
* 1000) + (now
.tv_usec
/ 1000);
2709 /* Prepare a mouse-event in *RESULT for placement in the input queue.
2711 If the event is a button press, then note that we have grabbed
2715 term_mouse_click (struct input_event
*result
, Gpm_Event
*event
,
2721 result
->kind
= GPM_CLICK_EVENT
;
2722 for (i
= 0, j
= GPM_B_LEFT
; i
< 3; i
++, j
>>= 1 )
2724 if (event
->buttons
& j
) {
2725 result
->code
= i
; /* button number */
2729 gettimeofday(&now
, 0);
2730 result
->timestamp
= (now
.tv_sec
* 1000) + (now
.tv_usec
/ 1000);
2732 if (event
->type
& GPM_UP
)
2733 result
->modifiers
= up_modifier
;
2734 else if (event
->type
& GPM_DOWN
)
2735 result
->modifiers
= down_modifier
;
2737 result
->modifiers
= 0;
2739 if (event
->type
& GPM_SINGLE
)
2740 result
->modifiers
|= click_modifier
;
2742 if (event
->type
& GPM_DOUBLE
)
2743 result
->modifiers
|= double_modifier
;
2745 if (event
->type
& GPM_TRIPLE
)
2746 result
->modifiers
|= triple_modifier
;
2748 if (event
->type
& GPM_DRAG
)
2749 result
->modifiers
|= drag_modifier
;
2751 if (!(event
->type
& (GPM_MOVE
| GPM_DRAG
))) {
2754 if (event
->modifiers
& (1 << 0))
2755 result
->modifiers
|= shift_modifier
;
2758 if (event
->modifiers
& (1 << 2))
2759 result
->modifiers
|= ctrl_modifier
;
2761 /* 1 << KG_ALT || KG_ALTGR */
2762 if (event
->modifiers
& (1 << 3)
2763 || event
->modifiers
& (1 << 1))
2764 result
->modifiers
|= meta_modifier
;
2767 XSETINT (result
->x
, event
->x
);
2768 XSETINT (result
->y
, event
->y
);
2769 XSETFRAME (result
->frame_or_window
, f
);
2775 handle_one_term_event (struct tty_display_info
*tty
, Gpm_Event
*event
, struct input_event
* hold_quit
)
2777 struct frame
*f
= XFRAME (tty
->top_frame
);
2778 struct input_event ie
;
2786 if (event
->type
& (GPM_MOVE
| GPM_DRAG
)) {
2787 previous_help_echo_string
= help_echo_string
;
2788 help_echo_string
= Qnil
;
2790 Gpm_DrawPointer (event
->x
, event
->y
, fileno (tty
->output
));
2792 if (!term_mouse_movement (f
, event
))
2793 help_echo_string
= previous_help_echo_string
;
2795 /* If the contents of the global variable help_echo_string
2796 has changed, generate a HELP_EVENT. */
2797 if (!NILP (help_echo_string
)
2798 || !NILP (previous_help_echo_string
))
2805 term_mouse_click (&ie
, event
, f
);
2809 if (ie
.kind
!= NO_EVENT
)
2811 kbd_buffer_store_event_hold (&ie
, hold_quit
);
2816 && !(hold_quit
&& hold_quit
->kind
!= NO_EVENT
))
2821 XSETFRAME (frame
, f
);
2825 gen_help_event (help_echo_string
, frame
, help_echo_window
,
2826 help_echo_object
, help_echo_pos
);
2833 DEFUN ("gpm-mouse-start", Fgpm_mouse_start
, Sgpm_mouse_start
,
2835 doc
: /* Open a connection to Gpm.
2836 Gpm-mouse can only be activated for one tty at a time. */)
2839 struct frame
*f
= SELECTED_FRAME ();
2840 struct tty_display_info
*tty
2841 = ((f
)->output_method
== output_termcap
2842 ? (f
)->terminal
->display_info
.tty
: NULL
);
2843 Gpm_Connect connection
;
2846 error ("Gpm-mouse only works in the GNU/Linux console");
2848 return Qnil
; /* Already activated, nothing to do. */
2850 error ("Gpm-mouse can only be activated for one tty at a time");
2852 connection
.eventMask
= ~0;
2853 connection
.defaultMask
= ~GPM_HARD
;
2854 connection
.maxMod
= ~0;
2855 connection
.minMod
= 0;
2858 if (Gpm_Open (&connection
, 0) < 0)
2859 error ("Gpm-mouse failed to connect to the gpm daemon");
2863 /* `init_sys_modes' arranges for mouse movements sent through gpm_fd
2864 to generate SIGIOs. Apparently we need to call reset_sys_modes
2865 before calling init_sys_modes. */
2866 reset_sys_modes (tty
);
2867 init_sys_modes (tty
);
2868 add_gpm_wait_descriptor (gpm_fd
);
2877 delete_gpm_wait_descriptor (fd
);
2878 while (Gpm_Close()); /* close all the stack */
2882 DEFUN ("gpm-mouse-stop", Fgpm_mouse_stop
, Sgpm_mouse_stop
,
2884 doc
: /* Close a connection to Gpm. */)
2887 struct frame
*f
= SELECTED_FRAME ();
2888 struct tty_display_info
*tty
2889 = ((f
)->output_method
== output_termcap
2890 ? (f
)->terminal
->display_info
.tty
: NULL
);
2892 if (!tty
|| gpm_tty
!= tty
)
2893 return Qnil
; /* Not activated on this terminal, nothing to do. */
2898 #endif /* HAVE_GPM */
2902 /***********************************************************************
2904 ***********************************************************************/
2906 /* Initialize the tty-dependent part of frame F. The frame must
2907 already have its device initialized. */
2910 create_tty_output (struct frame
*f
)
2912 struct tty_output
*t
;
2914 if (! FRAME_TERMCAP_P (f
))
2917 t
= xmalloc (sizeof (struct tty_output
));
2918 memset (t
, 0, sizeof (struct tty_output
));
2920 t
->display_info
= FRAME_TERMINAL (f
)->display_info
.tty
;
2922 f
->output_data
.tty
= t
;
2925 /* Delete frame F's face cache, and its tty-dependent part. */
2928 tty_free_frame_resources (struct frame
*f
)
2930 if (! FRAME_TERMCAP_P (f
))
2933 if (FRAME_FACE_CACHE (f
))
2934 free_frame_faces (f
);
2936 xfree (f
->output_data
.tty
);
2941 /* Delete frame F's face cache. */
2944 tty_free_frame_resources (struct frame
*f
)
2946 if (! FRAME_TERMCAP_P (f
) && ! FRAME_MSDOS_P (f
))
2949 if (FRAME_FACE_CACHE (f
))
2950 free_frame_faces (f
);
2954 /* Reset the hooks in TERMINAL. */
2957 clear_tty_hooks (struct terminal
*terminal
)
2960 terminal
->cursor_to_hook
= 0;
2961 terminal
->raw_cursor_to_hook
= 0;
2962 terminal
->clear_to_end_hook
= 0;
2963 terminal
->clear_frame_hook
= 0;
2964 terminal
->clear_end_of_line_hook
= 0;
2965 terminal
->ins_del_lines_hook
= 0;
2966 terminal
->insert_glyphs_hook
= 0;
2967 terminal
->write_glyphs_hook
= 0;
2968 terminal
->delete_glyphs_hook
= 0;
2969 terminal
->ring_bell_hook
= 0;
2970 terminal
->reset_terminal_modes_hook
= 0;
2971 terminal
->set_terminal_modes_hook
= 0;
2972 terminal
->update_begin_hook
= 0;
2973 terminal
->update_end_hook
= 0;
2974 terminal
->set_terminal_window_hook
= 0;
2975 terminal
->mouse_position_hook
= 0;
2976 terminal
->frame_rehighlight_hook
= 0;
2977 terminal
->frame_raise_lower_hook
= 0;
2978 terminal
->fullscreen_hook
= 0;
2979 terminal
->set_vertical_scroll_bar_hook
= 0;
2980 terminal
->condemn_scroll_bars_hook
= 0;
2981 terminal
->redeem_scroll_bar_hook
= 0;
2982 terminal
->judge_scroll_bars_hook
= 0;
2983 terminal
->read_socket_hook
= 0;
2984 terminal
->frame_up_to_date_hook
= 0;
2986 /* Leave these two set, or suspended frames are not deleted
2988 terminal
->delete_frame_hook
= &tty_free_frame_resources
;
2989 terminal
->delete_terminal_hook
= &delete_tty
;
2992 /* Initialize hooks in TERMINAL with the values needed for a tty. */
2995 set_tty_hooks (struct terminal
*terminal
)
2997 terminal
->rif
= 0; /* ttys don't support window-based redisplay. */
2999 terminal
->cursor_to_hook
= &tty_cursor_to
;
3000 terminal
->raw_cursor_to_hook
= &tty_raw_cursor_to
;
3002 terminal
->clear_to_end_hook
= &tty_clear_to_end
;
3003 terminal
->clear_frame_hook
= &tty_clear_frame
;
3004 terminal
->clear_end_of_line_hook
= &tty_clear_end_of_line
;
3006 terminal
->ins_del_lines_hook
= &tty_ins_del_lines
;
3008 terminal
->insert_glyphs_hook
= &tty_insert_glyphs
;
3009 terminal
->write_glyphs_hook
= &tty_write_glyphs
;
3010 terminal
->delete_glyphs_hook
= &tty_delete_glyphs
;
3012 terminal
->ring_bell_hook
= &tty_ring_bell
;
3014 terminal
->reset_terminal_modes_hook
= &tty_reset_terminal_modes
;
3015 terminal
->set_terminal_modes_hook
= &tty_set_terminal_modes
;
3016 terminal
->update_begin_hook
= 0; /* Not needed. */
3017 terminal
->update_end_hook
= &tty_update_end
;
3018 terminal
->set_terminal_window_hook
= &tty_set_terminal_window
;
3020 terminal
->mouse_position_hook
= 0; /* Not needed. */
3021 terminal
->frame_rehighlight_hook
= 0; /* Not needed. */
3022 terminal
->frame_raise_lower_hook
= 0; /* Not needed. */
3024 terminal
->set_vertical_scroll_bar_hook
= 0; /* Not needed. */
3025 terminal
->condemn_scroll_bars_hook
= 0; /* Not needed. */
3026 terminal
->redeem_scroll_bar_hook
= 0; /* Not needed. */
3027 terminal
->judge_scroll_bars_hook
= 0; /* Not needed. */
3029 terminal
->read_socket_hook
= &tty_read_avail_input
; /* keyboard.c */
3030 terminal
->frame_up_to_date_hook
= 0; /* Not needed. */
3032 terminal
->delete_frame_hook
= &tty_free_frame_resources
;
3033 terminal
->delete_terminal_hook
= &delete_tty
;
3036 /* Drop the controlling terminal if fd is the same device. */
3038 dissociate_if_controlling_tty (int fd
)
3041 int pgid
= tcgetpgrp (fd
); /* If tcgetpgrp succeeds, fd is the ctty. */
3046 no_controlling_tty
= 1;
3047 #elif defined (CYGWIN)
3049 no_controlling_tty
= 1;
3051 #ifdef TIOCNOTTY /* Try BSD ioctls. */
3052 sigblock (sigmask (SIGTTOU
));
3053 fd
= emacs_open (DEV_TTY
, O_RDWR
, 0);
3054 if (fd
!= -1 && ioctl (fd
, TIOCNOTTY
, 0) != -1)
3056 no_controlling_tty
= 1;
3060 sigunblock (sigmask (SIGTTOU
));
3062 /* Unknown system. */
3064 #endif /* ! TIOCNOTTY */
3067 #endif /* !DOS_NT */
3070 /* Create a termcap display on the tty device with the given name and
3073 If NAME is NULL, then use the controlling tty, i.e., "/dev/tty".
3074 Otherwise NAME should be a path to the tty device file,
3077 TERMINAL_TYPE is the termcap type of the device, e.g. "vt100".
3079 If MUST_SUCCEED is true, then all errors are fatal. */
3082 init_tty (const char *name
, const char *terminal_type
, int must_succeed
)
3085 char **address
= &area
;
3086 int buffer_size
= 4096;
3087 register char *p
= NULL
;
3089 struct tty_display_info
*tty
= NULL
;
3090 struct terminal
*terminal
= NULL
;
3091 int ctty
= 0; /* 1 if asked to open controlling tty. */
3094 maybe_fatal (must_succeed
, 0,
3095 "Unknown terminal type",
3096 "Unknown terminal type");
3100 if (!strcmp (name
, DEV_TTY
))
3103 /* If we already have a terminal on the given device, use that. If
3104 all such terminals are suspended, create a new one instead. */
3105 /* XXX Perhaps this should be made explicit by having init_tty
3106 always create a new terminal and separating terminal and frame
3107 creation on Lisp level. */
3108 terminal
= get_named_tty (name
);
3112 terminal
= create_terminal ();
3115 maybe_fatal (1, 0, "Attempt to create another terminal %s", "",
3118 tty
= &the_only_display_info
;
3120 tty
= (struct tty_display_info
*) xmalloc (sizeof (struct tty_display_info
));
3122 memset (tty
, 0, sizeof (struct tty_display_info
));
3123 tty
->next
= tty_list
;
3126 terminal
->type
= output_termcap
;
3127 terminal
->display_info
.tty
= tty
;
3128 tty
->terminal
= terminal
;
3130 tty
->Wcm
= (struct cm
*) xmalloc (sizeof (struct cm
));
3133 encode_terminal_src_size
= 0;
3134 encode_terminal_dst_size
= 0;
3137 terminal
->mouse_position_hook
= term_mouse_position
;
3138 tty
->mouse_highlight
.mouse_face_window
= Qnil
;
3143 set_tty_hooks (terminal
);
3149 #ifdef O_IGNORE_CTTY
3151 /* Open the terminal device. Don't recognize it as our
3152 controlling terminal, and don't make it the controlling tty
3153 if we don't have one at the moment. */
3154 fd
= emacs_open (name
, O_RDWR
| O_IGNORE_CTTY
| O_NOCTTY
, 0);
3157 /* Alas, O_IGNORE_CTTY is a GNU extension that seems to be only
3158 defined on Hurd. On other systems, we need to explicitly
3159 dissociate ourselves from the controlling tty when we want to
3160 open a frame on the same terminal. */
3161 fd
= emacs_open (name
, O_RDWR
| O_NOCTTY
, 0);
3162 #endif /* O_IGNORE_CTTY */
3164 tty
->name
= xstrdup (name
);
3165 terminal
->name
= xstrdup (name
);
3168 maybe_fatal (must_succeed
, terminal
,
3169 "Could not open file: %s",
3170 "Could not open file: %s",
3175 maybe_fatal (must_succeed
, terminal
,
3176 "Not a tty device: %s",
3177 "Not a tty device: %s",
3181 #ifndef O_IGNORE_CTTY
3183 dissociate_if_controlling_tty (fd
);
3186 file
= fdopen (fd
, "w+");
3191 tty
->type
= xstrdup (terminal_type
);
3193 add_keyboard_wait_descriptor (fileno (tty
->input
));
3197 tty
->termcap_term_buffer
= (char *) xmalloc (buffer_size
);
3199 /* On some systems, tgetent tries to access the controlling
3201 sigblock (sigmask (SIGTTOU
));
3202 status
= tgetent (tty
->termcap_term_buffer
, terminal_type
);
3203 sigunblock (sigmask (SIGTTOU
));
3208 maybe_fatal (must_succeed
, terminal
,
3209 "Cannot open terminfo database file",
3210 "Cannot open terminfo database file");
3212 maybe_fatal (must_succeed
, terminal
,
3213 "Cannot open termcap database file",
3214 "Cannot open termcap database file");
3219 maybe_fatal (must_succeed
, terminal
,
3220 "Terminal type %s is not defined",
3221 "Terminal type %s is not defined.\n\
3222 If that is not the actual type of terminal you have,\n\
3223 use the Bourne shell command `TERM=... export TERM' (C-shell:\n\
3224 `setenv TERM ...') to specify the correct type. It may be necessary\n"
3226 "to do `unset TERMINFO' (C-shell: `unsetenv TERMINFO') as well.",
3228 "to do `unset TERMCAP' (C-shell: `unsetenv TERMCAP') as well.",
3234 if (strlen (tty
->termcap_term_buffer
) >= buffer_size
)
3236 buffer_size
= strlen (tty
->termcap_term_buffer
);
3238 tty
->termcap_strings_buffer
= area
= (char *) xmalloc (buffer_size
);
3239 tty
->TS_ins_line
= tgetstr ("al", address
);
3240 tty
->TS_ins_multi_lines
= tgetstr ("AL", address
);
3241 tty
->TS_bell
= tgetstr ("bl", address
);
3242 BackTab (tty
) = tgetstr ("bt", address
);
3243 tty
->TS_clr_to_bottom
= tgetstr ("cd", address
);
3244 tty
->TS_clr_line
= tgetstr ("ce", address
);
3245 tty
->TS_clr_frame
= tgetstr ("cl", address
);
3246 ColPosition (tty
) = NULL
; /* tgetstr ("ch", address); */
3247 AbsPosition (tty
) = tgetstr ("cm", address
);
3248 CR (tty
) = tgetstr ("cr", address
);
3249 tty
->TS_set_scroll_region
= tgetstr ("cs", address
);
3250 tty
->TS_set_scroll_region_1
= tgetstr ("cS", address
);
3251 RowPosition (tty
) = tgetstr ("cv", address
);
3252 tty
->TS_del_char
= tgetstr ("dc", address
);
3253 tty
->TS_del_multi_chars
= tgetstr ("DC", address
);
3254 tty
->TS_del_line
= tgetstr ("dl", address
);
3255 tty
->TS_del_multi_lines
= tgetstr ("DL", address
);
3256 tty
->TS_delete_mode
= tgetstr ("dm", address
);
3257 tty
->TS_end_delete_mode
= tgetstr ("ed", address
);
3258 tty
->TS_end_insert_mode
= tgetstr ("ei", address
);
3259 Home (tty
) = tgetstr ("ho", address
);
3260 tty
->TS_ins_char
= tgetstr ("ic", address
);
3261 tty
->TS_ins_multi_chars
= tgetstr ("IC", address
);
3262 tty
->TS_insert_mode
= tgetstr ("im", address
);
3263 tty
->TS_pad_inserted_char
= tgetstr ("ip", address
);
3264 tty
->TS_end_keypad_mode
= tgetstr ("ke", address
);
3265 tty
->TS_keypad_mode
= tgetstr ("ks", address
);
3266 LastLine (tty
) = tgetstr ("ll", address
);
3267 Right (tty
) = tgetstr ("nd", address
);
3268 Down (tty
) = tgetstr ("do", address
);
3270 Down (tty
) = tgetstr ("nl", address
); /* Obsolete name for "do" */
3271 if (tgetflag ("bs"))
3272 Left (tty
) = "\b"; /* can't possibly be longer! */
3273 else /* (Actually, "bs" is obsolete...) */
3274 Left (tty
) = tgetstr ("le", address
);
3276 Left (tty
) = tgetstr ("bc", address
); /* Obsolete name for "le" */
3277 tty
->TS_pad_char
= tgetstr ("pc", address
);
3278 tty
->TS_repeat
= tgetstr ("rp", address
);
3279 tty
->TS_end_standout_mode
= tgetstr ("se", address
);
3280 tty
->TS_fwd_scroll
= tgetstr ("sf", address
);
3281 tty
->TS_standout_mode
= tgetstr ("so", address
);
3282 tty
->TS_rev_scroll
= tgetstr ("sr", address
);
3283 tty
->Wcm
->cm_tab
= tgetstr ("ta", address
);
3284 tty
->TS_end_termcap_modes
= tgetstr ("te", address
);
3285 tty
->TS_termcap_modes
= tgetstr ("ti", address
);
3286 Up (tty
) = tgetstr ("up", address
);
3287 tty
->TS_visible_bell
= tgetstr ("vb", address
);
3288 tty
->TS_cursor_normal
= tgetstr ("ve", address
);
3289 tty
->TS_cursor_visible
= tgetstr ("vs", address
);
3290 tty
->TS_cursor_invisible
= tgetstr ("vi", address
);
3291 tty
->TS_set_window
= tgetstr ("wi", address
);
3293 tty
->TS_enter_underline_mode
= tgetstr ("us", address
);
3294 tty
->TS_exit_underline_mode
= tgetstr ("ue", address
);
3295 tty
->TS_enter_bold_mode
= tgetstr ("md", address
);
3296 tty
->TS_enter_dim_mode
= tgetstr ("mh", address
);
3297 tty
->TS_enter_blink_mode
= tgetstr ("mb", address
);
3298 tty
->TS_enter_reverse_mode
= tgetstr ("mr", address
);
3299 tty
->TS_enter_alt_charset_mode
= tgetstr ("as", address
);
3300 tty
->TS_exit_alt_charset_mode
= tgetstr ("ae", address
);
3301 tty
->TS_exit_attribute_mode
= tgetstr ("me", address
);
3303 MultiUp (tty
) = tgetstr ("UP", address
);
3304 MultiDown (tty
) = tgetstr ("DO", address
);
3305 MultiLeft (tty
) = tgetstr ("LE", address
);
3306 MultiRight (tty
) = tgetstr ("RI", address
);
3308 /* SVr4/ANSI color suppert. If "op" isn't available, don't support
3309 color because we can't switch back to the default foreground and
3311 tty
->TS_orig_pair
= tgetstr ("op", address
);
3312 if (tty
->TS_orig_pair
)
3314 tty
->TS_set_foreground
= tgetstr ("AF", address
);
3315 tty
->TS_set_background
= tgetstr ("AB", address
);
3316 if (!tty
->TS_set_foreground
)
3319 tty
->TS_set_foreground
= tgetstr ("Sf", address
);
3320 tty
->TS_set_background
= tgetstr ("Sb", address
);
3323 tty
->TN_max_colors
= tgetnum ("Co");
3324 tty
->TN_max_pairs
= tgetnum ("pa");
3326 tty
->TN_no_color_video
= tgetnum ("NC");
3327 if (tty
->TN_no_color_video
== -1)
3328 tty
->TN_no_color_video
= 0;
3331 tty_default_color_capabilities (tty
, 1);
3333 MagicWrap (tty
) = tgetflag ("xn");
3334 /* Since we make MagicWrap terminals look like AutoWrap, we need to have
3335 the former flag imply the latter. */
3336 AutoWrap (tty
) = MagicWrap (tty
) || tgetflag ("am");
3337 terminal
->memory_below_frame
= tgetflag ("db");
3338 tty
->TF_hazeltine
= tgetflag ("hz");
3339 terminal
->must_write_spaces
= tgetflag ("in");
3340 tty
->meta_key
= tgetflag ("km") || tgetflag ("MT");
3341 tty
->TF_insmode_motion
= tgetflag ("mi");
3342 tty
->TF_standout_motion
= tgetflag ("ms");
3343 tty
->TF_underscore
= tgetflag ("ul");
3344 tty
->TF_teleray
= tgetflag ("xt");
3349 struct frame
*f
= XFRAME (selected_frame
);
3351 initialize_w32_display (terminal
);
3353 FrameRows (tty
) = FRAME_LINES (f
);
3354 FrameCols (tty
) = FRAME_COLS (f
);
3355 tty
->specified_window
= FRAME_LINES (f
);
3357 FRAME_CAN_HAVE_SCROLL_BARS (f
) = 0;
3358 FRAME_VERTICAL_SCROLL_BAR_TYPE (f
) = vertical_scroll_bar_none
;
3359 terminal
->char_ins_del_ok
= 1;
3365 if (strcmp (terminal_type
, "internal") == 0)
3366 terminal
->type
= output_msdos_raw
;
3367 initialize_msdos_display (terminal
);
3369 get_tty_size (fileno (tty
->input
), &width
, &height
);
3370 FrameCols (tty
) = width
;
3371 FrameRows (tty
) = height
;
3372 terminal
->char_ins_del_ok
= 0;
3373 init_baud_rate (fileno (tty
->input
));
3376 tty
->output
= stdout
;
3378 /* The following two are inaccessible from w32console.c. */
3379 terminal
->delete_frame_hook
= &tty_free_frame_resources
;
3380 terminal
->delete_terminal_hook
= &delete_tty
;
3382 tty
->name
= xstrdup (name
);
3383 terminal
->name
= xstrdup (name
);
3384 tty
->type
= xstrdup (terminal_type
);
3386 add_keyboard_wait_descriptor (0);
3388 tty
->delete_in_insert_mode
= 1;
3391 terminal
->scroll_region_ok
= 0;
3393 /* Seems to insert lines when it's not supposed to, messing up the
3394 display. In doing a trace, it didn't seem to be called much, so I
3395 don't think we're losing anything by turning it off. */
3396 terminal
->line_ins_del_ok
= 0;
3398 tty
->TN_max_colors
= 16; /* Required to be non-zero for tty-display-color-p */
3401 terminal
->kboard
= (KBOARD
*) xmalloc (sizeof (KBOARD
));
3402 init_kboard (terminal
->kboard
);
3403 KVAR (terminal
->kboard
, Vwindow_system
) = Qnil
;
3404 terminal
->kboard
->next_kboard
= all_kboards
;
3405 all_kboards
= terminal
->kboard
;
3406 terminal
->kboard
->reference_count
++;
3407 /* Don't let the initial kboard remain current longer than necessary.
3408 That would cause problems if a file loaded on startup tries to
3409 prompt in the mini-buffer. */
3410 if (current_kboard
== initial_kboard
)
3411 current_kboard
= terminal
->kboard
;
3413 term_get_fkeys (address
, terminal
->kboard
);
3415 /* Get frame size from system, or else from termcap. */
3418 get_tty_size (fileno (tty
->input
), &width
, &height
);
3419 FrameCols (tty
) = width
;
3420 FrameRows (tty
) = height
;
3423 if (FrameCols (tty
) <= 0)
3424 FrameCols (tty
) = tgetnum ("co");
3425 if (FrameRows (tty
) <= 0)
3426 FrameRows (tty
) = tgetnum ("li");
3428 if (FrameRows (tty
) < 3 || FrameCols (tty
) < 3)
3429 maybe_fatal (must_succeed
, terminal
,
3430 "Screen size %dx%d is too small",
3431 "Screen size %dx%d is too small",
3432 FrameCols (tty
), FrameRows (tty
));
3434 TabWidth (tty
) = tgetnum ("tw");
3437 tty
->TS_bell
= "\07";
3439 if (!tty
->TS_fwd_scroll
)
3440 tty
->TS_fwd_scroll
= Down (tty
);
3442 PC
= tty
->TS_pad_char
? *tty
->TS_pad_char
: 0;
3444 if (TabWidth (tty
) < 0)
3447 /* Turned off since /etc/termcap seems to have :ta= for most terminals
3448 and newer termcap doc does not seem to say there is a default.
3449 if (!tty->Wcm->cm_tab)
3450 tty->Wcm->cm_tab = "\t";
3453 /* We don't support standout modes that use `magic cookies', so
3454 turn off any that do. */
3455 if (tty
->TS_standout_mode
&& tgetnum ("sg") >= 0)
3457 tty
->TS_standout_mode
= 0;
3458 tty
->TS_end_standout_mode
= 0;
3460 if (tty
->TS_enter_underline_mode
&& tgetnum ("ug") >= 0)
3462 tty
->TS_enter_underline_mode
= 0;
3463 tty
->TS_exit_underline_mode
= 0;
3466 /* If there's no standout mode, try to use underlining instead. */
3467 if (tty
->TS_standout_mode
== 0)
3469 tty
->TS_standout_mode
= tty
->TS_enter_underline_mode
;
3470 tty
->TS_end_standout_mode
= tty
->TS_exit_underline_mode
;
3473 /* If no `se' string, try using a `me' string instead.
3474 If that fails, we can't use standout mode at all. */
3475 if (tty
->TS_end_standout_mode
== 0)
3477 char *s
= tgetstr ("me", address
);
3479 tty
->TS_end_standout_mode
= s
;
3481 tty
->TS_standout_mode
= 0;
3484 if (tty
->TF_teleray
)
3486 tty
->Wcm
->cm_tab
= 0;
3487 /* We can't support standout mode, because it uses magic cookies. */
3488 tty
->TS_standout_mode
= 0;
3489 /* But that means we cannot rely on ^M to go to column zero! */
3491 /* LF can't be trusted either -- can alter hpos */
3492 /* if move at column 0 thru a line with TS_standout_mode */
3496 /* Special handling for certain terminal types known to need it */
3498 if (!strcmp (terminal_type
, "supdup"))
3500 terminal
->memory_below_frame
= 1;
3501 tty
->Wcm
->cm_losewrap
= 1;
3503 if (!strncmp (terminal_type
, "c10", 3)
3504 || !strcmp (terminal_type
, "perq"))
3506 /* Supply a makeshift :wi string.
3507 This string is not valid in general since it works only
3508 for windows starting at the upper left corner;
3509 but that is all Emacs uses.
3511 This string works only if the frame is using
3512 the top of the video memory, because addressing is memory-relative.
3513 So first check the :ti string to see if that is true.
3515 It would be simpler if the :wi string could go in the termcap
3516 entry, but it can't because it is not fully valid.
3517 If it were in the termcap entry, it would confuse other programs. */
3518 if (!tty
->TS_set_window
)
3520 const char *m
= tty
->TS_termcap_modes
;
3521 while (*m
&& strcmp (m
, "\033v "))
3524 tty
->TS_set_window
= "\033v%C %C %C %C ";
3526 /* Termcap entry often fails to have :in: flag */
3527 terminal
->must_write_spaces
= 1;
3528 /* :ti string typically fails to have \E^G! in it */
3529 /* This limits scope of insert-char to one line. */
3530 strcpy (area
, tty
->TS_termcap_modes
);
3531 strcat (area
, "\033\007!");
3532 tty
->TS_termcap_modes
= area
;
3533 area
+= strlen (area
) + 1;
3534 p
= AbsPosition (tty
);
3535 /* Change all %+ parameters to %C, to handle
3536 values above 96 correctly for the C100. */
3539 if (p
[0] == '%' && p
[1] == '+')
3545 tty
->specified_window
= FrameRows (tty
);
3547 if (Wcm_init (tty
) == -1) /* can't do cursor motion */
3549 maybe_fatal (must_succeed
, terminal
,
3550 "Terminal type \"%s\" is not powerful enough to run Emacs",
3551 "Terminal type \"%s\" is not powerful enough to run Emacs.\n\
3552 It lacks the ability to position the cursor.\n\
3553 If that is not the actual type of terminal you have,\n\
3554 use the Bourne shell command `TERM=... export TERM' (C-shell:\n\
3555 `setenv TERM ...') to specify the correct type. It may be necessary\n"
3557 "to do `unset TERMINFO' (C-shell: `unsetenv TERMINFO') as well.",
3558 # else /* TERMCAP */
3559 "to do `unset TERMCAP' (C-shell: `unsetenv TERMCAP') as well.",
3560 # endif /* TERMINFO */
3564 if (FrameRows (tty
) <= 0 || FrameCols (tty
) <= 0)
3565 maybe_fatal (must_succeed
, terminal
,
3566 "Could not determine the frame size",
3567 "Could not determine the frame size");
3569 tty
->delete_in_insert_mode
3570 = tty
->TS_delete_mode
&& tty
->TS_insert_mode
3571 && !strcmp (tty
->TS_delete_mode
, tty
->TS_insert_mode
);
3573 tty
->se_is_so
= (tty
->TS_standout_mode
3574 && tty
->TS_end_standout_mode
3575 && !strcmp (tty
->TS_standout_mode
, tty
->TS_end_standout_mode
));
3577 UseTabs (tty
) = tabs_safe_p (fileno (tty
->input
)) && TabWidth (tty
) == 8;
3579 terminal
->scroll_region_ok
3581 && (tty
->TS_set_window
|| tty
->TS_set_scroll_region
|| tty
->TS_set_scroll_region_1
));
3583 terminal
->line_ins_del_ok
3584 = (((tty
->TS_ins_line
|| tty
->TS_ins_multi_lines
)
3585 && (tty
->TS_del_line
|| tty
->TS_del_multi_lines
))
3586 || (terminal
->scroll_region_ok
3587 && tty
->TS_fwd_scroll
&& tty
->TS_rev_scroll
));
3589 terminal
->char_ins_del_ok
3590 = ((tty
->TS_ins_char
|| tty
->TS_insert_mode
3591 || tty
->TS_pad_inserted_char
|| tty
->TS_ins_multi_chars
)
3592 && (tty
->TS_del_char
|| tty
->TS_del_multi_chars
));
3594 terminal
->fast_clear_end_of_line
= tty
->TS_clr_line
!= 0;
3596 init_baud_rate (fileno (tty
->input
));
3598 #endif /* not DOS_NT */
3600 /* Init system terminal modes (RAW or CBREAK, etc.). */
3601 init_sys_modes (tty
);
3608 vfatal (const char *str
, va_list ap
)
3610 fprintf (stderr
, "emacs: ");
3611 vfprintf (stderr
, str
, ap
);
3612 if (!(strlen (str
) > 0 && str
[strlen (str
) - 1] == '\n'))
3613 fprintf (stderr
, "\n");
3620 /* Auxiliary error-handling function for init_tty.
3621 Delete TERMINAL, then call error or fatal with str1 or str2,
3622 respectively, according to MUST_SUCCEED. */
3625 maybe_fatal (int must_succeed
, struct terminal
*terminal
,
3626 const char *str1
, const char *str2
, ...)
3629 va_start (ap
, str2
);
3631 delete_tty (terminal
);
3643 fatal (const char *str
, ...)
3653 /* Delete the given tty terminal, closing all frames on it. */
3656 delete_tty (struct terminal
*terminal
)
3658 struct tty_display_info
*tty
;
3660 /* Protect against recursive calls. delete_frame in
3661 delete_terminal calls us back when it deletes our last frame. */
3662 if (!terminal
->name
)
3665 if (terminal
->type
!= output_termcap
)
3668 tty
= terminal
->display_info
.tty
;
3670 if (tty
== tty_list
)
3671 tty_list
= tty
->next
;
3674 struct tty_display_info
*p
;
3675 for (p
= tty_list
; p
&& p
->next
!= tty
; p
= p
->next
)
3679 /* This should not happen. */
3682 p
->next
= tty
->next
;
3686 /* reset_sys_modes needs a valid device, so this call needs to be
3687 before delete_terminal. */
3688 reset_sys_modes (tty
);
3690 delete_terminal (terminal
);
3697 delete_keyboard_wait_descriptor (fileno (tty
->input
));
3698 if (tty
->input
!= stdin
)
3699 fclose (tty
->input
);
3701 if (tty
->output
&& tty
->output
!= stdout
&& tty
->output
!= tty
->input
)
3702 fclose (tty
->output
);
3703 if (tty
->termscript
)
3704 fclose (tty
->termscript
);
3706 xfree (tty
->old_tty
);
3708 xfree (tty
->termcap_strings_buffer
);
3709 xfree (tty
->termcap_term_buffer
);
3711 memset (tty
, 0, sizeof (struct tty_display_info
));
3717 /* Mark the pointers in the tty_display_info objects.
3718 Called by the Fgarbage_collector. */
3723 struct tty_display_info
*tty
;
3725 for (tty
= tty_list
; tty
; tty
= tty
->next
)
3726 mark_object (tty
->top_frame
);
3734 DEFVAR_BOOL ("system-uses-terminfo", system_uses_terminfo
,
3735 doc
: /* Non-nil means the system uses terminfo rather than termcap.
3736 This variable can be used by terminal emulator packages. */);
3738 system_uses_terminfo
= 1;
3740 system_uses_terminfo
= 0;
3743 DEFVAR_LISP ("suspend-tty-functions", Vsuspend_tty_functions
,
3744 doc
: /* Functions to be run after suspending a tty.
3745 The functions are run with one argument, the terminal object to be suspended.
3746 See `suspend-tty'. */);
3747 Vsuspend_tty_functions
= Qnil
;
3750 DEFVAR_LISP ("resume-tty-functions", Vresume_tty_functions
,
3751 doc
: /* Functions to be run after resuming a tty.
3752 The functions are run with one argument, the terminal object that was revived.
3753 See `resume-tty'. */);
3754 Vresume_tty_functions
= Qnil
;
3756 DEFVAR_BOOL ("visible-cursor", visible_cursor
,
3757 doc
: /* Non-nil means to make the cursor very visible.
3758 This only has an effect when running in a text terminal.
3759 What means \"very visible\" is up to your terminal. It may make the cursor
3760 bigger, or it may make it blink, or it may do nothing at all. */);
3763 defsubr (&Stty_display_color_p
);
3764 defsubr (&Stty_display_color_cells
);
3765 defsubr (&Stty_no_underline
);
3766 defsubr (&Stty_type
);
3767 defsubr (&Scontrolling_tty_p
);
3768 defsubr (&Ssuspend_tty
);
3769 defsubr (&Sresume_tty
);
3771 defsubr (&Sgpm_mouse_start
);
3772 defsubr (&Sgpm_mouse_stop
);
3773 #endif /* HAVE_GPM */
3776 default_orig_pair
= NULL
;
3777 default_set_foreground
= NULL
;
3778 default_set_background
= NULL
;
3779 #endif /* !DOS_NT */
3781 encode_terminal_src
= NULL
;
3782 encode_terminal_dst
= NULL
;