Reduce complexity of TerminalSettings::ColorTable
This commit is contained in:
parent
54ed295588
commit
e9b36d1bd8
|
@ -90,10 +90,8 @@ namespace winrt::SampleApp::implementation
|
||||||
|
|
||||||
MySettings()
|
MySettings()
|
||||||
{
|
{
|
||||||
const auto campbellSpan = ::Microsoft::Console::Utils::CampbellColorTable();
|
const auto& campbellSpan = ::Microsoft::Console::Utils::CampbellColorTable();
|
||||||
std::transform(campbellSpan.begin(), campbellSpan.end(), _ColorTable.begin(), [](auto&& color) {
|
std::copy(campbellSpan.begin(), campbellSpan.end(), _ColorTable.begin());
|
||||||
return static_cast<winrt::Microsoft::Terminal::Core::Color>(til::color{ color });
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -62,7 +62,7 @@ namespace Microsoft.Terminal.Core
|
||||||
{
|
{
|
||||||
Microsoft.Terminal.Core.Color DefaultForeground;
|
Microsoft.Terminal.Core.Color DefaultForeground;
|
||||||
Microsoft.Terminal.Core.Color DefaultBackground;
|
Microsoft.Terminal.Core.Color DefaultBackground;
|
||||||
Microsoft.Terminal.Core.Color GetColorTableEntry(Int32 index);
|
Microsoft.Terminal.Core.Color[] ColorTable();
|
||||||
Microsoft.Terminal.Core.Color CursorColor;
|
Microsoft.Terminal.Core.Color CursorColor;
|
||||||
CursorStyle CursorShape;
|
CursorStyle CursorShape;
|
||||||
UInt32 CursorHeight;
|
UInt32 CursorHeight;
|
||||||
|
|
|
@ -176,9 +176,14 @@ void Terminal::UpdateAppearance(const ICoreAppearance& appearance)
|
||||||
_defaultFg = appearance.DefaultForeground();
|
_defaultFg = appearance.DefaultForeground();
|
||||||
_intenseIsBright = appearance.IntenseIsBright();
|
_intenseIsBright = appearance.IntenseIsBright();
|
||||||
|
|
||||||
for (int i = 0; i < 16; i++)
|
|
||||||
{
|
{
|
||||||
_colorTable.at(i) = til::color{ appearance.GetColorTableEntry(i) };
|
const auto table = appearance.ColorTable();
|
||||||
|
Expects(table.size() == 16);
|
||||||
|
|
||||||
|
for (uint32_t i = 0; i < 16; ++i)
|
||||||
|
{
|
||||||
|
_colorTable[i] = til::color{ table[i] };
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
CursorType cursorShape = CursorType::VerticalBar;
|
CursorType cursorShape = CursorType::VerticalBar;
|
||||||
|
|
|
@ -345,7 +345,7 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation
|
||||||
ClearDefaultBackground();
|
ClearDefaultBackground();
|
||||||
ClearSelectionBackground();
|
ClearSelectionBackground();
|
||||||
ClearCursorColor();
|
ClearCursorColor();
|
||||||
_ColorTable = std::nullopt;
|
_colorTable = std::nullopt;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -356,56 +356,45 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation
|
||||||
_CursorColor = til::color{ scheme.CursorColor() };
|
_CursorColor = til::color{ scheme.CursorColor() };
|
||||||
|
|
||||||
const auto table = scheme.Table();
|
const auto table = scheme.Table();
|
||||||
std::array<winrt::Microsoft::Terminal::Core::Color, COLOR_TABLE_SIZE> colorTable{};
|
Expects(table.size() == 16);
|
||||||
std::transform(table.cbegin(), table.cend(), colorTable.begin(), [](auto&& color) {
|
std::copy_n(table.data(), 16, _colorTable.emplace().data());
|
||||||
return static_cast<winrt::Microsoft::Terminal::Core::Color>(til::color{ color });
|
|
||||||
});
|
|
||||||
ColorTable(colorTable);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
winrt::Microsoft::Terminal::Core::Color TerminalSettings::GetColorTableEntry(int32_t index) noexcept
|
winrt::com_array<Core::Color> TerminalSettings::ColorTable() const noexcept
|
||||||
{
|
{
|
||||||
return ColorTable().at(index);
|
winrt::com_array<Core::Color> colorTable{ 16 };
|
||||||
}
|
|
||||||
|
|
||||||
void TerminalSettings::ColorTable(std::array<winrt::Microsoft::Terminal::Core::Color, 16> colors)
|
if (const auto table = _getColorTableImpl())
|
||||||
{
|
|
||||||
_ColorTable = colors;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::array<winrt::Microsoft::Terminal::Core::Color, COLOR_TABLE_SIZE> TerminalSettings::ColorTable()
|
|
||||||
{
|
|
||||||
auto span = _getColorTableImpl();
|
|
||||||
std::array<winrt::Microsoft::Terminal::Core::Color, COLOR_TABLE_SIZE> colorTable{};
|
|
||||||
if (span.size() > 0)
|
|
||||||
{
|
{
|
||||||
std::copy(span.begin(), span.end(), colorTable.begin());
|
static_assert(std::tuple_size<std::remove_pointer_t<decltype(table)>>::value == 16);
|
||||||
|
std::copy_n(table->data(), 16, colorTable.data());
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
const auto campbellSpan = CampbellColorTable();
|
const auto& campbell = CampbellColorTable();
|
||||||
std::transform(campbellSpan.begin(), campbellSpan.end(), colorTable.begin(), [](auto&& color) {
|
static_assert(std::tuple_size<std::remove_reference_t<decltype(campbell)>>::value == 16);
|
||||||
return static_cast<winrt::Microsoft::Terminal::Core::Color>(til::color{ color });
|
std::copy_n(campbell.data(), 16, colorTable.data());
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return colorTable;
|
return colorTable;
|
||||||
}
|
}
|
||||||
|
|
||||||
gsl::span<winrt::Microsoft::Terminal::Core::Color> TerminalSettings::_getColorTableImpl()
|
const std::array<Core::Color, 16>* TerminalSettings::_getColorTableImpl() const noexcept
|
||||||
{
|
{
|
||||||
if (_ColorTable.has_value())
|
if (_colorTable)
|
||||||
{
|
{
|
||||||
return gsl::make_span(*_ColorTable);
|
return &*_colorTable;
|
||||||
}
|
}
|
||||||
for (auto&& parent : _parents)
|
|
||||||
|
for (const auto& parent : _parents)
|
||||||
{
|
{
|
||||||
auto parentSpan = parent->_getColorTableImpl();
|
if (const auto table = parent->_getColorTableImpl())
|
||||||
if (parentSpan.size() > 0)
|
|
||||||
{
|
{
|
||||||
return parentSpan;
|
return table;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return {};
|
|
||||||
|
return nullptr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -75,11 +75,7 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation
|
||||||
// --------------------------- Core Settings ---------------------------
|
// --------------------------- Core Settings ---------------------------
|
||||||
// All of these settings are defined in ICoreSettings.
|
// All of these settings are defined in ICoreSettings.
|
||||||
|
|
||||||
// GetColorTableEntry needs to be implemented manually, to get a
|
winrt::com_array<Core::Color> ColorTable() const noexcept;
|
||||||
// particular value from the array.
|
|
||||||
Microsoft::Terminal::Core::Color GetColorTableEntry(int32_t index) noexcept;
|
|
||||||
void ColorTable(std::array<Microsoft::Terminal::Core::Color, 16> colors);
|
|
||||||
std::array<Microsoft::Terminal::Core::Color, 16> ColorTable();
|
|
||||||
|
|
||||||
INHERITABLE_SETTING(Model::TerminalSettings, til::color, DefaultForeground, DEFAULT_FOREGROUND);
|
INHERITABLE_SETTING(Model::TerminalSettings, til::color, DefaultForeground, DEFAULT_FOREGROUND);
|
||||||
INHERITABLE_SETTING(Model::TerminalSettings, til::color, DefaultBackground, DEFAULT_BACKGROUND);
|
INHERITABLE_SETTING(Model::TerminalSettings, til::color, DefaultBackground, DEFAULT_BACKGROUND);
|
||||||
|
@ -156,13 +152,12 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation
|
||||||
INHERITABLE_SETTING(Model::TerminalSettings, bool, IntenseIsBold);
|
INHERITABLE_SETTING(Model::TerminalSettings, bool, IntenseIsBold);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::optional<std::array<Microsoft::Terminal::Core::Color, COLOR_TABLE_SIZE>> _ColorTable;
|
std::optional<std::array<Core::Color, 16>> _colorTable;
|
||||||
gsl::span<Microsoft::Terminal::Core::Color> _getColorTableImpl();
|
|
||||||
void _ApplyProfileSettings(const Model::Profile& profile);
|
|
||||||
|
|
||||||
|
const std::array<Core::Color, 16>* _getColorTableImpl() const noexcept;
|
||||||
|
void _ApplyProfileSettings(const Model::Profile& profile);
|
||||||
void _ApplyGlobalSettings(const Model::GlobalAppSettings& globalSettings) noexcept;
|
void _ApplyGlobalSettings(const Model::GlobalAppSettings& globalSettings) noexcept;
|
||||||
void _ApplyAppearanceSettings(const Microsoft::Terminal::Settings::Model::IAppearanceConfig& appearance,
|
void _ApplyAppearanceSettings(const Model::IAppearanceConfig& appearance, const Windows::Foundation::Collections::IMapView<hstring, Model::ColorScheme>& schemes);
|
||||||
const Windows::Foundation::Collections::IMapView<hstring, Microsoft::Terminal::Settings::Model::ColorScheme>& schemes);
|
|
||||||
|
|
||||||
friend class SettingsModelLocalTests::TerminalSettingsTests;
|
friend class SettingsModelLocalTests::TerminalSettingsTests;
|
||||||
};
|
};
|
||||||
|
|
|
@ -475,9 +475,9 @@ void Utils::InitializeCampbellColorTable(const gsl::span<til::color> table)
|
||||||
std::copy(campbellColorTable.begin(), campbellColorTable.end(), table.begin());
|
std::copy(campbellColorTable.begin(), campbellColorTable.end(), table.begin());
|
||||||
}
|
}
|
||||||
|
|
||||||
gsl::span<const til::color> Utils::CampbellColorTable()
|
const std::array<til::color, 16>& Utils::CampbellColorTable()
|
||||||
{
|
{
|
||||||
return gsl::make_span(campbellColorTable);
|
return campbellColorTable;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Function Description:
|
// Function Description:
|
||||||
|
|
|
@ -17,7 +17,7 @@ namespace Microsoft::Console::Utils
|
||||||
void InitializeCampbellColorTableForConhost(const gsl::span<COLORREF> table);
|
void InitializeCampbellColorTableForConhost(const gsl::span<COLORREF> table);
|
||||||
void SwapANSIColorOrderForConhost(const gsl::span<COLORREF> table);
|
void SwapANSIColorOrderForConhost(const gsl::span<COLORREF> table);
|
||||||
void Initialize256ColorTable(const gsl::span<COLORREF> table);
|
void Initialize256ColorTable(const gsl::span<COLORREF> table);
|
||||||
gsl::span<const til::color> CampbellColorTable();
|
const std::array<til::color, 16>& CampbellColorTable();
|
||||||
|
|
||||||
std::optional<til::color> ColorFromXOrgAppColorName(const std::wstring_view wstr) noexcept;
|
std::optional<til::color> ColorFromXOrgAppColorName(const std::wstring_view wstr) noexcept;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue