#include "termchar.h"
#include "termopts.h"
#include "lisp.h"
+#include "buffer.h"
+#include "character.h"
#include "charset.h"
#include "coding.h"
#include "keyboard.h"
}
}
- result = encode_coding (coding, buf, dst, len, dst_end - dst);
+ coding->source = buf;
+ coding->destination = dst;
+ coding->dst_bytes = dst_end - dst;
+ encode_coding_object (coding, Qnil, 0, 0, 1, len, Qnil);
len -= coding->consumed;
dst += coding->produced;
- if (result == CODING_FINISH_INSUFFICIENT_DST
- || (result == CODING_FINISH_INSUFFICIENT_SRC
- && len > dst_end - dst))
+ if (coding->result == CODING_RESULT_INSUFFICIENT_DST)
/* The remaining output buffer is too short. We must
break the loop here without increasing SRC so that the
next call of this function starts from the same glyph. */
if (CODING_REQUIRE_FLUSHING (&terminal_coding))
{
terminal_coding.mode |= CODING_MODE_LAST_BLOCK;
- encode_coding (&terminal_coding, "", conversion_buffer,
- 0, conversion_buffer_size);
+ terminal_coding.source = (unsigned char *) "";
+ terminal_coding.destination = conversion_buffer;
+ terminal_coding.dst_bytes = conversion_buffer_size;
+ encode_coding_object (&terminal_coding, Qnil, 0, 0, 0, 0, Qnil);
if (terminal_coding.produced > 0)
{
fwrite (conversion_buffer, 1, terminal_coding.produced, stdout);
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)));
}
}
else
{
- /* A multi-byte character. The display width is fixed for all
- characters of the set. Some of the glyphs may have to be
- ignored because they are already displayed in a continued
- line. */
- int charset = CHAR_CHARSET (it->c);
-
- it->pixel_width = CHARSET_WIDTH (charset);
+ it->pixel_width = CHAR_WIDTH (it->c);
it->nglyphs = it->pixel_width;
if (it->glyph_row)
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
+ 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;
+ 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
/***********************************************************************
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. */
Vring_bell_function = Qnil;
defsubr (&Stty_display_color_p);
+ defsubr (&Stty_display_color_cells);
}