Commit 2e64b768 authored by Egmont Koblinger's avatar Egmont Koblinger

widget: Make dim color handling more xterm-like

https://bugzilla.gnome.org/show_bug.cgi?id=735245
parent 1d489818
......@@ -33,7 +33,6 @@ vte_terminal_get_rewrap_on_resize
vte_terminal_set_color_bold
vte_terminal_set_color_foreground
vte_terminal_set_color_background
vte_terminal_set_color_dim
vte_terminal_set_color_cursor
vte_terminal_set_color_highlight
vte_terminal_set_color_highlight_foreground
......
#!/usr/bin/env bash
# Test 256 color support along with bold and dim attributes.
# Copyright (C) 2014 Egmont Koblinger
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
format_number() {
local c=$'\u254F'
if [ $1 -lt 10 ]; then
printf "$c %d" $1
else
printf "$c%02d" $(($1%100))
fi
}
somecolors() {
local from="$1"
local to="$2"
local prefix="$3"
local line
for line in \
"\e[2mdim " \
"normal " \
"\e[1mbold " \
"\e[1;2mbold+dim "; do
echo -ne "$line"
i=$from
while [ $i -le $to ]; do
echo -ne "\e[$prefix${i}m"
format_number $i
i=$((i+1))
done
echo $'\e[0m\e[K'
done
}
allcolors() {
echo "-- 8 standard colors: SGR ${1}0..${1}7 --"
somecolors 0 7 "$1"
echo
echo "-- 8 bright colors: SGR ${2}0..${2}7 --"
somecolors 0 7 "$2"
echo
echo "-- 256 colors: SGR ${1}8;5;0..255 --"
somecolors 0 15 "${1}8;5;"
echo
somecolors 16 51 "${1}8;5;"
somecolors 52 87 "${1}8;5;"
somecolors 88 123 "${1}8;5;"
somecolors 124 159 "${1}8;5;"
somecolors 160 195 "${1}8;5;"
somecolors 196 231 "${1}8;5;"
echo
somecolors 232 255 "${1}8;5;"
}
allcolors 3 9
echo
allcolors 4 10
EXTRA_DIST = \
256test.sh \
UTF-8-demo.txt \
img.sh \
inc.sh \
......
......@@ -63,7 +63,7 @@ G_BEGIN_DECLS
* Colors set by SGR 256-color extension (38/48;5;index).
* These are direct indices into the color palette.
*
* 256 .. VTE_PALETTE_SIZE - 1 (262):
* 256 .. VTE_PALETTE_SIZE - 1 (261):
* Special values, such as default colors.
* These are direct indices into the color palette.
*
......@@ -71,6 +71,10 @@ G_BEGIN_DECLS
* Colors set by legacy escapes (30..37/40..47, 90..97/100..107).
* These are translated to 0 .. 15 before looking up in the palette, taking bold into account.
*
* VTE_DIM_COLORS (2^10) .. :
* Dimmed version of the above, for foreground colors.
* Cell attributes can't have these colors.
*
* VTE_RGB_COLOR (2^24) .. VTE_RGB_COLOR + 16Mi - 1 (2^25 - 1):
* Colors set by SGR truecolor extension (38/48;2;red;green;blue)
* These are direct RGB values.
......@@ -80,7 +84,7 @@ G_BEGIN_DECLS
#define VTE_LEGACY_FULL_COLOR_SET_SIZE 16
#define VTE_COLOR_PLAIN_OFFSET 0
#define VTE_COLOR_BRIGHT_OFFSET 8
#define VTE_COLOR_DIM_OFFSET 16
#define VTE_DIM_COLOR (1 << 10)
#define VTE_RGB_COLOR (1 << 24)
/* More color defines in vterowdata.h */
......
......@@ -289,10 +289,6 @@ G_DEFINE_TYPE_WITH_CODE(VteTerminal, vte_terminal, GTK_TYPE_WIDGET,
G_IMPLEMENT_INTERFACE(GTK_TYPE_SCROLLABLE, NULL))
#endif
/* Indexes in the "palette" color array for the dim colors.
* Only the first %VTE_LEGACY_COLOR_SET_SIZE colors have dim versions. */
static const guchar corresponding_dim_index[] = {16,88,28,100,18,90,30,102};
static void
vte_g_array_fill(GArray *array, gconstpointer item, guint final_size)
{
......@@ -2388,23 +2384,6 @@ _vte_terminal_set_color_bold(VteTerminal *terminal,
_vte_terminal_set_color_internal(terminal, VTE_BOLD_FG, VTE_COLOR_SOURCE_API, bold);
}
/*
* _vte_terminal_set_color_dim:
* @terminal: a #VteTerminal
* @dim: the new dim color
*
* Sets the color used to draw dim text in the default foreground color.
*/
static void
_vte_terminal_set_color_dim(VteTerminal *terminal,
const PangoColor *dim)
{
_vte_debug_print(VTE_DEBUG_MISC,
"Set dim color to (%04x,%04x,%04x).\n",
dim->red, dim->green, dim->blue);
_vte_terminal_set_color_internal(terminal, VTE_DIM_FG, VTE_COLOR_SOURCE_API, dim);
}
/*
* _vte_terminal_set_color_foreground:
* @terminal: a #VteTerminal
......@@ -2642,12 +2621,6 @@ _vte_terminal_set_colors(VteTerminal *terminal,
1.8,
&color);
break;
case VTE_DIM_FG:
vte_terminal_generate_bold(_vte_terminal_get_color(terminal, VTE_DEFAULT_FG),
_vte_terminal_get_color(terminal, VTE_DEFAULT_BG),
0.5,
&color);
break;
case VTE_HIGHLIGHT_BG:
unset = TRUE;
break;
......@@ -2714,37 +2687,6 @@ vte_terminal_set_color_bold(VteTerminal *terminal,
_vte_terminal_set_color_bold(terminal, &color);
}
/**
* vte_terminal_set_color_dim:
* @terminal: a #VteTerminal
* @dim: (allow-none): the new dim color or %NULL
*
* Sets the color used to draw dim text in the default foreground color.
* If @dim is %NULL then the default color is used.
*/
void
vte_terminal_set_color_dim(VteTerminal *terminal,
const GdkRGBA *dim)
{
PangoColor color;
g_return_if_fail(VTE_IS_TERMINAL(terminal));
if (dim == NULL)
{
vte_terminal_generate_bold(_vte_terminal_get_color(terminal, VTE_DEFAULT_FG),
_vte_terminal_get_color(terminal, VTE_DEFAULT_BG),
0.5,
&color);
}
else
{
_pango_color_from_rgba(&color, dim);
}
_vte_terminal_set_color_dim(terminal, &color);
}
/**
* vte_terminal_set_color_foreground:
* @terminal: a #VteTerminal
......@@ -5904,10 +5846,22 @@ vte_terminal_copy_cb(GtkClipboard *clipboard, GtkSelectionData *data,
static void
vte_terminal_get_rgb_from_index(const VteTerminal *terminal, guint index, PangoColor *color)
{
gboolean dim = FALSE;
if (!(index & VTE_RGB_COLOR) && (index & VTE_DIM_COLOR)) {
index &= ~VTE_DIM_COLOR;
dim = TRUE;
}
if (index >= VTE_LEGACY_COLORS_OFFSET && index < VTE_LEGACY_COLORS_OFFSET + VTE_LEGACY_FULL_COLOR_SET_SIZE)
index -= VTE_LEGACY_COLORS_OFFSET;
if (index < VTE_PALETTE_SIZE) {
memcpy(color, _vte_terminal_get_color(terminal, index), sizeof(PangoColor));
if (dim) {
/* magic formula taken from xterm */
color->red = color->red * 2 / 3;
color->green = color->green * 2 / 3;
color->blue = color->blue * 2 / 3;
}
} else if (index & VTE_RGB_COLOR) {
color->red = ((index >> 16) & 0xFF) * 257;
color->green = ((index >> 8) & 0xFF) * 257;
......@@ -8729,13 +8683,12 @@ vte_terminal_determine_colors_internal(VteTerminal *terminal,
}
}
/* Handle half similarly */
if (cell->attr.half) {
if (fore == VTE_DEFAULT_FG)
fore = VTE_DIM_FG;
else if (fore >= VTE_LEGACY_COLORS_OFFSET && fore < VTE_LEGACY_COLORS_OFFSET + VTE_LEGACY_COLOR_SET_SIZE)
fore = corresponding_dim_index[fore - VTE_LEGACY_COLORS_OFFSET];
}
/* Handle dim colors. Only apply to palette colors, dimming direct RGB wouldn't make sense.
* Apply to the foreground color only, but do this before handling reverse/highlight so that
* those can be used to dim the background instead. */
if (cell->attr.dim && !(fore & VTE_RGB_COLOR)) {
fore |= VTE_DIM_COLOR;
}
/* Reverse cell? */
if (cell->attr.reverse) {
......
......@@ -32,11 +32,10 @@ G_BEGIN_DECLS
#define VTE_DEFAULT_FG 256
#define VTE_DEFAULT_BG 257
#define VTE_BOLD_FG 258
#define VTE_DIM_FG 259
#define VTE_HIGHLIGHT_FG 260
#define VTE_HIGHLIGHT_BG 261
#define VTE_CURSOR_BG 262
#define VTE_PALETTE_SIZE 263
#define VTE_HIGHLIGHT_FG 259
#define VTE_HIGHLIGHT_BG 260
#define VTE_CURSOR_BG 261
#define VTE_PALETTE_SIZE 262
/*
* VteCellAttr: A single cell style attributes
......@@ -64,7 +63,7 @@ typedef struct _VteCellAttr {
guint64 reverse: 1;
guint64 blink: 1;
guint64 half: 1;
guint64 dim: 1; /* also known as faint, half intensity etc. */
guint64 invisible: 1;
/* 1 bit unused */
......
......@@ -1974,11 +1974,9 @@ vte_sequence_handler_character_attributes (VteTerminal *terminal, GValueArray *p
break;
case 1:
terminal->pvt->screen->defaults.attr.bold = 1;
terminal->pvt->screen->defaults.attr.half = 0;
break;
case 2:
terminal->pvt->screen->defaults.attr.half = 1;
terminal->pvt->screen->defaults.attr.bold = 0;
terminal->pvt->screen->defaults.attr.dim = 1;
break;
case 3:
terminal->pvt->screen->defaults.attr.italic = 1;
......@@ -2001,7 +1999,7 @@ vte_sequence_handler_character_attributes (VteTerminal *terminal, GValueArray *p
case 21: /* Error in old versions of linux console. */
case 22: /* ECMA 48. */
terminal->pvt->screen->defaults.attr.bold = 0;
terminal->pvt->screen->defaults.attr.half = 0;
terminal->pvt->screen->defaults.attr.dim = 0;
break;
case 23:
terminal->pvt->screen->defaults.attr.italic = 0;
......
......@@ -197,8 +197,6 @@ gboolean vte_terminal_get_rewrap_on_resize(VteTerminal *terminal) _VTE_GNUC_NONN
/* Set the color scheme. */
void vte_terminal_set_color_bold(VteTerminal *terminal,
const GdkRGBA *bold) _VTE_GNUC_NONNULL(1);
void vte_terminal_set_color_dim(VteTerminal *terminal,
const GdkRGBA *dim) _VTE_GNUC_NONNULL(1);
void vte_terminal_set_color_foreground(VteTerminal *terminal,
const GdkRGBA *foreground) _VTE_GNUC_NONNULL(1) _VTE_GNUC_NONNULL(2);
void vte_terminal_set_color_background(VteTerminal *terminal,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment