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