char *TS_exit_underline_mode, *TS_enter_underline_mode;
-/* "ug" -- number of blanks left by underline. */
-
-int TN_magic_cookie_glitch_ul;
-
/* "as"/"ae" -- start/end alternate character set. Not really
supported, yet. */
int TF_teleray; /* termcap xt flag: many weird consequences.
For t1061. */
-int TF_xs; /* Nonzero for "xs". If set together with
- TN_standout_width == 0, it means don't bother
- to write any end-standout cookies. */
-
-int TN_standout_width; /* termcap sg number: width occupied by standout
- markers */
-
static int RPov; /* # chars to start a TS_repeat */
static int delete_in_insert_mode; /* delete mode == insert mode */
{
if (FRAME_TERMCAP_P (XFRAME (selected_frame)))
{
- if (TN_standout_width < 0)
- turn_off_highlight ();
+ turn_off_highlight ();
turn_off_insert ();
OUTPUT_IF (TS_end_keypad_mode);
OUTPUT_IF (TS_cursor_normal);
OUTPUT_IF (TS_end_termcap_modes);
OUTPUT_IF (TS_orig_pair);
/* Output raw CR so kernel can track the cursor hpos. */
- /* But on magic-cookie terminals this can erase an end-standout
- marker and cause the rest of the frame to be in standout, so
- move down first. */
- if (TN_standout_width >= 0)
- cmputc ('\n');
cmputc ('\r');
}
else if (reset_terminal_modes_hook)
insert_mode = 0;
}
\f
-/* Handle highlighting when TN_standout_width (termcap sg) is not specified.
- In these terminals, output is affected by the value of standout
- mode when the output is written.
-
- These functions are called on all terminals, but do nothing
- on terminals whose standout mode does not work that way. */
+/* Handle highlighting. */
void
turn_off_highlight ()
{
- if (TN_standout_width < 0)
- {
- if (standout_mode)
- OUTPUT_IF (TS_end_standout_mode);
- standout_mode = 0;
- }
+ if (standout_mode)
+ OUTPUT_IF (TS_end_standout_mode);
+ standout_mode = 0;
}
static void
turn_on_highlight ()
{
- if (TN_standout_width < 0)
- {
- if (!standout_mode)
- OUTPUT_IF (TS_standout_mode);
- standout_mode = 1;
- }
+ if (!standout_mode)
+ OUTPUT_IF (TS_standout_mode);
+ standout_mode = 1;
}
static void
void
background_highlight ()
{
- if (TN_standout_width >= 0)
- return;
if (inverse_video)
turn_on_highlight ();
else
static void
highlight_if_desired ()
{
- if (TN_standout_width >= 0)
- return;
if (inverse_video)
turn_on_highlight ();
else
set_scroll_region (0, specified_window);
}
- if (TN_standout_width >= 0)
- {
- register int lower_limit
- = (scroll_region_ok
- ? specified_window
- : FRAME_HEIGHT (sf));
- }
if (!scroll_region_ok && memory_below_frame && n < 0)
{
cursor_to (FRAME_HEIGHT (sf) + n, 0);
static struct fkey_table keys[] =
{
- "kh", "home", /* termcap */
- "kl", "left", /* termcap */
- "ku", "up", /* termcap */
- "kr", "right", /* termcap */
- "kd", "down", /* termcap */
- "%8", "prior", /* terminfo */
- "%5", "next", /* terminfo */
- "@7", "end", /* terminfo */
- "@1", "begin", /* terminfo */
- "*6", "select", /* terminfo */
- "%9", "print", /* terminfo */
- "@4", "execute", /* terminfo --- actually the `command' key */
+ {"kh", "home"}, /* termcap */
+ {"kl", "left"}, /* termcap */
+ {"ku", "up"}, /* termcap */
+ {"kr", "right"}, /* termcap */
+ {"kd", "down"}, /* termcap */
+ {"%8", "prior"}, /* terminfo */
+ {"%5", "next"}, /* terminfo */
+ {"@7", "end"}, /* terminfo */
+ {"@1", "begin"}, /* terminfo */
+ {"*6", "select"}, /* terminfo */
+ {"%9", "print"}, /* terminfo */
+ {"@4", "execute"}, /* terminfo --- actually the `command' key */
/*
* "insert" --- see below
*/
- "&8", "undo", /* terminfo */
- "%0", "redo", /* terminfo */
- "%7", "menu", /* terminfo --- actually the `options' key */
- "@0", "find", /* terminfo */
- "@2", "cancel", /* terminfo */
- "%1", "help", /* terminfo */
+ {"&8", "undo"}, /* terminfo */
+ {"%0", "redo"}, /* terminfo */
+ {"%7", "menu"}, /* terminfo --- actually the `options' key */
+ {"@0", "find"}, /* terminfo */
+ {"@2", "cancel"}, /* terminfo */
+ {"%1", "help"}, /* terminfo */
/*
* "break" goes here, but can't be reliably intercepted with termcap
*/
- "&4", "reset", /* terminfo --- actually `restart' */
+ {"&4", "reset"}, /* terminfo --- actually `restart' */
/*
* "system" and "user" --- no termcaps
*/
- "kE", "clearline", /* terminfo */
- "kA", "insertline", /* terminfo */
- "kL", "deleteline", /* terminfo */
- "kI", "insertchar", /* terminfo */
- "kD", "deletechar", /* terminfo */
- "kB", "backtab", /* terminfo */
+ {"kE", "clearline"}, /* terminfo */
+ {"kA", "insertline"}, /* terminfo */
+ {"kL", "deleteline"}, /* terminfo */
+ {"kI", "insertchar"}, /* terminfo */
+ {"kD", "deletechar"}, /* terminfo */
+ {"kB", "backtab"}, /* terminfo */
/*
* "kp_backtab", "kp-space", "kp-tab" --- no termcaps
*/
- "@8", "kp-enter", /* terminfo */
+ {"@8", "kp-enter"}, /* terminfo */
/*
* "kp-f1", "kp-f2", "kp-f3" "kp-f4",
* "kp-multiply", "kp-add", "kp-separator",
* "kp-subtract", "kp-decimal", "kp-divide", "kp-0";
* --- no termcaps for any of these.
*/
- "K4", "kp-1", /* terminfo */
+ {"K4", "kp-1"}, /* terminfo */
/*
* "kp-2" --- no termcap
*/
- "K5", "kp-3", /* terminfo */
+ {"K5", "kp-3"}, /* terminfo */
/*
* "kp-4" --- no termcap
*/
- "K2", "kp-5", /* terminfo */
+ {"K2", "kp-5"}, /* terminfo */
/*
* "kp-6" --- no termcap
*/
- "K1", "kp-7", /* terminfo */
+ {"K1", "kp-7"}, /* terminfo */
/*
* "kp-8" --- no termcap
*/
- "K3", "kp-9", /* terminfo */
+ {"K3", "kp-9"}, /* terminfo */
/*
* "kp-equal" --- no termcap
*/
- "k1", "f1",
- "k2", "f2",
- "k3", "f3",
- "k4", "f4",
- "k5", "f5",
- "k6", "f6",
- "k7", "f7",
- "k8", "f8",
- "k9", "f9",
+ {"k1", "f1"},
+ {"k2", "f2"},
+ {"k3", "f3"},
+ {"k4", "f4"},
+ {"k5", "f5"},
+ {"k6", "f6"},
+ {"k7", "f7"},
+ {"k8", "f8"},
+ {"k9", "f9"}
};
static char **term_get_fkeys_arg;
&& MAY_USE_WITH_COLORS_P (NC_BLINK))
OUTPUT1_IF (TS_enter_blink_mode);
- if (face->tty_underline_p
- /* Don't underline if that's difficult. */
- && TN_magic_cookie_glitch_ul <= 0
- && MAY_USE_WITH_COLORS_P (NC_UNDERLINE))
+ if (face->tty_underline_p && MAY_USE_WITH_COLORS_P (NC_UNDERLINE))
OUTPUT1_IF (TS_enter_underline_mode);
if (TN_max_colors > 0)
if (face->tty_alt_charset_p)
OUTPUT_IF (TS_exit_alt_charset_mode);
- if (face->tty_underline_p
- /* We don't underline if that's difficult. */
- && TN_magic_cookie_glitch_ul <= 0)
+ if (face->tty_underline_p)
OUTPUT_IF (TS_exit_underline_mode);
}
return TN_max_colors > 0 ? Qt : Qnil;
}
+#ifndef WINDOWSNT
+/* Save or restore the default color-related capabilities of this
+ terminal. */
+static void
+tty_default_color_capabilities (save)
+ int save;
+{
+ static char
+ *default_orig_pair, *default_set_foreground, *default_set_background;
+ static int default_max_colors, default_max_pairs, default_no_color_video;
+
+ if (save)
+ {
+ if (default_orig_pair)
+ xfree (default_orig_pair);
+ default_orig_pair = TS_orig_pair ? xstrdup (TS_orig_pair) : NULL;
+
+ if (default_set_foreground)
+ xfree (default_set_foreground);
+ default_set_foreground = TS_set_foreground ? xstrdup (TS_set_foreground)
+ : NULL;
+
+ if (default_set_background)
+ xfree (default_set_background);
+ default_set_background = TS_set_background ? xstrdup (TS_set_background)
+ : NULL;
+
+ default_max_colors = TN_max_colors;
+ default_max_pairs = TN_max_pairs;
+ default_no_color_video = TN_no_color_video;
+ }
+ else
+ {
+ TS_orig_pair = default_orig_pair;
+ TS_set_foreground = default_set_foreground;
+ TS_set_background = default_set_background;
+ TN_max_colors = default_max_colors;
+ TN_max_pairs = default_max_pairs;
+ TN_no_color_video = default_no_color_video;
+ }
+}
+
+/* Setup one of the standard tty color schemes according to MODE.
+ MODE's value is generally the number of colors which we want to
+ support; zero means set up for the default capabilities, the ones
+ we saw at term_init time; -1 means turn off color support. */
+void
+tty_setup_colors (mode)
+ int mode;
+{
+ switch (mode)
+ {
+ case -1: /* no colors at all */
+ TN_max_colors = 0;
+ TN_max_pairs = 0;
+ TN_no_color_video = 0;
+ TS_set_foreground = TS_set_background = TS_orig_pair = NULL;
+ break;
+ case 0: /* default colors, if any */
+ default:
+ tty_default_color_capabilities (0);
+ break;
+ case 8: /* 8 standard ANSI colors */
+ TS_orig_pair = "\033[0m";
+#ifdef TERMINFO
+ TS_set_foreground = "\033[3%p1%dm";
+ TS_set_background = "\033[4%p1%dm";
+#else
+ TS_set_foreground = "\033[3%dm";
+ TS_set_background = "\033[4%dm";
+#endif
+ TN_max_colors = 8;
+ TN_max_pairs = 64;
+ TN_no_color_video = 0;
+ break;
+ }
+}
+
+void
+set_tty_color_mode (f, val)
+ struct frame *f;
+ Lisp_Object val;
+{
+ Lisp_Object color_mode_spec, current_mode_spec, tem;
+ Lisp_Object color_mode, current_mode;
+ int mode, old_mode;
+ extern Lisp_Object Qtty_color_mode;
+ Lisp_Object tty_color_mode_alist;
+
+ tty_color_mode_alist = Fintern_soft (build_string ("tty-color-mode-alist"),
+ Qnil);
+
+ if (NATNUMP (val))
+ color_mode = val;
+ else
+ {
+ if (NILP (tty_color_mode_alist))
+ color_mode_spec = Qnil;
+ else
+ color_mode_spec = Fassq (val, XSYMBOL (tty_color_mode_alist)->value);
+ current_mode_spec = assq_no_quit (Qtty_color_mode, f->param_alist);
+
+ if (CONSP (color_mode_spec))
+ color_mode = XCDR (color_mode_spec);
+ else
+ color_mode = Qnil;
+ }
+ if (CONSP (current_mode_spec))
+ current_mode = XCDR (current_mode_spec);
+ else
+ current_mode = Qnil;
+ if (NATNUMP (color_mode))
+ mode = XINT (color_mode);
+ else
+ mode = 0; /* meaning default */
+ if (NATNUMP (current_mode))
+ old_mode = XINT (current_mode);
+ else
+ old_mode = 0;
+
+ if (mode != old_mode)
+ {
+ tty_setup_colors (mode);
+ /* This recomputes all the faces given the new color
+ definitions. */
+ call0 (intern ("tty-set-up-initial-frame-faces"));
+ redraw_frame (f);
+ }
+}
+
+#endif /* !WINDOWSNT */
\f
/***********************************************************************
TS_enter_underline_mode = tgetstr ("us", address);
TS_exit_underline_mode = tgetstr ("ue", address);
- TN_magic_cookie_glitch_ul = tgetnum ("ug");
TS_enter_bold_mode = tgetstr ("md", address);
TS_enter_dim_mode = tgetstr ("mh", address);
TS_enter_blink_mode = tgetstr ("mb", address);
TN_no_color_video = 0;
}
+ tty_default_color_capabilities (1);
+
MagicWrap = tgetflag ("xn");
/* Since we make MagicWrap terminals look like AutoWrap, we need to have
the former flag imply the latter. */
TF_insmode_motion = tgetflag ("mi");
TF_standout_motion = tgetflag ("ms");
TF_underscore = tgetflag ("ul");
- TF_xs = tgetflag ("xs");
TF_teleray = tgetflag ("xt");
term_get_fkeys (address);
FRAME_HEIGHT (sf), FRAME_WIDTH (sf));
min_padding_speed = tgetnum ("pb");
- TN_standout_width = tgetnum ("sg");
TabWidth = tgetnum ("tw");
#ifdef VMS
Wcm.cm_tab = "\t";
*/
+ /* We don't support standout modes that use `magic cookies', so
+ turn off any that do. */
+ if (TS_standout_mode && tgetnum ("sg") >= 0)
+ {
+ TS_standout_mode = 0;
+ TS_end_standout_mode = 0;
+ }
+ if (TS_enter_underline_mode && tgetnum ("ug") >= 0)
+ {
+ TS_enter_underline_mode = 0;
+ TS_exit_underline_mode = 0;
+ }
+
+ /* If there's no standout mode, try to use underlining instead. */
if (TS_standout_mode == 0)
{
- TN_standout_width = tgetnum ("ug");
- TS_end_standout_mode = tgetstr ("ue", address);
- TS_standout_mode = tgetstr ("us", address);
+ TS_standout_mode = TS_enter_underline_mode;
+ TS_end_standout_mode = TS_exit_underline_mode;
}
/* If no `se' string, try using a `me' string instead.
if (TF_teleray)
{
Wcm.cm_tab = 0;
- /* Teleray: most programs want a space in front of TS_standout_mode,
- but Emacs can do without it (and give one extra column). */
- TS_standout_mode = "\033RD";
- TN_standout_width = 1;
+ /* We can't support standout mode, because it uses magic cookies. */
+ TS_standout_mode = 0;
/* But that means we cannot rely on ^M to go to column zero! */
CR = 0;
/* LF can't be trusted either -- can alter hpos */
&& TS_end_standout_mode
&& !strcmp (TS_standout_mode, TS_end_standout_mode));
- /* Remove width of standout marker from usable width of line */
- if (TN_standout_width > 0)
- SET_FRAME_WIDTH (sf, FRAME_WIDTH (sf) - TN_standout_width);
-
UseTabs = tabs_safe_p () && TabWidth == 8;
scroll_region_ok