Skip to content

Commit 9a6e2ac

Browse files
committed
Implement dynamic 8-bit color palettes
1 parent e20e1f7 commit 9a6e2ac

50 files changed

Lines changed: 390 additions & 210 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/actions/spelling/allow/apis.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,8 @@ xlocnum
213213
xloctime
214214
XMax
215215
xmemory
216+
XMVECTOR
217+
XMVECTORF
216218
XParse
217219
xpath
218220
xstddef

.github/actions/spelling/expect/expect.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,7 @@ codepages
198198
coinit
199199
colorizing
200200
COLORONCOLOR
201+
colorref
201202
COLORREFs
202203
colorschemes
203204
colorspec

src/cascadia/TerminalControl/ControlCore.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1022,6 +1022,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation
10221022
.scheme = renderSettings.GetColorTable(),
10231023
.foregroundAlias = renderSettings.GetColorAliasIndex(ColorAlias::DefaultForeground),
10241024
.backgroundAlias = renderSettings.GetColorAliasIndex(ColorAlias::DefaultBackground),
1025+
.generatePalette = renderSettings.GetRenderMode(Render::RenderSettings::Mode::Generate256Colors),
10251026
};
10261027
}
10271028
_terminal->UpdateColorScheme(scheme);
@@ -1041,6 +1042,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation
10411042
}
10421043
renderSettings.SetColorAliasIndex(ColorAlias::DefaultForeground, stashedScheme.foregroundAlias);
10431044
renderSettings.SetColorAliasIndex(ColorAlias::DefaultBackground, stashedScheme.backgroundAlias);
1045+
renderSettings.SetRenderMode(Render::RenderSettings::Mode::Generate256Colors, stashedScheme.generatePalette);
10441046
_renderer->TriggerRedrawAll(true);
10451047
}
10461048
_stashedColorScheme.reset();

src/cascadia/TerminalControl/ControlCore.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation
428428
std::array<COLORREF, TextColor::TABLE_SIZE> scheme;
429429
size_t foregroundAlias;
430430
size_t backgroundAlias;
431+
bool generatePalette;
431432
};
432433
std::unique_ptr<StashedColorScheme> _stashedColorScheme;
433434

src/cascadia/TerminalCore/ICoreSettings.idl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ namespace Microsoft.Terminal.Core
101101
Boolean IntenseIsBold { get; };
102102
Boolean IntenseIsBright { get; };
103103
AdjustTextMode AdjustIndistinguishableColors { get; };
104+
Boolean GeneratePalette { get; };
104105

105106
// NOTE! When adding something here, make sure to update ControlProperties.h too!
106107
};

