Skip to content

Commit

Permalink
Merge pull request #1386 from contour-terminal/feature/default-text-b…
Browse files Browse the repository at this point in the history
…right

Add config option to customize default bold/bright and dimmed foreground colors
  • Loading branch information
christianparpart committed Dec 25, 2023
2 parents 480d109 + 2117299 commit 6aaed91
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 13 deletions.
6 changes: 5 additions & 1 deletion docs/configuration/colors.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,15 @@ color_schemes:
default:
background: '#1a1716'
foreground: '#d0d0d0'
bright_foreground: '#ffffff'
dimmed_foreground: '#808080'


```
:octicons-horizontal-rule-16: ==background== determines the default background color of the terminal. <br/>
:octicons-horizontal-rule-16: ==foreground== option sets the default foreground text color of the terminal.
:octicons-horizontal-rule-16: ==foreground== option sets the default foreground text color of the terminal. <br/>
:octicons-horizontal-rule-16: ==bright\_foreground== option sets the default foreground text color of the terminal when text text is instructed to be bold (/bright). This is only used if profile option `draw_bold_text_with_bright_colors` is set to `true`<br/>
:octicons-horizontal-rule-16: ==dimmed\_foreground== option sets the default foreground text color of the terminal when text text is instructed to be dimmed. <br/>



Expand Down
1 change: 1 addition & 0 deletions metainfo.xml
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@
<li>Remove `contour-latest` terminfo file. Please use `contour` terminfo instead.</li>
<li>Adds `Command` as modifier to input mappings on MacOS to work along with `Meta` for convenience reasons (#1379).</li>
<li>Adds config option `profiles.*.margins` to allow customizing the horizontal / vertical margins (#1384).</li>
<li>Adds config option for colorscheme `default.bright_foreground` and `default.dimmed_foreground` to configure bright and dimmed default foreground text respectively (#1383).</li>
</ul>
</description>
</release>
Expand Down
10 changes: 10 additions & 0 deletions src/contour/Config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1030,6 +1030,16 @@ namespace
usedKeys.emplace(basePath + ".default.foreground");
colors.defaultForeground = fg.as<string>();
}
if (auto fg = def["bright_foreground"]; fg)
{
usedKeys.emplace(basePath + ".default.bright_foreground");
colors.defaultForegroundBright = fg.as<string>();
}
if (auto fg = def["dimmed_foreground"]; fg)
{
usedKeys.emplace(basePath + ".default.dimmed_foreground");
colors.defaultForegroundDimmed = fg.as<string>();
}
if (auto bg = def["background"]; bg)
{
usedKeys.emplace(basePath + ".default.background");
Expand Down
33 changes: 21 additions & 12 deletions src/vtbackend/ColorPalette.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,32 +97,41 @@ void ImageData::updateHash() noexcept

RGBColor apply(ColorPalette const& colorPalette, Color color, ColorTarget target, ColorMode mode) noexcept
{
// clang-format off
switch (color.type())
{
case ColorType::RGB:
case ColorType::RGB: {
return color.rgb();
case ColorType::Indexed:
{
}
case ColorType::Indexed: {
auto const index = static_cast<size_t>(color.index());
if (mode == ColorMode::Bright && index < 8)
return colorPalette.brightColor(index);
else if (mode == ColorMode::Dimmed && index < 8)
return colorPalette.dimColor(index);
else
return colorPalette.indexedColor(index);
break;
}
case ColorType::Bright:
case ColorType::Bright: {
return colorPalette.brightColor(static_cast<size_t>(color.index()));
}
case ColorType::Undefined:
case ColorType::Default:
break;
case ColorType::Default: {
if (target == ColorTarget::Foreground)
{
switch (mode)
{
case ColorMode::Normal: return colorPalette.defaultForeground;
case ColorMode::Bright: return colorPalette.defaultForegroundBright;
case ColorMode::Dimmed: return colorPalette.defaultForegroundDimmed;
}
}
else
{
return colorPalette.defaultBackground;
}
}
}
// clang-format on
auto const defaultColor =
target == ColorTarget::Foreground ? colorPalette.defaultForeground : colorPalette.defaultBackground;
return mode == ColorMode::Dimmed ? defaultColor * 0.75 : defaultColor;
crispy::unreachable();
}

} // namespace vtbackend
2 changes: 2 additions & 0 deletions src/vtbackend/ColorPalette.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ struct ColorPalette
}

RGBColor defaultForeground = 0xD0D0D0_rgb;
RGBColor defaultForegroundBright = 0xFFFFFF_rgb;
RGBColor defaultForegroundDimmed = 0x808080_rgb;
RGBColor defaultBackground = 0x000000_rgb;

CursorColor cursor;
Expand Down
9 changes: 9 additions & 0 deletions test/dimmed-bold-bright-text.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#! /bin/bash

DIMMED="DIMMED █"
NORMAL="█ NORMAL █"
BOLD_OR_BRIGHT="█ BOLD/BRIGHT"

for i in {0..8} ; do
printf "${i}: \e[0;2;3${i}m${DIMMED}\e[0;3${i}m${NORMAL}\e[0;1;3${i}m${BOLD_OR_BRIGHT}\e[0m\n"
done

0 comments on commit 6aaed91

Please sign in to comment.