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>. */
31 #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_ ((void));
73 static void tty_hide_cursor
P_ ((void));
75 #define OUTPUT(tty, a) \
76 emacs_tputs ((tty), a, (int) (FRAME_LINES (XFRAME (selected_frame)) - curY), cmputc)
77 #define OUTPUT1(tty, a) emacs_tputs ((tty), a, 1, cmputc)
78 #define OUTPUTL(tty, a, lines) emacs_tputs ((tty), a, lines, cmputc)
80 #define OUTPUT_IF(tty, a) \
83 emacs_tputs ((tty), a, (int) (FRAME_LINES (XFRAME (selected_frame)) \
87 #define OUTPUT1_IF(tty, a) do { if (a) emacs_tputs ((tty), a, 1, cmputc); } while (0)
89 /* Function to use to ring the bell. */
91 Lisp_Object Vring_bell_function
;
93 /* Terminal characteristics that higher levels want to look at. */
95 struct tty_output
*tty_list
;
97 /* Nonzero means no need to redraw the entire frame on resuming
98 a suspended Emacs. This is useful on terminals with multiple pages,
99 where one page is used for Emacs and another for all else. */
100 int no_redraw_on_reenter
;
102 /* Hook functions that you can set to snap out the functions in this file.
103 These are all extern'd in termhooks.h */
105 void (*cursor_to_hook
) P_ ((int, int));
106 void (*raw_cursor_to_hook
) P_ ((int, int));
107 void (*clear_to_end_hook
) P_ ((void));
108 void (*clear_frame_hook
) P_ ((void));
109 void (*clear_end_of_line_hook
) P_ ((int));
111 void (*ins_del_lines_hook
) P_ ((int, int));
113 void (*delete_glyphs_hook
) P_ ((int));
115 void (*ring_bell_hook
) P_ ((void));
117 void (*reset_terminal_modes_hook
) P_ ((void));
118 void (*set_terminal_modes_hook
) P_ ((void));
119 void (*update_begin_hook
) P_ ((struct frame
*));
120 void (*update_end_hook
) P_ ((struct frame
*));
121 void (*set_terminal_window_hook
) P_ ((int));
122 void (*insert_glyphs_hook
) P_ ((struct glyph
*, int));
123 void (*write_glyphs_hook
) P_ ((struct glyph
*, int));
124 void (*delete_glyphs_hook
) P_ ((int));
126 int (*read_socket_hook
) P_ ((int, struct input_event
*, int, int));
128 void (*frame_up_to_date_hook
) P_ ((struct frame
*));
130 /* Return the current position of the mouse.
132 Set *f to the frame the mouse is in, or zero if the mouse is in no
133 Emacs frame. If it is set to zero, all the other arguments are
136 If the motion started in a scroll bar, set *bar_window to the
137 scroll bar's window, *part to the part the mouse is currently over,
138 *x to the position of the mouse along the scroll bar, and *y to the
139 overall length of the scroll bar.
141 Otherwise, set *bar_window to Qnil, and *x and *y to the column and
142 row of the character cell the mouse is over.
144 Set *time to the time the mouse was at the returned position.
146 This should clear mouse_moved until the next motion
149 void (*mouse_position_hook
) P_ ((FRAME_PTR
*f
, int insist
,
150 Lisp_Object
*bar_window
,
151 enum scroll_bar_part
*part
,
154 unsigned long *time
));
156 /* When reading from a minibuffer in a different frame, Emacs wants
157 to shift the highlight from the selected frame to the mini-buffer's
158 frame; under X, this means it lies about where the focus is.
159 This hook tells the window system code to re-decide where to put
162 void (*frame_rehighlight_hook
) P_ ((FRAME_PTR f
));
164 /* If we're displaying frames using a window system that can stack
165 frames on top of each other, this hook allows you to bring a frame
166 to the front, or bury it behind all the other windows. If this
167 hook is zero, that means the device we're displaying on doesn't
168 support overlapping frames, so there's no need to raise or lower
171 If RAISE is non-zero, F is brought to the front, before all other
172 windows. If RAISE is zero, F is sent to the back, behind all other
175 void (*frame_raise_lower_hook
) P_ ((FRAME_PTR f
, int raise
));
177 /* Set the vertical scroll bar for WINDOW to have its upper left corner
178 at (TOP, LEFT), and be LENGTH rows high. Set its handle to
179 indicate that we are displaying PORTION characters out of a total
180 of WHOLE characters, starting at POSITION. If WINDOW doesn't yet
181 have a scroll bar, create one for it. */
183 void (*set_vertical_scroll_bar_hook
)
184 P_ ((struct window
*window
,
185 int portion
, int whole
, int position
));
188 /* The following three hooks are used when we're doing a thorough
189 redisplay of the frame. We don't explicitly know which scroll bars
190 are going to be deleted, because keeping track of when windows go
191 away is a real pain - can you say set-window-configuration?
192 Instead, we just assert at the beginning of redisplay that *all*
193 scroll bars are to be removed, and then save scroll bars from the
194 fiery pit when we actually redisplay their window. */
196 /* Arrange for all scroll bars on FRAME to be removed at the next call
197 to `*judge_scroll_bars_hook'. A scroll bar may be spared if
198 `*redeem_scroll_bar_hook' is applied to its window before the judgment.
200 This should be applied to each frame each time its window tree is
201 redisplayed, even if it is not displaying scroll bars at the moment;
202 if the HAS_SCROLL_BARS flag has just been turned off, only calling
203 this and the judge_scroll_bars_hook will get rid of them.
205 If non-zero, this hook should be safe to apply to any frame,
206 whether or not it can support scroll bars, and whether or not it is
207 currently displaying them. */
209 void (*condemn_scroll_bars_hook
) P_ ((FRAME_PTR frame
));
211 /* Unmark WINDOW's scroll bar for deletion in this judgement cycle.
212 Note that it's okay to redeem a scroll bar that is not condemned. */
214 void (*redeem_scroll_bar_hook
) P_ ((struct window
*window
));
216 /* Remove all scroll bars on FRAME that haven't been saved since the
217 last call to `*condemn_scroll_bars_hook'.
219 This should be applied to each frame after each time its window
220 tree is redisplayed, even if it is not displaying scroll bars at the
221 moment; if the HAS_SCROLL_BARS flag has just been turned off, only
222 calling this and condemn_scroll_bars_hook will get rid of them.
224 If non-zero, this hook should be safe to apply to any frame,
225 whether or not it can support scroll bars, and whether or not it is
226 currently displaying them. */
228 void (*judge_scroll_bars_hook
) P_ ((FRAME_PTR FRAME
));
230 /* Strings, numbers and flags taken from the termcap entry. */
232 char *TS_ins_line
; /* "al" */
233 char *TS_ins_multi_lines
; /* "AL" (one parameter, # lines to insert) */
234 char *TS_bell
; /* "bl" */
235 char *TS_clr_to_bottom
; /* "cd" */
236 char *TS_clr_line
; /* "ce", clear to end of line */
237 char *TS_clr_frame
; /* "cl" */
238 char *TS_set_scroll_region
; /* "cs" (2 params, first line and last line) */
239 char *TS_set_scroll_region_1
; /* "cS" (4 params: total lines,
240 lines above scroll region, lines below it,
241 total lines again) */
242 char *TS_del_char
; /* "dc" */
243 char *TS_del_multi_chars
; /* "DC" (one parameter, # chars to delete) */
244 char *TS_del_line
; /* "dl" */
245 char *TS_del_multi_lines
; /* "DL" (one parameter, # lines to delete) */
246 char *TS_delete_mode
; /* "dm", enter character-delete mode */
247 char *TS_end_delete_mode
; /* "ed", leave character-delete mode */
248 char *TS_end_insert_mode
; /* "ei", leave character-insert mode */
249 char *TS_ins_char
; /* "ic" */
250 char *TS_ins_multi_chars
; /* "IC" (one parameter, # chars to insert) */
251 char *TS_insert_mode
; /* "im", enter character-insert mode */
252 char *TS_pad_inserted_char
; /* "ip". Just padding, no commands. */
253 char *TS_end_keypad_mode
; /* "ke" */
254 char *TS_keypad_mode
; /* "ks" */
255 char *TS_pad_char
; /* "pc", char to use as padding */
256 char *TS_repeat
; /* "rp" (2 params, # times to repeat
257 and character to be repeated) */
258 char *TS_end_standout_mode
; /* "se" */
259 char *TS_fwd_scroll
; /* "sf" */
260 char *TS_standout_mode
; /* "so" */
261 char *TS_rev_scroll
; /* "sr" */
262 char *TS_end_termcap_modes
; /* "te" */
263 char *TS_termcap_modes
; /* "ti" */
264 char *TS_visible_bell
; /* "vb" */
265 char *TS_cursor_normal
; /* "ve" */
266 char *TS_cursor_visible
; /* "vs" */
267 char *TS_cursor_invisible
; /* "vi" */
268 char *TS_set_window
; /* "wi" (4 params, start and end of window,
269 each as vpos and hpos) */
271 /* Value of the "NC" (no_color_video) capability, or 0 if not
274 static int TN_no_color_video
;
276 /* Meaning of bits in no_color_video. Each bit set means that the
277 corresponding attribute cannot be combined with colors. */
281 NC_STANDOUT
= 1 << 0,
282 NC_UNDERLINE
= 1 << 1,
289 NC_ALT_CHARSET
= 1 << 8
292 /* "md" -- turn on bold (extra bright mode). */
294 char *TS_enter_bold_mode
;
296 /* "mh" -- turn on half-bright mode. */
298 char *TS_enter_dim_mode
;
300 /* "mb" -- enter blinking mode. */
302 char *TS_enter_blink_mode
;
304 /* "mr" -- enter reverse video mode. */
306 char *TS_enter_reverse_mode
;
308 /* "us"/"ue" -- start/end underlining. */
310 char *TS_exit_underline_mode
, *TS_enter_underline_mode
;
312 /* "as"/"ae" -- start/end alternate character set. Not really
315 char *TS_enter_alt_charset_mode
, *TS_exit_alt_charset_mode
;
317 /* "me" -- switch appearances off. */
319 char *TS_exit_attribute_mode
;
321 /* "Co" -- number of colors. */
325 /* "pa" -- max. number of color pairs on screen. Not handled yet.
326 Could be a problem if not equal to TN_max_colors * TN_max_colors. */
330 /* "op" -- SVr4 set default pair to its original value. */
334 /* "AF"/"AB" or "Sf"/"Sb"-- set ANSI or SVr4 foreground/background color.
335 1 param, the color index. */
337 char *TS_set_foreground
, *TS_set_background
;
339 int TF_hazeltine
; /* termcap hz flag. */
340 int TF_insmode_motion
; /* termcap mi flag: can move while in insert mode. */
341 int TF_standout_motion
; /* termcap mi flag: can move while in standout mode. */
342 int TF_underscore
; /* termcap ul flag: _ underlines if over-struck on
343 non-blank position. Must clear before writing _. */
344 int TF_teleray
; /* termcap xt flag: many weird consequences.
347 static int RPov
; /* # chars to start a TS_repeat */
349 static int delete_in_insert_mode
; /* delete mode == insert mode */
351 static int se_is_so
; /* 1 if same string both enters and leaves
356 /* The largest frame width in any call to calculate_costs. */
360 /* The largest frame height in any call to calculate_costs. */
364 static int costs_set
; /* Nonzero if costs have been calculated. */
366 int insert_mode
; /* Nonzero when in insert mode. */
367 int standout_mode
; /* Nonzero when in standout mode. */
369 /* Size of window specified by higher levels.
370 This is the number of lines, from the top of frame downwards,
371 which can participate in insert-line/delete-line operations.
373 Effectively it excludes the bottom frame_lines - specified_window_size
374 lines from those operations. */
376 int specified_window
;
378 /* Frame currently being redisplayed; 0 if not currently redisplaying.
379 (Direct output does not count). */
381 FRAME_PTR updating_frame
;
383 /* Provided for lisp packages. */
385 static int system_uses_terminfo
;
387 /* Flag used in tty_show/hide_cursor. */
389 static int tty_cursor_hidden
;
393 extern char *tgetstr ();
397 /* We aren't X windows, but we aren't termcap either. This makes me
398 uncertain as to what value to use for frame.output_method. For
399 this file, we'll define FRAME_TERMCAP_P to be zero so that our
400 output hooks get called instead of the termcap functions. Probably
401 the best long-term solution is to define an output_windows_nt... */
403 #undef FRAME_TERMCAP_P
404 #define FRAME_TERMCAP_P(_f_) 0
405 #endif /* WINDOWSNT */
410 if (!NILP (Vring_bell_function
))
412 Lisp_Object function
;
414 /* Temporarily set the global variable to nil
415 so that if we get an error, it stays nil
416 and we don't call it over and over.
418 We don't specbind it, because that would carefully
419 restore the bad value if there's an error
420 and make the loop of errors happen anyway. */
422 function
= Vring_bell_function
;
423 Vring_bell_function
= Qnil
;
427 Vring_bell_function
= function
;
429 else if (!FRAME_TERMCAP_P (XFRAME (selected_frame
)))
430 (*ring_bell_hook
) ();
432 OUTPUT (CURTTY (), TS_visible_bell
&& visible_bell
? TS_visible_bell
: TS_bell
);
437 set_terminal_modes (struct tty_output
*tty
)
439 if (FRAME_TERMCAP_P (XFRAME (selected_frame
)))
441 OUTPUT_IF (tty
, TS_termcap_modes
);
442 OUTPUT_IF (tty
, TS_cursor_visible
);
443 OUTPUT_IF (tty
, TS_keypad_mode
);
447 (*set_terminal_modes_hook
) ();
451 reset_terminal_modes (struct tty_output
*tty
)
453 if (FRAME_TERMCAP_P (XFRAME (selected_frame
)))
455 turn_off_highlight ();
457 OUTPUT_IF (tty
, TS_end_keypad_mode
);
458 OUTPUT_IF (tty
, TS_cursor_normal
);
459 OUTPUT_IF (tty
, TS_end_termcap_modes
);
460 OUTPUT_IF (tty
, TS_orig_pair
);
461 /* Output raw CR so kernel can track the cursor hpos. */
465 else if (reset_terminal_modes_hook
)
466 (*reset_terminal_modes_hook
) ();
474 if (!FRAME_TERMCAP_P (f
))
475 update_begin_hook (f
);
482 if (FRAME_TERMCAP_P (f
))
484 if (!XWINDOW (selected_window
)->cursor_off_p
)
487 background_highlight ();
492 updating_frame
= NULL
;
496 set_terminal_window (size
)
499 if (FRAME_TERMCAP_P (updating_frame
))
501 specified_window
= size
? size
: FRAME_LINES (updating_frame
);
502 if (TTY_SCROLL_REGION_OK (FRAME_TTY (updating_frame
)))
503 set_scroll_region (0, specified_window
);
506 set_terminal_window_hook (size
);
510 set_scroll_region (start
, stop
)
514 struct frame
*f
= (updating_frame
516 : XFRAME (selected_frame
));
518 if (TS_set_scroll_region
)
519 buf
= tparam (TS_set_scroll_region
, 0, 0, start
, stop
- 1);
520 else if (TS_set_scroll_region_1
)
521 buf
= tparam (TS_set_scroll_region_1
, 0, 0,
522 FRAME_LINES (f
), start
,
523 FRAME_LINES (f
) - stop
,
526 buf
= tparam (TS_set_window
, 0, 0, start
, 0, stop
, FRAME_COLS (f
));
528 OUTPUT (FRAME_TTY (f
), buf
);
537 struct frame
*f
= (updating_frame
539 : XFRAME (selected_frame
));
541 OUTPUT (FRAME_TTY (f
), TS_insert_mode
);
548 struct frame
*f
= (updating_frame
550 : XFRAME (selected_frame
));
552 OUTPUT (FRAME_TTY (f
), TS_end_insert_mode
);
556 /* Handle highlighting. */
559 turn_off_highlight ()
561 struct frame
*f
= (updating_frame
563 : XFRAME (selected_frame
));
565 OUTPUT_IF (FRAME_TTY (f
), TS_end_standout_mode
);
572 struct frame
*f
= (updating_frame
574 : XFRAME (selected_frame
));
576 OUTPUT_IF (FRAME_TTY (f
), TS_standout_mode
);
584 turn_off_highlight ();
586 turn_on_highlight ();
590 /* Make cursor invisible. */
595 struct frame
*f
= (updating_frame
597 : XFRAME (selected_frame
));
599 if (tty_cursor_hidden
== 0)
601 tty_cursor_hidden
= 1;
602 OUTPUT_IF (FRAME_TTY (f
), TS_cursor_invisible
);
607 /* Ensure that cursor is visible. */
612 struct frame
*f
= (updating_frame
614 : XFRAME (selected_frame
));
616 if (tty_cursor_hidden
)
618 tty_cursor_hidden
= 0;
619 OUTPUT_IF (FRAME_TTY (f
), TS_cursor_normal
);
620 OUTPUT_IF (FRAME_TTY (f
), TS_cursor_visible
);
625 /* Set standout mode to the state it should be in for
626 empty space inside windows. What this is,
627 depends on the user option inverse-video. */
630 background_highlight ()
633 turn_on_highlight ();
635 turn_off_highlight ();
638 /* Set standout mode to the mode specified for the text to be output. */
641 highlight_if_desired ()
644 turn_on_highlight ();
646 turn_off_highlight ();
650 /* Move cursor to row/column position VPOS/HPOS. HPOS/VPOS are
651 frame-relative coordinates. */
654 cursor_to (vpos
, hpos
)
657 struct frame
*f
= updating_frame
? updating_frame
: XFRAME (selected_frame
);
659 if (! FRAME_TERMCAP_P (f
) && cursor_to_hook
)
661 (*cursor_to_hook
) (vpos
, hpos
);
665 /* Detect the case where we are called from reset_sys_modes
666 and the costs have never been calculated. Do nothing. */
670 if (curY
== vpos
&& curX
== hpos
)
672 if (!TF_standout_motion
)
673 background_highlight ();
674 if (!TF_insmode_motion
)
676 cmgoto (FRAME_TTY (f
), vpos
, hpos
);
679 /* Similar but don't take any account of the wasted characters. */
682 raw_cursor_to (row
, col
)
685 struct frame
*f
= updating_frame
? updating_frame
: XFRAME (selected_frame
);
686 if (! FRAME_TERMCAP_P (f
))
688 (*raw_cursor_to_hook
) (row
, col
);
691 if (curY
== row
&& curX
== col
)
693 if (!TF_standout_motion
)
694 background_highlight ();
695 if (!TF_insmode_motion
)
697 cmgoto (FRAME_TTY (f
), row
, col
);
700 /* Erase operations */
702 /* clear from cursor to end of frame */
708 struct frame
*f
= (updating_frame
710 : XFRAME (selected_frame
));
712 if (clear_to_end_hook
&& ! FRAME_TERMCAP_P (f
))
714 (*clear_to_end_hook
) ();
717 if (TS_clr_to_bottom
)
719 background_highlight ();
720 OUTPUT (FRAME_TTY (f
), TS_clr_to_bottom
);
724 for (i
= curY
; i
< FRAME_LINES (f
); i
++)
727 clear_end_of_line (FRAME_COLS (f
));
732 /* Clear entire frame */
737 struct frame
*f
= (updating_frame
739 : XFRAME (selected_frame
));
741 if (clear_frame_hook
&& ! FRAME_TERMCAP_P (f
))
743 (*clear_frame_hook
) ();
748 background_highlight ();
749 OUTPUT (FRAME_TTY (f
), TS_clr_frame
);
759 /* Clear from cursor to end of line.
760 Assume that the line is already clear starting at column first_unused_hpos.
762 Note that the cursor may be moved, on terminals lacking a `ce' string. */
765 clear_end_of_line (first_unused_hpos
)
766 int first_unused_hpos
;
770 struct frame
*f
= (updating_frame
772 : XFRAME (selected_frame
));
774 if (clear_end_of_line_hook
775 && ! FRAME_TERMCAP_P (f
))
777 (*clear_end_of_line_hook
) (first_unused_hpos
);
781 /* Detect the case where we are called from reset_sys_modes
782 and the costs have never been calculated. Do nothing. */
786 if (curX
>= first_unused_hpos
)
788 background_highlight ();
791 OUTPUT1 (FRAME_TTY (f
), TS_clr_line
);
794 { /* have to do it the hard way */
795 struct frame
*sf
= XFRAME (selected_frame
);
798 /* Do not write in last row last col with Auto-wrap on. */
799 if (AutoWrap
&& curY
== FRAME_LINES (sf
) - 1
800 && first_unused_hpos
== FRAME_COLS (sf
))
803 for (i
= curX
; i
< first_unused_hpos
; i
++)
805 if (TTY_TERMSCRIPT (FRAME_TTY (f
)))
806 fputc (' ', TTY_TERMSCRIPT (FRAME_TTY (f
)));
807 fputc (' ', TTY_OUTPUT (FRAME_TTY (f
)));
809 cmplus (first_unused_hpos
- curX
);
813 /* Encode SRC_LEN glyphs starting at SRC to terminal output codes and
814 store them at DST. Do not write more than DST_LEN bytes. That may
815 require stopping before all SRC_LEN input glyphs have been
818 We store the number of glyphs actually converted in *CONSUMED. The
819 return value is the number of bytes store in DST. */
822 encode_terminal_code (src
, dst
, src_len
, dst_len
, consumed
)
826 int dst_len
, *consumed
;
828 struct glyph
*src_start
= src
, *src_end
= src
+ src_len
;
829 unsigned char *dst_start
= dst
, *dst_end
= dst
+ dst_len
;
831 unsigned char workbuf
[MAX_MULTIBYTE_LENGTH
];
832 const unsigned char *buf
;
834 register int tlen
= GLYPH_TABLE_LENGTH
;
835 register Lisp_Object
*tbase
= GLYPH_TABLE_BASE
;
837 struct coding_system
*coding
;
839 /* If terminal_coding does any conversion, use it, otherwise use
840 safe_terminal_coding. We can't use CODING_REQUIRE_ENCODING here
841 because it always return 1 if the member src_multibyte is 1. */
842 coding
= (terminal_coding
.common_flags
& CODING_REQUIRE_ENCODING_MASK
844 : &safe_terminal_coding
);
846 while (src
< src_end
)
848 /* We must skip glyphs to be padded for a wide character. */
849 if (! CHAR_GLYPH_PADDING_P (*src
))
851 g
= GLYPH_FROM_CHAR_GLYPH (src
[0]);
853 if (g
< 0 || g
>= tlen
)
855 /* This glyph doesn't has an entry in Vglyph_table. */
856 if (! CHAR_VALID_P (src
->u
.ch
, 0))
860 coding
->src_multibyte
= 0;
864 len
= CHAR_STRING (src
->u
.ch
, workbuf
);
866 coding
->src_multibyte
= 1;
871 /* This glyph has an entry in Vglyph_table,
872 so process any alias before testing for simpleness. */
873 GLYPH_FOLLOW_ALIASES (tbase
, tlen
, g
);
875 if (GLYPH_SIMPLE_P (tbase
, tlen
, g
))
877 /* We set the multi-byte form of a character in G
878 (that should be an ASCII character) at
880 workbuf
[0] = FAST_GLYPH_CHAR (g
);
883 coding
->src_multibyte
= 0;
887 /* We have a string in Vglyph_table. */
888 len
= GLYPH_LENGTH (tbase
, g
);
889 buf
= GLYPH_STRING (tbase
, g
);
890 coding
->src_multibyte
= STRING_MULTIBYTE (tbase
[g
]);
894 result
= encode_coding (coding
, buf
, dst
, len
, dst_end
- dst
);
895 len
-= coding
->consumed
;
896 dst
+= coding
->produced
;
897 if (result
== CODING_FINISH_INSUFFICIENT_DST
898 || (result
== CODING_FINISH_INSUFFICIENT_SRC
899 && len
> dst_end
- dst
))
900 /* The remaining output buffer is too short. We must
901 break the loop here without increasing SRC so that the
902 next call of this function starts from the same glyph. */
907 /* This is the case that a code of the range 0200..0237
908 exists in buf. We must just write out such a code. */
909 buf
+= coding
->consumed
;
917 *consumed
= src
- src_start
;
918 return (dst
- dst_start
);
923 write_glyphs (string
, len
)
924 register struct glyph
*string
;
927 int produced
, consumed
;
928 struct frame
*sf
= XFRAME (selected_frame
);
929 struct frame
*f
= updating_frame
? updating_frame
: sf
;
930 unsigned char conversion_buffer
[1024];
931 int conversion_buffer_size
= sizeof conversion_buffer
;
933 if (write_glyphs_hook
934 && ! FRAME_TERMCAP_P (f
))
936 (*write_glyphs_hook
) (string
, len
);
943 /* Don't dare write in last column of bottom line, if Auto-Wrap,
944 since that would scroll the whole frame on some terminals. */
947 && curY
+ 1 == FRAME_LINES (sf
)
948 && (curX
+ len
) == FRAME_COLS (sf
))
955 /* The mode bit CODING_MODE_LAST_BLOCK should be set to 1 only at
957 terminal_coding
.mode
&= ~CODING_MODE_LAST_BLOCK
;
961 /* Identify a run of glyphs with the same face. */
962 int face_id
= string
->face_id
;
965 for (n
= 1; n
< len
; ++n
)
966 if (string
[n
].face_id
!= face_id
)
969 /* Turn appearance modes of the face of the run on. */
970 highlight_if_desired ();
971 turn_on_face (f
, face_id
);
975 /* We use a fixed size (1024 bytes) of conversion buffer.
976 Usually it is sufficient, but if not, we just repeat the
978 produced
= encode_terminal_code (string
, conversion_buffer
,
979 n
, conversion_buffer_size
,
983 fwrite (conversion_buffer
, 1, produced
,
984 TTY_OUTPUT (FRAME_TTY (f
)));
985 if (ferror (TTY_OUTPUT (FRAME_TTY (f
))))
986 clearerr (TTY_OUTPUT (FRAME_TTY (f
)));
987 if (TTY_TERMSCRIPT (FRAME_TTY (f
)))
988 fwrite (conversion_buffer
, 1, produced
,
989 TTY_TERMSCRIPT (FRAME_TTY (f
)));
996 /* Turn appearance modes off. */
997 turn_off_face (f
, face_id
);
998 turn_off_highlight ();
1001 /* We may have to output some codes to terminate the writing. */
1002 if (CODING_REQUIRE_FLUSHING (&terminal_coding
))
1004 terminal_coding
.mode
|= CODING_MODE_LAST_BLOCK
;
1005 encode_coding (&terminal_coding
, "", conversion_buffer
,
1006 0, conversion_buffer_size
);
1007 if (terminal_coding
.produced
> 0)
1009 fwrite (conversion_buffer
, 1, terminal_coding
.produced
,
1010 TTY_OUTPUT (FRAME_TTY (f
)));
1011 if (ferror (TTY_OUTPUT (FRAME_TTY (f
))))
1012 clearerr (TTY_OUTPUT (FRAME_TTY (f
)));
1013 if (TTY_TERMSCRIPT (FRAME_TTY (f
)))
1014 fwrite (conversion_buffer
, 1, terminal_coding
.produced
,
1015 TTY_TERMSCRIPT (FRAME_TTY (f
)));
1019 cmcheckmagic (FRAME_TTY (f
));
1022 /* If start is zero, insert blanks instead of a string at start */
1025 insert_glyphs (start
, len
)
1026 register struct glyph
*start
;
1030 struct glyph
*glyph
= NULL
;
1031 struct frame
*f
, *sf
;
1036 if (insert_glyphs_hook
)
1038 (*insert_glyphs_hook
) (start
, len
);
1042 sf
= XFRAME (selected_frame
);
1043 f
= updating_frame
? updating_frame
: sf
;
1045 if (TS_ins_multi_chars
)
1047 buf
= tparam (TS_ins_multi_chars
, 0, 0, len
);
1048 OUTPUT1 (FRAME_TTY (f
), buf
);
1051 write_glyphs (start
, len
);
1057 /* The bit CODING_MODE_LAST_BLOCK should be set to 1 only at the tail. */
1058 terminal_coding
.mode
&= ~CODING_MODE_LAST_BLOCK
;
1061 int produced
, consumed
;
1062 unsigned char conversion_buffer
[1024];
1063 int conversion_buffer_size
= sizeof conversion_buffer
;
1065 OUTPUT1_IF (FRAME_TTY (f
), TS_ins_char
);
1068 conversion_buffer
[0] = SPACEGLYPH
;
1073 highlight_if_desired ();
1074 turn_on_face (f
, start
->face_id
);
1077 /* We must open sufficient space for a character which
1078 occupies more than one column. */
1079 while (len
&& CHAR_GLYPH_PADDING_P (*start
))
1081 OUTPUT1_IF (FRAME_TTY (f
), TS_ins_char
);
1086 /* This is the last glyph. */
1087 terminal_coding
.mode
|= CODING_MODE_LAST_BLOCK
;
1089 /* The size of conversion buffer (1024 bytes) is surely
1090 sufficient for just one glyph. */
1091 produced
= encode_terminal_code (glyph
, conversion_buffer
, 1,
1092 conversion_buffer_size
, &consumed
);
1097 fwrite (conversion_buffer
, 1, produced
,
1098 TTY_OUTPUT (FRAME_TTY (f
)));
1099 if (ferror (TTY_OUTPUT (FRAME_TTY (f
))))
1100 clearerr (TTY_OUTPUT (FRAME_TTY (f
)));
1101 if (TTY_TERMSCRIPT (FRAME_TTY (f
)))
1102 fwrite (conversion_buffer
, 1, produced
,
1103 TTY_TERMSCRIPT (FRAME_TTY (f
)));
1106 OUTPUT1_IF (FRAME_TTY (f
), TS_pad_inserted_char
);
1109 turn_off_face (f
, glyph
->face_id
);
1110 turn_off_highlight ();
1114 cmcheckmagic (FRAME_TTY (f
));
1124 if (delete_glyphs_hook
&& ! FRAME_TERMCAP_P (updating_frame
))
1126 (*delete_glyphs_hook
) (n
);
1130 if (delete_in_insert_mode
)
1137 OUTPUT_IF (FRAME_TTY (updating_frame
), TS_delete_mode
);
1140 if (TS_del_multi_chars
)
1142 buf
= tparam (TS_del_multi_chars
, 0, 0, n
);
1143 OUTPUT1 (FRAME_TTY (updating_frame
), buf
);
1147 for (i
= 0; i
< n
; i
++)
1148 OUTPUT1 (FRAME_TTY (updating_frame
), TS_del_char
);
1149 if (!delete_in_insert_mode
)
1150 OUTPUT_IF (FRAME_TTY (updating_frame
), TS_end_delete_mode
);
1153 /* Insert N lines at vpos VPOS. If N is negative, delete -N lines. */
1156 ins_del_lines (vpos
, n
)
1159 char *multi
= n
> 0 ? TS_ins_multi_lines
: TS_del_multi_lines
;
1160 char *single
= n
> 0 ? TS_ins_line
: TS_del_line
;
1161 char *scroll
= n
> 0 ? TS_rev_scroll
: TS_fwd_scroll
;
1164 register int i
= n
> 0 ? n
: -n
;
1167 if (ins_del_lines_hook
&& ! FRAME_TERMCAP_P (updating_frame
))
1169 (*ins_del_lines_hook
) (vpos
, n
);
1173 sf
= XFRAME (selected_frame
);
1175 /* If the lines below the insertion are being pushed
1176 into the end of the window, this is the same as clearing;
1177 and we know the lines are already clear, since the matching
1178 deletion has already been done. So can ignore this. */
1179 /* If the lines below the deletion are blank lines coming
1180 out of the end of the window, don't bother,
1181 as there will be a matching inslines later that will flush them. */
1182 if (TTY_SCROLL_REGION_OK (FRAME_TTY (sf
))
1183 && vpos
+ i
>= specified_window
)
1185 if (!TTY_MEMORY_BELOW_FRAME (FRAME_TTY (sf
))
1186 && vpos
+ i
>= FRAME_LINES (sf
))
1191 raw_cursor_to (vpos
, 0);
1192 background_highlight ();
1193 buf
= tparam (multi
, 0, 0, i
);
1194 OUTPUT (FRAME_TTY (sf
), buf
);
1199 raw_cursor_to (vpos
, 0);
1200 background_highlight ();
1202 OUTPUT (FRAME_TTY (sf
), single
);
1208 set_scroll_region (vpos
, specified_window
);
1210 raw_cursor_to (specified_window
- 1, 0);
1212 raw_cursor_to (vpos
, 0);
1213 background_highlight ();
1215 OUTPUTL (FRAME_TTY (sf
), scroll
, specified_window
- vpos
);
1216 set_scroll_region (0, specified_window
);
1219 if (!TTY_SCROLL_REGION_OK (FRAME_TTY (sf
))
1220 && TTY_MEMORY_BELOW_FRAME (FRAME_TTY (sf
))
1223 cursor_to (FRAME_LINES (sf
) + n
, 0);
1228 /* Compute cost of sending "str", in characters,
1229 not counting any line-dependent padding. */
1237 tputs (str
, 0, evalcost
);
1241 /* Compute cost of sending "str", in characters,
1242 counting any line-dependent padding at one line. */
1245 string_cost_one_line (str
)
1250 tputs (str
, 1, evalcost
);
1254 /* Compute per line amount of line-dependent padding,
1255 in tenths of characters. */
1263 tputs (str
, 0, evalcost
);
1266 tputs (str
, 10, evalcost
);
1271 /* char_ins_del_cost[n] is cost of inserting N characters.
1272 char_ins_del_cost[-n] is cost of deleting N characters.
1273 The length of this vector is based on max_frame_cols. */
1275 int *char_ins_del_vector
;
1277 #define char_ins_del_cost(f) (&char_ins_del_vector[FRAME_COLS ((f))])
1282 calculate_ins_del_char_costs (frame
)
1285 int ins_startup_cost
, del_startup_cost
;
1286 int ins_cost_per_char
, del_cost_per_char
;
1290 if (TS_ins_multi_chars
)
1292 ins_cost_per_char
= 0;
1293 ins_startup_cost
= string_cost_one_line (TS_ins_multi_chars
);
1295 else if (TS_ins_char
|| TS_pad_inserted_char
1296 || (TS_insert_mode
&& TS_end_insert_mode
))
1298 ins_startup_cost
= (30 * (string_cost (TS_insert_mode
)
1299 + string_cost (TS_end_insert_mode
))) / 100;
1300 ins_cost_per_char
= (string_cost_one_line (TS_ins_char
)
1301 + string_cost_one_line (TS_pad_inserted_char
));
1305 ins_startup_cost
= 9999;
1306 ins_cost_per_char
= 0;
1309 if (TS_del_multi_chars
)
1311 del_cost_per_char
= 0;
1312 del_startup_cost
= string_cost_one_line (TS_del_multi_chars
);
1314 else if (TS_del_char
)
1316 del_startup_cost
= (string_cost (TS_delete_mode
)
1317 + string_cost (TS_end_delete_mode
));
1318 if (delete_in_insert_mode
)
1319 del_startup_cost
/= 2;
1320 del_cost_per_char
= string_cost_one_line (TS_del_char
);
1324 del_startup_cost
= 9999;
1325 del_cost_per_char
= 0;
1328 /* Delete costs are at negative offsets */
1329 p
= &char_ins_del_cost (frame
)[0];
1330 for (i
= FRAME_COLS (frame
); --i
>= 0;)
1331 *--p
= (del_startup_cost
+= del_cost_per_char
);
1333 /* Doing nothing is free */
1334 p
= &char_ins_del_cost (frame
)[0];
1337 /* Insert costs are at positive offsets */
1338 for (i
= FRAME_COLS (frame
); --i
>= 0;)
1339 *p
++ = (ins_startup_cost
+= ins_cost_per_char
);
1343 calculate_costs (frame
)
1346 register char *f
= (TS_set_scroll_region
1347 ? TS_set_scroll_region
1348 : TS_set_scroll_region_1
);
1350 FRAME_COST_BAUD_RATE (frame
) = baud_rate
;
1352 if (FRAME_TERMCAP_P (frame
))
1353 TTY_SCROLL_REGION_COST (frame
->output_data
.tty
) = string_cost (f
);
1355 /* These variables are only used for terminal stuff. They are allocated
1356 once for the terminal frame of X-windows emacs, but not used afterwards.
1358 char_ins_del_vector (i.e., char_ins_del_cost) isn't used because
1359 X turns off char_ins_del_ok. */
1361 max_frame_lines
= max (max_frame_lines
, FRAME_LINES (frame
));
1362 max_frame_cols
= max (max_frame_cols
, FRAME_COLS (frame
));
1366 if (char_ins_del_vector
!= 0)
1368 = (int *) xrealloc (char_ins_del_vector
,
1370 + 2 * max_frame_cols
* sizeof (int)));
1373 = (int *) xmalloc (sizeof (int)
1374 + 2 * max_frame_cols
* sizeof (int));
1376 bzero (char_ins_del_vector
, (sizeof (int)
1377 + 2 * max_frame_cols
* sizeof (int)));
1379 if (f
&& (!TS_ins_line
&& !TS_del_line
))
1380 do_line_insertion_deletion_costs (frame
,
1381 TS_rev_scroll
, TS_ins_multi_lines
,
1382 TS_fwd_scroll
, TS_del_multi_lines
,
1385 do_line_insertion_deletion_costs (frame
,
1386 TS_ins_line
, TS_ins_multi_lines
,
1387 TS_del_line
, TS_del_multi_lines
,
1390 calculate_ins_del_char_costs (frame
);
1392 /* Don't use TS_repeat if its padding is worse than sending the chars */
1393 if (TS_repeat
&& per_line_cost (TS_repeat
) * baud_rate
< 9000)
1394 RPov
= string_cost (TS_repeat
);
1396 RPov
= FRAME_COLS (frame
) * 2;
1398 cmcostinit (); /* set up cursor motion costs */
1405 /* Termcap capability names that correspond directly to X keysyms.
1406 Some of these (marked "terminfo") aren't supplied by old-style
1407 (Berkeley) termcap entries. They're listed in X keysym order;
1408 except we put the keypad keys first, so that if they clash with
1409 other keys (as on the IBM PC keyboard) they get overridden.
1412 static struct fkey_table keys
[] =
1414 {"kh", "home"}, /* termcap */
1415 {"kl", "left"}, /* termcap */
1416 {"ku", "up"}, /* termcap */
1417 {"kr", "right"}, /* termcap */
1418 {"kd", "down"}, /* termcap */
1419 {"%8", "prior"}, /* terminfo */
1420 {"%5", "next"}, /* terminfo */
1421 {"@7", "end"}, /* terminfo */
1422 {"@1", "begin"}, /* terminfo */
1423 {"*6", "select"}, /* terminfo */
1424 {"%9", "print"}, /* terminfo */
1425 {"@4", "execute"}, /* terminfo --- actually the `command' key */
1427 * "insert" --- see below
1429 {"&8", "undo"}, /* terminfo */
1430 {"%0", "redo"}, /* terminfo */
1431 {"%7", "menu"}, /* terminfo --- actually the `options' key */
1432 {"@0", "find"}, /* terminfo */
1433 {"@2", "cancel"}, /* terminfo */
1434 {"%1", "help"}, /* terminfo */
1436 * "break" goes here, but can't be reliably intercepted with termcap
1438 {"&4", "reset"}, /* terminfo --- actually `restart' */
1440 * "system" and "user" --- no termcaps
1442 {"kE", "clearline"}, /* terminfo */
1443 {"kA", "insertline"}, /* terminfo */
1444 {"kL", "deleteline"}, /* terminfo */
1445 {"kI", "insertchar"}, /* terminfo */
1446 {"kD", "deletechar"}, /* terminfo */
1447 {"kB", "backtab"}, /* terminfo */
1449 * "kp_backtab", "kp-space", "kp-tab" --- no termcaps
1451 {"@8", "kp-enter"}, /* terminfo */
1453 * "kp-f1", "kp-f2", "kp-f3" "kp-f4",
1454 * "kp-multiply", "kp-add", "kp-separator",
1455 * "kp-subtract", "kp-decimal", "kp-divide", "kp-0";
1456 * --- no termcaps for any of these.
1458 {"K4", "kp-1"}, /* terminfo */
1460 * "kp-2" --- no termcap
1462 {"K5", "kp-3"}, /* terminfo */
1464 * "kp-4" --- no termcap
1466 {"K2", "kp-5"}, /* terminfo */
1468 * "kp-6" --- no termcap
1470 {"K1", "kp-7"}, /* terminfo */
1472 * "kp-8" --- no termcap
1474 {"K3", "kp-9"}, /* terminfo */
1476 * "kp-equal" --- no termcap
1489 static char **term_get_fkeys_arg
;
1490 static Lisp_Object
term_get_fkeys_1 ();
1492 /* Find the escape codes sent by the function keys for Vfunction_key_map.
1493 This function scans the termcap function key sequence entries, and
1494 adds entries to Vfunction_key_map for each function key it finds. */
1497 term_get_fkeys (address
)
1500 /* We run the body of the function (term_get_fkeys_1) and ignore all Lisp
1501 errors during the call. The only errors should be from Fdefine_key
1502 when given a key sequence containing an invalid prefix key. If the
1503 termcap defines function keys which use a prefix that is already bound
1504 to a command by the default bindings, we should silently ignore that
1505 function key specification, rather than giving the user an error and
1506 refusing to run at all on such a terminal. */
1508 extern Lisp_Object
Fidentity ();
1509 term_get_fkeys_arg
= address
;
1510 internal_condition_case (term_get_fkeys_1
, Qerror
, Fidentity
);
1518 char **address
= term_get_fkeys_arg
;
1520 /* This can happen if CANNOT_DUMP or with strange options. */
1522 Vfunction_key_map
= Fmake_sparse_keymap (Qnil
);
1524 for (i
= 0; i
< (sizeof (keys
)/sizeof (keys
[0])); i
++)
1526 char *sequence
= tgetstr (keys
[i
].cap
, address
);
1528 Fdefine_key (Vfunction_key_map
, build_string (sequence
),
1529 Fmake_vector (make_number (1),
1530 intern (keys
[i
].name
)));
1533 /* The uses of the "k0" capability are inconsistent; sometimes it
1534 describes F10, whereas othertimes it describes F0 and "k;" describes F10.
1535 We will attempt to politely accommodate both systems by testing for
1536 "k;", and if it is present, assuming that "k0" denotes F0, otherwise F10.
1539 char *k_semi
= tgetstr ("k;", address
);
1540 char *k0
= tgetstr ("k0", address
);
1541 char *k0_name
= "f10";
1546 /* Define f0 first, so that f10 takes precedence in case the
1547 key sequences happens to be the same. */
1548 Fdefine_key (Vfunction_key_map
, build_string (k0
),
1549 Fmake_vector (make_number (1), intern ("f0")));
1550 Fdefine_key (Vfunction_key_map
, build_string (k_semi
),
1551 Fmake_vector (make_number (1), intern ("f10")));
1554 Fdefine_key (Vfunction_key_map
, build_string (k0
),
1555 Fmake_vector (make_number (1), intern (k0_name
)));
1558 /* Set up cookies for numbered function keys above f10. */
1560 char fcap
[3], fkey
[4];
1562 fcap
[0] = 'F'; fcap
[2] = '\0';
1563 for (i
= 11; i
< 64; i
++)
1566 fcap
[1] = '1' + i
- 11;
1568 fcap
[1] = 'A' + i
- 20;
1570 fcap
[1] = 'a' + i
- 46;
1573 char *sequence
= tgetstr (fcap
, address
);
1576 sprintf (fkey
, "f%d", i
);
1577 Fdefine_key (Vfunction_key_map
, build_string (sequence
),
1578 Fmake_vector (make_number (1),
1586 * Various mappings to try and get a better fit.
1589 #define CONDITIONAL_REASSIGN(cap1, cap2, sym) \
1590 if (!tgetstr (cap1, address)) \
1592 char *sequence = tgetstr (cap2, address); \
1594 Fdefine_key (Vfunction_key_map, build_string (sequence), \
1595 Fmake_vector (make_number (1), \
1599 /* if there's no key_next keycap, map key_npage to `next' keysym */
1600 CONDITIONAL_REASSIGN ("%5", "kN", "next");
1601 /* if there's no key_prev keycap, map key_ppage to `previous' keysym */
1602 CONDITIONAL_REASSIGN ("%8", "kP", "prior");
1603 /* if there's no key_dc keycap, map key_ic to `insert' keysym */
1604 CONDITIONAL_REASSIGN ("kD", "kI", "insert");
1605 /* if there's no key_end keycap, map key_ll to 'end' keysym */
1606 CONDITIONAL_REASSIGN ("@7", "kH", "end");
1608 /* IBM has their own non-standard dialect of terminfo.
1609 If the standard name isn't found, try the IBM name. */
1610 CONDITIONAL_REASSIGN ("kB", "KO", "backtab");
1611 CONDITIONAL_REASSIGN ("@4", "kJ", "execute"); /* actually "action" */
1612 CONDITIONAL_REASSIGN ("@4", "kc", "execute"); /* actually "command" */
1613 CONDITIONAL_REASSIGN ("%7", "ki", "menu");
1614 CONDITIONAL_REASSIGN ("@7", "kw", "end");
1615 CONDITIONAL_REASSIGN ("F1", "k<", "f11");
1616 CONDITIONAL_REASSIGN ("F2", "k>", "f12");
1617 CONDITIONAL_REASSIGN ("%1", "kq", "help");
1618 CONDITIONAL_REASSIGN ("*6", "kU", "select");
1619 #undef CONDITIONAL_REASSIGN
1626 /***********************************************************************
1627 Character Display Information
1628 ***********************************************************************/
1630 static void append_glyph
P_ ((struct it
*));
1633 /* Append glyphs to IT's glyph_row. Called from produce_glyphs for
1634 terminal frames if IT->glyph_row != NULL. IT->c is the character
1635 for which to produce glyphs; IT->face_id contains the character's
1636 face. Padding glyphs are appended if IT->c has a IT->pixel_width >
1643 struct glyph
*glyph
, *end
;
1646 xassert (it
->glyph_row
);
1647 glyph
= (it
->glyph_row
->glyphs
[it
->area
]
1648 + it
->glyph_row
->used
[it
->area
]);
1649 end
= it
->glyph_row
->glyphs
[1 + it
->area
];
1652 i
< it
->pixel_width
&& glyph
< end
;
1655 glyph
->type
= CHAR_GLYPH
;
1656 glyph
->pixel_width
= 1;
1657 glyph
->u
.ch
= it
->c
;
1658 glyph
->face_id
= it
->face_id
;
1659 glyph
->padding_p
= i
> 0;
1660 glyph
->charpos
= CHARPOS (it
->position
);
1661 glyph
->object
= it
->object
;
1663 ++it
->glyph_row
->used
[it
->area
];
1669 /* Produce glyphs for the display element described by IT. *IT
1670 specifies what we want to produce a glyph for (character, image, ...),
1671 and where in the glyph matrix we currently are (glyph row and hpos).
1672 produce_glyphs fills in output fields of *IT with information such as the
1673 pixel width and height of a character, and maybe output actual glyphs at
1674 the same time if IT->glyph_row is non-null. See the explanation of
1675 struct display_iterator in dispextern.h for an overview.
1677 produce_glyphs also stores the result of glyph width, ascent
1678 etc. computations in *IT.
1680 IT->glyph_row may be null, in which case produce_glyphs does not
1681 actually fill in the glyphs. This is used in the move_* functions
1682 in xdisp.c for text width and height computations.
1684 Callers usually don't call produce_glyphs directly;
1685 instead they use the macro PRODUCE_GLYPHS. */
1691 /* If a hook is installed, let it do the work. */
1692 xassert (it
->what
== IT_CHARACTER
1693 || it
->what
== IT_COMPOSITION
1694 || it
->what
== IT_IMAGE
1695 || it
->what
== IT_STRETCH
);
1697 /* Nothing but characters are supported on terminal frames. For a
1698 composition sequence, it->c is the first character of the
1700 xassert (it
->what
== IT_CHARACTER
1701 || it
->what
== IT_COMPOSITION
);
1703 if (it
->c
>= 040 && it
->c
< 0177)
1705 it
->pixel_width
= it
->nglyphs
= 1;
1709 else if (it
->c
== '\n')
1710 it
->pixel_width
= it
->nglyphs
= 0;
1711 else if (it
->c
== '\t')
1713 int absolute_x
= (it
->current_x
1714 + it
->continuation_lines_width
);
1716 = (((1 + absolute_x
+ it
->tab_width
- 1)
1721 /* If part of the TAB has been displayed on the previous line
1722 which is continued now, continuation_lines_width will have
1723 been incremented already by the part that fitted on the
1724 continued line. So, we will get the right number of spaces
1726 nspaces
= next_tab_x
- absolute_x
;
1733 it
->pixel_width
= it
->len
= 1;
1741 it
->pixel_width
= nspaces
;
1742 it
->nglyphs
= nspaces
;
1744 else if (SINGLE_BYTE_CHAR_P (it
->c
))
1746 /* Coming here means that it->c is from display table, thus we
1747 must send the code as is to the terminal. Although there's
1748 no way to know how many columns it occupies on a screen, it
1749 is a good assumption that a single byte code has 1-column
1751 it
->pixel_width
= it
->nglyphs
= 1;
1757 /* A multi-byte character. The display width is fixed for all
1758 characters of the set. Some of the glyphs may have to be
1759 ignored because they are already displayed in a continued
1761 int charset
= CHAR_CHARSET (it
->c
);
1763 it
->pixel_width
= CHARSET_WIDTH (charset
);
1764 it
->nglyphs
= it
->pixel_width
;
1770 /* Advance current_x by the pixel width as a convenience for
1772 if (it
->area
== TEXT_AREA
)
1773 it
->current_x
+= it
->pixel_width
;
1774 it
->ascent
= it
->max_ascent
= it
->phys_ascent
= it
->max_phys_ascent
= 0;
1775 it
->descent
= it
->max_descent
= it
->phys_descent
= it
->max_phys_descent
= 1;
1779 /* Get information about special display element WHAT in an
1780 environment described by IT. WHAT is one of IT_TRUNCATION or
1781 IT_CONTINUATION. Maybe produce glyphs for WHAT if IT has a
1782 non-null glyph_row member. This function ensures that fields like
1783 face_id, c, len of IT are left untouched. */
1786 produce_special_glyphs (it
, what
)
1788 enum display_element_type what
;
1794 temp_it
.what
= IT_CHARACTER
;
1796 temp_it
.object
= make_number (0);
1797 bzero (&temp_it
.current
, sizeof temp_it
.current
);
1799 if (what
== IT_CONTINUATION
)
1801 /* Continuation glyph. */
1803 && INTEGERP (DISP_CONTINUE_GLYPH (it
->dp
))
1804 && GLYPH_CHAR_VALID_P (XINT (DISP_CONTINUE_GLYPH (it
->dp
))))
1806 temp_it
.c
= FAST_GLYPH_CHAR (XINT (DISP_CONTINUE_GLYPH (it
->dp
)));
1807 temp_it
.len
= CHAR_BYTES (temp_it
.c
);
1812 produce_glyphs (&temp_it
);
1813 it
->pixel_width
= temp_it
.pixel_width
;
1814 it
->nglyphs
= temp_it
.pixel_width
;
1816 else if (what
== IT_TRUNCATION
)
1818 /* Truncation glyph. */
1820 && INTEGERP (DISP_TRUNC_GLYPH (it
->dp
))
1821 && GLYPH_CHAR_VALID_P (XINT (DISP_TRUNC_GLYPH (it
->dp
))))
1823 temp_it
.c
= FAST_GLYPH_CHAR (XINT (DISP_TRUNC_GLYPH (it
->dp
)));
1824 temp_it
.len
= CHAR_BYTES (temp_it
.c
);
1829 produce_glyphs (&temp_it
);
1830 it
->pixel_width
= temp_it
.pixel_width
;
1831 it
->nglyphs
= temp_it
.pixel_width
;
1839 /***********************************************************************
1841 ***********************************************************************/
1843 /* Value is non-zero if attribute ATTR may be used. ATTR should be
1844 one of the enumerators from enum no_color_bit, or a bit set built
1845 from them. Some display attributes may not be used together with
1846 color; the termcap capability `NC' specifies which ones. */
1848 #define MAY_USE_WITH_COLORS_P(ATTR) \
1849 (TN_max_colors > 0 \
1850 ? (TN_no_color_video & (ATTR)) == 0 \
1853 /* Turn appearances of face FACE_ID on tty frame F on. */
1856 turn_on_face (f
, face_id
)
1860 struct face
*face
= FACE_FROM_ID (f
, face_id
);
1861 long fg
= face
->foreground
;
1862 long bg
= face
->background
;
1864 /* Do this first because TS_end_standout_mode may be the same
1865 as TS_exit_attribute_mode, which turns all appearances off. */
1866 if (MAY_USE_WITH_COLORS_P (NC_REVERSE
))
1868 if (TN_max_colors
> 0)
1870 if (fg
>= 0 && bg
>= 0)
1872 /* If the terminal supports colors, we can set them
1873 below without using reverse video. The face's fg
1874 and bg colors are set as they should appear on
1875 the screen, i.e. they take the inverse-video'ness
1876 of the face already into account. */
1878 else if (inverse_video
)
1880 if (fg
== FACE_TTY_DEFAULT_FG_COLOR
1881 || bg
== FACE_TTY_DEFAULT_BG_COLOR
)
1882 toggle_highlight ();
1886 if (fg
== FACE_TTY_DEFAULT_BG_COLOR
1887 || bg
== FACE_TTY_DEFAULT_FG_COLOR
)
1888 toggle_highlight ();
1893 /* If we can't display colors, use reverse video
1894 if the face specifies that. */
1897 if (fg
== FACE_TTY_DEFAULT_FG_COLOR
1898 || bg
== FACE_TTY_DEFAULT_BG_COLOR
)
1899 toggle_highlight ();
1903 if (fg
== FACE_TTY_DEFAULT_BG_COLOR
1904 || bg
== FACE_TTY_DEFAULT_FG_COLOR
)
1905 toggle_highlight ();
1910 if (face
->tty_bold_p
)
1912 if (MAY_USE_WITH_COLORS_P (NC_BOLD
))
1913 OUTPUT1_IF (FRAME_TTY (f
), TS_enter_bold_mode
);
1915 else if (face
->tty_dim_p
)
1916 if (MAY_USE_WITH_COLORS_P (NC_DIM
))
1917 OUTPUT1_IF (FRAME_TTY (f
), TS_enter_dim_mode
);
1919 /* Alternate charset and blinking not yet used. */
1920 if (face
->tty_alt_charset_p
1921 && MAY_USE_WITH_COLORS_P (NC_ALT_CHARSET
))
1922 OUTPUT1_IF (FRAME_TTY (f
), TS_enter_alt_charset_mode
);
1924 if (face
->tty_blinking_p
1925 && MAY_USE_WITH_COLORS_P (NC_BLINK
))
1926 OUTPUT1_IF (FRAME_TTY (f
), TS_enter_blink_mode
);
1928 if (face
->tty_underline_p
&& MAY_USE_WITH_COLORS_P (NC_UNDERLINE
))
1929 OUTPUT1_IF (FRAME_TTY (f
), TS_enter_underline_mode
);
1931 if (TN_max_colors
> 0)
1935 if (fg
>= 0 && TS_set_foreground
)
1937 p
= tparam (TS_set_foreground
, NULL
, 0, (int) fg
);
1938 OUTPUT (FRAME_TTY (f
), p
);
1942 if (bg
>= 0 && TS_set_background
)
1944 p
= tparam (TS_set_background
, NULL
, 0, (int) bg
);
1945 OUTPUT (FRAME_TTY (f
), p
);
1952 /* Turn off appearances of face FACE_ID on tty frame F. */
1955 turn_off_face (f
, face_id
)
1959 struct face
*face
= FACE_FROM_ID (f
, face_id
);
1961 xassert (face
!= NULL
);
1963 if (TS_exit_attribute_mode
)
1965 /* Capability "me" will turn off appearance modes double-bright,
1966 half-bright, reverse-video, standout, underline. It may or
1967 may not turn off alt-char-mode. */
1968 if (face
->tty_bold_p
1970 || face
->tty_reverse_p
1971 || face
->tty_alt_charset_p
1972 || face
->tty_blinking_p
1973 || face
->tty_underline_p
)
1975 OUTPUT1_IF (FRAME_TTY (f
), TS_exit_attribute_mode
);
1976 if (strcmp (TS_exit_attribute_mode
, TS_end_standout_mode
) == 0)
1980 if (face
->tty_alt_charset_p
)
1981 OUTPUT_IF (FRAME_TTY (f
), TS_exit_alt_charset_mode
);
1985 /* If we don't have "me" we can only have those appearances
1986 that have exit sequences defined. */
1987 if (face
->tty_alt_charset_p
)
1988 OUTPUT_IF (FRAME_TTY (f
), TS_exit_alt_charset_mode
);
1990 if (face
->tty_underline_p
)
1991 OUTPUT_IF (FRAME_TTY (f
), TS_exit_underline_mode
);
1994 /* Switch back to default colors. */
1995 if (TN_max_colors
> 0
1996 && ((face
->foreground
!= FACE_TTY_DEFAULT_COLOR
1997 && face
->foreground
!= FACE_TTY_DEFAULT_FG_COLOR
)
1998 || (face
->background
!= FACE_TTY_DEFAULT_COLOR
1999 && face
->background
!= FACE_TTY_DEFAULT_BG_COLOR
)))
2000 OUTPUT1_IF (FRAME_TTY (f
), TS_orig_pair
);
2004 /* Return non-zero if the terminal on frame F supports all of the
2005 capabilities in CAPS simultaneously, with foreground and background
2006 colors FG and BG. */
2009 tty_capable_p (f
, caps
, fg
, bg
)
2012 unsigned long fg
, bg
;
2014 #define TTY_CAPABLE_P_TRY(cap, TS, NC_bit) \
2015 if ((caps & (cap)) && (!(TS) || !MAY_USE_WITH_COLORS_P(NC_bit))) \
2018 TTY_CAPABLE_P_TRY (TTY_CAP_INVERSE
, TS_standout_mode
, NC_REVERSE
);
2019 TTY_CAPABLE_P_TRY (TTY_CAP_UNDERLINE
, TS_enter_underline_mode
, NC_UNDERLINE
);
2020 TTY_CAPABLE_P_TRY (TTY_CAP_BOLD
, TS_enter_bold_mode
, NC_BOLD
);
2021 TTY_CAPABLE_P_TRY (TTY_CAP_DIM
, TS_enter_dim_mode
, NC_DIM
);
2022 TTY_CAPABLE_P_TRY (TTY_CAP_BLINK
, TS_enter_blink_mode
, NC_BLINK
);
2023 TTY_CAPABLE_P_TRY (TTY_CAP_ALT_CHARSET
, TS_enter_alt_charset_mode
, NC_ALT_CHARSET
);
2030 /* Return non-zero if the terminal is capable to display colors. */
2032 DEFUN ("tty-display-color-p", Ftty_display_color_p
, Stty_display_color_p
,
2034 doc
: /* Return non-nil if TTY can display colors on DISPLAY. */)
2036 Lisp_Object display
;
2038 return TN_max_colors
> 0 ? Qt
: Qnil
;
2041 /* Return the number of supported colors. */
2042 DEFUN ("tty-display-color-cells", Ftty_display_color_cells
,
2043 Stty_display_color_cells
, 0, 1, 0,
2044 doc
: /* Return the number of colors supported by TTY on DISPLAY. */)
2046 Lisp_Object display
;
2048 return make_number (TN_max_colors
);
2053 /* Save or restore the default color-related capabilities of this
2056 tty_default_color_capabilities (save
)
2060 *default_orig_pair
, *default_set_foreground
, *default_set_background
;
2061 static int default_max_colors
, default_max_pairs
, default_no_color_video
;
2065 if (default_orig_pair
)
2066 xfree (default_orig_pair
);
2067 default_orig_pair
= TS_orig_pair
? xstrdup (TS_orig_pair
) : NULL
;
2069 if (default_set_foreground
)
2070 xfree (default_set_foreground
);
2071 default_set_foreground
= TS_set_foreground
? xstrdup (TS_set_foreground
)
2074 if (default_set_background
)
2075 xfree (default_set_background
);
2076 default_set_background
= TS_set_background
? xstrdup (TS_set_background
)
2079 default_max_colors
= TN_max_colors
;
2080 default_max_pairs
= TN_max_pairs
;
2081 default_no_color_video
= TN_no_color_video
;
2085 TS_orig_pair
= default_orig_pair
;
2086 TS_set_foreground
= default_set_foreground
;
2087 TS_set_background
= default_set_background
;
2088 TN_max_colors
= default_max_colors
;
2089 TN_max_pairs
= default_max_pairs
;
2090 TN_no_color_video
= default_no_color_video
;
2094 /* Setup one of the standard tty color schemes according to MODE.
2095 MODE's value is generally the number of colors which we want to
2096 support; zero means set up for the default capabilities, the ones
2097 we saw at term_init time; -1 means turn off color support. */
2099 tty_setup_colors (mode
)
2102 /* Canonicalize all negative values of MODE. */
2108 case -1: /* no colors at all */
2111 TN_no_color_video
= 0;
2112 TS_set_foreground
= TS_set_background
= TS_orig_pair
= NULL
;
2114 case 0: /* default colors, if any */
2116 tty_default_color_capabilities (0);
2118 case 8: /* 8 standard ANSI colors */
2119 TS_orig_pair
= "\033[0m";
2121 TS_set_foreground
= "\033[3%p1%dm";
2122 TS_set_background
= "\033[4%p1%dm";
2124 TS_set_foreground
= "\033[3%dm";
2125 TS_set_background
= "\033[4%dm";
2129 TN_no_color_video
= 0;
2135 set_tty_color_mode (f
, val
)
2139 Lisp_Object color_mode_spec
, current_mode_spec
;
2140 Lisp_Object color_mode
, current_mode
;
2142 extern Lisp_Object Qtty_color_mode
;
2143 Lisp_Object tty_color_mode_alist
;
2145 tty_color_mode_alist
= Fintern_soft (build_string ("tty-color-mode-alist"),
2152 if (NILP (tty_color_mode_alist
))
2153 color_mode_spec
= Qnil
;
2155 color_mode_spec
= Fassq (val
, XSYMBOL (tty_color_mode_alist
)->value
);
2157 if (CONSP (color_mode_spec
))
2158 color_mode
= XCDR (color_mode_spec
);
2163 current_mode_spec
= assq_no_quit (Qtty_color_mode
, f
->param_alist
);
2165 if (CONSP (current_mode_spec
))
2166 current_mode
= XCDR (current_mode_spec
);
2168 current_mode
= Qnil
;
2169 if (INTEGERP (color_mode
))
2170 mode
= XINT (color_mode
);
2172 mode
= 0; /* meaning default */
2173 if (INTEGERP (current_mode
))
2174 old_mode
= XINT (current_mode
);
2178 if (mode
!= old_mode
)
2180 tty_setup_colors (mode
);
2181 /* This recomputes all the faces given the new color
2183 call0 (intern ("tty-set-up-initial-frame-faces"));
2188 #endif /* !WINDOWSNT */
2193 get_named_tty (name
)
2196 struct tty_output
*tty
= tty_list
;
2199 if ((tty
->name
== 0 && name
== 0)
2200 || (name
&& tty
->name
&& !strcmp (tty
->name
, name
)))
2209 /***********************************************************************
2211 ***********************************************************************/
2214 term_dummy_init (void)
2216 if (initialized
|| tty_list
)
2217 error ("tty already initialized");
2219 tty_list
= xmalloc (sizeof (struct tty_output
));
2220 bzero (tty_list
, sizeof (struct tty_output
));
2221 TTY_NAME (tty_list
) = 0;
2222 TTY_INPUT (tty_list
) = stdin
;
2223 TTY_OUTPUT (tty_list
) = stdout
;
2229 term_init (name
, terminal_type
)
2231 char *terminal_type
;
2234 char **address
= &area
;
2235 char *buffer
= NULL
;
2236 int buffer_size
= 4096;
2239 struct frame
*sf
= XFRAME (selected_frame
);
2241 struct tty_output
*tty
;
2243 tty
= get_named_tty (name
);
2246 /* Return the previously initialized terminal, except if it is the dummy
2247 terminal created for the initial frame. */
2254 error ("Unknown terminal type");
2256 tty
= (struct tty_output
*) xmalloc (sizeof (struct tty_output
));
2257 bzero (tty
, sizeof (struct tty_output
));
2258 tty
->next
= tty_list
;
2266 fd
= emacs_open (name
, O_RDWR
, 0);
2269 tty_list
= tty
->next
;
2271 error ("could not open file: %s", name
);
2273 f
= fdopen (fd
, "w+");
2274 TTY_NAME (tty
) = xstrdup (name
);
2275 TTY_INPUT (tty
) = f
;
2276 TTY_OUTPUT (tty
) = f
;
2281 TTY_INPUT (tty
) = stdin
;
2282 TTY_OUTPUT (tty
) = stdout
;
2285 init_sys_modes (tty
);
2288 initialize_w32_display ();
2292 area
= (char *) xmalloc (2044);
2294 FrameRows
= FRAME_LINES (sf
);
2295 FrameCols
= FRAME_COLS (sf
);
2296 specified_window
= FRAME_LINES (sf
);
2298 delete_in_insert_mode
= 1;
2301 TTY_SCROLL_REGION_OK (tty
) = 0;
2303 /* Seems to insert lines when it's not supposed to, messing
2304 up the display. In doing a trace, it didn't seem to be
2305 called much, so I don't think we're losing anything by
2307 TTY_LINE_INS_DEL_OK (tty
) = 0;
2309 TTY_CHAR_INS_DEL_OK (tty
) = 1;
2313 FRAME_CAN_HAVE_SCROLL_BARS (sf
) = 0;
2314 FRAME_VERTICAL_SCROLL_BAR_TYPE (sf
) = vertical_scroll_bar_none
;
2315 TN_max_colors
= 16; /* Required to be non-zero for tty-display-color-p */
2318 #else /* not WINDOWSNT */
2322 TTY_TYPE (tty
) = xstrdup (terminal_type
);
2324 buffer
= (char *) xmalloc (buffer_size
);
2325 status
= tgetent (buffer
, terminal_type
);
2329 fatal ("Cannot open terminfo database file");
2331 fatal ("Cannot open termcap database file");
2337 fatal ("Terminal type %s is not defined.\n\
2338 If that is not the actual type of terminal you have,\n\
2339 use the Bourne shell command `TERM=... export TERM' (C-shell:\n\
2340 `setenv TERM ...') to specify the correct type. It may be necessary\n\
2341 to do `unset TERMINFO' (C-shell: `unsetenv TERMINFO') as well.",
2344 fatal ("Terminal type %s is not defined.\n\
2345 If that is not the actual type of terminal you have,\n\
2346 use the Bourne shell command `TERM=... export TERM' (C-shell:\n\
2347 `setenv TERM ...') to specify the correct type. It may be necessary\n\
2348 to do `unset TERMCAP' (C-shell: `unsetenv TERMCAP') as well.",
2354 if (strlen (buffer
) >= buffer_size
)
2356 buffer_size
= strlen (buffer
);
2358 area
= (char *) xmalloc (buffer_size
);
2360 TS_ins_line
= tgetstr ("al", address
);
2361 TS_ins_multi_lines
= tgetstr ("AL", address
);
2362 TS_bell
= tgetstr ("bl", address
);
2363 BackTab
= tgetstr ("bt", address
);
2364 TS_clr_to_bottom
= tgetstr ("cd", address
);
2365 TS_clr_line
= tgetstr ("ce", address
);
2366 TS_clr_frame
= tgetstr ("cl", address
);
2367 ColPosition
= NULL
; /* tgetstr ("ch", address); */
2368 AbsPosition
= tgetstr ("cm", address
);
2369 CR
= tgetstr ("cr", address
);
2370 TS_set_scroll_region
= tgetstr ("cs", address
);
2371 TS_set_scroll_region_1
= tgetstr ("cS", address
);
2372 RowPosition
= tgetstr ("cv", address
);
2373 TS_del_char
= tgetstr ("dc", address
);
2374 TS_del_multi_chars
= tgetstr ("DC", address
);
2375 TS_del_line
= tgetstr ("dl", address
);
2376 TS_del_multi_lines
= tgetstr ("DL", address
);
2377 TS_delete_mode
= tgetstr ("dm", address
);
2378 TS_end_delete_mode
= tgetstr ("ed", address
);
2379 TS_end_insert_mode
= tgetstr ("ei", address
);
2380 Home
= tgetstr ("ho", address
);
2381 TS_ins_char
= tgetstr ("ic", address
);
2382 TS_ins_multi_chars
= tgetstr ("IC", address
);
2383 TS_insert_mode
= tgetstr ("im", address
);
2384 TS_pad_inserted_char
= tgetstr ("ip", address
);
2385 TS_end_keypad_mode
= tgetstr ("ke", address
);
2386 TS_keypad_mode
= tgetstr ("ks", address
);
2387 LastLine
= tgetstr ("ll", address
);
2388 Right
= tgetstr ("nd", address
);
2389 Down
= tgetstr ("do", address
);
2391 Down
= tgetstr ("nl", address
); /* Obsolete name for "do" */
2393 /* VMS puts a carriage return before each linefeed,
2394 so it is not safe to use linefeeds. */
2395 if (Down
&& Down
[0] == '\n' && Down
[1] == '\0')
2398 if (tgetflag ("bs"))
2399 Left
= "\b"; /* can't possibly be longer! */
2400 else /* (Actually, "bs" is obsolete...) */
2401 Left
= tgetstr ("le", address
);
2403 Left
= tgetstr ("bc", address
); /* Obsolete name for "le" */
2404 TS_pad_char
= tgetstr ("pc", address
);
2405 TS_repeat
= tgetstr ("rp", address
);
2406 TS_end_standout_mode
= tgetstr ("se", address
);
2407 TS_fwd_scroll
= tgetstr ("sf", address
);
2408 TS_standout_mode
= tgetstr ("so", address
);
2409 TS_rev_scroll
= tgetstr ("sr", address
);
2410 Wcm
.cm_tab
= tgetstr ("ta", address
);
2411 TS_end_termcap_modes
= tgetstr ("te", address
);
2412 TS_termcap_modes
= tgetstr ("ti", address
);
2413 Up
= tgetstr ("up", address
);
2414 TS_visible_bell
= tgetstr ("vb", address
);
2415 TS_cursor_normal
= tgetstr ("ve", address
);
2416 TS_cursor_visible
= tgetstr ("vs", address
);
2417 TS_cursor_invisible
= tgetstr ("vi", address
);
2418 TS_set_window
= tgetstr ("wi", address
);
2420 TS_enter_underline_mode
= tgetstr ("us", address
);
2421 TS_exit_underline_mode
= tgetstr ("ue", address
);
2422 TS_enter_bold_mode
= tgetstr ("md", address
);
2423 TS_enter_dim_mode
= tgetstr ("mh", address
);
2424 TS_enter_blink_mode
= tgetstr ("mb", address
);
2425 TS_enter_reverse_mode
= tgetstr ("mr", address
);
2426 TS_enter_alt_charset_mode
= tgetstr ("as", address
);
2427 TS_exit_alt_charset_mode
= tgetstr ("ae", address
);
2428 TS_exit_attribute_mode
= tgetstr ("me", address
);
2430 MultiUp
= tgetstr ("UP", address
);
2431 MultiDown
= tgetstr ("DO", address
);
2432 MultiLeft
= tgetstr ("LE", address
);
2433 MultiRight
= tgetstr ("RI", address
);
2435 /* SVr4/ANSI color suppert. If "op" isn't available, don't support
2436 color because we can't switch back to the default foreground and
2438 TS_orig_pair
= tgetstr ("op", address
);
2441 TS_set_foreground
= tgetstr ("AF", address
);
2442 TS_set_background
= tgetstr ("AB", address
);
2443 if (!TS_set_foreground
)
2446 TS_set_foreground
= tgetstr ("Sf", address
);
2447 TS_set_background
= tgetstr ("Sb", address
);
2450 TN_max_colors
= tgetnum ("Co");
2451 TN_max_pairs
= tgetnum ("pa");
2453 TN_no_color_video
= tgetnum ("NC");
2454 if (TN_no_color_video
== -1)
2455 TN_no_color_video
= 0;
2458 tty_default_color_capabilities (1);
2460 MagicWrap
= tgetflag ("xn");
2461 /* Since we make MagicWrap terminals look like AutoWrap, we need to have
2462 the former flag imply the latter. */
2463 AutoWrap
= MagicWrap
|| tgetflag ("am");
2464 TTY_MEMORY_BELOW_FRAME (tty
) = tgetflag ("db");
2465 TF_hazeltine
= tgetflag ("hz");
2466 TTY_MUST_WRITE_SPACES (tty
) = tgetflag ("in");
2467 meta_key
= tgetflag ("km") || tgetflag ("MT");
2468 TF_insmode_motion
= tgetflag ("mi");
2469 TF_standout_motion
= tgetflag ("ms");
2470 TF_underscore
= tgetflag ("ul");
2471 TF_teleray
= tgetflag ("xt");
2473 term_get_fkeys (address
);
2475 /* Get frame size from system, or else from termcap. */
2478 get_frame_size (&width
, &height
);
2479 FRAME_COLS (sf
) = width
;
2480 FRAME_LINES (sf
) = height
;
2483 if (FRAME_COLS (sf
) <= 0)
2484 SET_FRAME_COLS (sf
, tgetnum ("co"));
2486 /* Keep width and external_width consistent */
2487 SET_FRAME_COLS (sf
, FRAME_COLS (sf
));
2488 if (FRAME_LINES (sf
) <= 0)
2489 FRAME_LINES (sf
) = tgetnum ("li");
2491 if (FRAME_LINES (sf
) < 3 || FRAME_COLS (sf
) < 3)
2492 fatal ("Screen size %dx%d is too small",
2493 FRAME_LINES (sf
), FRAME_COLS (sf
));
2495 #if 0 /* This is not used anywhere. */
2496 TTY_MIN_PADDING_SPEED (tty
) = tgetnum ("pb");
2499 TabWidth
= tgetnum ("tw");
2502 /* These capabilities commonly use ^J.
2503 I don't know why, but sending them on VMS does not work;
2504 it causes following spaces to be lost, sometimes.
2505 For now, the simplest fix is to avoid using these capabilities ever. */
2506 if (Down
&& Down
[0] == '\n')
2514 TS_fwd_scroll
= Down
;
2516 PC
= TS_pad_char
? *TS_pad_char
: 0;
2521 /* Turned off since /etc/termcap seems to have :ta= for most terminals
2522 and newer termcap doc does not seem to say there is a default.
2527 /* We don't support standout modes that use `magic cookies', so
2528 turn off any that do. */
2529 if (TS_standout_mode
&& tgetnum ("sg") >= 0)
2531 TS_standout_mode
= 0;
2532 TS_end_standout_mode
= 0;
2534 if (TS_enter_underline_mode
&& tgetnum ("ug") >= 0)
2536 TS_enter_underline_mode
= 0;
2537 TS_exit_underline_mode
= 0;
2540 /* If there's no standout mode, try to use underlining instead. */
2541 if (TS_standout_mode
== 0)
2543 TS_standout_mode
= TS_enter_underline_mode
;
2544 TS_end_standout_mode
= TS_exit_underline_mode
;
2547 /* If no `se' string, try using a `me' string instead.
2548 If that fails, we can't use standout mode at all. */
2549 if (TS_end_standout_mode
== 0)
2551 char *s
= tgetstr ("me", address
);
2553 TS_end_standout_mode
= s
;
2555 TS_standout_mode
= 0;
2561 /* We can't support standout mode, because it uses magic cookies. */
2562 TS_standout_mode
= 0;
2563 /* But that means we cannot rely on ^M to go to column zero! */
2565 /* LF can't be trusted either -- can alter hpos */
2566 /* if move at column 0 thru a line with TS_standout_mode */
2570 /* Special handling for certain terminal types known to need it */
2572 if (!strcmp (terminal_type
, "supdup"))
2574 TTY_MEMORY_BELOW_FRAME (tty
) = 1;
2575 Wcm
.cm_losewrap
= 1;
2577 if (!strncmp (terminal_type
, "c10", 3)
2578 || !strcmp (terminal_type
, "perq"))
2580 /* Supply a makeshift :wi string.
2581 This string is not valid in general since it works only
2582 for windows starting at the upper left corner;
2583 but that is all Emacs uses.
2585 This string works only if the frame is using
2586 the top of the video memory, because addressing is memory-relative.
2587 So first check the :ti string to see if that is true.
2589 It would be simpler if the :wi string could go in the termcap
2590 entry, but it can't because it is not fully valid.
2591 If it were in the termcap entry, it would confuse other programs. */
2594 p
= TS_termcap_modes
;
2595 while (*p
&& strcmp (p
, "\033v "))
2598 TS_set_window
= "\033v%C %C %C %C ";
2600 /* Termcap entry often fails to have :in: flag */
2601 TTY_MUST_WRITE_SPACES (tty
) = 1;
2602 /* :ti string typically fails to have \E^G! in it */
2603 /* This limits scope of insert-char to one line. */
2604 strcpy (area
, TS_termcap_modes
);
2605 strcat (area
, "\033\007!");
2606 TS_termcap_modes
= area
;
2607 area
+= strlen (area
) + 1;
2609 /* Change all %+ parameters to %C, to handle
2610 values above 96 correctly for the C100. */
2613 if (p
[0] == '%' && p
[1] == '+')
2619 FrameRows
= FRAME_LINES (sf
);
2620 FrameCols
= FRAME_COLS (sf
);
2621 specified_window
= FRAME_LINES (sf
);
2623 if (Wcm_init () == -1) /* can't do cursor motion */
2625 fatal ("Terminal type \"%s\" is not powerful enough to run Emacs.\n\
2626 It lacks the ability to position the cursor.\n\
2627 If that is not the actual type of terminal you have, use either the\n\
2628 DCL command `SET TERMINAL/DEVICE= ...' for DEC-compatible terminals,\n\
2629 or `define EMACS_TERM \"terminal type\"' for non-DEC terminals.",
2633 fatal ("Terminal type \"%s\" is not powerful enough to run Emacs.\n\
2634 It lacks the ability to position the cursor.\n\
2635 If that is not the actual type of terminal you have,\n\
2636 use the Bourne shell command `TERM=... export TERM' (C-shell:\n\
2637 `setenv TERM ...') to specify the correct type. It may be necessary\n\
2638 to do `unset TERMINFO' (C-shell: `unsetenv TERMINFO') as well.",
2640 # else /* TERMCAP */
2641 fatal ("Terminal type \"%s\" is not powerful enough to run Emacs.\n\
2642 It lacks the ability to position the cursor.\n\
2643 If that is not the actual type of terminal you have,\n\
2644 use the Bourne shell command `TERM=... export TERM' (C-shell:\n\
2645 `setenv TERM ...') to specify the correct type. It may be necessary\n\
2646 to do `unset TERMCAP' (C-shell: `unsetenv TERMCAP') as well.",
2648 # endif /* TERMINFO */
2650 if (FRAME_LINES (sf
) <= 0
2651 || FRAME_COLS (sf
) <= 0)
2652 fatal ("The frame size has not been specified");
2654 delete_in_insert_mode
2655 = TS_delete_mode
&& TS_insert_mode
2656 && !strcmp (TS_delete_mode
, TS_insert_mode
);
2658 se_is_so
= (TS_standout_mode
2659 && TS_end_standout_mode
2660 && !strcmp (TS_standout_mode
, TS_end_standout_mode
));
2662 UseTabs
= tabs_safe_p () && TabWidth
== 8;
2664 TTY_SCROLL_REGION_OK (tty
)
2666 && (TS_set_window
|| TS_set_scroll_region
|| TS_set_scroll_region_1
));
2668 TTY_LINE_INS_DEL_OK (tty
)
2669 = (((TS_ins_line
|| TS_ins_multi_lines
)
2670 && (TS_del_line
|| TS_del_multi_lines
))
2671 || (TTY_SCROLL_REGION_OK (tty
)
2672 && TS_fwd_scroll
&& TS_rev_scroll
));
2674 TTY_CHAR_INS_DEL_OK (tty
)
2675 = ((TS_ins_char
|| TS_insert_mode
2676 || TS_pad_inserted_char
|| TS_ins_multi_chars
)
2677 && (TS_del_char
|| TS_del_multi_chars
));
2679 TTY_FAST_CLEAR_END_OF_LINE (tty
) = TS_clr_line
!= 0;
2682 if (read_socket_hook
) /* Baudrate is somewhat
2683 meaningless in this case */
2686 FRAME_CAN_HAVE_SCROLL_BARS (sf
) = 0;
2687 FRAME_VERTICAL_SCROLL_BAR_TYPE (sf
) = vertical_scroll_bar_none
;
2688 #endif /* WINDOWSNT */
2697 fatal (str
, arg1
, arg2
)
2698 char *str
, *arg1
, *arg2
;
2700 fprintf (stderr
, "emacs: ");
2701 fprintf (stderr
, str
, arg1
, arg2
);
2702 fprintf (stderr
, "\n");
2710 DEFVAR_BOOL ("system-uses-terminfo", &system_uses_terminfo
,
2711 doc
: /* Non-nil means the system uses terminfo rather than termcap.
2712 This variable can be used by terminal emulator packages. */);
2714 system_uses_terminfo
= 1;
2716 system_uses_terminfo
= 0;
2719 DEFVAR_LISP ("ring-bell-function", &Vring_bell_function
,
2720 doc
: /* Non-nil means call this function to ring the bell.
2721 The function should accept no arguments. */);
2722 Vring_bell_function
= Qnil
;
2724 defsubr (&Stty_display_color_p
);
2725 defsubr (&Stty_display_color_cells
);
2735 /* arch-tag: 498e7449-6f2e-45e2-91dd-b7d4ca488193
2736 (do not change this comment) */