src/cascadia/TerminalCore/Terminal.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ void Terminal::UpdateAppearance(const ICoreAppearance& appearance)
141141
{
142142
auto& renderSettings = GetRenderSettings();
143143

144+
renderSettings.SetRenderMode(RenderSettings::Mode::Generate256Colors, appearance.GeneratePalette());
144145
renderSettings.SetRenderMode(RenderSettings::Mode::IntenseIsBold, appearance.IntenseIsBold());
145146
renderSettings.SetRenderMode(RenderSettings::Mode::IntenseIsBright, appearance.IntenseIsBright());
146147

@@ -1230,7 +1231,7 @@ void Terminal::_clearPatternTree()
12301231
// Method Description:
12311232
// - Returns the tab color
12321233
// If the starting color exists, its value is preferred
1233-
const std::optional<til::color> Terminal::GetTabColor() const
1234+
const std::optional<til::color> Terminal::GetTabColor()
12341235
{
12351236
if (_startingTabColor.has_value())
12361237
{
@@ -1493,14 +1494,14 @@ std::vector<MarkExtents> Terminal::GetMarkExtents() const
14931494
return _inAltBuffer() ? std::vector<MarkExtents>{} : _activeBuffer().GetMarkExtents();
14941495
}
14951496

1496-
til::color Terminal::GetColorForMark(const ScrollbarData& markData) const
1497+
til::color Terminal::GetColorForMark(const ScrollbarData& markData)
14971498
{
14981499
if (markData.color.has_value())
14991500
{
15001501
return *markData.color;
15011502
}
15021503

1503-
const auto& renderSettings = GetRenderSettings();
1504+
auto& renderSettings = GetRenderSettings();
15041505

15051506
switch (markData.category)
15061507
{

src/cascadia/TerminalCore/Terminal.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ class Microsoft::Terminal::Core::Terminal final :
166166

167167
void ClearMark();
168168
void ClearAllMarks();
169-
til::color GetColorForMark(const ScrollbarData& markData) const;
169+
til::color GetColorForMark(const ScrollbarData& markData);
170170

171171
#pragma region ITerminalInput
172172
// These methods are defined in Terminal.cpp
@@ -206,7 +206,7 @@ class Microsoft::Terminal::Core::Terminal final :
206206
std::wstring GetHyperlinkCustomId(uint16_t id) const override;
207207
std::vector<size_t> GetPatternId(const til::point location) const override;
208208

209-
std::pair<COLORREF, COLORREF> GetAttributeColors(const TextAttribute& attr) const noexcept override;
209+
std::pair<COLORREF, COLORREF> GetAttributeColors(const TextAttribute& attr) noexcept override;
210210
std::span<const til::point_span> GetSelectionSpans() const noexcept override;
211211
std::span<const til::point_span> GetSearchHighlights() const noexcept override;
212212
const til::point_span* GetSearchHighlightFocused() const noexcept override;
@@ -238,7 +238,7 @@ class Microsoft::Terminal::Core::Terminal final :
238238

239239
void UpdatePatternsUnderLock();
240240

241-
const std::optional<til::color> GetTabColor() const;
241+
const std::optional<til::color> GetTabColor();
242242

243243
const size_t GetTaskbarState() const noexcept;
244244
const size_t GetTaskbarProgress() const noexcept;
@@ -311,7 +311,7 @@ class Microsoft::Terminal::Core::Terminal final :
311311
til::point SelectionEndForRendering() const;
312312
SelectionEndpoint SelectionEndpointTarget() const noexcept;
313313

314-
TextCopyData RetrieveSelectedTextFromBuffer(const bool singleLine, const bool withControlSequences = false, const bool html = false, const bool rtf = false) const;
314+
TextCopyData RetrieveSelectedTextFromBuffer(const bool singleLine, const bool withControlSequences = false, const bool html = false, const bool rtf = false);
315315
#pragma endregion
316316

317317
#ifndef NDEBUG

src/cascadia/TerminalCore/TerminalSelection.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -959,7 +959,7 @@ void Terminal::ClearSelection()
959959
// Return Value:
960960
// - Plain and formatted selected text from buffer. Empty string represents no data for that format.
961961
// - If extended to multiple lines, each line is separated by \r\n
962-
Terminal::TextCopyData Terminal::RetrieveSelectedTextFromBuffer(const bool singleLine, const bool withControlSequences, const bool html, const bool rtf) const
962+
Terminal::TextCopyData Terminal::RetrieveSelectedTextFromBuffer(const bool singleLine, const bool withControlSequences, const bool html, const bool rtf)
963963
{
964964
TextCopyData data;
965965

src/cascadia/TerminalCore/terminalrenderdata.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ std::vector<size_t> Terminal::GetPatternId(const til::point location) const
9999
return {};
100100
}
101101

102-
std::pair<COLORREF, COLORREF> Terminal::GetAttributeColors(const TextAttribute& attr) const noexcept
102+
std::pair<COLORREF, COLORREF> Terminal::GetAttributeColors(const TextAttribute& attr) noexcept
103103
{
104104
return GetRenderSettings().GetAttributeColors(attr);
105105
}

src/cascadia/TerminalSettingsAppAdapterLib/TerminalSettings.cpp

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -230,21 +230,21 @@ namespace winrt::Microsoft::Terminal::Settings
230230
break;
231231
}
232232

233-
if (appearance.Foreground())
233+
if (const auto v = appearance.Foreground())
234234
{
235-
_DefaultForeground = til::color{ appearance.Foreground().Value() };
235+
_DefaultForeground = til::color{ v.Value() };
236236
}
237-
if (appearance.Background())
237+
if (const auto v = appearance.Background())
238238
{
239-
_DefaultBackground = til::color{ appearance.Background().Value() };
239+
_DefaultBackground = til::color{ v.Value() };
240240
}
241-
if (appearance.SelectionBackground())
241+
if (const auto v = appearance.SelectionBackground())
242242
{
243-
_SelectionBackground = til::color{ appearance.SelectionBackground().Value() };
243+
_SelectionBackground = til::color{ v.Value() };
244244
}
245-
if (appearance.CursorColor())
245+
if (const auto v = appearance.CursorColor())
246246
{
247-
_CursorColor = til::color{ appearance.CursorColor().Value() };
247+
_CursorColor = til::color{ v.Value() };
248248
}
249249

250250
if (const auto backgroundImage{ appearance.BackgroundImagePath() })
@@ -272,6 +272,7 @@ namespace winrt::Microsoft::Terminal::Settings
272272
_IntenseIsBright = WI_IsFlagSet(appearance.IntenseTextStyle(), Microsoft::Terminal::Settings::Model::IntenseStyle::Bright);
273273

274274
_AdjustIndistinguishableColors = appearance.AdjustIndistinguishableColors();
275+
_GeneratePalette = appearance.GeneratePalette();
275276
_Opacity = appearance.Opacity();
276277
_UseAcrylic = appearance.UseAcrylic();
277278
}

0 commit comments

Comments
 (0)