Skip to content

Commit

Permalink
Merge pull request #1547 from contour-terminal/improvements/config_in…
Browse files Browse the repository at this point in the history
…dicator_statusline

Add mode dependent configuration for indicator statusline colors
  • Loading branch information
christianparpart committed Jun 30, 2024
2 parents 4b2ab0c + 9f07325 commit 7fa8576
Show file tree
Hide file tree
Showing 6 changed files with 83 additions and 51 deletions.
42 changes: 19 additions & 23 deletions docs/configuration/colors.md
Original file line number Diff line number Diff line change
Expand Up @@ -172,37 +172,33 @@ color_schemes:


### `indicator_statusline`
Defines the colors to be used for the Indicator status line.
Defines the colors to be used for the Indicator status line. Configuration entry consist of following sections, namely `default`, `inactive`, `insert_mode`, `normal_mode`, `visual_mode`. Each section have `foreground` and `background` options. You can specify only the sections you want to customize after configuring the `default` section.
Minimal configuration looks like this:
``` yaml
color_schemes:
default:
indicator_statusline:
foreground: '#808080'
background: '#000000'
```



### `indicator_statusline_inactive`
Alternate colors to be used for the indicator status line when this terminal is currently not in focus.
``` yaml
color_schemes:
default:
indicator_statusline_inactive:
foreground: '#808080'
background: '#000000'
default:
foreground: '#808080'
background: '#000000'
```



### `input_method_editor`
Colors for the IME (Input Method Editor) area.
Complete configuration looks like this:
``` yaml
color_schemes:
default:
indicator_statusline_inactive:
foreground: '#808080'
background: '#000000'
indicator_statusline:
default:
foreground: '#FFFFFF'
background: '#0270C0'
inactive:
foreground: '#FFFFFF'
background: '#0270C0'
normal_mode:
foreground: '#0f0002'
background: '#0270C0'
visual_mode:
foreground: '#ffffff'
background: '#0270C0'
```


