/* Terminal control module for terminals described by TERMCAP
- Copyright (C) 1985, 86, 87, 93, 94, 95, 98, 2000, 2001
+ Copyright (C) 1985, 86, 87, 93, 94, 95, 98, 2000, 2001, 2002
Free Software Foundation, Inc.
This file is part of GNU Emacs.
#ifdef HAVE_X_WINDOWS
#include "xterm.h"
#endif
-#ifdef macintosh
+#ifdef MAC_OS
#include "macterm.h"
#endif
tputs (a, (int) (FRAME_HEIGHT (XFRAME (selected_frame)) \
- curY), cmputc); \
} while (0)
-
+
#define OUTPUT1_IF(a) do { if (a) tputs (a, 1, cmputc); } while (0)
/* Function to use to ring the bell. */
/* Arrange for all scroll bars on FRAME to be removed at the next call
to `*judge_scroll_bars_hook'. A scroll bar may be spared if
- `*redeem_scroll_bar_hook' is applied to its window before the judgment.
+ `*redeem_scroll_bar_hook' is applied to its window before the judgment.
This should be applied to each frame each time its window tree is
redisplayed, even if it is not displaying scroll bars at the moment;
void (*redeem_scroll_bar_hook) P_ ((struct window *window));
/* Remove all scroll bars on FRAME that haven't been saved since the
- last call to `*condemn_scroll_bars_hook'.
+ last call to `*condemn_scroll_bars_hook'.
This should be applied to each frame after each time its window
tree is redisplayed, even if it is not displaying scroll bars at the
void (*judge_scroll_bars_hook) P_ ((FRAME_PTR FRAME));
-/* Hook to call in estimate_mode_line_height, if any. */
-
-int (* estimate_mode_line_height_hook) P_ ((struct frame *f, enum face_id));
-
-
/* Strings, numbers and flags taken from the termcap entry. */
char *TS_ins_line; /* "al" */
int max_frame_height;
-int costs_set = 0; /* Nonzero if costs have been calculated. */
+static int costs_set; /* Nonzero if costs have been calculated. */
int insert_mode; /* Nonzero when in insert mode. */
int standout_mode; /* Nonzero when in standout mode. */
We don't specbind it, because that would carefully
restore the bad value if there's an error
and make the loop of errors happen anyway. */
-
+
function = Vring_bell_function;
Vring_bell_function = Qnil;
}
else
update_end_hook (f);
-
+
updating_frame = NULL;
}
{
char *buf;
struct frame *sf = XFRAME (selected_frame);
-
+
if (TS_set_scroll_region)
buf = tparam (TS_set_scroll_region, 0, 0, start, stop - 1);
else if (TS_set_scroll_region_1)
FRAME_HEIGHT (sf));
else
buf = tparam (TS_set_window, 0, 0, start, 0, stop, FRAME_WIDTH (sf));
-
+
OUTPUT (buf);
xfree (buf);
losecursor ();
int vpos, hpos;
{
struct frame *f = updating_frame ? updating_frame : XFRAME (selected_frame);
-
+
if (! FRAME_TERMCAP_P (f) && cursor_to_hook)
{
(*cursor_to_hook) (vpos, hpos);
clear_frame ()
{
struct frame *sf = XFRAME (selected_frame);
-
+
if (clear_frame_hook
&& ! FRAME_TERMCAP_P ((updating_frame ? updating_frame : sf)))
{
struct glyph *src_start = src, *src_end = src + src_len;
unsigned char *dst_start = dst, *dst_end = dst + dst_len;
register GLYPH g;
- unsigned char workbuf[MAX_MULTIBYTE_LENGTH], *buf;
+ unsigned char workbuf[MAX_MULTIBYTE_LENGTH];
+ const unsigned char *buf;
int len;
register int tlen = GLYPH_TABLE_LENGTH;
register Lisp_Object *tbase = GLYPH_TABLE_BASE;
coding->src_multibyte = STRING_MULTIBYTE (tbase[g]);
}
}
-
+
result = encode_coding (coding, buf, dst, len, dst_end - dst);
len -= coding->consumed;
dst += coding->produced;
}
src++;
}
-
+
*consumed = src - src_start;
return (dst - dst_start);
}
return;
cmplus (len);
-
+
/* The mode bit CODING_MODE_LAST_BLOCK should be set to 1 only at
the tail. */
terminal_coding.mode &= ~CODING_MODE_LAST_BLOCK;
-
+
while (len > 0)
{
/* Identify a run of glyphs with the same face. */
int face_id = string->face_id;
int n;
-
+
for (n = 1; n < len; ++n)
if (string[n].face_id != face_id)
break;
turn_off_face (f, face_id);
turn_off_highlight ();
}
-
+
/* We may have to output some codes to terminate the writing. */
if (CODING_REQUIRE_FLUSHING (&terminal_coding))
{
termscript);
}
}
-
+
cmcheckmagic ();
}
/* If start is zero, insert blanks instead of a string at start */
-
+
void
insert_glyphs (start, len)
register struct glyph *start;
turn_off_highlight ();
}
}
-
+
cmcheckmagic ();
}
}
sf = XFRAME (selected_frame);
-
+
/* If the lines below the insertion are being pushed
into the end of the window, this is the same as clearing;
and we know the lines are already clear, since the matching
static Lisp_Object term_get_fkeys_1 ();
/* Find the escape codes sent by the function keys for Vfunction_key_map.
- This function scans the termcap function key sequence entries, and
+ This function scans the termcap function key sequence entries, and
adds entries to Vfunction_key_map for each function key it finds. */
void
if (k_semi)
{
+ if (k0)
+ /* Define f0 first, so that f10 takes precedence in case the
+ key sequences happens to be the same. */
+ Fdefine_key (Vfunction_key_map, build_string (k0),
+ Fmake_vector (make_number (1), intern ("f0")));
Fdefine_key (Vfunction_key_map, build_string (k_semi),
Fmake_vector (make_number (1), intern ("f10")));
- k0_name = "f0";
}
-
- if (k0)
+ else if (k0)
Fdefine_key (Vfunction_key_map, build_string (k0),
Fmake_vector (make_number (1), intern (k0_name)));
}
Fmake_vector (make_number (1), \
intern (sym))); \
}
-
+
/* if there's no key_next keycap, map key_npage to `next' keysym */
CONDITIONAL_REASSIGN ("%5", "kN", "next");
/* if there's no key_prev keycap, map key_ppage to `previous' keysym */
for which to produce glyphs; IT->face_id contains the character's
face. Padding glyphs are appended if IT->c has a IT->pixel_width >
1. */
-
+
static void
append_glyph (it)
struct it *it;
+ it->glyph_row->used[it->area]);
end = it->glyph_row->glyphs[1 + it->area];
- for (i = 0;
- i < it->pixel_width && glyph < end;
+ for (i = 0;
+ i < it->pixel_width && glyph < end;
++i)
{
glyph->type = CHAR_GLYPH;
glyph->padding_p = i > 0;
glyph->charpos = CHARPOS (it->position);
glyph->object = it->object;
-
+
++it->glyph_row->used[it->area];
++glyph;
}
}
-/* Produce glyphs for the display element described by IT. The
- function fills output fields of IT with pixel information like the
- pixel width and height of a character, and maybe produces glyphs at
+/* Produce glyphs for the display element described by IT. *IT
+ specifies what we want to produce a glyph for (character, image, ...),
+ and where in the glyph matrix we currently are (glyph row and hpos).
+ produce_glyphs fills in output fields of *IT with information such as the
+ pixel width and height of a character, and maybe output actual glyphs at
the same time if IT->glyph_row is non-null. See the explanation of
- struct display_iterator in dispextern.h for an overview. */
+ struct display_iterator in dispextern.h for an overview.
+
+ produce_glyphs also stores the result of glyph width, ascent
+ etc. computations in *IT.
-void
+ IT->glyph_row may be null, in which case produce_glyphs does not
+ actually fill in the glyphs. This is used in the move_* functions
+ in xdisp.c for text width and height computations.
+
+ Callers usually don't call produce_glyphs directly;
+ instead they use the macro PRODUCE_GLYPHS. */
+
+void
produce_glyphs (it)
struct it *it;
{
|| it->what == IT_COMPOSITION
|| it->what == IT_IMAGE
|| it->what == IT_STRETCH);
-
+
/* Nothing but characters are supported on terminal frames. For a
composition sequence, it->c is the first character of the
sequence. */
{
int absolute_x = (it->current_x
+ it->continuation_lines_width);
- int next_tab_x
- = (((1 + absolute_x + it->tab_width - 1)
+ int next_tab_x
+ = (((1 + absolute_x + it->tab_width - 1)
/ it->tab_width)
* it->tab_width);
int nspaces;
continued line. So, we will get the right number of spaces
here. */
nspaces = next_tab_x - absolute_x;
-
+
if (it->glyph_row)
{
int n = nspaces;
-
+
it->c = ' ';
it->pixel_width = it->len = 1;
-
+
while (n--)
append_glyph (it);
-
+
it->c = '\t';
}
it->pixel_width = CHARSET_WIDTH (charset);
it->nglyphs = it->pixel_width;
-
+
if (it->glyph_row)
append_glyph (it);
}
- /* Advance current_x by the pixel width as a convenience for
+ /* Advance current_x by the pixel width as a convenience for
the caller. */
if (it->area == TEXT_AREA)
it->current_x += it->pixel_width;
enum display_element_type what;
{
struct it temp_it;
-
+
temp_it = *it;
temp_it.dp = NULL;
temp_it.what = IT_CHARACTER;
}
else
temp_it.c = '\\';
-
+
produce_glyphs (&temp_it);
it->pixel_width = temp_it.pixel_width;
it->nglyphs = temp_it.pixel_width;
}
else
temp_it.c = '$';
-
+
produce_glyphs (&temp_it);
it->pixel_width = temp_it.pixel_width;
it->nglyphs = temp_it.pixel_width;
}
-/* Return an estimation of the pixel height of mode or top lines on
- frame F. FACE_ID specifies what line's height to estimate. */
-
-int
-estimate_mode_line_height (f, face_id)
- struct frame *f;
- enum face_id face_id;
-{
- if (estimate_mode_line_height_hook)
- return estimate_mode_line_height_hook (f, face_id);
- else
- return 1;
-}
-
-
\f
/***********************************************************************
Faces
if (TN_max_colors > 0)
{
char *p;
-
+
if (fg >= 0 && TS_set_foreground)
{
p = tparam (TS_set_foreground, NULL, 0, (int) fg);
}
}
}
-
+
/* Turn off appearances of face FACE_ID on tty frame F. */
&& face->background != FACE_TTY_DEFAULT_BG_COLOR)))
OUTPUT1_IF (TS_orig_pair);
}
-
-
+
+
+/* Return non-zero if the terminal on frame F supports all of the
+ capabilities in CAPS simultaneously, with foreground and background
+ colors FG and BG. */
+
+int
+tty_capable_p (f, caps, fg, bg)
+ struct frame *f;
+ unsigned caps;
+ unsigned long fg, bg;
+{
+#define TTY_CAPABLE_P_TRY(cap, TS, NC_bit) \
+ if ((caps & (cap)) && (!(TS) || !MAY_USE_WITH_COLORS_P(NC_bit))) \
+ return 0;
+
+ TTY_CAPABLE_P_TRY (TTY_CAP_INVERSE, TS_standout_mode, NC_REVERSE);
+ TTY_CAPABLE_P_TRY (TTY_CAP_UNDERLINE, TS_enter_underline_mode, NC_UNDERLINE);
+ TTY_CAPABLE_P_TRY (TTY_CAP_BOLD, TS_enter_bold_mode, NC_BOLD);
+ TTY_CAPABLE_P_TRY (TTY_CAP_DIM, TS_enter_dim_mode, NC_DIM);
+ TTY_CAPABLE_P_TRY (TTY_CAP_BLINK, TS_enter_blink_mode, NC_BLINK);
+ TTY_CAPABLE_P_TRY (TTY_CAP_ALT_CHARSET, TS_enter_alt_charset_mode, NC_ALT_CHARSET);
+
+ /* We can do it! */
+ return 1;
+}
+
+
/* Return non-zero if the terminal is capable to display colors. */
DEFUN ("tty-display-color-p", Ftty_display_color_p, Stty_display_color_p,
0, 1, 0,
- doc: /* Return non-nil if TTY can display colors on FRAME. */)
- (frame)
- Lisp_Object frame;
+ doc: /* Return non-nil if TTY can display colors on DISPLAY. */)
+ (display)
+ Lisp_Object display;
{
return TN_max_colors > 0 ? Qt : Qnil;
}
+/* Return the number of supported colors. */
+DEFUN ("tty-display-color-cells", Ftty_display_color_cells,
+ Stty_display_color_cells, 0, 1, 0,
+ doc: /* Return the number of colors supported by TTY on DISPLAY. */)
+ (display)
+ Lisp_Object display;
+{
+ return make_number (TN_max_colors);
+}
+
#ifndef WINDOWSNT
/* Save or restore the default color-related capabilities of this
TS_cursor_visible = tgetstr ("vs", address);
TS_cursor_invisible = tgetstr ("vi", address);
TS_set_window = tgetstr ("wi", address);
-
+
TS_enter_underline_mode = tgetstr ("us", address);
TS_exit_underline_mode = tgetstr ("ue", address);
TS_enter_bold_mode = tgetstr ("md", address);
TS_enter_alt_charset_mode = tgetstr ("as", address);
TS_exit_alt_charset_mode = tgetstr ("ae", address);
TS_exit_attribute_mode = tgetstr ("me", address);
-
+
MultiUp = tgetstr ("UP", address);
MultiDown = tgetstr ("DO", address);
MultiLeft = tgetstr ("LE", address);
TS_set_foreground = tgetstr ("Sf", address);
TS_set_background = tgetstr ("Sb", address);
}
-
+
TN_max_colors = tgetnum ("Co");
TN_max_pairs = tgetnum ("pa");
-
+
TN_no_color_video = tgetnum ("NC");
if (TN_no_color_video == -1)
TN_no_color_video = 0;
SET_FRAME_WIDTH (sf, FRAME_WIDTH (sf));
if (FRAME_HEIGHT (sf) <= 0)
FRAME_HEIGHT (sf) = tgetnum ("li");
-
+
if (FRAME_HEIGHT (sf) < 3 || FRAME_WIDTH (sf) < 3)
fatal ("Screen size %dx%d is too small",
FRAME_HEIGHT (sf), FRAME_WIDTH (sf));
if (TabWidth < 0)
TabWidth = 8;
-
+
/* Turned off since /etc/termcap seems to have :ta= for most terminals
and newer termcap doc does not seem to say there is a default.
if (!Wcm.cm_tab)
Vring_bell_function = Qnil;
defsubr (&Stty_display_color_p);
+ defsubr (&Stty_display_color_cells);
}