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_ ((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_ ((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 */
797 /* Do not write in last row last col with Auto-wrap on. */
798 if (AutoWrap
&& curY
== FRAME_LINES (f
) - 1
799 && first_unused_hpos
== FRAME_COLS (f
))
802 for (i
= curX
; i
< first_unused_hpos
; i
++)
804 if (TTY_TERMSCRIPT (FRAME_TTY (f
)))
805 fputc (' ', TTY_TERMSCRIPT (FRAME_TTY (f
)));
806 fputc (' ', TTY_OUTPUT (FRAME_TTY (f
)));
808 cmplus (first_unused_hpos
- curX
);
812 /* Encode SRC_LEN glyphs starting at SRC to terminal output codes and
813 store them at DST. Do not write more than DST_LEN bytes. That may
814 require stopping before all SRC_LEN input glyphs have been
817 We store the number of glyphs actually converted in *CONSUMED. The
818 return value is the number of bytes store in DST. */
821 encode_terminal_code (src
, dst
, src_len
, dst_len
, consumed
)
825 int dst_len
, *consumed
;
827 struct glyph
*src_start
= src
, *src_end
= src
+ src_len
;
828 unsigned char *dst_start
= dst
, *dst_end
= dst
+ dst_len
;
830 unsigned char workbuf
[MAX_MULTIBYTE_LENGTH
];
831 const unsigned char *buf
;
833 register int tlen
= GLYPH_TABLE_LENGTH
;
834 register Lisp_Object
*tbase
= GLYPH_TABLE_BASE
;
836 struct coding_system
*coding
;
838 /* If terminal_coding does any conversion, use it, otherwise use
839 safe_terminal_coding. We can't use CODING_REQUIRE_ENCODING here
840 because it always return 1 if the member src_multibyte is 1. */
841 coding
= (terminal_coding
.common_flags
& CODING_REQUIRE_ENCODING_MASK
843 : &safe_terminal_coding
);
845 while (src
< src_end
)
847 /* We must skip glyphs to be padded for a wide character. */
848 if (! CHAR_GLYPH_PADDING_P (*src
))
850 g
= GLYPH_FROM_CHAR_GLYPH (src
[0]);
852 if (g
< 0 || g
>= tlen
)
854 /* This glyph doesn't has an entry in Vglyph_table. */
855 if (! CHAR_VALID_P (src
->u
.ch
, 0))
859 coding
->src_multibyte
= 0;
863 len
= CHAR_STRING (src
->u
.ch
, workbuf
);
865 coding
->src_multibyte
= 1;
870 /* This glyph has an entry in Vglyph_table,
871 so process any alias before testing for simpleness. */
872 GLYPH_FOLLOW_ALIASES (tbase
, tlen
, g
);
874 if (GLYPH_SIMPLE_P (tbase
, tlen
, g
))
876 /* We set the multi-byte form of a character in G
877 (that should be an ASCII character) at
879 workbuf
[0] = FAST_GLYPH_CHAR (g
);
882 coding
->src_multibyte
= 0;
886 /* We have a string in Vglyph_table. */
887 len
= GLYPH_LENGTH (tbase
, g
);
888 buf
= GLYPH_STRING (tbase
, g
);
889 coding
->src_multibyte
= STRING_MULTIBYTE (tbase
[g
]);
893 result
= encode_coding (coding
, buf
, dst
, len
, dst_end
- dst
);
894 len
-= coding
->consumed
;
895 dst
+= coding
->produced
;
896 if (result
== CODING_FINISH_INSUFFICIENT_DST
897 || (result
== CODING_FINISH_INSUFFICIENT_SRC
898 && len
> dst_end
- dst
))
899 /* The remaining output buffer is too short. We must
900 break the loop here without increasing SRC so that the
901 next call of this function starts from the same glyph. */
906 /* This is the case that a code of the range 0200..0237
907 exists in buf. We must just write out such a code. */
908 buf
+= coding
->consumed
;
916 *consumed
= src
- src_start
;
917 return (dst
- dst_start
);
922 write_glyphs (string
, len
)
923 register struct glyph
*string
;
926 int produced
, consumed
;
927 struct frame
*f
= updating_frame
? updating_frame
: XFRAME (selected_frame
);
928 unsigned char conversion_buffer
[1024];
929 int conversion_buffer_size
= sizeof conversion_buffer
;
931 if (write_glyphs_hook
932 && ! FRAME_TERMCAP_P (f
))
934 (*write_glyphs_hook
) (string
, len
);
941 /* Don't dare write in last column of bottom line, if Auto-Wrap,
942 since that would scroll the whole frame on some terminals. */
945 && curY
+ 1 == FRAME_LINES (f
)
946 && (curX
+ len
) == FRAME_COLS (f
))
953 /* The mode bit CODING_MODE_LAST_BLOCK should be set to 1 only at
955 terminal_coding
.mode
&= ~CODING_MODE_LAST_BLOCK
;
959 /* Identify a run of glyphs with the same face. */
960 int face_id
= string
->face_id
;
963 for (n
= 1; n
< len
; ++n
)
964 if (string
[n
].face_id
!= face_id
)
967 /* Turn appearance modes of the face of the run on. */
968 highlight_if_desired ();
969 turn_on_face (f
, face_id
);
973 /* We use a fixed size (1024 bytes) of conversion buffer.
974 Usually it is sufficient, but if not, we just repeat the
976 produced
= encode_terminal_code (string
, conversion_buffer
,
977 n
, conversion_buffer_size
,
981 fwrite (conversion_buffer
, 1, produced
,
982 TTY_OUTPUT (FRAME_TTY (f
)));
983 if (ferror (TTY_OUTPUT (FRAME_TTY (f
))))
984 clearerr (TTY_OUTPUT (FRAME_TTY (f
)));
985 if (TTY_TERMSCRIPT (FRAME_TTY (f
)))
986 fwrite (conversion_buffer
, 1, produced
,
987 TTY_TERMSCRIPT (FRAME_TTY (f
)));
994 /* Turn appearance modes off. */
995 turn_off_face (f
, face_id
);
996 turn_off_highlight ();
999 /* We may have to output some codes to terminate the writing. */
1000 if (CODING_REQUIRE_FLUSHING (&terminal_coding
))
1002 terminal_coding
.mode
|= CODING_MODE_LAST_BLOCK
;
1003 encode_coding (&terminal_coding
, "", conversion_buffer
,
1004 0, conversion_buffer_size
);
1005 if (terminal_coding
.produced
> 0)
1007 fwrite (conversion_buffer
, 1, terminal_coding
.produced
,
1008 TTY_OUTPUT (FRAME_TTY (f
)));
1009 if (ferror (TTY_OUTPUT (FRAME_TTY (f
))))
1010 clearerr (TTY_OUTPUT (FRAME_TTY (f
)));
1011 if (TTY_TERMSCRIPT (FRAME_TTY (f
)))
1012 fwrite (conversion_buffer
, 1, terminal_coding
.produced
,
1013 TTY_TERMSCRIPT (FRAME_TTY (f
)));
1017 cmcheckmagic (FRAME_TTY (f
));
1020 /* If start is zero, insert blanks instead of a string at start */
1023 insert_glyphs (start
, len
)
1024 register struct glyph
*start
;
1028 struct glyph
*glyph
= NULL
;
1034 if (insert_glyphs_hook
)
1036 (*insert_glyphs_hook
) (start
, len
);
1040 f
= updating_frame
? updating_frame
: XFRAME (selected_frame
);
1042 if (TS_ins_multi_chars
)
1044 buf
= tparam (TS_ins_multi_chars
, 0, 0, len
);
1045 OUTPUT1 (FRAME_TTY (f
), buf
);
1048 write_glyphs (start
, len
);
1054 /* The bit CODING_MODE_LAST_BLOCK should be set to 1 only at the tail. */
1055 terminal_coding
.mode
&= ~CODING_MODE_LAST_BLOCK
;
1058 int produced
, consumed
;
1059 unsigned char conversion_buffer
[1024];
1060 int conversion_buffer_size
= sizeof conversion_buffer
;
1062 OUTPUT1_IF (FRAME_TTY (f
), TS_ins_char
);
1065 conversion_buffer
[0] = SPACEGLYPH
;
1070 highlight_if_desired ();
1071 turn_on_face (f
, start
->face_id
);
1074 /* We must open sufficient space for a character which
1075 occupies more than one column. */
1076 while (len
&& CHAR_GLYPH_PADDING_P (*start
))
1078 OUTPUT1_IF (FRAME_TTY (f
), TS_ins_char
);
1083 /* This is the last glyph. */
1084 terminal_coding
.mode
|= CODING_MODE_LAST_BLOCK
;
1086 /* The size of conversion buffer (1024 bytes) is surely
1087 sufficient for just one glyph. */
1088 produced
= encode_terminal_code (glyph
, conversion_buffer
, 1,
1089 conversion_buffer_size
, &consumed
);
1094 fwrite (conversion_buffer
, 1, produced
,
1095 TTY_OUTPUT (FRAME_TTY (f
)));
1096 if (ferror (TTY_OUTPUT (FRAME_TTY (f
))))
1097 clearerr (TTY_OUTPUT (FRAME_TTY (f
)));
1098 if (TTY_TERMSCRIPT (FRAME_TTY (f
)))
1099 fwrite (conversion_buffer
, 1, produced
,
1100 TTY_TERMSCRIPT (FRAME_TTY (f
)));
1103 OUTPUT1_IF (FRAME_TTY (f
), TS_pad_inserted_char
);
1106 turn_off_face (f
, glyph
->face_id
);
1107 turn_off_highlight ();
1111 cmcheckmagic (FRAME_TTY (f
));
1121 if (delete_glyphs_hook
&& ! FRAME_TERMCAP_P (updating_frame
))
1123 (*delete_glyphs_hook
) (n
);
1127 if (delete_in_insert_mode
)
1134 OUTPUT_IF (FRAME_TTY (updating_frame
), TS_delete_mode
);
1137 if (TS_del_multi_chars
)
1139 buf
= tparam (TS_del_multi_chars
, 0, 0, n
);
1140 OUTPUT1 (FRAME_TTY (updating_frame
), buf
);
1144 for (i
= 0; i
< n
; i
++)
1145 OUTPUT1 (FRAME_TTY (updating_frame
), TS_del_char
);
1146 if (!delete_in_insert_mode
)
1147 OUTPUT_IF (FRAME_TTY (updating_frame
), TS_end_delete_mode
);
1150 /* Insert N lines at vpos VPOS. If N is negative, delete -N lines. */
1153 ins_del_lines (vpos
, n
)
1156 char *multi
= n
> 0 ? TS_ins_multi_lines
: TS_del_multi_lines
;
1157 char *single
= n
> 0 ? TS_ins_line
: TS_del_line
;
1158 char *scroll
= n
> 0 ? TS_rev_scroll
: TS_fwd_scroll
;
1161 register int i
= n
> 0 ? n
: -n
;
1164 if (ins_del_lines_hook
&& ! FRAME_TERMCAP_P (updating_frame
))
1166 (*ins_del_lines_hook
) (vpos
, n
);
1170 f
= (updating_frame
? updating_frame
: XFRAME (selected_frame
));
1172 /* If the lines below the insertion are being pushed
1173 into the end of the window, this is the same as clearing;
1174 and we know the lines are already clear, since the matching
1175 deletion has already been done. So can ignore this. */
1176 /* If the lines below the deletion are blank lines coming
1177 out of the end of the window, don't bother,
1178 as there will be a matching inslines later that will flush them. */
1179 if (TTY_SCROLL_REGION_OK (FRAME_TTY (f
))
1180 && vpos
+ i
>= specified_window
)
1182 if (!TTY_MEMORY_BELOW_FRAME (FRAME_TTY (f
))
1183 && vpos
+ i
>= FRAME_LINES (f
))
1188 raw_cursor_to (vpos
, 0);
1189 background_highlight ();
1190 buf
= tparam (multi
, 0, 0, i
);
1191 OUTPUT (FRAME_TTY (f
), buf
);
1196 raw_cursor_to (vpos
, 0);
1197 background_highlight ();
1199 OUTPUT (FRAME_TTY (f
), single
);
1205 set_scroll_region (vpos
, specified_window
);
1207 raw_cursor_to (specified_window
- 1, 0);
1209 raw_cursor_to (vpos
, 0);
1210 background_highlight ();
1212 OUTPUTL (FRAME_TTY (f
), scroll
, specified_window
- vpos
);
1213 set_scroll_region (0, specified_window
);
1216 if (!TTY_SCROLL_REGION_OK (FRAME_TTY (f
))
1217 && TTY_MEMORY_BELOW_FRAME (FRAME_TTY (f
))
1220 cursor_to (FRAME_LINES (f
) + n
, 0);
1225 /* Compute cost of sending "str", in characters,
1226 not counting any line-dependent padding. */
1234 tputs (str
, 0, evalcost
);
1238 /* Compute cost of sending "str", in characters,
1239 counting any line-dependent padding at one line. */
1242 string_cost_one_line (str
)
1247 tputs (str
, 1, evalcost
);
1251 /* Compute per line amount of line-dependent padding,
1252 in tenths of characters. */
1260 tputs (str
, 0, evalcost
);
1263 tputs (str
, 10, evalcost
);
1268 /* char_ins_del_cost[n] is cost of inserting N characters.
1269 char_ins_del_cost[-n] is cost of deleting N characters.
1270 The length of this vector is based on max_frame_cols. */
1272 int *char_ins_del_vector
;
1274 #define char_ins_del_cost(f) (&char_ins_del_vector[FRAME_COLS ((f))])
1279 calculate_ins_del_char_costs (frame
)
1282 int ins_startup_cost
, del_startup_cost
;
1283 int ins_cost_per_char
, del_cost_per_char
;
1287 if (TS_ins_multi_chars
)
1289 ins_cost_per_char
= 0;
1290 ins_startup_cost
= string_cost_one_line (TS_ins_multi_chars
);
1292 else if (TS_ins_char
|| TS_pad_inserted_char
1293 || (TS_insert_mode
&& TS_end_insert_mode
))
1295 ins_startup_cost
= (30 * (string_cost (TS_insert_mode
)
1296 + string_cost (TS_end_insert_mode
))) / 100;
1297 ins_cost_per_char
= (string_cost_one_line (TS_ins_char
)
1298 + string_cost_one_line (TS_pad_inserted_char
));
1302 ins_startup_cost
= 9999;
1303 ins_cost_per_char
= 0;
1306 if (TS_del_multi_chars
)
1308 del_cost_per_char
= 0;
1309 del_startup_cost
= string_cost_one_line (TS_del_multi_chars
);
1311 else if (TS_del_char
)
1313 del_startup_cost
= (string_cost (TS_delete_mode
)
1314 + string_cost (TS_end_delete_mode
));
1315 if (delete_in_insert_mode
)
1316 del_startup_cost
/= 2;
1317 del_cost_per_char
= string_cost_one_line (TS_del_char
);
1321 del_startup_cost
= 9999;
1322 del_cost_per_char
= 0;
1325 /* Delete costs are at negative offsets */
1326 p
= &char_ins_del_cost (frame
)[0];
1327 for (i
= FRAME_COLS (frame
); --i
>= 0;)
1328 *--p
= (del_startup_cost
+= del_cost_per_char
);
1330 /* Doing nothing is free */
1331 p
= &char_ins_del_cost (frame
)[0];
1334 /* Insert costs are at positive offsets */
1335 for (i
= FRAME_COLS (frame
); --i
>= 0;)
1336 *p
++ = (ins_startup_cost
+= ins_cost_per_char
);
1340 calculate_costs (frame
)
1343 register char *f
= (TS_set_scroll_region
1344 ? TS_set_scroll_region
1345 : TS_set_scroll_region_1
);
1347 FRAME_COST_BAUD_RATE (frame
) = baud_rate
;
1349 if (FRAME_TERMCAP_P (frame
))
1350 TTY_SCROLL_REGION_COST (frame
->output_data
.tty
) = string_cost (f
);
1352 /* These variables are only used for terminal stuff. They are allocated
1353 once for the terminal frame of X-windows emacs, but not used afterwards.
1355 char_ins_del_vector (i.e., char_ins_del_cost) isn't used because
1356 X turns off char_ins_del_ok. */
1358 max_frame_lines
= max (max_frame_lines
, FRAME_LINES (frame
));
1359 max_frame_cols
= max (max_frame_cols
, FRAME_COLS (frame
));
1363 if (char_ins_del_vector
!= 0)
1365 = (int *) xrealloc (char_ins_del_vector
,
1367 + 2 * max_frame_cols
* sizeof (int)));
1370 = (int *) xmalloc (sizeof (int)
1371 + 2 * max_frame_cols
* sizeof (int));
1373 bzero (char_ins_del_vector
, (sizeof (int)
1374 + 2 * max_frame_cols
* sizeof (int)));
1376 if (f
&& (!TS_ins_line
&& !TS_del_line
))
1377 do_line_insertion_deletion_costs (frame
,
1378 TS_rev_scroll
, TS_ins_multi_lines
,
1379 TS_fwd_scroll
, TS_del_multi_lines
,
1382 do_line_insertion_deletion_costs (frame
,
1383 TS_ins_line
, TS_ins_multi_lines
,
1384 TS_del_line
, TS_del_multi_lines
,
1387 calculate_ins_del_char_costs (frame
);
1389 /* Don't use TS_repeat if its padding is worse than sending the chars */
1390 if (TS_repeat
&& per_line_cost (TS_repeat
) * baud_rate
< 9000)
1391 RPov
= string_cost (TS_repeat
);
1393 RPov
= FRAME_COLS (frame
) * 2;
1395 cmcostinit (); /* set up cursor motion costs */
1402 /* Termcap capability names that correspond directly to X keysyms.
1403 Some of these (marked "terminfo") aren't supplied by old-style
1404 (Berkeley) termcap entries. They're listed in X keysym order;
1405 except we put the keypad keys first, so that if they clash with
1406 other keys (as on the IBM PC keyboard) they get overridden.
1409 static struct fkey_table keys
[] =
1411 {"kh", "home"}, /* termcap */
1412 {"kl", "left"}, /* termcap */
1413 {"ku", "up"}, /* termcap */
1414 {"kr", "right"}, /* termcap */
1415 {"kd", "down"}, /* termcap */
1416 {"%8", "prior"}, /* terminfo */
1417 {"%5", "next"}, /* terminfo */
1418 {"@7", "end"}, /* terminfo */
1419 {"@1", "begin"}, /* terminfo */
1420 {"*6", "select"}, /* terminfo */
1421 {"%9", "print"}, /* terminfo */
1422 {"@4", "execute"}, /* terminfo --- actually the `command' key */
1424 * "insert" --- see below
1426 {"&8", "undo"}, /* terminfo */
1427 {"%0", "redo"}, /* terminfo */
1428 {"%7", "menu"}, /* terminfo --- actually the `options' key */
1429 {"@0", "find"}, /* terminfo */
1430 {"@2", "cancel"}, /* terminfo */
1431 {"%1", "help"}, /* terminfo */
1433 * "break" goes here, but can't be reliably intercepted with termcap
1435 {"&4", "reset"}, /* terminfo --- actually `restart' */
1437 * "system" and "user" --- no termcaps
1439 {"kE", "clearline"}, /* terminfo */
1440 {"kA", "insertline"}, /* terminfo */
1441 {"kL", "deleteline"}, /* terminfo */
1442 {"kI", "insertchar"}, /* terminfo */
1443 {"kD", "deletechar"}, /* terminfo */
1444 {"kB", "backtab"}, /* terminfo */
1446 * "kp_backtab", "kp-space", "kp-tab" --- no termcaps
1448 {"@8", "kp-enter"}, /* terminfo */
1450 * "kp-f1", "kp-f2", "kp-f3" "kp-f4",
1451 * "kp-multiply", "kp-add", "kp-separator",
1452 * "kp-subtract", "kp-decimal", "kp-divide", "kp-0";
1453 * --- no termcaps for any of these.
1455 {"K4", "kp-1"}, /* terminfo */
1457 * "kp-2" --- no termcap
1459 {"K5", "kp-3"}, /* terminfo */
1461 * "kp-4" --- no termcap
1463 {"K2", "kp-5"}, /* terminfo */
1465 * "kp-6" --- no termcap
1467 {"K1", "kp-7"}, /* terminfo */
1469 * "kp-8" --- no termcap
1471 {"K3", "kp-9"}, /* terminfo */
1473 * "kp-equal" --- no termcap
1486 static char **term_get_fkeys_arg
;
1487 static Lisp_Object
term_get_fkeys_1 ();
1489 /* Find the escape codes sent by the function keys for Vfunction_key_map.
1490 This function scans the termcap function key sequence entries, and
1491 adds entries to Vfunction_key_map for each function key it finds. */
1494 term_get_fkeys (address
)
1497 /* We run the body of the function (term_get_fkeys_1) and ignore all Lisp
1498 errors during the call. The only errors should be from Fdefine_key
1499 when given a key sequence containing an invalid prefix key. If the
1500 termcap defines function keys which use a prefix that is already bound
1501 to a command by the default bindings, we should silently ignore that
1502 function key specification, rather than giving the user an error and
1503 refusing to run at all on such a terminal. */
1505 extern Lisp_Object
Fidentity ();
1506 term_get_fkeys_arg
= address
;
1507 internal_condition_case (term_get_fkeys_1
, Qerror
, Fidentity
);
1515 char **address
= term_get_fkeys_arg
;
1517 /* This can happen if CANNOT_DUMP or with strange options. */
1519 Vfunction_key_map
= Fmake_sparse_keymap (Qnil
);
1521 for (i
= 0; i
< (sizeof (keys
)/sizeof (keys
[0])); i
++)
1523 char *sequence
= tgetstr (keys
[i
].cap
, address
);
1525 Fdefine_key (Vfunction_key_map
, build_string (sequence
),
1526 Fmake_vector (make_number (1),
1527 intern (keys
[i
].name
)));
1530 /* The uses of the "k0" capability are inconsistent; sometimes it
1531 describes F10, whereas othertimes it describes F0 and "k;" describes F10.
1532 We will attempt to politely accommodate both systems by testing for
1533 "k;", and if it is present, assuming that "k0" denotes F0, otherwise F10.
1536 char *k_semi
= tgetstr ("k;", address
);
1537 char *k0
= tgetstr ("k0", address
);
1538 char *k0_name
= "f10";
1543 /* Define f0 first, so that f10 takes precedence in case the
1544 key sequences happens to be the same. */
1545 Fdefine_key (Vfunction_key_map
, build_string (k0
),
1546 Fmake_vector (make_number (1), intern ("f0")));
1547 Fdefine_key (Vfunction_key_map
, build_string (k_semi
),
1548 Fmake_vector (make_number (1), intern ("f10")));
1551 Fdefine_key (Vfunction_key_map
, build_string (k0
),
1552 Fmake_vector (make_number (1), intern (k0_name
)));
1555 /* Set up cookies for numbered function keys above f10. */
1557 char fcap
[3], fkey
[4];
1559 fcap
[0] = 'F'; fcap
[2] = '\0';
1560 for (i
= 11; i
< 64; i
++)
1563 fcap
[1] = '1' + i
- 11;
1565 fcap
[1] = 'A' + i
- 20;
1567 fcap
[1] = 'a' + i
- 46;
1570 char *sequence
= tgetstr (fcap
, address
);
1573 sprintf (fkey
, "f%d", i
);
1574 Fdefine_key (Vfunction_key_map
, build_string (sequence
),
1575 Fmake_vector (make_number (1),
1583 * Various mappings to try and get a better fit.
1586 #define CONDITIONAL_REASSIGN(cap1, cap2, sym) \
1587 if (!tgetstr (cap1, address)) \
1589 char *sequence = tgetstr (cap2, address); \
1591 Fdefine_key (Vfunction_key_map, build_string (sequence), \
1592 Fmake_vector (make_number (1), \
1596 /* if there's no key_next keycap, map key_npage to `next' keysym */
1597 CONDITIONAL_REASSIGN ("%5", "kN", "next");
1598 /* if there's no key_prev keycap, map key_ppage to `previous' keysym */
1599 CONDITIONAL_REASSIGN ("%8", "kP", "prior");
1600 /* if there's no key_dc keycap, map key_ic to `insert' keysym */
1601 CONDITIONAL_REASSIGN ("kD", "kI", "insert");
1602 /* if there's no key_end keycap, map key_ll to 'end' keysym */
1603 CONDITIONAL_REASSIGN ("@7", "kH", "end");
1605 /* IBM has their own non-standard dialect of terminfo.
1606 If the standard name isn't found, try the IBM name. */
1607 CONDITIONAL_REASSIGN ("kB", "KO", "backtab");
1608 CONDITIONAL_REASSIGN ("@4", "kJ", "execute"); /* actually "action" */
1609 CONDITIONAL_REASSIGN ("@4", "kc", "execute"); /* actually "command" */
1610 CONDITIONAL_REASSIGN ("%7", "ki", "menu");
1611 CONDITIONAL_REASSIGN ("@7", "kw", "end");
1612 CONDITIONAL_REASSIGN ("F1", "k<", "f11");
1613 CONDITIONAL_REASSIGN ("F2", "k>", "f12");
1614 CONDITIONAL_REASSIGN ("%1", "kq", "help");
1615 CONDITIONAL_REASSIGN ("*6", "kU", "select");
1616 #undef CONDITIONAL_REASSIGN
1623 /***********************************************************************
1624 Character Display Information
1625 ***********************************************************************/
1627 static void append_glyph
P_ ((struct it
*));
1630 /* Append glyphs to IT's glyph_row. Called from produce_glyphs for
1631 terminal frames if IT->glyph_row != NULL. IT->c is the character
1632 for which to produce glyphs; IT->face_id contains the character's
1633 face. Padding glyphs are appended if IT->c has a IT->pixel_width >
1640 struct glyph
*glyph
, *end
;
1643 xassert (it
->glyph_row
);
1644 glyph
= (it
->glyph_row
->glyphs
[it
->area
]
1645 + it
->glyph_row
->used
[it
->area
]);
1646 end
= it
->glyph_row
->glyphs
[1 + it
->area
];
1649 i
< it
->pixel_width
&& glyph
< end
;
1652 glyph
->type
= CHAR_GLYPH
;
1653 glyph
->pixel_width
= 1;
1654 glyph
->u
.ch
= it
->c
;
1655 glyph
->face_id
= it
->face_id
;
1656 glyph
->padding_p
= i
> 0;
1657 glyph
->charpos
= CHARPOS (it
->position
);
1658 glyph
->object
= it
->object
;
1660 ++it
->glyph_row
->used
[it
->area
];
1666 /* Produce glyphs for the display element described by IT. *IT
1667 specifies what we want to produce a glyph for (character, image, ...),
1668 and where in the glyph matrix we currently are (glyph row and hpos).
1669 produce_glyphs fills in output fields of *IT with information such as the
1670 pixel width and height of a character, and maybe output actual glyphs at
1671 the same time if IT->glyph_row is non-null. See the explanation of
1672 struct display_iterator in dispextern.h for an overview.
1674 produce_glyphs also stores the result of glyph width, ascent
1675 etc. computations in *IT.
1677 IT->glyph_row may be null, in which case produce_glyphs does not
1678 actually fill in the glyphs. This is used in the move_* functions
1679 in xdisp.c for text width and height computations.
1681 Callers usually don't call produce_glyphs directly;
1682 instead they use the macro PRODUCE_GLYPHS. */
1688 /* If a hook is installed, let it do the work. */
1689 xassert (it
->what
== IT_CHARACTER
1690 || it
->what
== IT_COMPOSITION
1691 || it
->what
== IT_IMAGE
1692 || it
->what
== IT_STRETCH
);
1694 /* Nothing but characters are supported on terminal frames. For a
1695 composition sequence, it->c is the first character of the
1697 xassert (it
->what
== IT_CHARACTER
1698 || it
->what
== IT_COMPOSITION
);
1700 if (it
->c
>= 040 && it
->c
< 0177)
1702 it
->pixel_width
= it
->nglyphs
= 1;
1706 else if (it
->c
== '\n')
1707 it
->pixel_width
= it
->nglyphs
= 0;
1708 else if (it
->c
== '\t')
1710 int absolute_x
= (it
->current_x
1711 + it
->continuation_lines_width
);
1713 = (((1 + absolute_x
+ it
->tab_width
- 1)
1718 /* If part of the TAB has been displayed on the previous line
1719 which is continued now, continuation_lines_width will have
1720 been incremented already by the part that fitted on the
1721 continued line. So, we will get the right number of spaces
1723 nspaces
= next_tab_x
- absolute_x
;
1730 it
->pixel_width
= it
->len
= 1;
1738 it
->pixel_width
= nspaces
;
1739 it
->nglyphs
= nspaces
;
1741 else if (SINGLE_BYTE_CHAR_P (it
->c
))
1743 /* Coming here means that it->c is from display table, thus we
1744 must send the code as is to the terminal. Although there's
1745 no way to know how many columns it occupies on a screen, it
1746 is a good assumption that a single byte code has 1-column
1748 it
->pixel_width
= it
->nglyphs
= 1;
1754 /* A multi-byte character. The display width is fixed for all
1755 characters of the set. Some of the glyphs may have to be
1756 ignored because they are already displayed in a continued
1758 int charset
= CHAR_CHARSET (it
->c
);
1760 it
->pixel_width
= CHARSET_WIDTH (charset
);
1761 it
->nglyphs
= it
->pixel_width
;
1767 /* Advance current_x by the pixel width as a convenience for
1769 if (it
->area
== TEXT_AREA
)
1770 it
->current_x
+= it
->pixel_width
;
1771 it
->ascent
= it
->max_ascent
= it
->phys_ascent
= it
->max_phys_ascent
= 0;
1772 it
->descent
= it
->max_descent
= it
->phys_descent
= it
->max_phys_descent
= 1;
1776 /* Get information about special display element WHAT in an
1777 environment described by IT. WHAT is one of IT_TRUNCATION or
1778 IT_CONTINUATION. Maybe produce glyphs for WHAT if IT has a
1779 non-null glyph_row member. This function ensures that fields like
1780 face_id, c, len of IT are left untouched. */
1783 produce_special_glyphs (it
, what
)
1785 enum display_element_type what
;
1791 temp_it
.what
= IT_CHARACTER
;
1793 temp_it
.object
= make_number (0);
1794 bzero (&temp_it
.current
, sizeof temp_it
.current
);
1796 if (what
== IT_CONTINUATION
)
1798 /* Continuation glyph. */
1800 && INTEGERP (DISP_CONTINUE_GLYPH (it
->dp
))
1801 && GLYPH_CHAR_VALID_P (XINT (DISP_CONTINUE_GLYPH (it
->dp
))))
1803 temp_it
.c
= FAST_GLYPH_CHAR (XINT (DISP_CONTINUE_GLYPH (it
->dp
)));
1804 temp_it
.len
= CHAR_BYTES (temp_it
.c
);
1809 produce_glyphs (&temp_it
);
1810 it
->pixel_width
= temp_it
.pixel_width
;
1811 it
->nglyphs
= temp_it
.pixel_width
;
1813 else if (what
== IT_TRUNCATION
)
1815 /* Truncation glyph. */
1817 && INTEGERP (DISP_TRUNC_GLYPH (it
->dp
))
1818 && GLYPH_CHAR_VALID_P (XINT (DISP_TRUNC_GLYPH (it
->dp
))))
1820 temp_it
.c
= FAST_GLYPH_CHAR (XINT (DISP_TRUNC_GLYPH (it
->dp
)));
1821 temp_it
.len
= CHAR_BYTES (temp_it
.c
);
1826 produce_glyphs (&temp_it
);
1827 it
->pixel_width
= temp_it
.pixel_width
;
1828 it
->nglyphs
= temp_it
.pixel_width
;
1836 /***********************************************************************
1838 ***********************************************************************/
1840 /* Value is non-zero if attribute ATTR may be used. ATTR should be
1841 one of the enumerators from enum no_color_bit, or a bit set built
1842 from them. Some display attributes may not be used together with
1843 color; the termcap capability `NC' specifies which ones. */
1845 #define MAY_USE_WITH_COLORS_P(ATTR) \
1846 (TN_max_colors > 0 \
1847 ? (TN_no_color_video & (ATTR)) == 0 \
1850 /* Turn appearances of face FACE_ID on tty frame F on. */
1853 turn_on_face (f
, face_id
)
1857 struct face
*face
= FACE_FROM_ID (f
, face_id
);
1858 long fg
= face
->foreground
;
1859 long bg
= face
->background
;
1861 /* Do this first because TS_end_standout_mode may be the same
1862 as TS_exit_attribute_mode, which turns all appearances off. */
1863 if (MAY_USE_WITH_COLORS_P (NC_REVERSE
))
1865 if (TN_max_colors
> 0)
1867 if (fg
>= 0 && bg
>= 0)
1869 /* If the terminal supports colors, we can set them
1870 below without using reverse video. The face's fg
1871 and bg colors are set as they should appear on
1872 the screen, i.e. they take the inverse-video'ness
1873 of the face already into account. */
1875 else if (inverse_video
)
1877 if (fg
== FACE_TTY_DEFAULT_FG_COLOR
1878 || bg
== FACE_TTY_DEFAULT_BG_COLOR
)
1879 toggle_highlight ();
1883 if (fg
== FACE_TTY_DEFAULT_BG_COLOR
1884 || bg
== FACE_TTY_DEFAULT_FG_COLOR
)
1885 toggle_highlight ();
1890 /* If we can't display colors, use reverse video
1891 if the face specifies that. */
1894 if (fg
== FACE_TTY_DEFAULT_FG_COLOR
1895 || bg
== FACE_TTY_DEFAULT_BG_COLOR
)
1896 toggle_highlight ();
1900 if (fg
== FACE_TTY_DEFAULT_BG_COLOR
1901 || bg
== FACE_TTY_DEFAULT_FG_COLOR
)
1902 toggle_highlight ();
1907 if (face
->tty_bold_p
)
1909 if (MAY_USE_WITH_COLORS_P (NC_BOLD
))
1910 OUTPUT1_IF (FRAME_TTY (f
), TS_enter_bold_mode
);
1912 else if (face
->tty_dim_p
)
1913 if (MAY_USE_WITH_COLORS_P (NC_DIM
))
1914 OUTPUT1_IF (FRAME_TTY (f
), TS_enter_dim_mode
);
1916 /* Alternate charset and blinking not yet used. */
1917 if (face
->tty_alt_charset_p
1918 && MAY_USE_WITH_COLORS_P (NC_ALT_CHARSET
))
1919 OUTPUT1_IF (FRAME_TTY (f
), TS_enter_alt_charset_mode
);
1921 if (face
->tty_blinking_p
1922 && MAY_USE_WITH_COLORS_P (NC_BLINK
))
1923 OUTPUT1_IF (FRAME_TTY (f
), TS_enter_blink_mode
);
1925 if (face
->tty_underline_p
&& MAY_USE_WITH_COLORS_P (NC_UNDERLINE
))
1926 OUTPUT1_IF (FRAME_TTY (f
), TS_enter_underline_mode
);
1928 if (TN_max_colors
> 0)
1932 if (fg
>= 0 && TS_set_foreground
)
1934 p
= tparam (TS_set_foreground
, NULL
, 0, (int) fg
);
1935 OUTPUT (FRAME_TTY (f
), p
);
1939 if (bg
>= 0 && TS_set_background
)
1941 p
= tparam (TS_set_background
, NULL
, 0, (int) bg
);
1942 OUTPUT (FRAME_TTY (f
), p
);
1949 /* Turn off appearances of face FACE_ID on tty frame F. */
1952 turn_off_face (f
, face_id
)
1956 struct face
*face
= FACE_FROM_ID (f
, face_id
);
1958 xassert (face
!= NULL
);
1960 if (TS_exit_attribute_mode
)
1962 /* Capability "me" will turn off appearance modes double-bright,
1963 half-bright, reverse-video, standout, underline. It may or
1964 may not turn off alt-char-mode. */
1965 if (face
->tty_bold_p
1967 || face
->tty_reverse_p
1968 || face
->tty_alt_charset_p
1969 || face
->tty_blinking_p
1970 || face
->tty_underline_p
)
1972 OUTPUT1_IF (FRAME_TTY (f
), TS_exit_attribute_mode
);
1973 if (strcmp (TS_exit_attribute_mode
, TS_end_standout_mode
) == 0)
1977 if (face
->tty_alt_charset_p
)
1978 OUTPUT_IF (FRAME_TTY (f
), TS_exit_alt_charset_mode
);
1982 /* If we don't have "me" we can only have those appearances
1983 that have exit sequences defined. */
1984 if (face
->tty_alt_charset_p
)
1985 OUTPUT_IF (FRAME_TTY (f
), TS_exit_alt_charset_mode
);
1987 if (face
->tty_underline_p
)
1988 OUTPUT_IF (FRAME_TTY (f
), TS_exit_underline_mode
);
1991 /* Switch back to default colors. */
1992 if (TN_max_colors
> 0
1993 && ((face
->foreground
!= FACE_TTY_DEFAULT_COLOR
1994 && face
->foreground
!= FACE_TTY_DEFAULT_FG_COLOR
)
1995 || (face
->background
!= FACE_TTY_DEFAULT_COLOR
1996 && face
->background
!= FACE_TTY_DEFAULT_BG_COLOR
)))
1997 OUTPUT1_IF (FRAME_TTY (f
), TS_orig_pair
);
2001 /* Return non-zero if the terminal on frame F supports all of the
2002 capabilities in CAPS simultaneously, with foreground and background
2003 colors FG and BG. */
2006 tty_capable_p (f
, caps
, fg
, bg
)
2009 unsigned long fg
, bg
;
2011 #define TTY_CAPABLE_P_TRY(cap, TS, NC_bit) \
2012 if ((caps & (cap)) && (!(TS) || !MAY_USE_WITH_COLORS_P(NC_bit))) \
2015 TTY_CAPABLE_P_TRY (TTY_CAP_INVERSE
, TS_standout_mode
, NC_REVERSE
);
2016 TTY_CAPABLE_P_TRY (TTY_CAP_UNDERLINE
, TS_enter_underline_mode
, NC_UNDERLINE
);
2017 TTY_CAPABLE_P_TRY (TTY_CAP_BOLD
, TS_enter_bold_mode
, NC_BOLD
);
2018 TTY_CAPABLE_P_TRY (TTY_CAP_DIM
, TS_enter_dim_mode
, NC_DIM
);
2019 TTY_CAPABLE_P_TRY (TTY_CAP_BLINK
, TS_enter_blink_mode
, NC_BLINK
);
2020 TTY_CAPABLE_P_TRY (TTY_CAP_ALT_CHARSET
, TS_enter_alt_charset_mode
, NC_ALT_CHARSET
);
2027 /* Return non-zero if the terminal is capable to display colors. */
2029 DEFUN ("tty-display-color-p", Ftty_display_color_p
, Stty_display_color_p
,
2031 doc
: /* Return non-nil if TTY can display colors on DISPLAY. */)
2033 Lisp_Object display
;
2035 return TN_max_colors
> 0 ? Qt
: Qnil
;
2038 /* Return the number of supported colors. */
2039 DEFUN ("tty-display-color-cells", Ftty_display_color_cells
,
2040 Stty_display_color_cells
, 0, 1, 0,
2041 doc
: /* Return the number of colors supported by TTY on DISPLAY. */)
2043 Lisp_Object display
;
2045 return make_number (TN_max_colors
);
2050 /* Save or restore the default color-related capabilities of this
2053 tty_default_color_capabilities (save
)
2057 *default_orig_pair
, *default_set_foreground
, *default_set_background
;
2058 static int default_max_colors
, default_max_pairs
, default_no_color_video
;
2062 if (default_orig_pair
)
2063 xfree (default_orig_pair
);
2064 default_orig_pair
= TS_orig_pair
? xstrdup (TS_orig_pair
) : NULL
;
2066 if (default_set_foreground
)
2067 xfree (default_set_foreground
);
2068 default_set_foreground
= TS_set_foreground
? xstrdup (TS_set_foreground
)
2071 if (default_set_background
)
2072 xfree (default_set_background
);
2073 default_set_background
= TS_set_background
? xstrdup (TS_set_background
)
2076 default_max_colors
= TN_max_colors
;
2077 default_max_pairs
= TN_max_pairs
;
2078 default_no_color_video
= TN_no_color_video
;
2082 TS_orig_pair
= default_orig_pair
;
2083 TS_set_foreground
= default_set_foreground
;
2084 TS_set_background
= default_set_background
;
2085 TN_max_colors
= default_max_colors
;
2086 TN_max_pairs
= default_max_pairs
;
2087 TN_no_color_video
= default_no_color_video
;
2091 /* Setup one of the standard tty color schemes according to MODE.
2092 MODE's value is generally the number of colors which we want to
2093 support; zero means set up for the default capabilities, the ones
2094 we saw at term_init time; -1 means turn off color support. */
2096 tty_setup_colors (mode
)
2099 /* Canonicalize all negative values of MODE. */
2105 case -1: /* no colors at all */
2108 TN_no_color_video
= 0;
2109 TS_set_foreground
= TS_set_background
= TS_orig_pair
= NULL
;
2111 case 0: /* default colors, if any */
2113 tty_default_color_capabilities (0);
2115 case 8: /* 8 standard ANSI colors */
2116 TS_orig_pair
= "\033[0m";
2118 TS_set_foreground
= "\033[3%p1%dm";
2119 TS_set_background
= "\033[4%p1%dm";
2121 TS_set_foreground
= "\033[3%dm";
2122 TS_set_background
= "\033[4%dm";
2126 TN_no_color_video
= 0;
2132 set_tty_color_mode (f
, val
)
2136 Lisp_Object color_mode_spec
, current_mode_spec
;
2137 Lisp_Object color_mode
, current_mode
;
2139 extern Lisp_Object Qtty_color_mode
;
2140 Lisp_Object tty_color_mode_alist
;
2142 tty_color_mode_alist
= Fintern_soft (build_string ("tty-color-mode-alist"),
2149 if (NILP (tty_color_mode_alist
))
2150 color_mode_spec
= Qnil
;
2152 color_mode_spec
= Fassq (val
, XSYMBOL (tty_color_mode_alist
)->value
);
2154 if (CONSP (color_mode_spec
))
2155 color_mode
= XCDR (color_mode_spec
);
2160 current_mode_spec
= assq_no_quit (Qtty_color_mode
, f
->param_alist
);
2162 if (CONSP (current_mode_spec
))
2163 current_mode
= XCDR (current_mode_spec
);
2165 current_mode
= Qnil
;
2166 if (INTEGERP (color_mode
))
2167 mode
= XINT (color_mode
);
2169 mode
= 0; /* meaning default */
2170 if (INTEGERP (current_mode
))
2171 old_mode
= XINT (current_mode
);
2175 if (mode
!= old_mode
)
2177 tty_setup_colors (mode
);
2178 /* This recomputes all the faces given the new color
2180 call0 (intern ("tty-set-up-initial-frame-faces"));
2185 #endif /* !WINDOWSNT */
2190 get_named_tty (name
)
2193 struct tty_output
*tty
= tty_list
;
2196 if ((tty
->name
== 0 && name
== 0)
2197 || (name
&& tty
->name
&& !strcmp (tty
->name
, name
)))
2206 /***********************************************************************
2208 ***********************************************************************/
2211 term_dummy_init (void)
2213 if (initialized
|| tty_list
)
2214 error ("tty already initialized");
2216 tty_list
= xmalloc (sizeof (struct tty_output
));
2217 bzero (tty_list
, sizeof (struct tty_output
));
2218 TTY_NAME (tty_list
) = 0;
2219 TTY_INPUT (tty_list
) = stdin
;
2220 TTY_OUTPUT (tty_list
) = stdout
;
2226 term_init (name
, terminal_type
)
2228 char *terminal_type
;
2231 char **address
= &area
;
2232 char *buffer
= NULL
;
2233 int buffer_size
= 4096;
2236 struct frame
*sf
= XFRAME (selected_frame
);
2238 struct tty_output
*tty
;
2240 tty
= get_named_tty (name
);
2243 /* Return the previously initialized terminal, except if it is the dummy
2244 terminal created for the initial frame. */
2251 error ("Unknown terminal type");
2253 tty
= (struct tty_output
*) xmalloc (sizeof (struct tty_output
));
2254 bzero (tty
, sizeof (struct tty_output
));
2255 tty
->next
= tty_list
;
2263 fd
= emacs_open (name
, O_RDWR
, 0);
2266 tty_list
= tty
->next
;
2268 error ("could not open file: %s", name
);
2270 f
= fdopen (fd
, "w+");
2271 TTY_NAME (tty
) = xstrdup (name
);
2272 TTY_INPUT (tty
) = f
;
2273 TTY_OUTPUT (tty
) = f
;
2278 TTY_INPUT (tty
) = stdin
;
2279 TTY_OUTPUT (tty
) = stdout
;
2282 init_sys_modes (tty
);
2285 initialize_w32_display ();
2289 area
= (char *) xmalloc (2044);
2291 FrameRows
= FRAME_LINES (sf
);
2292 FrameCols
= FRAME_COLS (sf
);
2293 specified_window
= FRAME_LINES (sf
);
2295 delete_in_insert_mode
= 1;
2298 TTY_SCROLL_REGION_OK (tty
) = 0;
2300 /* Seems to insert lines when it's not supposed to, messing
2301 up the display. In doing a trace, it didn't seem to be
2302 called much, so I don't think we're losing anything by
2304 TTY_LINE_INS_DEL_OK (tty
) = 0;
2306 TTY_CHAR_INS_DEL_OK (tty
) = 1;
2310 FRAME_CAN_HAVE_SCROLL_BARS (sf
) = 0;
2311 FRAME_VERTICAL_SCROLL_BAR_TYPE (sf
) = vertical_scroll_bar_none
;
2312 TN_max_colors
= 16; /* Required to be non-zero for tty-display-color-p */
2315 #else /* not WINDOWSNT */
2319 TTY_TYPE (tty
) = xstrdup (terminal_type
);
2321 buffer
= (char *) xmalloc (buffer_size
);
2322 status
= tgetent (buffer
, terminal_type
);
2326 fatal ("Cannot open terminfo database file");
2328 fatal ("Cannot open termcap database file");
2334 fatal ("Terminal type %s is not defined.\n\
2335 If that is not the actual type of terminal you have,\n\
2336 use the Bourne shell command `TERM=... export TERM' (C-shell:\n\
2337 `setenv TERM ...') to specify the correct type. It may be necessary\n\
2338 to do `unset TERMINFO' (C-shell: `unsetenv TERMINFO') as well.",
2341 fatal ("Terminal type %s is not defined.\n\
2342 If that is not the actual type of terminal you have,\n\
2343 use the Bourne shell command `TERM=... export TERM' (C-shell:\n\
2344 `setenv TERM ...') to specify the correct type. It may be necessary\n\
2345 to do `unset TERMCAP' (C-shell: `unsetenv TERMCAP') as well.",
2351 if (strlen (buffer
) >= buffer_size
)
2353 buffer_size
= strlen (buffer
);
2355 area
= (char *) xmalloc (buffer_size
);
2357 TS_ins_line
= tgetstr ("al", address
);
2358 TS_ins_multi_lines
= tgetstr ("AL", address
);
2359 TS_bell
= tgetstr ("bl", address
);
2360 BackTab
= tgetstr ("bt", address
);
2361 TS_clr_to_bottom
= tgetstr ("cd", address
);
2362 TS_clr_line
= tgetstr ("ce", address
);
2363 TS_clr_frame
= tgetstr ("cl", address
);
2364 ColPosition
= NULL
; /* tgetstr ("ch", address); */
2365 AbsPosition
= tgetstr ("cm", address
);
2366 CR
= tgetstr ("cr", address
);
2367 TS_set_scroll_region
= tgetstr ("cs", address
);
2368 TS_set_scroll_region_1
= tgetstr ("cS", address
);
2369 RowPosition
= tgetstr ("cv", address
);
2370 TS_del_char
= tgetstr ("dc", address
);
2371 TS_del_multi_chars
= tgetstr ("DC", address
);
2372 TS_del_line
= tgetstr ("dl", address
);
2373 TS_del_multi_lines
= tgetstr ("DL", address
);
2374 TS_delete_mode
= tgetstr ("dm", address
);
2375 TS_end_delete_mode
= tgetstr ("ed", address
);
2376 TS_end_insert_mode
= tgetstr ("ei", address
);
2377 Home
= tgetstr ("ho", address
);
2378 TS_ins_char
= tgetstr ("ic", address
);
2379 TS_ins_multi_chars
= tgetstr ("IC", address
);
2380 TS_insert_mode
= tgetstr ("im", address
);
2381 TS_pad_inserted_char
= tgetstr ("ip", address
);
2382 TS_end_keypad_mode
= tgetstr ("ke", address
);
2383 TS_keypad_mode
= tgetstr ("ks", address
);
2384 LastLine
= tgetstr ("ll", address
);
2385 Right
= tgetstr ("nd", address
);
2386 Down
= tgetstr ("do", address
);
2388 Down
= tgetstr ("nl", address
); /* Obsolete name for "do" */
2390 /* VMS puts a carriage return before each linefeed,
2391 so it is not safe to use linefeeds. */
2392 if (Down
&& Down
[0] == '\n' && Down
[1] == '\0')
2395 if (tgetflag ("bs"))
2396 Left
= "\b"; /* can't possibly be longer! */
2397 else /* (Actually, "bs" is obsolete...) */
2398 Left
= tgetstr ("le", address
);
2400 Left
= tgetstr ("bc", address
); /* Obsolete name for "le" */
2401 TS_pad_char
= tgetstr ("pc", address
);
2402 TS_repeat
= tgetstr ("rp", address
);
2403 TS_end_standout_mode
= tgetstr ("se", address
);
2404 TS_fwd_scroll
= tgetstr ("sf", address
);
2405 TS_standout_mode
= tgetstr ("so", address
);
2406 TS_rev_scroll
= tgetstr ("sr", address
);
2407 Wcm
.cm_tab
= tgetstr ("ta", address
);
2408 TS_end_termcap_modes
= tgetstr ("te", address
);
2409 TS_termcap_modes
= tgetstr ("ti", address
);
2410 Up
= tgetstr ("up", address
);
2411 TS_visible_bell
= tgetstr ("vb", address
);
2412 TS_cursor_normal
= tgetstr ("ve", address
);
2413 TS_cursor_visible
= tgetstr ("vs", address
);
2414 TS_cursor_invisible
= tgetstr ("vi", address
);
2415 TS_set_window
= tgetstr ("wi", address
);
2417 TS_enter_underline_mode
= tgetstr ("us", address
);
2418 TS_exit_underline_mode
= tgetstr ("ue", address
);
2419 TS_enter_bold_mode
= tgetstr ("md", address
);
2420 TS_enter_dim_mode
= tgetstr ("mh", address
);
2421 TS_enter_blink_mode
= tgetstr ("mb", address
);
2422 TS_enter_reverse_mode
= tgetstr ("mr", address
);
2423 TS_enter_alt_charset_mode
= tgetstr ("as", address
);
2424 TS_exit_alt_charset_mode
= tgetstr ("ae", address
);
2425 TS_exit_attribute_mode
= tgetstr ("me", address
);
2427 MultiUp
= tgetstr ("UP", address
);
2428 MultiDown
= tgetstr ("DO", address
);
2429 MultiLeft
= tgetstr ("LE", address
);
2430 MultiRight
= tgetstr ("RI", address
);
2432 /* SVr4/ANSI color suppert. If "op" isn't available, don't support
2433 color because we can't switch back to the default foreground and
2435 TS_orig_pair
= tgetstr ("op", address
);
2438 TS_set_foreground
= tgetstr ("AF", address
);
2439 TS_set_background
= tgetstr ("AB", address
);
2440 if (!TS_set_foreground
)
2443 TS_set_foreground
= tgetstr ("Sf", address
);
2444 TS_set_background
= tgetstr ("Sb", address
);
2447 TN_max_colors
= tgetnum ("Co");
2448 TN_max_pairs
= tgetnum ("pa");
2450 TN_no_color_video
= tgetnum ("NC");
2451 if (TN_no_color_video
== -1)
2452 TN_no_color_video
= 0;
2455 tty_default_color_capabilities (1);
2457 MagicWrap
= tgetflag ("xn");
2458 /* Since we make MagicWrap terminals look like AutoWrap, we need to have
2459 the former flag imply the latter. */
2460 AutoWrap
= MagicWrap
|| tgetflag ("am");
2461 TTY_MEMORY_BELOW_FRAME (tty
) = tgetflag ("db");
2462 TF_hazeltine
= tgetflag ("hz");
2463 TTY_MUST_WRITE_SPACES (tty
) = tgetflag ("in");
2464 meta_key
= tgetflag ("km") || tgetflag ("MT");
2465 TF_insmode_motion
= tgetflag ("mi");
2466 TF_standout_motion
= tgetflag ("ms");
2467 TF_underscore
= tgetflag ("ul");
2468 TF_teleray
= tgetflag ("xt");
2470 term_get_fkeys (address
);
2472 /* Get frame size from system, or else from termcap. */
2475 get_tty_size (tty
, &width
, &height
);
2476 FRAME_COLS (sf
) = width
;
2477 FRAME_LINES (sf
) = height
;
2480 if (FRAME_COLS (sf
) <= 0)
2481 SET_FRAME_COLS (sf
, tgetnum ("co"));
2483 /* Keep width and external_width consistent */
2484 SET_FRAME_COLS (sf
, FRAME_COLS (sf
));
2485 if (FRAME_LINES (sf
) <= 0)
2486 FRAME_LINES (sf
) = tgetnum ("li");
2488 if (FRAME_LINES (sf
) < 3 || FRAME_COLS (sf
) < 3)
2489 fatal ("Screen size %dx%d is too small",
2490 FRAME_LINES (sf
), FRAME_COLS (sf
));
2492 #if 0 /* This is not used anywhere. */
2493 TTY_MIN_PADDING_SPEED (tty
) = tgetnum ("pb");
2496 TabWidth
= tgetnum ("tw");
2499 /* These capabilities commonly use ^J.
2500 I don't know why, but sending them on VMS does not work;
2501 it causes following spaces to be lost, sometimes.
2502 For now, the simplest fix is to avoid using these capabilities ever. */
2503 if (Down
&& Down
[0] == '\n')
2511 TS_fwd_scroll
= Down
;
2513 PC
= TS_pad_char
? *TS_pad_char
: 0;
2518 /* Turned off since /etc/termcap seems to have :ta= for most terminals
2519 and newer termcap doc does not seem to say there is a default.
2524 /* We don't support standout modes that use `magic cookies', so
2525 turn off any that do. */
2526 if (TS_standout_mode
&& tgetnum ("sg") >= 0)
2528 TS_standout_mode
= 0;
2529 TS_end_standout_mode
= 0;
2531 if (TS_enter_underline_mode
&& tgetnum ("ug") >= 0)
2533 TS_enter_underline_mode
= 0;
2534 TS_exit_underline_mode
= 0;
2537 /* If there's no standout mode, try to use underlining instead. */
2538 if (TS_standout_mode
== 0)
2540 TS_standout_mode
= TS_enter_underline_mode
;
2541 TS_end_standout_mode
= TS_exit_underline_mode
;
2544 /* If no `se' string, try using a `me' string instead.
2545 If that fails, we can't use standout mode at all. */
2546 if (TS_end_standout_mode
== 0)
2548 char *s
= tgetstr ("me", address
);
2550 TS_end_standout_mode
= s
;
2552 TS_standout_mode
= 0;
2558 /* We can't support standout mode, because it uses magic cookies. */
2559 TS_standout_mode
= 0;
2560 /* But that means we cannot rely on ^M to go to column zero! */
2562 /* LF can't be trusted either -- can alter hpos */
2563 /* if move at column 0 thru a line with TS_standout_mode */
2567 /* Special handling for certain terminal types known to need it */
2569 if (!strcmp (terminal_type
, "supdup"))
2571 TTY_MEMORY_BELOW_FRAME (tty
) = 1;
2572 Wcm
.cm_losewrap
= 1;
2574 if (!strncmp (terminal_type
, "c10", 3)
2575 || !strcmp (terminal_type
, "perq"))
2577 /* Supply a makeshift :wi string.
2578 This string is not valid in general since it works only
2579 for windows starting at the upper left corner;
2580 but that is all Emacs uses.
2582 This string works only if the frame is using
2583 the top of the video memory, because addressing is memory-relative.
2584 So first check the :ti string to see if that is true.
2586 It would be simpler if the :wi string could go in the termcap
2587 entry, but it can't because it is not fully valid.
2588 If it were in the termcap entry, it would confuse other programs. */
2591 p
= TS_termcap_modes
;
2592 while (*p
&& strcmp (p
, "\033v "))
2595 TS_set_window
= "\033v%C %C %C %C ";
2597 /* Termcap entry often fails to have :in: flag */
2598 TTY_MUST_WRITE_SPACES (tty
) = 1;
2599 /* :ti string typically fails to have \E^G! in it */
2600 /* This limits scope of insert-char to one line. */
2601 strcpy (area
, TS_termcap_modes
);
2602 strcat (area
, "\033\007!");
2603 TS_termcap_modes
= area
;
2604 area
+= strlen (area
) + 1;
2606 /* Change all %+ parameters to %C, to handle
2607 values above 96 correctly for the C100. */
2610 if (p
[0] == '%' && p
[1] == '+')
2616 FrameRows
= FRAME_LINES (sf
);
2617 FrameCols
= FRAME_COLS (sf
);
2618 specified_window
= FRAME_LINES (sf
);
2620 if (Wcm_init () == -1) /* can't do cursor motion */
2622 fatal ("Terminal type \"%s\" is not powerful enough to run Emacs.\n\
2623 It lacks the ability to position the cursor.\n\
2624 If that is not the actual type of terminal you have, use either the\n\
2625 DCL command `SET TERMINAL/DEVICE= ...' for DEC-compatible terminals,\n\
2626 or `define EMACS_TERM \"terminal type\"' for non-DEC terminals.",
2630 fatal ("Terminal type \"%s\" is not powerful enough to run Emacs.\n\
2631 It lacks the ability to position the cursor.\n\
2632 If that is not the actual type of terminal you have,\n\
2633 use the Bourne shell command `TERM=... export TERM' (C-shell:\n\
2634 `setenv TERM ...') to specify the correct type. It may be necessary\n\
2635 to do `unset TERMINFO' (C-shell: `unsetenv TERMINFO') as well.",
2637 # else /* TERMCAP */
2638 fatal ("Terminal type \"%s\" is not powerful enough to run Emacs.\n\
2639 It lacks the ability to position the cursor.\n\
2640 If that is not the actual type of terminal you have,\n\
2641 use the Bourne shell command `TERM=... export TERM' (C-shell:\n\
2642 `setenv TERM ...') to specify the correct type. It may be necessary\n\
2643 to do `unset TERMCAP' (C-shell: `unsetenv TERMCAP') as well.",
2645 # endif /* TERMINFO */
2647 if (FRAME_LINES (sf
) <= 0
2648 || FRAME_COLS (sf
) <= 0)
2649 fatal ("The frame size has not been specified");
2651 delete_in_insert_mode
2652 = TS_delete_mode
&& TS_insert_mode
2653 && !strcmp (TS_delete_mode
, TS_insert_mode
);
2655 se_is_so
= (TS_standout_mode
2656 && TS_end_standout_mode
2657 && !strcmp (TS_standout_mode
, TS_end_standout_mode
));
2659 UseTabs
= tabs_safe_p () && TabWidth
== 8;
2661 TTY_SCROLL_REGION_OK (tty
)
2663 && (TS_set_window
|| TS_set_scroll_region
|| TS_set_scroll_region_1
));
2665 TTY_LINE_INS_DEL_OK (tty
)
2666 = (((TS_ins_line
|| TS_ins_multi_lines
)
2667 && (TS_del_line
|| TS_del_multi_lines
))
2668 || (TTY_SCROLL_REGION_OK (tty
)
2669 && TS_fwd_scroll
&& TS_rev_scroll
));
2671 TTY_CHAR_INS_DEL_OK (tty
)
2672 = ((TS_ins_char
|| TS_insert_mode
2673 || TS_pad_inserted_char
|| TS_ins_multi_chars
)
2674 && (TS_del_char
|| TS_del_multi_chars
));
2676 TTY_FAST_CLEAR_END_OF_LINE (tty
) = TS_clr_line
!= 0;
2679 if (read_socket_hook
) /* Baudrate is somewhat
2680 meaningless in this case */
2683 FRAME_CAN_HAVE_SCROLL_BARS (sf
) = 0;
2684 FRAME_VERTICAL_SCROLL_BAR_TYPE (sf
) = vertical_scroll_bar_none
;
2685 #endif /* WINDOWSNT */
2694 fatal (str
, arg1
, arg2
)
2695 char *str
, *arg1
, *arg2
;
2697 fprintf (stderr
, "emacs: ");
2698 fprintf (stderr
, str
, arg1
, arg2
);
2699 fprintf (stderr
, "\n");
2707 DEFVAR_BOOL ("system-uses-terminfo", &system_uses_terminfo
,
2708 doc
: /* Non-nil means the system uses terminfo rather than termcap.
2709 This variable can be used by terminal emulator packages. */);
2711 system_uses_terminfo
= 1;
2713 system_uses_terminfo
= 0;
2716 DEFVAR_LISP ("ring-bell-function", &Vring_bell_function
,
2717 doc
: /* Non-nil means call this function to ring the bell.
2718 The function should accept no arguments. */);
2719 Vring_bell_function
= Qnil
;
2721 defsubr (&Stty_display_color_p
);
2722 defsubr (&Stty_display_color_cells
);
2732 /* arch-tag: 498e7449-6f2e-45e2-91dd-b7d4ca488193
2733 (do not change this comment) */