Expand Down
1 change: 1 addition & 0 deletions metainfo.xml
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@
<li>Add handling of different input commands (#629)</li>
<li>Add key bindings disabled indicator for status line (#783)</li>
<li>When switching to normal mode screen will stay in same position (#808)</li>
<li>Add customizable per-input-mode default text/background coloring for indicator statusline (#1528)</li>
<li>Update of contour.desktop file (#1423)</li>
<li>Changed configuration entry values for `font_locator` down to `native` and `mock` only (#1538).</li>
<li>Fixes forwarding of input while in normal mode (#1468)</li>
Expand Down
46 changes: 33 additions & 13 deletions src/contour/Config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -514,16 +514,38 @@ void YAMLConfigReader::loadFromEntry(YAML::Node const& node, vtbackend::ColorPal

loadWithLog("cursor", where.cursor);
loadWithLog("vi_mode_highlight", where.yankHighlight);
loadWithLog("vi_mode_cursosrline", where.indicatorStatusLine);
loadWithLog("vi_mode_cursosrline", where.normalModeCursorline);
loadWithLog("selection", where.selection);
loadWithLog("search_highlight", where.searchHighlight);
loadWithLog("search_highlight_focused", where.searchHighlightFocused);
loadWithLog("word_highlight_current", where.wordHighlightCurrent);
loadWithLog("word_highlight_other", where.wordHighlight);
loadWithLog("indicator_statusline", where.indicatorStatusLine);
loadWithLog("indicator_statusline_inactive", where.indicatorStatusLineInactive);
loadWithLog("input_method_editor", where.inputMethodEditor);

if (child["indicator_statusline"])
{
logger()("*** loading indicator_statusline");
if (child["indicator_statusline"]["default"])
{
logger()("*** loading default indicator_statusline");
vtbackend::RGBColorPair defaultIndicatorStatusLine;
loadFromEntry(child["indicator_statusline"], "default", defaultIndicatorStatusLine);
where.indicatorStatusLineInactive = defaultIndicatorStatusLine;
where.indicatorStatusLineNormalMode = defaultIndicatorStatusLine;
where.indicatorStatusLineVisualMode = defaultIndicatorStatusLine;
}
for (auto const& [name, defaultColor]:
{ pair { "inactive", &where.indicatorStatusLineInactive },
pair { "normal_mode", &where.indicatorStatusLineNormalMode },
pair { "visual_mode", &where.indicatorStatusLineVisualMode } })
{
if (child["indicator_statusline"][name])
{
logger()("*** loading {} indicator_statusline", name);
loadFromEntry(child["indicator_statusline"], name, defaultColor);
}
}
}
logger()("*** loading pallete");
loadFromEntry(child, "", where.palette);
}
Expand Down Expand Up @@ -1255,12 +1277,12 @@ void YAMLConfigReader::loadFromEntry(YAML::Node const& node, std::string const&
{
if (tryAddKey(where, *mode, *mods, mapping["key"], *action))
{
logger()(
"Adding input mapping: mods: {:<20} modifiers: {:<20} key: {:<20} action: {:<20}",
*mods,
*mode,
mapping["key"].as<std::string>(),
*action);
logger()("Adding input mapping: mods: {:<20} modifiers: {:<20} key: {:<20} "
"action: {:<20}",
*mods,
*mode,
mapping["key"].as<std::string>(),
*action);
}
else if (tryAddMouse(where.mouseMappings, *mode, *mods, mapping["mouse"], *action))
{
Expand Down Expand Up @@ -2139,10 +2161,8 @@ std::string createString(Config const& c)
entry.wordHighlight.backgroundAlpha);

processWithDoc(documentation::IndicatorStatusLine,
entry.indicatorStatusLine.foreground,
entry.indicatorStatusLine.background);

processWithDoc(documentation::IndicatorStatusLineInactive,
entry.indicatorStatusLineInsertMode.foreground,
entry.indicatorStatusLineInsertMode.background,
entry.indicatorStatusLineInactive.foreground,
entry.indicatorStatusLineInactive.background);

Expand Down
21 changes: 9 additions & 12 deletions src/contour/ConfigDocumentation.h
Original file line number Diff line number Diff line change
Expand Up @@ -943,19 +943,16 @@ constexpr StringLiteral WordHighlight {
constexpr StringLiteral IndicatorStatusLine {
"\n"
"{comment} Defines the colors to be used for the Indicator status line.\n"
"{comment} Values must be in RGB form.\n"
"{comment} Configuration consist of different sections: default, inactive, insert_mode, normal_mode, "
"visual_mode.\n"
"{comment} Each section customize status line colors for corresponding mode.\n"
"indicator_statusline:\n"
" foreground: {}\n"
" background: {}\n"
};

constexpr StringLiteral IndicatorStatusLineInactive {
"\n"
"{comment} Alternate colors to be used for the indicator status line when\n"
"{comment} this terminal is currently not in focus.\n"
"indicator_statusline_inactive:\n"
" foreground: {}\n"
" background: {}\n"
" default:\n"
" foreground: {}\n"
" background: {}\n"
" inactive:\n"
" foreground: {}\n"
" background: {}\n"
};

constexpr StringLiteral InputMethodEditor { "\n"
Expand Down
4 changes: 3 additions & 1 deletion src/vtbackend/ColorPalette.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,10 @@ struct ColorPalette
CellRGBColorAndAlphaPair normalModeCursorline = { 0xFFFFFF_rgb, 0.2f, 0x808080_rgb, 0.4f };
// clang-format on

RGBColorPair indicatorStatusLine = { 0xFFFFFF_rgb, 0x0270c0_rgb };
RGBColorPair indicatorStatusLineInactive = { 0xFFFFFF_rgb, 0x0270c0_rgb };
RGBColorPair indicatorStatusLineInsertMode = { 0xFFFFFF_rgb, 0x0270c0_rgb };
RGBColorPair indicatorStatusLineNormalMode = { 0xFFFFFF_rgb, 0x0270c0_rgb };
RGBColorPair indicatorStatusLineVisualMode = { 0xFFFFFF_rgb, 0x0270c0_rgb };
};

enum class ColorTarget : uint8_t
Expand Down
20 changes: 18 additions & 2 deletions src/vtbackend/Terminal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -539,8 +539,24 @@ void Terminal::updateIndicatorStatusLine()
{
Require(_activeStatusDisplay != ActiveStatusDisplay::IndicatorStatusLine);

auto const colors =
_focused ? colorPalette().indicatorStatusLine : colorPalette().indicatorStatusLineInactive;
auto const colors = [&]() {
if (!_focused)
{
return colorPalette().indicatorStatusLineInactive;
}
else
{
switch (_inputHandler.mode())
{
case ViMode::Insert: return colorPalette().indicatorStatusLineInsertMode;
case ViMode::Normal: return colorPalette().indicatorStatusLineNormalMode;
case ViMode::Visual:
case ViMode::VisualLine:
case ViMode::VisualBlock: return colorPalette().indicatorStatusLineVisualMode;
}
}
crispy::unreachable();
}();

auto const backupForeground = _colorPalette.defaultForeground;
auto const backupBackground = _colorPalette.defaultBackground;
Expand Down

0 comments on commit 7fa8576

Please sign in to comment.