168d28b036
This commit reduces the code surface that interacts with raw JSON data, reducing code complexity and improving maintainability. Files that needed to be changed drastically were additionally cleaned up to remove any code cruft that has accrued over time. In order to facility this the following changes were made: * Move JSON handling from `CascadiaSettings` into `SettingsLoader` This allows us to use STL containers for data model instances. For instance profiles are now added to a hashmap for O(1) lookup. * JSON parsing within `SettingsLoader` doesn't differentiate between user, inbox and fragment JSON data, reducing code complexity and size. It also centralizes common concerns, like profile deduplication and ensuring that all profiles are assigned a GUID. * Direct JSON modification, like the insertion of dynamic profiles into settings.json were removed. This vastly reduces code complexity, but unfortunately removes support for comments in JSON on first start. * `ColorScheme`s cannot be layered. As such its `LayerJson` API was replaced with `FromJson`, allowing us to remove JSON-based color scheme validation. * `Profile`s used to test their wish to layer using `ShouldBeLayered`, which was replaced with a GUID-based hashmap lookup on previously parsed profiles. Further changes were made as improvements upon the previous changes: * Compact the JSON files embedded binary, saving 28kB * Prevent double-initialization of the color table in `ColorScheme` * Making `til::color` getters `constexpr`, allow better optimizations The result is a reduction of: * 48kB binary size for the Settings.Model.dll * 5-10% startup duration * 26% code for the `CascadiaSettings` class * 1% overall code in this project Furthermore this results in the following breaking changes: * The long deprecated "globals" settings object will not be detected and no warning will be created during load. * The initial creation of a new settings.json will not produce helpful comments. Both cases are caused by the removal of manual JSON handling and the move to representing the settings file with model objects instead ## PR Checklist * [x] Closes #5276 * [x] Closes #7421 * [x] I work here * [x] Tests added/passed ## Validation Steps Performed * Out-of-box-experience is identical to before ✔️ (Except for the settings.json file lacking comments.) * Existing user settings load correctly ✔️ * New WSL instances are added to user settings ✔️ * New fragments are added to user settings ✔️ * All profiles are assigned GUIDs ✔️
70 lines
2 KiB
C++
70 lines
2 KiB
C++
/*++
|
|
Copyright (c) Microsoft Corporation
|
|
Licensed under the MIT license.
|
|
|
|
Module Name:
|
|
- ColorScheme.hpp
|
|
|
|
Abstract:
|
|
- A color scheme is a single set of colors to use as the terminal colors. These
|
|
schemes are named, and can be used to quickly change all the colors of the
|
|
terminal to another scheme.
|
|
|
|
Author(s):
|
|
- Mike Griese - March 2019
|
|
|
|
--*/
|
|
#pragma once
|
|
|
|
#include "../../inc/conattrs.hpp"
|
|
#include "inc/cppwinrt_utils.h"
|
|
#include "DefaultSettings.h"
|
|
|
|
#include "ColorScheme.g.h"
|
|
|
|
namespace winrt::Microsoft::Terminal::Settings::Model::implementation
|
|
{
|
|
struct ColorScheme : ColorSchemeT<ColorScheme>
|
|
{
|
|
// A ColorScheme constructed with uninitialized_t
|
|
// leaves _table uninitialized.
|
|
struct uninitialized_t
|
|
{
|
|
};
|
|
|
|
public:
|
|
ColorScheme() noexcept;
|
|
explicit ColorScheme(uninitialized_t) noexcept {}
|
|
explicit ColorScheme(const winrt::hstring& name) noexcept;
|
|
|
|
com_ptr<ColorScheme> Copy() const;
|
|
|
|
hstring ToString()
|
|
{
|
|
return Name();
|
|
}
|
|
|
|
static com_ptr<ColorScheme> FromJson(const Json::Value& json);
|
|
Json::Value ToJson() const;
|
|
|
|
com_array<Core::Color> Table() const noexcept;
|
|
void SetColorTableEntry(uint8_t index, const Core::Color& value) noexcept;
|
|
|
|
WINRT_PROPERTY(winrt::hstring, Name);
|
|
WINRT_PROPERTY(Core::Color, Foreground, static_cast<Core::Color>(DEFAULT_FOREGROUND));
|
|
WINRT_PROPERTY(Core::Color, Background, static_cast<Core::Color>(DEFAULT_BACKGROUND));
|
|
WINRT_PROPERTY(Core::Color, SelectionBackground, static_cast<Core::Color>(DEFAULT_FOREGROUND));
|
|
WINRT_PROPERTY(Core::Color, CursorColor, static_cast<Core::Color>(DEFAULT_CURSOR_COLOR));
|
|
|
|
private:
|
|
bool _layerJson(const Json::Value& json);
|
|
|
|
std::array<Core::Color, COLOR_TABLE_SIZE> _table;
|
|
};
|
|
}
|
|
|
|
namespace winrt::Microsoft::Terminal::Settings::Model::factory_implementation
|
|
{
|
|
BASIC_FACTORY(ColorScheme);
|
|
}
|