1 /* Terminal control module for terminals described by TERMCAP
2 Copyright (C) 1985, 86, 87, 93, 94, 95, 98, 2000, 2001, 2002
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 2, or (at your option)
12 GNU Emacs is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU Emacs; see the file COPYING. If not, write to
19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
22 /* New redisplay, TTY faces by Gerd Moellmann <gerd@gnu.org>. */
32 #include "systty.h" /* For emacs_tty in termchar.h */
40 #include "termhooks.h"
41 #include "dispextern.h"
45 /* For now, don't try to include termcap.h. On some systems,
46 configure finds a non-standard termcap.h that the main build
49 #if defined HAVE_TERMCAP_H && 0
52 extern void tputs
P_ ((const char *, int, int (*)(int)));
53 extern int tgetent
P_ ((char *, const char *));
54 extern int tgetflag
P_ ((char *id
));
55 extern int tgetnum
P_ ((char *id
));
70 static void turn_on_face
P_ ((struct frame
*, int face_id
));
71 static void turn_off_face
P_ ((struct frame
*, int face_id
));
72 static void tty_show_cursor
P_ ((struct tty_output
*));
73 static void tty_hide_cursor
P_ ((struct tty_output
*));
75 void delete_tty
P_ ((struct tty_output
*));
76 static void delete_tty_1
P_ ((struct tty_output
*));
79 #define OUTPUT(tty, a) \
80 emacs_tputs ((tty), a, \
81 (int) (FRAME_LINES (XFRAME (selected_frame)) \
85 #define OUTPUT1(tty, a) emacs_tputs ((tty), a, 1, cmputc)
86 #define OUTPUTL(tty, a, lines) emacs_tputs ((tty), a, lines, cmputc)
88 #define OUTPUT_IF(tty, a) \
91 emacs_tputs ((tty), a, \
92 (int) (FRAME_LINES (XFRAME (selected_frame)) \
97 #define OUTPUT1_IF(tty, a) do { if (a) emacs_tputs ((tty), a, 1, cmputc); } while (0)
99 /* Function to use to ring the bell. */
101 Lisp_Object Vring_bell_function
;
103 /* Terminal characteristics that higher levels want to look at. */
105 struct tty_output
*tty_list
;
107 /* Nonzero means no need to redraw the entire frame on resuming a
108 suspended Emacs. This is useful on terminals with multiple
109 pages, where one page is used for Emacs and another for all
111 int no_redraw_on_reenter
;
113 /* Hook functions that you can set to snap out the functions in this file.
114 These are all extern'd in termhooks.h */
116 void (*cursor_to_hook
) P_ ((int, int));
117 void (*raw_cursor_to_hook
) P_ ((int, int));
118 void (*clear_to_end_hook
) P_ ((void));
119 void (*clear_frame_hook
) P_ ((void));
120 void (*clear_end_of_line_hook
) P_ ((int));
122 void (*ins_del_lines_hook
) P_ ((int, int));
124 void (*delete_glyphs_hook
) P_ ((int));
126 void (*ring_bell_hook
) P_ ((void));
128 void (*reset_terminal_modes_hook
) P_ ((void));
129 void (*set_terminal_modes_hook
) P_ ((void));
130 void (*update_begin_hook
) P_ ((struct frame
*));
131 void (*update_end_hook
) P_ ((struct frame
*));
132 void (*set_terminal_window_hook
) P_ ((int));
133 void (*insert_glyphs_hook
) P_ ((struct glyph
*, int));
134 void (*write_glyphs_hook
) P_ ((struct glyph
*, int));
135 void (*delete_glyphs_hook
) P_ ((int));
137 int (*read_socket_hook
) P_ ((struct input_event
*, int, int));
139 void (*frame_up_to_date_hook
) P_ ((struct frame
*));
141 /* Return the current position of the mouse.
143 Set *f to the frame the mouse is in, or zero if the mouse is in no
144 Emacs frame. If it is set to zero, all the other arguments are
147 If the motion started in a scroll bar, set *bar_window to the
148 scroll bar's window, *part to the part the mouse is currently over,
149 *x to the position of the mouse along the scroll bar, and *y to the
150 overall length of the scroll bar.
152 Otherwise, set *bar_window to Qnil, and *x and *y to the column and
153 row of the character cell the mouse is over.
155 Set *time to the time the mouse was at the returned position.
157 This should clear mouse_moved until the next motion
160 void (*mouse_position_hook
) P_ ((FRAME_PTR
*f
, int insist
,
161 Lisp_Object
*bar_window
,
162 enum scroll_bar_part
*part
,
165 unsigned long *time
));
167 /* When reading from a minibuffer in a different frame, Emacs wants
168 to shift the highlight from the selected frame to the mini-buffer's
169 frame; under X, this means it lies about where the focus is.
170 This hook tells the window system code to re-decide where to put
173 void (*frame_rehighlight_hook
) P_ ((FRAME_PTR f
));
175 /* If we're displaying frames using a window system that can stack
176 frames on top of each other, this hook allows you to bring a frame
177 to the front, or bury it behind all the other windows. If this
178 hook is zero, that means the device we're displaying on doesn't
179 support overlapping frames, so there's no need to raise or lower
182 If RAISE is non-zero, F is brought to the front, before all other
183 windows. If RAISE is zero, F is sent to the back, behind all other
186 void (*frame_raise_lower_hook
) P_ ((FRAME_PTR f
, int raise
));
188 /* Set the vertical scroll bar for WINDOW to have its upper left corner
189 at (TOP, LEFT), and be LENGTH rows high. Set its handle to
190 indicate that we are displaying PORTION characters out of a total
191 of WHOLE characters, starting at POSITION. If WINDOW doesn't yet
192 have a scroll bar, create one for it. */
194 void (*set_vertical_scroll_bar_hook
)
195 P_ ((struct window
*window
,
196 int portion
, int whole
, int position
));
199 /* The following three hooks are used when we're doing a thorough
200 redisplay of the frame. We don't explicitly know which scroll bars
201 are going to be deleted, because keeping track of when windows go
202 away is a real pain - can you say set-window-configuration?
203 Instead, we just assert at the beginning of redisplay that *all*
204 scroll bars are to be removed, and then save scroll bars from the
205 fiery pit when we actually redisplay their window. */
207 /* Arrange for all scroll bars on FRAME to be removed at the next call
208 to `*judge_scroll_bars_hook'. A scroll bar may be spared if
209 `*redeem_scroll_bar_hook' is applied to its window before the judgment.
211 This should be applied to each frame each time its window tree is
212 redisplayed, even if it is not displaying scroll bars at the moment;
213 if the HAS_SCROLL_BARS flag has just been turned off, only calling
214 this and the judge_scroll_bars_hook will get rid of them.
216 If non-zero, this hook should be safe to apply to any frame,
217 whether or not it can support scroll bars, and whether or not it is
218 currently displaying them. */
220 void (*condemn_scroll_bars_hook
) P_ ((FRAME_PTR frame
));
222 /* Unmark WINDOW's scroll bar for deletion in this judgement cycle.
223 Note that it's okay to redeem a scroll bar that is not condemned. */
225 void (*redeem_scroll_bar_hook
) P_ ((struct window
*window
));
227 /* Remove all scroll bars on FRAME that haven't been saved since the
228 last call to `*condemn_scroll_bars_hook'.
230 This should be applied to each frame after each time its window
231 tree is redisplayed, even if it is not displaying scroll bars at the
232 moment; if the HAS_SCROLL_BARS flag has just been turned off, only
233 calling this and condemn_scroll_bars_hook will get rid of them.
235 If non-zero, this hook should be safe to apply to any frame,
236 whether or not it can support scroll bars, and whether or not it is
237 currently displaying them. */
239 void (*judge_scroll_bars_hook
) P_ ((FRAME_PTR FRAME
));
242 /* Meaning of bits in no_color_video. Each bit set means that the
243 corresponding attribute cannot be combined with colors. */
247 NC_STANDOUT
= 1 << 0,
248 NC_UNDERLINE
= 1 << 1,
255 NC_ALT_CHARSET
= 1 << 8
260 /* The largest frame width in any call to calculate_costs. */
264 /* The largest frame height in any call to calculate_costs. */
268 /* Frame currently being redisplayed; 0 if not currently redisplaying.
269 (Direct output does not count). */
271 FRAME_PTR updating_frame
;
273 /* Provided for lisp packages. */
275 static int system_uses_terminfo
;
279 extern char *tgetstr ();
283 /* We aren't X windows, but we aren't termcap either. This makes me
284 uncertain as to what value to use for frame.output_method. For
285 this file, we'll define FRAME_TERMCAP_P to be zero so that our
286 output hooks get called instead of the termcap functions. Probably
287 the best long-term solution is to define an output_windows_nt... */
289 #undef FRAME_TERMCAP_P
290 #define FRAME_TERMCAP_P(_f_) 0
291 #endif /* WINDOWSNT */
296 struct frame
*f
= (updating_frame
? updating_frame
: XFRAME (selected_frame
));
298 if (!NILP (Vring_bell_function
))
300 Lisp_Object function
;
302 /* Temporarily set the global variable to nil
303 so that if we get an error, it stays nil
304 and we don't call it over and over.
306 We don't specbind it, because that would carefully
307 restore the bad value if there's an error
308 and make the loop of errors happen anyway. */
310 function
= Vring_bell_function
;
311 Vring_bell_function
= Qnil
;
315 Vring_bell_function
= function
;
317 else if (!FRAME_TERMCAP_P (f
))
318 (*ring_bell_hook
) ();
320 struct tty_output
*tty
= FRAME_TTY (f
);
321 OUTPUT (tty
, tty
->TS_visible_bell
&& visible_bell
? tty
->TS_visible_bell
: tty
->TS_bell
);
325 void tty_set_terminal_modes (struct tty_output
*tty
)
327 OUTPUT_IF (tty
, tty
->TS_termcap_modes
);
328 OUTPUT_IF (tty
, tty
->TS_cursor_visible
);
329 OUTPUT_IF (tty
, tty
->TS_keypad_mode
);
334 set_terminal_modes ()
336 struct frame
*f
= (updating_frame
? updating_frame
: XFRAME (selected_frame
));
337 if (FRAME_TERMCAP_P (f
))
338 tty_set_terminal_modes (FRAME_TTY (f
));
340 (*set_terminal_modes_hook
) ();
343 void tty_reset_terminal_modes (struct tty_output
*tty
)
345 turn_off_highlight (tty
);
346 turn_off_insert (tty
);
347 OUTPUT_IF (tty
, tty
->TS_end_keypad_mode
);
348 OUTPUT_IF (tty
, tty
->TS_cursor_normal
);
349 OUTPUT_IF (tty
, tty
->TS_end_termcap_modes
);
350 OUTPUT_IF (tty
, tty
->TS_orig_pair
);
351 /* Output raw CR so kernel can track the cursor hpos. */
357 reset_terminal_modes ()
359 struct frame
*f
= (updating_frame
? updating_frame
: XFRAME (selected_frame
));
360 if (FRAME_TERMCAP_P (f
))
361 tty_reset_terminal_modes (FRAME_TTY (f
));
362 else if (reset_terminal_modes_hook
)
363 (*reset_terminal_modes_hook
) ();
371 if (!FRAME_TERMCAP_P (f
))
372 update_begin_hook (f
);
379 if (FRAME_TERMCAP_P (f
))
381 struct tty_output
*tty
= FRAME_TTY (f
);
382 if (!XWINDOW (selected_window
)->cursor_off_p
)
383 tty_show_cursor (tty
);
384 turn_off_insert (tty
);
385 background_highlight (tty
);
390 updating_frame
= NULL
;
394 set_terminal_window (size
)
397 struct frame
*f
= (updating_frame
? updating_frame
: XFRAME (selected_frame
));
398 if (FRAME_TERMCAP_P (f
))
400 struct tty_output
*tty
= FRAME_TTY (f
);
401 tty
->specified_window
= size
? size
: FRAME_LINES (f
);
402 if (TTY_SCROLL_REGION_OK (tty
))
403 set_scroll_region (0, tty
->specified_window
);
406 set_terminal_window_hook (size
);
410 set_scroll_region (start
, stop
)
414 struct frame
*f
= (updating_frame
? updating_frame
: XFRAME (selected_frame
));
415 struct tty_output
*tty
= FRAME_TTY (f
);
417 if (tty
->TS_set_scroll_region
)
418 buf
= tparam (tty
->TS_set_scroll_region
, 0, 0, start
, stop
- 1);
419 else if (tty
->TS_set_scroll_region_1
)
420 buf
= tparam (tty
->TS_set_scroll_region_1
, 0, 0,
421 FRAME_LINES (f
), start
,
422 FRAME_LINES (f
) - stop
,
425 buf
= tparam (tty
->TS_set_window
, 0, 0, start
, 0, stop
, FRAME_COLS (f
));
434 turn_on_insert (struct tty_output
*tty
)
436 if (!tty
->insert_mode
)
437 OUTPUT (tty
, tty
->TS_insert_mode
);
438 tty
->insert_mode
= 1;
442 turn_off_insert (struct tty_output
*tty
)
444 if (tty
->insert_mode
)
445 OUTPUT (tty
, tty
->TS_end_insert_mode
);
446 tty
->insert_mode
= 0;
449 /* Handle highlighting. */
452 turn_off_highlight (struct tty_output
*tty
)
454 if (tty
->standout_mode
)
455 OUTPUT_IF (tty
, tty
->TS_end_standout_mode
);
456 tty
->standout_mode
= 0;
460 turn_on_highlight (struct tty_output
*tty
)
462 if (!tty
->standout_mode
)
463 OUTPUT_IF (tty
, tty
->TS_standout_mode
);
464 tty
->standout_mode
= 1;
468 toggle_highlight (struct tty_output
*tty
)
470 if (tty
->standout_mode
)
471 turn_off_highlight (tty
);
473 turn_on_highlight (tty
);
477 /* Make cursor invisible. */
480 tty_hide_cursor (struct tty_output
*tty
)
482 if (tty
->cursor_hidden
== 0)
484 tty
->cursor_hidden
= 1;
485 OUTPUT_IF (tty
, tty
->TS_cursor_invisible
);
490 /* Ensure that cursor is visible. */
493 tty_show_cursor (struct tty_output
*tty
)
495 if (tty
->cursor_hidden
)
497 tty
->cursor_hidden
= 0;
498 OUTPUT_IF (tty
, tty
->TS_cursor_normal
);
499 OUTPUT_IF (tty
, tty
->TS_cursor_visible
);
504 /* Set standout mode to the state it should be in for
505 empty space inside windows. What this is,
506 depends on the user option inverse-video. */
509 background_highlight (struct tty_output
*tty
)
512 turn_on_highlight (tty
);
514 turn_off_highlight (tty
);
517 /* Set standout mode to the mode specified for the text to be output. */
520 highlight_if_desired (struct tty_output
*tty
)
523 turn_on_highlight (tty
);
525 turn_off_highlight (tty
);
529 /* Move cursor to row/column position VPOS/HPOS. HPOS/VPOS are
530 frame-relative coordinates. */
533 cursor_to (vpos
, hpos
)
536 struct frame
*f
= (updating_frame
? updating_frame
: XFRAME (selected_frame
));
537 struct tty_output
*tty
;
539 if (! FRAME_TERMCAP_P (f
) && cursor_to_hook
)
541 (*cursor_to_hook
) (vpos
, hpos
);
547 /* Detect the case where we are called from reset_sys_modes
548 and the costs have never been calculated. Do nothing. */
549 if (! tty
->costs_set
)
552 if (curY (tty
) == vpos
553 && curX (tty
) == hpos
)
555 if (!tty
->TF_standout_motion
)
556 background_highlight (tty
);
557 if (!tty
->TF_insmode_motion
)
558 turn_off_insert (tty
);
559 cmgoto (tty
, vpos
, hpos
);
562 /* Similar but don't take any account of the wasted characters. */
565 raw_cursor_to (row
, col
)
568 struct frame
*f
= updating_frame
? updating_frame
: XFRAME (selected_frame
);
569 struct tty_output
*tty
;
570 if (! FRAME_TERMCAP_P (f
))
572 (*raw_cursor_to_hook
) (row
, col
);
576 if (curY (tty
) == row
577 && curX (tty
) == col
)
579 if (!tty
->TF_standout_motion
)
580 background_highlight (tty
);
581 if (!tty
->TF_insmode_motion
)
582 turn_off_insert (tty
);
583 cmgoto (tty
, row
, col
);
586 /* Erase operations */
588 /* clear from cursor to end of frame */
594 struct frame
*f
= (updating_frame
? updating_frame
: XFRAME (selected_frame
));
595 struct tty_output
*tty
;
597 if (clear_to_end_hook
&& ! FRAME_TERMCAP_P (f
))
599 (*clear_to_end_hook
) ();
603 if (tty
->TS_clr_to_bottom
)
605 background_highlight (tty
);
606 OUTPUT (tty
, tty
->TS_clr_to_bottom
);
610 for (i
= curY (tty
); i
< FRAME_LINES (f
); i
++)
613 clear_end_of_line (FRAME_COLS (f
));
618 /* Clear entire frame */
623 struct frame
*f
= (updating_frame
? updating_frame
: XFRAME (selected_frame
));
624 struct tty_output
*tty
;
626 if (clear_frame_hook
&& ! FRAME_TERMCAP_P (f
))
628 (*clear_frame_hook
) ();
632 if (tty
->TS_clr_frame
)
634 background_highlight (tty
);
635 OUTPUT (tty
, tty
->TS_clr_frame
);
645 /* Clear from cursor to end of line.
646 Assume that the line is already clear starting at column first_unused_hpos.
648 Note that the cursor may be moved, on terminals lacking a `ce' string. */
651 clear_end_of_line (first_unused_hpos
)
652 int first_unused_hpos
;
656 struct frame
*f
= (updating_frame
? updating_frame
: XFRAME (selected_frame
));
657 struct tty_output
*tty
;
659 if (clear_end_of_line_hook
660 && ! FRAME_TERMCAP_P (f
))
662 (*clear_end_of_line_hook
) (first_unused_hpos
);
668 /* Detect the case where we are called from reset_sys_modes
669 and the costs have never been calculated. Do nothing. */
670 if (! tty
->costs_set
)
673 if (curX (tty
) >= first_unused_hpos
)
675 background_highlight (tty
);
676 if (tty
->TS_clr_line
)
678 OUTPUT1 (tty
, tty
->TS_clr_line
);
681 { /* have to do it the hard way */
682 turn_off_insert (tty
);
684 /* Do not write in last row last col with Auto-wrap on. */
686 && curY (tty
) == FRAME_LINES (f
) - 1
687 && first_unused_hpos
== FRAME_COLS (f
))
690 for (i
= curX (tty
); i
< first_unused_hpos
; i
++)
692 if (TTY_TERMSCRIPT (tty
))
693 fputc (' ', TTY_TERMSCRIPT (tty
));
694 fputc (' ', TTY_OUTPUT (tty
));
696 cmplus (tty
, first_unused_hpos
- curX (tty
));
700 /* Encode SRC_LEN glyphs starting at SRC to terminal output codes and
701 store them at DST. Do not write more than DST_LEN bytes. That may
702 require stopping before all SRC_LEN input glyphs have been
705 We store the number of glyphs actually converted in *CONSUMED. The
706 return value is the number of bytes store in DST. */
709 encode_terminal_code (src
, dst
, src_len
, dst_len
, consumed
)
713 int dst_len
, *consumed
;
715 struct glyph
*src_start
= src
, *src_end
= src
+ src_len
;
716 unsigned char *dst_start
= dst
, *dst_end
= dst
+ dst_len
;
718 unsigned char workbuf
[MAX_MULTIBYTE_LENGTH
];
719 const unsigned char *buf
;
721 register int tlen
= GLYPH_TABLE_LENGTH
;
722 register Lisp_Object
*tbase
= GLYPH_TABLE_BASE
;
724 struct coding_system
*coding
;
726 /* If terminal_coding does any conversion, use it, otherwise use
727 safe_terminal_coding. We can't use CODING_REQUIRE_ENCODING here
728 because it always return 1 if the member src_multibyte is 1. */
729 coding
= (terminal_coding
.common_flags
& CODING_REQUIRE_ENCODING_MASK
731 : &safe_terminal_coding
);
733 while (src
< src_end
)
735 /* We must skip glyphs to be padded for a wide character. */
736 if (! CHAR_GLYPH_PADDING_P (*src
))
738 g
= GLYPH_FROM_CHAR_GLYPH (src
[0]);
740 if (g
< 0 || g
>= tlen
)
742 /* This glyph doesn't has an entry in Vglyph_table. */
743 if (! CHAR_VALID_P (src
->u
.ch
, 0))
747 coding
->src_multibyte
= 0;
751 len
= CHAR_STRING (src
->u
.ch
, workbuf
);
753 coding
->src_multibyte
= 1;
758 /* This glyph has an entry in Vglyph_table,
759 so process any alias before testing for simpleness. */
760 GLYPH_FOLLOW_ALIASES (tbase
, tlen
, g
);
762 if (GLYPH_SIMPLE_P (tbase
, tlen
, g
))
764 /* We set the multi-byte form of a character in G
765 (that should be an ASCII character) at
767 workbuf
[0] = FAST_GLYPH_CHAR (g
);
770 coding
->src_multibyte
= 0;
774 /* We have a string in Vglyph_table. */
775 len
= GLYPH_LENGTH (tbase
, g
);
776 buf
= GLYPH_STRING (tbase
, g
);
777 coding
->src_multibyte
= STRING_MULTIBYTE (tbase
[g
]);
781 result
= encode_coding (coding
, buf
, dst
, len
, dst_end
- dst
);
782 len
-= coding
->consumed
;
783 dst
+= coding
->produced
;
784 if (result
== CODING_FINISH_INSUFFICIENT_DST
785 || (result
== CODING_FINISH_INSUFFICIENT_SRC
786 && len
> dst_end
- dst
))
787 /* The remaining output buffer is too short. We must
788 break the loop here without increasing SRC so that the
789 next call of this function starts from the same glyph. */
794 /* This is the case that a code of the range 0200..0237
795 exists in buf. We must just write out such a code. */
796 buf
+= coding
->consumed
;
804 *consumed
= src
- src_start
;
805 return (dst
- dst_start
);
810 write_glyphs (string
, len
)
811 register struct glyph
*string
;
814 int produced
, consumed
;
815 struct frame
*f
= updating_frame
? updating_frame
: XFRAME (selected_frame
);
816 struct tty_output
*tty
;
817 unsigned char conversion_buffer
[1024];
818 int conversion_buffer_size
= sizeof conversion_buffer
;
820 if (write_glyphs_hook
821 && ! FRAME_TERMCAP_P (f
))
823 (*write_glyphs_hook
) (string
, len
);
829 turn_off_insert (tty
);
830 tty_hide_cursor (tty
);
832 /* Don't dare write in last column of bottom line, if Auto-Wrap,
833 since that would scroll the whole frame on some terminals. */
836 && curY (tty
) + 1 == FRAME_LINES (f
)
837 && (curX (tty
) + len
) == FRAME_COLS (f
))
844 /* The mode bit CODING_MODE_LAST_BLOCK should be set to 1 only at
846 terminal_coding
.mode
&= ~CODING_MODE_LAST_BLOCK
;
850 /* Identify a run of glyphs with the same face. */
851 int face_id
= string
->face_id
;
854 for (n
= 1; n
< len
; ++n
)
855 if (string
[n
].face_id
!= face_id
)
858 /* Turn appearance modes of the face of the run on. */
859 highlight_if_desired (tty
);
860 turn_on_face (f
, face_id
);
864 /* We use a fixed size (1024 bytes) of conversion buffer.
865 Usually it is sufficient, but if not, we just repeat the
867 produced
= encode_terminal_code (string
, conversion_buffer
,
868 n
, conversion_buffer_size
,
872 fwrite (conversion_buffer
, 1, produced
,
874 if (ferror (TTY_OUTPUT (tty
)))
875 clearerr (TTY_OUTPUT (tty
));
876 if (TTY_TERMSCRIPT (tty
))
877 fwrite (conversion_buffer
, 1, produced
,
878 TTY_TERMSCRIPT (tty
));
885 /* Turn appearance modes off. */
886 turn_off_face (f
, face_id
);
887 turn_off_highlight (tty
);
890 /* We may have to output some codes to terminate the writing. */
891 if (CODING_REQUIRE_FLUSHING (&terminal_coding
))
893 terminal_coding
.mode
|= CODING_MODE_LAST_BLOCK
;
894 encode_coding (&terminal_coding
, "", conversion_buffer
,
895 0, conversion_buffer_size
);
896 if (terminal_coding
.produced
> 0)
898 fwrite (conversion_buffer
, 1, terminal_coding
.produced
,
900 if (ferror (TTY_OUTPUT (tty
)))
901 clearerr (TTY_OUTPUT (tty
));
902 if (TTY_TERMSCRIPT (tty
))
903 fwrite (conversion_buffer
, 1, terminal_coding
.produced
,
904 TTY_TERMSCRIPT (tty
));
911 /* If start is zero, insert blanks instead of a string at start */
914 insert_glyphs (start
, len
)
915 register struct glyph
*start
;
919 struct glyph
*glyph
= NULL
;
920 struct frame
*f
= (updating_frame
? updating_frame
: XFRAME (selected_frame
));
921 struct tty_output
*tty
;
926 if (insert_glyphs_hook
&& ! FRAME_TERMCAP_P (f
))
928 (*insert_glyphs_hook
) (start
, len
);
934 if (tty
->TS_ins_multi_chars
)
936 buf
= tparam (tty
->TS_ins_multi_chars
, 0, 0, len
);
940 write_glyphs (start
, len
);
944 turn_on_insert (tty
);
946 /* The bit CODING_MODE_LAST_BLOCK should be set to 1 only at the tail. */
947 terminal_coding
.mode
&= ~CODING_MODE_LAST_BLOCK
;
950 int produced
, consumed
;
951 unsigned char conversion_buffer
[1024];
952 int conversion_buffer_size
= sizeof conversion_buffer
;
954 OUTPUT1_IF (tty
, tty
->TS_ins_char
);
957 conversion_buffer
[0] = SPACEGLYPH
;
962 highlight_if_desired (tty
);
963 turn_on_face (f
, start
->face_id
);
966 /* We must open sufficient space for a character which
967 occupies more than one column. */
968 while (len
&& CHAR_GLYPH_PADDING_P (*start
))
970 OUTPUT1_IF (tty
, tty
->TS_ins_char
);
975 /* This is the last glyph. */
976 terminal_coding
.mode
|= CODING_MODE_LAST_BLOCK
;
978 /* The size of conversion buffer (1024 bytes) is surely
979 sufficient for just one glyph. */
980 produced
= encode_terminal_code (glyph
, conversion_buffer
, 1,
981 conversion_buffer_size
, &consumed
);
986 fwrite (conversion_buffer
, 1, produced
,
988 if (ferror (TTY_OUTPUT (tty
)))
989 clearerr (TTY_OUTPUT (tty
));
990 if (TTY_TERMSCRIPT (tty
))
991 fwrite (conversion_buffer
, 1, produced
,
992 TTY_TERMSCRIPT (tty
));
995 OUTPUT1_IF (tty
, tty
->TS_pad_inserted_char
);
998 turn_off_face (f
, glyph
->face_id
);
999 turn_off_highlight (tty
);
1012 struct frame
*f
= (updating_frame
? updating_frame
: XFRAME (selected_frame
));
1013 struct tty_output
*tty
= FRAME_TTY (f
);
1015 if (delete_glyphs_hook
&& ! FRAME_TERMCAP_P (f
))
1017 (*delete_glyphs_hook
) (n
);
1022 if (tty
->delete_in_insert_mode
)
1024 turn_on_insert (tty
);
1028 turn_off_insert (tty
);
1029 OUTPUT_IF (tty
, tty
->TS_delete_mode
);
1032 if (tty
->TS_del_multi_chars
)
1034 buf
= tparam (tty
->TS_del_multi_chars
, 0, 0, n
);
1039 for (i
= 0; i
< n
; i
++)
1040 OUTPUT1 (tty
, tty
->TS_del_char
);
1041 if (!tty
->delete_in_insert_mode
)
1042 OUTPUT_IF (tty
, tty
->TS_end_delete_mode
);
1045 /* Insert N lines at vpos VPOS. If N is negative, delete -N lines. */
1048 ins_del_lines (vpos
, n
)
1051 struct frame
*f
= (updating_frame
? updating_frame
: XFRAME (selected_frame
));
1052 if (ins_del_lines_hook
&& ! FRAME_TERMCAP_P (f
))
1054 (*ins_del_lines_hook
) (vpos
, n
);
1059 struct tty_output
*tty
= FRAME_TTY (f
);
1060 char *multi
= n
> 0 ? tty
->TS_ins_multi_lines
: tty
->TS_del_multi_lines
;
1061 char *single
= n
> 0 ? tty
->TS_ins_line
: tty
->TS_del_line
;
1062 char *scroll
= n
> 0 ? tty
->TS_rev_scroll
: tty
->TS_fwd_scroll
;
1064 register int i
= n
> 0 ? n
: -n
;
1067 /* If the lines below the insertion are being pushed
1068 into the end of the window, this is the same as clearing;
1069 and we know the lines are already clear, since the matching
1070 deletion has already been done. So can ignore this. */
1071 /* If the lines below the deletion are blank lines coming
1072 out of the end of the window, don't bother,
1073 as there will be a matching inslines later that will flush them. */
1074 if (TTY_SCROLL_REGION_OK (tty
)
1075 && vpos
+ i
>= tty
->specified_window
)
1077 if (!TTY_MEMORY_BELOW_FRAME (tty
)
1078 && vpos
+ i
>= FRAME_LINES (f
))
1083 raw_cursor_to (vpos
, 0);
1084 background_highlight (tty
);
1085 buf
= tparam (multi
, 0, 0, i
);
1091 raw_cursor_to (vpos
, 0);
1092 background_highlight (tty
);
1094 OUTPUT (tty
, single
);
1095 if (tty
->TF_teleray
)
1100 set_scroll_region (vpos
, tty
->specified_window
);
1102 raw_cursor_to (tty
->specified_window
- 1, 0);
1104 raw_cursor_to (vpos
, 0);
1105 background_highlight (tty
);
1107 OUTPUTL (tty
, scroll
, tty
->specified_window
- vpos
);
1108 set_scroll_region (0, tty
->specified_window
);
1111 if (!TTY_SCROLL_REGION_OK (tty
)
1112 && TTY_MEMORY_BELOW_FRAME (tty
)
1115 cursor_to (FRAME_LINES (f
) + n
, 0);
1121 /* Compute cost of sending "str", in characters,
1122 not counting any line-dependent padding. */
1130 tputs (str
, 0, evalcost
);
1134 /* Compute cost of sending "str", in characters,
1135 counting any line-dependent padding at one line. */
1138 string_cost_one_line (str
)
1143 tputs (str
, 1, evalcost
);
1147 /* Compute per line amount of line-dependent padding,
1148 in tenths of characters. */
1156 tputs (str
, 0, evalcost
);
1159 tputs (str
, 10, evalcost
);
1164 /* char_ins_del_cost[n] is cost of inserting N characters.
1165 char_ins_del_cost[-n] is cost of deleting N characters.
1166 The length of this vector is based on max_frame_cols. */
1168 int *char_ins_del_vector
;
1170 #define char_ins_del_cost(f) (&char_ins_del_vector[FRAME_COLS ((f))])
1175 calculate_ins_del_char_costs (f
)
1178 struct tty_output
*tty
= FRAME_TTY (f
);
1179 int ins_startup_cost
, del_startup_cost
;
1180 int ins_cost_per_char
, del_cost_per_char
;
1184 if (tty
->TS_ins_multi_chars
)
1186 ins_cost_per_char
= 0;
1187 ins_startup_cost
= string_cost_one_line (tty
->TS_ins_multi_chars
);
1189 else if (tty
->TS_ins_char
|| tty
->TS_pad_inserted_char
1190 || (tty
->TS_insert_mode
&& tty
->TS_end_insert_mode
))
1192 ins_startup_cost
= (30 * (string_cost (tty
->TS_insert_mode
)
1193 + string_cost (tty
->TS_end_insert_mode
))) / 100;
1194 ins_cost_per_char
= (string_cost_one_line (tty
->TS_ins_char
)
1195 + string_cost_one_line (tty
->TS_pad_inserted_char
));
1199 ins_startup_cost
= 9999;
1200 ins_cost_per_char
= 0;
1203 if (tty
->TS_del_multi_chars
)
1205 del_cost_per_char
= 0;
1206 del_startup_cost
= string_cost_one_line (tty
->TS_del_multi_chars
);
1208 else if (tty
->TS_del_char
)
1210 del_startup_cost
= (string_cost (tty
->TS_delete_mode
)
1211 + string_cost (tty
->TS_end_delete_mode
));
1212 if (tty
->delete_in_insert_mode
)
1213 del_startup_cost
/= 2;
1214 del_cost_per_char
= string_cost_one_line (tty
->TS_del_char
);
1218 del_startup_cost
= 9999;
1219 del_cost_per_char
= 0;
1222 /* Delete costs are at negative offsets */
1223 p
= &char_ins_del_cost (f
)[0];
1224 for (i
= FRAME_COLS (f
); --i
>= 0;)
1225 *--p
= (del_startup_cost
+= del_cost_per_char
);
1227 /* Doing nothing is free */
1228 p
= &char_ins_del_cost (f
)[0];
1231 /* Insert costs are at positive offsets */
1232 for (i
= FRAME_COLS (f
); --i
>= 0;)
1233 *p
++ = (ins_startup_cost
+= ins_cost_per_char
);
1237 calculate_costs (frame
)
1240 struct tty_output
*tty
= FRAME_TTY (frame
);
1241 register char *f
= (tty
->TS_set_scroll_region
1242 ? tty
->TS_set_scroll_region
1243 : tty
->TS_set_scroll_region_1
);
1245 FRAME_COST_BAUD_RATE (frame
) = baud_rate
;
1247 if (FRAME_TERMCAP_P (frame
))
1248 TTY_SCROLL_REGION_COST (frame
->output_data
.tty
) = string_cost (f
);
1250 /* These variables are only used for terminal stuff. They are allocated
1251 once for the terminal frame of X-windows emacs, but not used afterwards.
1253 char_ins_del_vector (i.e., char_ins_del_cost) isn't used because
1254 X turns off char_ins_del_ok. */
1256 max_frame_lines
= max (max_frame_lines
, FRAME_LINES (frame
));
1257 max_frame_cols
= max (max_frame_cols
, FRAME_COLS (frame
));
1261 if (char_ins_del_vector
!= 0)
1263 = (int *) xrealloc (char_ins_del_vector
,
1265 + 2 * max_frame_cols
* sizeof (int)));
1268 = (int *) xmalloc (sizeof (int)
1269 + 2 * max_frame_cols
* sizeof (int));
1271 bzero (char_ins_del_vector
, (sizeof (int)
1272 + 2 * max_frame_cols
* sizeof (int)));
1274 if (f
&& (!tty
->TS_ins_line
&& !tty
->TS_del_line
))
1275 do_line_insertion_deletion_costs (frame
,
1276 tty
->TS_rev_scroll
, tty
->TS_ins_multi_lines
,
1277 tty
->TS_fwd_scroll
, tty
->TS_del_multi_lines
,
1280 do_line_insertion_deletion_costs (frame
,
1281 tty
->TS_ins_line
, tty
->TS_ins_multi_lines
,
1282 tty
->TS_del_line
, tty
->TS_del_multi_lines
,
1285 calculate_ins_del_char_costs (frame
);
1287 /* Don't use TS_repeat if its padding is worse than sending the chars */
1288 if (tty
->TS_repeat
&& per_line_cost (tty
->TS_repeat
) * baud_rate
< 9000)
1289 tty
->RPov
= string_cost (tty
->TS_repeat
);
1291 tty
->RPov
= FRAME_COLS (frame
) * 2;
1293 cmcostinit (FRAME_TTY (frame
)); /* set up cursor motion costs */
1300 /* Termcap capability names that correspond directly to X keysyms.
1301 Some of these (marked "terminfo") aren't supplied by old-style
1302 (Berkeley) termcap entries. They're listed in X keysym order;
1303 except we put the keypad keys first, so that if they clash with
1304 other keys (as on the IBM PC keyboard) they get overridden.
1307 static struct fkey_table keys
[] =
1309 {"kh", "home"}, /* termcap */
1310 {"kl", "left"}, /* termcap */
1311 {"ku", "up"}, /* termcap */
1312 {"kr", "right"}, /* termcap */
1313 {"kd", "down"}, /* termcap */
1314 {"%8", "prior"}, /* terminfo */
1315 {"%5", "next"}, /* terminfo */
1316 {"@7", "end"}, /* terminfo */
1317 {"@1", "begin"}, /* terminfo */
1318 {"*6", "select"}, /* terminfo */
1319 {"%9", "print"}, /* terminfo */
1320 {"@4", "execute"}, /* terminfo --- actually the `command' key */
1322 * "insert" --- see below
1324 {"&8", "undo"}, /* terminfo */
1325 {"%0", "redo"}, /* terminfo */
1326 {"%7", "menu"}, /* terminfo --- actually the `options' key */
1327 {"@0", "find"}, /* terminfo */
1328 {"@2", "cancel"}, /* terminfo */
1329 {"%1", "help"}, /* terminfo */
1331 * "break" goes here, but can't be reliably intercepted with termcap
1333 {"&4", "reset"}, /* terminfo --- actually `restart' */
1335 * "system" and "user" --- no termcaps
1337 {"kE", "clearline"}, /* terminfo */
1338 {"kA", "insertline"}, /* terminfo */
1339 {"kL", "deleteline"}, /* terminfo */
1340 {"kI", "insertchar"}, /* terminfo */
1341 {"kD", "deletechar"}, /* terminfo */
1342 {"kB", "backtab"}, /* terminfo */
1344 * "kp_backtab", "kp-space", "kp-tab" --- no termcaps
1346 {"@8", "kp-enter"}, /* terminfo */
1348 * "kp-f1", "kp-f2", "kp-f3" "kp-f4",
1349 * "kp-multiply", "kp-add", "kp-separator",
1350 * "kp-subtract", "kp-decimal", "kp-divide", "kp-0";
1351 * --- no termcaps for any of these.
1353 {"K4", "kp-1"}, /* terminfo */
1355 * "kp-2" --- no termcap
1357 {"K5", "kp-3"}, /* terminfo */
1359 * "kp-4" --- no termcap
1361 {"K2", "kp-5"}, /* terminfo */
1363 * "kp-6" --- no termcap
1365 {"K1", "kp-7"}, /* terminfo */
1367 * "kp-8" --- no termcap
1369 {"K3", "kp-9"}, /* terminfo */
1371 * "kp-equal" --- no termcap
1384 static char **term_get_fkeys_arg
;
1385 static Lisp_Object
term_get_fkeys_1 ();
1387 /* Find the escape codes sent by the function keys for Vfunction_key_map.
1388 This function scans the termcap function key sequence entries, and
1389 adds entries to Vfunction_key_map for each function key it finds. */
1392 term_get_fkeys (address
)
1395 /* We run the body of the function (term_get_fkeys_1) and ignore all Lisp
1396 errors during the call. The only errors should be from Fdefine_key
1397 when given a key sequence containing an invalid prefix key. If the
1398 termcap defines function keys which use a prefix that is already bound
1399 to a command by the default bindings, we should silently ignore that
1400 function key specification, rather than giving the user an error and
1401 refusing to run at all on such a terminal. */
1403 extern Lisp_Object
Fidentity ();
1404 term_get_fkeys_arg
= address
;
1405 internal_condition_case (term_get_fkeys_1
, Qerror
, Fidentity
);
1413 char **address
= term_get_fkeys_arg
;
1415 /* This can happen if CANNOT_DUMP or with strange options. */
1417 Vfunction_key_map
= Fmake_sparse_keymap (Qnil
);
1419 for (i
= 0; i
< (sizeof (keys
)/sizeof (keys
[0])); i
++)
1421 char *sequence
= tgetstr (keys
[i
].cap
, address
);
1423 Fdefine_key (Vfunction_key_map
, build_string (sequence
),
1424 Fmake_vector (make_number (1),
1425 intern (keys
[i
].name
)));
1428 /* The uses of the "k0" capability are inconsistent; sometimes it
1429 describes F10, whereas othertimes it describes F0 and "k;" describes F10.
1430 We will attempt to politely accommodate both systems by testing for
1431 "k;", and if it is present, assuming that "k0" denotes F0, otherwise F10.
1434 char *k_semi
= tgetstr ("k;", address
);
1435 char *k0
= tgetstr ("k0", address
);
1436 char *k0_name
= "f10";
1441 /* Define f0 first, so that f10 takes precedence in case the
1442 key sequences happens to be the same. */
1443 Fdefine_key (Vfunction_key_map
, build_string (k0
),
1444 Fmake_vector (make_number (1), intern ("f0")));
1445 Fdefine_key (Vfunction_key_map
, build_string (k_semi
),
1446 Fmake_vector (make_number (1), intern ("f10")));
1449 Fdefine_key (Vfunction_key_map
, build_string (k0
),
1450 Fmake_vector (make_number (1), intern (k0_name
)));
1453 /* Set up cookies for numbered function keys above f10. */
1455 char fcap
[3], fkey
[4];
1457 fcap
[0] = 'F'; fcap
[2] = '\0';
1458 for (i
= 11; i
< 64; i
++)
1461 fcap
[1] = '1' + i
- 11;
1463 fcap
[1] = 'A' + i
- 20;
1465 fcap
[1] = 'a' + i
- 46;
1468 char *sequence
= tgetstr (fcap
, address
);
1471 sprintf (fkey
, "f%d", i
);
1472 Fdefine_key (Vfunction_key_map
, build_string (sequence
),
1473 Fmake_vector (make_number (1),
1481 * Various mappings to try and get a better fit.
1484 #define CONDITIONAL_REASSIGN(cap1, cap2, sym) \
1485 if (!tgetstr (cap1, address)) \
1487 char *sequence = tgetstr (cap2, address); \
1489 Fdefine_key (Vfunction_key_map, build_string (sequence), \
1490 Fmake_vector (make_number (1), \
1494 /* if there's no key_next keycap, map key_npage to `next' keysym */
1495 CONDITIONAL_REASSIGN ("%5", "kN", "next");
1496 /* if there's no key_prev keycap, map key_ppage to `previous' keysym */
1497 CONDITIONAL_REASSIGN ("%8", "kP", "prior");
1498 /* if there's no key_dc keycap, map key_ic to `insert' keysym */
1499 CONDITIONAL_REASSIGN ("kD", "kI", "insert");
1500 /* if there's no key_end keycap, map key_ll to 'end' keysym */
1501 CONDITIONAL_REASSIGN ("@7", "kH", "end");
1503 /* IBM has their own non-standard dialect of terminfo.
1504 If the standard name isn't found, try the IBM name. */
1505 CONDITIONAL_REASSIGN ("kB", "KO", "backtab");
1506 CONDITIONAL_REASSIGN ("@4", "kJ", "execute"); /* actually "action" */
1507 CONDITIONAL_REASSIGN ("@4", "kc", "execute"); /* actually "command" */
1508 CONDITIONAL_REASSIGN ("%7", "ki", "menu");
1509 CONDITIONAL_REASSIGN ("@7", "kw", "end");
1510 CONDITIONAL_REASSIGN ("F1", "k<", "f11");
1511 CONDITIONAL_REASSIGN ("F2", "k>", "f12");
1512 CONDITIONAL_REASSIGN ("%1", "kq", "help");
1513 CONDITIONAL_REASSIGN ("*6", "kU", "select");
1514 #undef CONDITIONAL_REASSIGN
1521 /***********************************************************************
1522 Character Display Information
1523 ***********************************************************************/
1525 static void append_glyph
P_ ((struct it
*));
1528 /* Append glyphs to IT's glyph_row. Called from produce_glyphs for
1529 terminal frames if IT->glyph_row != NULL. IT->c is the character
1530 for which to produce glyphs; IT->face_id contains the character's
1531 face. Padding glyphs are appended if IT->c has a IT->pixel_width >
1538 struct glyph
*glyph
, *end
;
1541 xassert (it
->glyph_row
);
1542 glyph
= (it
->glyph_row
->glyphs
[it
->area
]
1543 + it
->glyph_row
->used
[it
->area
]);
1544 end
= it
->glyph_row
->glyphs
[1 + it
->area
];
1547 i
< it
->pixel_width
&& glyph
< end
;
1550 glyph
->type
= CHAR_GLYPH
;
1551 glyph
->pixel_width
= 1;
1552 glyph
->u
.ch
= it
->c
;
1553 glyph
->face_id
= it
->face_id
;
1554 glyph
->padding_p
= i
> 0;
1555 glyph
->charpos
= CHARPOS (it
->position
);
1556 glyph
->object
= it
->object
;
1558 ++it
->glyph_row
->used
[it
->area
];
1564 /* Produce glyphs for the display element described by IT. *IT
1565 specifies what we want to produce a glyph for (character, image, ...),
1566 and where in the glyph matrix we currently are (glyph row and hpos).
1567 produce_glyphs fills in output fields of *IT with information such as the
1568 pixel width and height of a character, and maybe output actual glyphs at
1569 the same time if IT->glyph_row is non-null. See the explanation of
1570 struct display_iterator in dispextern.h for an overview.
1572 produce_glyphs also stores the result of glyph width, ascent
1573 etc. computations in *IT.
1575 IT->glyph_row may be null, in which case produce_glyphs does not
1576 actually fill in the glyphs. This is used in the move_* functions
1577 in xdisp.c for text width and height computations.
1579 Callers usually don't call produce_glyphs directly;
1580 instead they use the macro PRODUCE_GLYPHS. */
1586 /* If a hook is installed, let it do the work. */
1587 xassert (it
->what
== IT_CHARACTER
1588 || it
->what
== IT_COMPOSITION
1589 || it
->what
== IT_IMAGE
1590 || it
->what
== IT_STRETCH
);
1592 /* Nothing but characters are supported on terminal frames. For a
1593 composition sequence, it->c is the first character of the
1595 xassert (it
->what
== IT_CHARACTER
1596 || it
->what
== IT_COMPOSITION
);
1598 if (it
->c
>= 040 && it
->c
< 0177)
1600 it
->pixel_width
= it
->nglyphs
= 1;
1604 else if (it
->c
== '\n')
1605 it
->pixel_width
= it
->nglyphs
= 0;
1606 else if (it
->c
== '\t')
1608 int absolute_x
= (it
->current_x
1609 + it
->continuation_lines_width
);
1611 = (((1 + absolute_x
+ it
->tab_width
- 1)
1616 /* If part of the TAB has been displayed on the previous line
1617 which is continued now, continuation_lines_width will have
1618 been incremented already by the part that fitted on the
1619 continued line. So, we will get the right number of spaces
1621 nspaces
= next_tab_x
- absolute_x
;
1628 it
->pixel_width
= it
->len
= 1;
1636 it
->pixel_width
= nspaces
;
1637 it
->nglyphs
= nspaces
;
1639 else if (SINGLE_BYTE_CHAR_P (it
->c
))
1641 /* Coming here means that it->c is from display table, thus we
1642 must send the code as is to the terminal. Although there's
1643 no way to know how many columns it occupies on a screen, it
1644 is a good assumption that a single byte code has 1-column
1646 it
->pixel_width
= it
->nglyphs
= 1;
1652 /* A multi-byte character. The display width is fixed for all
1653 characters of the set. Some of the glyphs may have to be
1654 ignored because they are already displayed in a continued
1656 int charset
= CHAR_CHARSET (it
->c
);
1658 it
->pixel_width
= CHARSET_WIDTH (charset
);
1659 it
->nglyphs
= it
->pixel_width
;
1665 /* Advance current_x by the pixel width as a convenience for
1667 if (it
->area
== TEXT_AREA
)
1668 it
->current_x
+= it
->pixel_width
;
1669 it
->ascent
= it
->max_ascent
= it
->phys_ascent
= it
->max_phys_ascent
= 0;
1670 it
->descent
= it
->max_descent
= it
->phys_descent
= it
->max_phys_descent
= 1;
1674 /* Get information about special display element WHAT in an
1675 environment described by IT. WHAT is one of IT_TRUNCATION or
1676 IT_CONTINUATION. Maybe produce glyphs for WHAT if IT has a
1677 non-null glyph_row member. This function ensures that fields like
1678 face_id, c, len of IT are left untouched. */
1681 produce_special_glyphs (it
, what
)
1683 enum display_element_type what
;
1689 temp_it
.what
= IT_CHARACTER
;
1691 temp_it
.object
= make_number (0);
1692 bzero (&temp_it
.current
, sizeof temp_it
.current
);
1694 if (what
== IT_CONTINUATION
)
1696 /* Continuation glyph. */
1698 && INTEGERP (DISP_CONTINUE_GLYPH (it
->dp
))
1699 && GLYPH_CHAR_VALID_P (XINT (DISP_CONTINUE_GLYPH (it
->dp
))))
1701 temp_it
.c
= FAST_GLYPH_CHAR (XINT (DISP_CONTINUE_GLYPH (it
->dp
)));
1702 temp_it
.len
= CHAR_BYTES (temp_it
.c
);
1707 produce_glyphs (&temp_it
);
1708 it
->pixel_width
= temp_it
.pixel_width
;
1709 it
->nglyphs
= temp_it
.pixel_width
;
1711 else if (what
== IT_TRUNCATION
)
1713 /* Truncation glyph. */
1715 && INTEGERP (DISP_TRUNC_GLYPH (it
->dp
))
1716 && GLYPH_CHAR_VALID_P (XINT (DISP_TRUNC_GLYPH (it
->dp
))))
1718 temp_it
.c
= FAST_GLYPH_CHAR (XINT (DISP_TRUNC_GLYPH (it
->dp
)));
1719 temp_it
.len
= CHAR_BYTES (temp_it
.c
);
1724 produce_glyphs (&temp_it
);
1725 it
->pixel_width
= temp_it
.pixel_width
;
1726 it
->nglyphs
= temp_it
.pixel_width
;
1734 /***********************************************************************
1736 ***********************************************************************/
1738 /* Value is non-zero if attribute ATTR may be used. ATTR should be
1739 one of the enumerators from enum no_color_bit, or a bit set built
1740 from them. Some display attributes may not be used together with
1741 color; the termcap capability `NC' specifies which ones. */
1743 #define MAY_USE_WITH_COLORS_P(tty, ATTR) \
1744 (tty->TN_max_colors > 0 \
1745 ? (tty->TN_no_color_video & (ATTR)) == 0 \
1748 /* Turn appearances of face FACE_ID on tty frame F on. */
1751 turn_on_face (f
, face_id
)
1755 struct face
*face
= FACE_FROM_ID (f
, face_id
);
1756 long fg
= face
->foreground
;
1757 long bg
= face
->background
;
1758 struct tty_output
*tty
= FRAME_TTY (f
);
1760 /* Do this first because TS_end_standout_mode may be the same
1761 as TS_exit_attribute_mode, which turns all appearances off. */
1762 if (MAY_USE_WITH_COLORS_P (tty
, NC_REVERSE
))
1764 if (tty
->TN_max_colors
> 0)
1766 if (fg
>= 0 && bg
>= 0)
1768 /* If the terminal supports colors, we can set them
1769 below without using reverse video. The face's fg
1770 and bg colors are set as they should appear on
1771 the screen, i.e. they take the inverse-video'ness
1772 of the face already into account. */
1774 else if (inverse_video
)
1776 if (fg
== FACE_TTY_DEFAULT_FG_COLOR
1777 || bg
== FACE_TTY_DEFAULT_BG_COLOR
)
1778 toggle_highlight (tty
);
1782 if (fg
== FACE_TTY_DEFAULT_BG_COLOR
1783 || bg
== FACE_TTY_DEFAULT_FG_COLOR
)
1784 toggle_highlight (tty
);
1789 /* If we can't display colors, use reverse video
1790 if the face specifies that. */
1793 if (fg
== FACE_TTY_DEFAULT_FG_COLOR
1794 || bg
== FACE_TTY_DEFAULT_BG_COLOR
)
1795 toggle_highlight (tty
);
1799 if (fg
== FACE_TTY_DEFAULT_BG_COLOR
1800 || bg
== FACE_TTY_DEFAULT_FG_COLOR
)
1801 toggle_highlight (tty
);
1806 if (face
->tty_bold_p
)
1808 if (MAY_USE_WITH_COLORS_P (tty
, NC_BOLD
))
1809 OUTPUT1_IF (tty
, tty
->TS_enter_bold_mode
);
1811 else if (face
->tty_dim_p
)
1812 if (MAY_USE_WITH_COLORS_P (tty
, NC_DIM
))
1813 OUTPUT1_IF (tty
, tty
->TS_enter_dim_mode
);
1815 /* Alternate charset and blinking not yet used. */
1816 if (face
->tty_alt_charset_p
1817 && MAY_USE_WITH_COLORS_P (tty
, NC_ALT_CHARSET
))
1818 OUTPUT1_IF (tty
, tty
->TS_enter_alt_charset_mode
);
1820 if (face
->tty_blinking_p
1821 && MAY_USE_WITH_COLORS_P (tty
, NC_BLINK
))
1822 OUTPUT1_IF (tty
, tty
->TS_enter_blink_mode
);
1824 if (face
->tty_underline_p
&& MAY_USE_WITH_COLORS_P (tty
, NC_UNDERLINE
))
1825 OUTPUT1_IF (tty
, tty
->TS_enter_underline_mode
);
1827 if (tty
->TN_max_colors
> 0)
1831 if (fg
>= 0 && tty
->TS_set_foreground
)
1833 p
= tparam (tty
->TS_set_foreground
, NULL
, 0, (int) fg
);
1838 if (bg
>= 0 && tty
->TS_set_background
)
1840 p
= tparam (tty
->TS_set_background
, NULL
, 0, (int) bg
);
1848 /* Turn off appearances of face FACE_ID on tty frame F. */
1851 turn_off_face (f
, face_id
)
1855 struct face
*face
= FACE_FROM_ID (f
, face_id
);
1856 struct tty_output
*tty
= FRAME_TTY (f
);
1858 xassert (face
!= NULL
);
1860 if (tty
->TS_exit_attribute_mode
)
1862 /* Capability "me" will turn off appearance modes double-bright,
1863 half-bright, reverse-video, standout, underline. It may or
1864 may not turn off alt-char-mode. */
1865 if (face
->tty_bold_p
1867 || face
->tty_reverse_p
1868 || face
->tty_alt_charset_p
1869 || face
->tty_blinking_p
1870 || face
->tty_underline_p
)
1872 OUTPUT1_IF (tty
, tty
->TS_exit_attribute_mode
);
1873 if (strcmp (tty
->TS_exit_attribute_mode
, tty
->TS_end_standout_mode
) == 0)
1874 tty
->standout_mode
= 0;
1877 if (face
->tty_alt_charset_p
)
1878 OUTPUT_IF (tty
, tty
->TS_exit_alt_charset_mode
);
1882 /* If we don't have "me" we can only have those appearances
1883 that have exit sequences defined. */
1884 if (face
->tty_alt_charset_p
)
1885 OUTPUT_IF (tty
, tty
->TS_exit_alt_charset_mode
);
1887 if (face
->tty_underline_p
)
1888 OUTPUT_IF (tty
, tty
->TS_exit_underline_mode
);
1891 /* Switch back to default colors. */
1892 if (tty
->TN_max_colors
> 0
1893 && ((face
->foreground
!= FACE_TTY_DEFAULT_COLOR
1894 && face
->foreground
!= FACE_TTY_DEFAULT_FG_COLOR
)
1895 || (face
->background
!= FACE_TTY_DEFAULT_COLOR
1896 && face
->background
!= FACE_TTY_DEFAULT_BG_COLOR
)))
1897 OUTPUT1_IF (tty
, tty
->TS_orig_pair
);
1901 /* Return non-zero if the terminal on frame F supports all of the
1902 capabilities in CAPS simultaneously, with foreground and background
1903 colors FG and BG. */
1906 tty_capable_p (tty
, caps
, fg
, bg
)
1907 struct tty_output
*tty
;
1909 unsigned long fg
, bg
;
1911 #define TTY_CAPABLE_P_TRY(tty, cap, TS, NC_bit) \
1912 if ((caps & (cap)) && (!(TS) || !MAY_USE_WITH_COLORS_P(tty, NC_bit))) \
1915 TTY_CAPABLE_P_TRY (tty
, TTY_CAP_INVERSE
, tty
->TS_standout_mode
, NC_REVERSE
);
1916 TTY_CAPABLE_P_TRY (tty
, TTY_CAP_UNDERLINE
, tty
->TS_enter_underline_mode
, NC_UNDERLINE
);
1917 TTY_CAPABLE_P_TRY (tty
, TTY_CAP_BOLD
, tty
->TS_enter_bold_mode
, NC_BOLD
);
1918 TTY_CAPABLE_P_TRY (tty
, TTY_CAP_DIM
, tty
->TS_enter_dim_mode
, NC_DIM
);
1919 TTY_CAPABLE_P_TRY (tty
, TTY_CAP_BLINK
, tty
->TS_enter_blink_mode
, NC_BLINK
);
1920 TTY_CAPABLE_P_TRY (tty
, TTY_CAP_ALT_CHARSET
, tty
->TS_enter_alt_charset_mode
, NC_ALT_CHARSET
);
1927 /* Return non-zero if the terminal is capable to display colors. */
1929 DEFUN ("tty-display-color-p", Ftty_display_color_p
, Stty_display_color_p
,
1931 doc
: /* Return non-nil if TTY can display colors on DISPLAY. */)
1933 Lisp_Object display
;
1935 struct tty_output
*tty
= FRAME_TTY (SELECTED_FRAME ());
1936 return tty
->TN_max_colors
> 0 ? Qt
: Qnil
;
1939 /* Return the number of supported colors. */
1940 DEFUN ("tty-display-color-cells", Ftty_display_color_cells
,
1941 Stty_display_color_cells
, 0, 1, 0,
1942 doc
: /* Return the number of colors supported by TTY on DISPLAY. */)
1944 Lisp_Object display
;
1946 struct tty_output
*tty
= FRAME_TTY (SELECTED_FRAME ());
1947 return make_number (tty
->TN_max_colors
);
1952 /* Save or restore the default color-related capabilities of this
1955 tty_default_color_capabilities (struct tty_output
*tty
, int save
)
1958 *default_orig_pair
, *default_set_foreground
, *default_set_background
;
1959 static int default_max_colors
, default_max_pairs
, default_no_color_video
;
1963 if (default_orig_pair
)
1964 xfree (default_orig_pair
);
1965 default_orig_pair
= tty
->TS_orig_pair
? xstrdup (tty
->TS_orig_pair
) : NULL
;
1967 if (default_set_foreground
)
1968 xfree (default_set_foreground
);
1969 default_set_foreground
= tty
->TS_set_foreground
? xstrdup (tty
->TS_set_foreground
)
1972 if (default_set_background
)
1973 xfree (default_set_background
);
1974 default_set_background
= tty
->TS_set_background
? xstrdup (tty
->TS_set_background
)
1977 default_max_colors
= tty
->TN_max_colors
;
1978 default_max_pairs
= tty
->TN_max_pairs
;
1979 default_no_color_video
= tty
->TN_no_color_video
;
1983 tty
->TS_orig_pair
= default_orig_pair
;
1984 tty
->TS_set_foreground
= default_set_foreground
;
1985 tty
->TS_set_background
= default_set_background
;
1986 tty
->TN_max_colors
= default_max_colors
;
1987 tty
->TN_max_pairs
= default_max_pairs
;
1988 tty
->TN_no_color_video
= default_no_color_video
;
1992 /* Setup one of the standard tty color schemes according to MODE.
1993 MODE's value is generally the number of colors which we want to
1994 support; zero means set up for the default capabilities, the ones
1995 we saw at term_init time; -1 means turn off color support. */
1997 tty_setup_colors (struct tty_output
*tty
, int mode
)
1999 /* Canonicalize all negative values of MODE. */
2005 case -1: /* no colors at all */
2006 tty
->TN_max_colors
= 0;
2007 tty
->TN_max_pairs
= 0;
2008 tty
->TN_no_color_video
= 0;
2009 tty
->TS_set_foreground
= tty
->TS_set_background
= tty
->TS_orig_pair
= NULL
;
2011 case 0: /* default colors, if any */
2013 tty_default_color_capabilities (tty
, 0);
2015 case 8: /* 8 standard ANSI colors */
2016 tty
->TS_orig_pair
= "\033[0m";
2018 tty
->TS_set_foreground
= "\033[3%p1%dm";
2019 tty
->TS_set_background
= "\033[4%p1%dm";
2021 tty
->TS_set_foreground
= "\033[3%dm";
2022 tty
->TS_set_background
= "\033[4%dm";
2024 tty
->TN_max_colors
= 8;
2025 tty
->TN_max_pairs
= 64;
2026 tty
->TN_no_color_video
= 0;
2032 set_tty_color_mode (f
, val
)
2036 Lisp_Object color_mode_spec
, current_mode_spec
;
2037 Lisp_Object color_mode
, current_mode
;
2039 extern Lisp_Object Qtty_color_mode
;
2040 Lisp_Object tty_color_mode_alist
;
2042 tty_color_mode_alist
= Fintern_soft (build_string ("tty-color-mode-alist"),
2049 if (NILP (tty_color_mode_alist
))
2050 color_mode_spec
= Qnil
;
2052 color_mode_spec
= Fassq (val
, XSYMBOL (tty_color_mode_alist
)->value
);
2054 if (CONSP (color_mode_spec
))
2055 color_mode
= XCDR (color_mode_spec
);
2060 current_mode_spec
= assq_no_quit (Qtty_color_mode
, f
->param_alist
);
2062 if (CONSP (current_mode_spec
))
2063 current_mode
= XCDR (current_mode_spec
);
2065 current_mode
= Qnil
;
2066 if (INTEGERP (color_mode
))
2067 mode
= XINT (color_mode
);
2069 mode
= 0; /* meaning default */
2070 if (INTEGERP (current_mode
))
2071 old_mode
= XINT (current_mode
);
2075 if (mode
!= old_mode
)
2077 tty_setup_colors (FRAME_TTY (f
), mode
);
2078 /* This recomputes all the faces given the new color
2080 call0 (intern ("tty-set-up-initial-frame-faces"));
2085 #endif /* !WINDOWSNT */
2090 get_named_tty (name
)
2093 struct tty_output
*tty
= tty_list
;
2096 if ((tty
->name
== 0 && name
== 0)
2097 || (name
&& tty
->name
&& !strcmp (tty
->name
, name
)))
2106 /***********************************************************************
2108 ***********************************************************************/
2111 term_dummy_init (void)
2113 if (initialized
|| tty_list
)
2114 error ("tty already initialized");
2116 tty_list
= xmalloc (sizeof (struct tty_output
));
2117 bzero (tty_list
, sizeof (struct tty_output
));
2118 TTY_NAME (tty_list
) = 0;
2119 TTY_INPUT (tty_list
) = stdin
;
2120 TTY_OUTPUT (tty_list
) = stdout
;
2126 term_init (name
, terminal_type
)
2128 char *terminal_type
;
2131 char **address
= &area
;
2132 char *buffer
= NULL
;
2133 int buffer_size
= 4096;
2136 struct frame
*sf
= XFRAME (selected_frame
);
2138 struct tty_output
*tty
;
2140 tty
= get_named_tty (name
);
2143 /* Return the previously initialized terminal, except if it is the dummy
2144 terminal created for the initial frame. */
2148 /* In the latter case, initialize top_frame to the current terminal. */
2149 tty
->top_frame
= selected_frame
;
2153 tty
= (struct tty_output
*) xmalloc (sizeof (struct tty_output
));
2154 bzero (tty
, sizeof (struct tty_output
));
2155 tty
->next
= tty_list
;
2162 tty
->Wcm
= (struct cm
*) xmalloc (sizeof (struct cm
));
2168 fd
= emacs_open (name
, O_RDWR
, 0);
2171 tty_list
= tty
->next
;
2173 error ("Could not open file: %s", name
);
2175 f
= fdopen (fd
, "w+");
2176 TTY_NAME (tty
) = xstrdup (name
);
2177 TTY_INPUT (tty
) = f
;
2178 TTY_OUTPUT (tty
) = f
;
2183 TTY_INPUT (tty
) = stdin
;
2184 TTY_OUTPUT (tty
) = stdout
;
2187 TTY_TYPE (tty
) = xstrdup (terminal_type
);
2189 init_sys_modes (tty
);
2192 initialize_w32_display ();
2196 area
= (char *) xmalloc (2044);
2198 FrameRows
= FRAME_LINES (sf
);
2199 FrameCols
= FRAME_COLS (sf
);
2200 specified_window
= FRAME_LINES (sf
);
2202 delete_in_insert_mode
= 1;
2205 TTY_SCROLL_REGION_OK (tty
) = 0;
2207 /* Seems to insert lines when it's not supposed to, messing
2208 up the display. In doing a trace, it didn't seem to be
2209 called much, so I don't think we're losing anything by
2211 TTY_LINE_INS_DEL_OK (tty
) = 0;
2213 TTY_CHAR_INS_DEL_OK (tty
) = 1;
2217 FRAME_CAN_HAVE_SCROLL_BARS (sf
) = 0;
2218 FRAME_VERTICAL_SCROLL_BAR_TYPE (sf
) = vertical_scroll_bar_none
;
2219 TN_max_colors
= 16; /* Required to be non-zero for tty-display-color-p */
2222 #else /* not WINDOWSNT */
2226 buffer
= (char *) xmalloc (buffer_size
);
2227 status
= tgetent (buffer
, terminal_type
);
2234 error ("Cannot open terminfo database file");
2237 fatal ("Cannot open terminfo database file");
2242 error ("Cannot open termcap database file");
2245 fatal ("Cannot open termcap database file");
2254 error ("Terminal type %s is not defined", terminal_type
);
2257 fatal ("Terminal type %s is not defined.\n\
2258 If that is not the actual type of terminal you have,\n \
2259 use the Bourne shell command `TERM=... export TERM' (C-shell:\n\
2260 `setenv TERM ...') to specify the correct type. It may be necessary\n\
2261 to do `unset TERMINFO' (C-shell: `unsetenv TERMINFO') as well.",
2267 error ("Terminal type %s is not defined", terminal_type
);
2270 fatal ("Terminal type %s is not defined.\n\
2271 If that is not the actual type of terminal you have,\n \
2272 use the Bourne shell command `TERM=... export TERM' (C-shell:\n\
2273 `setenv TERM ...') to specify the correct type. It may be necessary\n\
2274 to do `unset TERMCAP' (C-shell: `unsetenv TERMCAP') as well.",
2280 if (strlen (buffer
) >= buffer_size
)
2282 buffer_size
= strlen (buffer
);
2284 area
= (char *) xmalloc (buffer_size
);
2286 tty
->TS_ins_line
= tgetstr ("al", address
);
2287 tty
->TS_ins_multi_lines
= tgetstr ("AL", address
);
2288 tty
->TS_bell
= tgetstr ("bl", address
);
2289 BackTab (tty
) = tgetstr ("bt", address
);
2290 tty
->TS_clr_to_bottom
= tgetstr ("cd", address
);
2291 tty
->TS_clr_line
= tgetstr ("ce", address
);
2292 tty
->TS_clr_frame
= tgetstr ("cl", address
);
2293 ColPosition (tty
) = NULL
; /* tgetstr ("ch", address); */
2294 AbsPosition (tty
) = tgetstr ("cm", address
);
2295 CR (tty
) = tgetstr ("cr", address
);
2296 tty
->TS_set_scroll_region
= tgetstr ("cs", address
);
2297 tty
->TS_set_scroll_region_1
= tgetstr ("cS", address
);
2298 RowPosition (tty
) = tgetstr ("cv", address
);
2299 tty
->TS_del_char
= tgetstr ("dc", address
);
2300 tty
->TS_del_multi_chars
= tgetstr ("DC", address
);
2301 tty
->TS_del_line
= tgetstr ("dl", address
);
2302 tty
->TS_del_multi_lines
= tgetstr ("DL", address
);
2303 tty
->TS_delete_mode
= tgetstr ("dm", address
);
2304 tty
->TS_end_delete_mode
= tgetstr ("ed", address
);
2305 tty
->TS_end_insert_mode
= tgetstr ("ei", address
);
2306 Home (tty
) = tgetstr ("ho", address
);
2307 tty
->TS_ins_char
= tgetstr ("ic", address
);
2308 tty
->TS_ins_multi_chars
= tgetstr ("IC", address
);
2309 tty
->TS_insert_mode
= tgetstr ("im", address
);
2310 tty
->TS_pad_inserted_char
= tgetstr ("ip", address
);
2311 tty
->TS_end_keypad_mode
= tgetstr ("ke", address
);
2312 tty
->TS_keypad_mode
= tgetstr ("ks", address
);
2313 LastLine (tty
) = tgetstr ("ll", address
);
2314 Right (tty
) = tgetstr ("nd", address
);
2315 Down (tty
) = tgetstr ("do", address
);
2317 Down (tty
) = tgetstr ("nl", address
); /* Obsolete name for "do" */
2319 /* VMS puts a carriage return before each linefeed,
2320 so it is not safe to use linefeeds. */
2321 if (Down (tty
) && Down (tty
)[0] == '\n' && Down (tty
)[1] == '\0')
2324 if (tgetflag ("bs"))
2325 Left (tty
) = "\b"; /* can't possibly be longer! */
2326 else /* (Actually, "bs" is obsolete...) */
2327 Left (tty
) = tgetstr ("le", address
);
2329 Left (tty
) = tgetstr ("bc", address
); /* Obsolete name for "le" */
2330 tty
->TS_pad_char
= tgetstr ("pc", address
);
2331 tty
->TS_repeat
= tgetstr ("rp", address
);
2332 tty
->TS_end_standout_mode
= tgetstr ("se", address
);
2333 tty
->TS_fwd_scroll
= tgetstr ("sf", address
);
2334 tty
->TS_standout_mode
= tgetstr ("so", address
);
2335 tty
->TS_rev_scroll
= tgetstr ("sr", address
);
2336 tty
->Wcm
->cm_tab
= tgetstr ("ta", address
);
2337 tty
->TS_end_termcap_modes
= tgetstr ("te", address
);
2338 tty
->TS_termcap_modes
= tgetstr ("ti", address
);
2339 Up (tty
) = tgetstr ("up", address
);
2340 tty
->TS_visible_bell
= tgetstr ("vb", address
);
2341 tty
->TS_cursor_normal
= tgetstr ("ve", address
);
2342 tty
->TS_cursor_visible
= tgetstr ("vs", address
);
2343 tty
->TS_cursor_invisible
= tgetstr ("vi", address
);
2344 tty
->TS_set_window
= tgetstr ("wi", address
);
2346 tty
->TS_enter_underline_mode
= tgetstr ("us", address
);
2347 tty
->TS_exit_underline_mode
= tgetstr ("ue", address
);
2348 tty
->TS_enter_bold_mode
= tgetstr ("md", address
);
2349 tty
->TS_enter_dim_mode
= tgetstr ("mh", address
);
2350 tty
->TS_enter_blink_mode
= tgetstr ("mb", address
);
2351 tty
->TS_enter_reverse_mode
= tgetstr ("mr", address
);
2352 tty
->TS_enter_alt_charset_mode
= tgetstr ("as", address
);
2353 tty
->TS_exit_alt_charset_mode
= tgetstr ("ae", address
);
2354 tty
->TS_exit_attribute_mode
= tgetstr ("me", address
);
2356 MultiUp (tty
) = tgetstr ("UP", address
);
2357 MultiDown (tty
) = tgetstr ("DO", address
);
2358 MultiLeft (tty
) = tgetstr ("LE", address
);
2359 MultiRight (tty
) = tgetstr ("RI", address
);
2361 /* SVr4/ANSI color suppert. If "op" isn't available, don't support
2362 color because we can't switch back to the default foreground and
2364 tty
->TS_orig_pair
= tgetstr ("op", address
);
2365 if (tty
->TS_orig_pair
)
2367 tty
->TS_set_foreground
= tgetstr ("AF", address
);
2368 tty
->TS_set_background
= tgetstr ("AB", address
);
2369 if (!tty
->TS_set_foreground
)
2372 tty
->TS_set_foreground
= tgetstr ("Sf", address
);
2373 tty
->TS_set_background
= tgetstr ("Sb", address
);
2376 tty
->TN_max_colors
= tgetnum ("Co");
2377 tty
->TN_max_pairs
= tgetnum ("pa");
2379 tty
->TN_no_color_video
= tgetnum ("NC");
2380 if (tty
->TN_no_color_video
== -1)
2381 tty
->TN_no_color_video
= 0;
2384 tty_default_color_capabilities (tty
, 1);
2386 MagicWrap (tty
) = tgetflag ("xn");
2387 /* Since we make MagicWrap terminals look like AutoWrap, we need to have
2388 the former flag imply the latter. */
2389 AutoWrap (tty
) = MagicWrap (tty
) || tgetflag ("am");
2390 TTY_MEMORY_BELOW_FRAME (tty
) = tgetflag ("db");
2391 tty
->TF_hazeltine
= tgetflag ("hz");
2392 TTY_MUST_WRITE_SPACES (tty
) = tgetflag ("in");
2393 tty
->meta_key
= tgetflag ("km") || tgetflag ("MT");
2394 tty
->TF_insmode_motion
= tgetflag ("mi");
2395 tty
->TF_standout_motion
= tgetflag ("ms");
2396 tty
->TF_underscore
= tgetflag ("ul");
2397 tty
->TF_teleray
= tgetflag ("xt");
2399 term_get_fkeys (address
);
2401 /* Get frame size from system, or else from termcap. */
2404 get_tty_size (tty
, &width
, &height
);
2405 FRAME_COLS (sf
) = width
;
2406 FRAME_LINES (sf
) = height
;
2409 if (FRAME_COLS (sf
) <= 0)
2410 SET_FRAME_COLS (sf
, tgetnum ("co"));
2412 /* Keep width and external_width consistent */
2413 SET_FRAME_COLS (sf
, FRAME_COLS (sf
));
2414 if (FRAME_LINES (sf
) <= 0)
2415 FRAME_LINES (sf
) = tgetnum ("li");
2417 if (FRAME_LINES (sf
) < 3 || FRAME_COLS (sf
) < 3)
2418 fatal ("Screen size %dx%d is too small",
2419 FRAME_LINES (sf
), FRAME_COLS (sf
));
2421 #if 0 /* This is not used anywhere. */
2422 TTY_MIN_PADDING_SPEED (tty
) = tgetnum ("pb");
2425 TabWidth (tty
) = tgetnum ("tw");
2428 /* These capabilities commonly use ^J.
2429 I don't know why, but sending them on VMS does not work;
2430 it causes following spaces to be lost, sometimes.
2431 For now, the simplest fix is to avoid using these capabilities ever. */
2432 if (Down (tty
) && Down (tty
)[0] == '\n')
2437 tty
->TS_bell
= "\07";
2439 if (!tty
->TS_fwd_scroll
)
2440 tty
->TS_fwd_scroll
= Down (tty
);
2442 PC
= tty
->TS_pad_char
? *tty
->TS_pad_char
: 0;
2444 if (TabWidth (tty
) < 0)
2447 /* Turned off since /etc/termcap seems to have :ta= for most terminals
2448 and newer termcap doc does not seem to say there is a default.
2449 if (!tty->Wcm->cm_tab)
2450 tty->Wcm->cm_tab = "\t";
2453 /* We don't support standout modes that use `magic cookies', so
2454 turn off any that do. */
2455 if (tty
->TS_standout_mode
&& tgetnum ("sg") >= 0)
2457 tty
->TS_standout_mode
= 0;
2458 tty
->TS_end_standout_mode
= 0;
2460 if (tty
->TS_enter_underline_mode
&& tgetnum ("ug") >= 0)
2462 tty
->TS_enter_underline_mode
= 0;
2463 tty
->TS_exit_underline_mode
= 0;
2466 /* If there's no standout mode, try to use underlining instead. */
2467 if (tty
->TS_standout_mode
== 0)
2469 tty
->TS_standout_mode
= tty
->TS_enter_underline_mode
;
2470 tty
->TS_end_standout_mode
= tty
->TS_exit_underline_mode
;
2473 /* If no `se' string, try using a `me' string instead.
2474 If that fails, we can't use standout mode at all. */
2475 if (tty
->TS_end_standout_mode
== 0)
2477 char *s
= tgetstr ("me", address
);
2479 tty
->TS_end_standout_mode
= s
;
2481 tty
->TS_standout_mode
= 0;
2484 if (tty
->TF_teleray
)
2486 tty
->Wcm
->cm_tab
= 0;
2487 /* We can't support standout mode, because it uses magic cookies. */
2488 tty
->TS_standout_mode
= 0;
2489 /* But that means we cannot rely on ^M to go to column zero! */
2491 /* LF can't be trusted either -- can alter hpos */
2492 /* if move at column 0 thru a line with TS_standout_mode */
2496 /* Special handling for certain terminal types known to need it */
2498 if (!strcmp (terminal_type
, "supdup"))
2500 TTY_MEMORY_BELOW_FRAME (tty
) = 1;
2501 tty
->Wcm
->cm_losewrap
= 1;
2503 if (!strncmp (terminal_type
, "c10", 3)
2504 || !strcmp (terminal_type
, "perq"))
2506 /* Supply a makeshift :wi string.
2507 This string is not valid in general since it works only
2508 for windows starting at the upper left corner;
2509 but that is all Emacs uses.
2511 This string works only if the frame is using
2512 the top of the video memory, because addressing is memory-relative.
2513 So first check the :ti string to see if that is true.
2515 It would be simpler if the :wi string could go in the termcap
2516 entry, but it can't because it is not fully valid.
2517 If it were in the termcap entry, it would confuse other programs. */
2518 if (!tty
->TS_set_window
)
2520 p
= tty
->TS_termcap_modes
;
2521 while (*p
&& strcmp (p
, "\033v "))
2524 tty
->TS_set_window
= "\033v%C %C %C %C ";
2526 /* Termcap entry often fails to have :in: flag */
2527 TTY_MUST_WRITE_SPACES (tty
) = 1;
2528 /* :ti string typically fails to have \E^G! in it */
2529 /* This limits scope of insert-char to one line. */
2530 strcpy (area
, tty
->TS_termcap_modes
);
2531 strcat (area
, "\033\007!");
2532 tty
->TS_termcap_modes
= area
;
2533 area
+= strlen (area
) + 1;
2534 p
= AbsPosition (tty
);
2535 /* Change all %+ parameters to %C, to handle
2536 values above 96 correctly for the C100. */
2539 if (p
[0] == '%' && p
[1] == '+')
2545 FrameRows (tty
) = FRAME_LINES (sf
);
2546 FrameCols (tty
) = FRAME_COLS (sf
);
2547 tty
->specified_window
= FRAME_LINES (sf
);
2549 if (Wcm_init (tty
) == -1) /* can't do cursor motion */
2553 error ("Terminal type \"%s\" is not powerful enough to run Emacs");
2557 fatal ("Terminal type \"%s\" is not powerful enough to run Emacs.\n\
2558 It lacks the ability to position the cursor.\n\
2559 If that is not the actual type of terminal you have, use either the\n\
2560 DCL command `SET TERMINAL/DEVICE= ...' for DEC-compatible terminals,\n\
2561 or `define EMACS_TERM \"terminal type\"' for non-DEC terminals.",
2565 fatal ("Terminal type \"%s\" is not powerful enough to run Emacs.\n\
2566 It lacks the ability to position the cursor.\n \
2567 If that is not the actual type of terminal you have,\n \
2568 use the Bourne shell command `TERM=... export TERM' (C-shell:\n\
2569 `setenv TERM ...') to specify the correct type. It may be necessary\n\
2570 to do `unset TERMINFO' (C-shell: `unsetenv TERMINFO') as well.",
2572 # else /* TERMCAP */
2573 fatal ("Terminal type \"%s\" is not powerful enough to run Emacs.\n\
2574 It lacks the ability to position the cursor.\n \
2575 If that is not the actual type of terminal you have,\n\
2576 use the Bourne shell command `TERM=... export TERM' (C-shell:\n\
2577 `setenv TERM ...') to specify the correct type. It may be necessary\n\
2578 to do `unset TERMCAP' (C-shell: `unsetenv TERMCAP') as well.",
2580 # endif /* TERMINFO */
2584 if (FRAME_LINES (sf
) <= 0
2585 || FRAME_COLS (sf
) <= 0)
2590 error ("The frame size has not been specified");
2593 fatal ("The frame size has not been specified");
2596 tty
->delete_in_insert_mode
2597 = tty
->TS_delete_mode
&& tty
->TS_insert_mode
2598 && !strcmp (tty
->TS_delete_mode
, tty
->TS_insert_mode
);
2600 tty
->se_is_so
= (tty
->TS_standout_mode
2601 && tty
->TS_end_standout_mode
2602 && !strcmp (tty
->TS_standout_mode
, tty
->TS_end_standout_mode
));
2604 UseTabs (tty
) = tabs_safe_p (tty
) && TabWidth (tty
) == 8;
2606 TTY_SCROLL_REGION_OK (tty
)
2608 && (tty
->TS_set_window
|| tty
->TS_set_scroll_region
|| tty
->TS_set_scroll_region_1
));
2610 TTY_LINE_INS_DEL_OK (tty
)
2611 = (((tty
->TS_ins_line
|| tty
->TS_ins_multi_lines
)
2612 && (tty
->TS_del_line
|| tty
->TS_del_multi_lines
))
2613 || (TTY_SCROLL_REGION_OK (tty
)
2614 && tty
->TS_fwd_scroll
&& tty
->TS_rev_scroll
));
2616 TTY_CHAR_INS_DEL_OK (tty
)
2617 = ((tty
->TS_ins_char
|| tty
->TS_insert_mode
2618 || tty
->TS_pad_inserted_char
|| tty
->TS_ins_multi_chars
)
2619 && (tty
->TS_del_char
|| tty
->TS_del_multi_chars
));
2621 TTY_FAST_CLEAR_END_OF_LINE (tty
) = tty
->TS_clr_line
!= 0;
2624 if (read_socket_hook
) /* Baudrate is somewhat
2625 meaningless in this case */
2628 FRAME_CAN_HAVE_SCROLL_BARS (sf
) = 0;
2629 FRAME_VERTICAL_SCROLL_BAR_TYPE (sf
) = vertical_scroll_bar_none
;
2630 #endif /* WINDOWSNT */
2634 tty_set_terminal_modes (tty
);
2641 fatal (str
, arg1
, arg2
)
2642 char *str
, *arg1
, *arg2
;
2644 fprintf (stderr
, "emacs: ");
2645 fprintf (stderr
, str
, arg1
, arg2
);
2646 fprintf (stderr
, "\n");
2654 DEFVAR_BOOL ("system-uses-terminfo", &system_uses_terminfo
,
2655 doc
: /* Non-nil means the system uses terminfo rather than termcap.
2656 This variable can be used by terminal emulator packages. */);
2658 system_uses_terminfo
= 1;
2660 system_uses_terminfo
= 0;
2663 DEFVAR_LISP ("ring-bell-function", &Vring_bell_function
,
2664 doc
: /* Non-nil means call this function to ring the bell.
2665 The function should accept no arguments. */);
2666 Vring_bell_function
= Qnil
;
2668 defsubr (&Stty_display_color_p
);
2669 defsubr (&Stty_display_color_cells
);
2671 Fprovide (intern ("multi-tty"), Qnil
);
2675 delete_tty (struct tty_output
*tty
)
2677 Lisp_Object tail
, frame
;
2679 FOR_EACH_FRAME (tail
, frame
)
2681 struct frame
*f
= XFRAME (frame
);
2682 if (FRAME_LIVE_P (f
) && FRAME_TTY (f
) == tty
)
2684 Fdelete_frame (frame
, Qt
);
2685 f
->output_data
.tty
= 0;
2689 /* Close the terminal and free memory. */
2694 delete_tty_1 (struct tty_output
*tty
)
2697 if (tty
== tty_list
)
2698 tty_list
= tty
->next
;
2701 struct tty_output
*p
;
2702 for (p
= tty_list
; p
&& p
->next
!= tty
; p
= p
->next
)
2706 /* This should not happen. */
2709 p
->next
= p
->next
->next
;
2713 /* reset_sys_modes (tty); */
2720 fclose (tty
->input
);
2722 fclose (tty
->output
);
2723 if (tty
->termscript
)
2724 fclose (tty
->termscript
);
2728 xfree (tty->old_tty);
2732 bzero (tty->Wcm, sizeof (struct cm));
2736 bzero (tty, sizeof (struct tty_output));
2752 /* XXX Debug function. */
2753 Lisp_Object frame
, tail
;
2754 FOR_EACH_FRAME (tail
, frame
)
2756 fprintf (stderr
, "Frame: %x\n", XFRAME (frame
));
2762 /* arch-tag: 498e7449-6f2e-45e2-91dd-b7d4ca488193
2763 (do not change this comment) */