Skip to content

Update ColorScheme with Json Serializer and color table API - #7609

Merged
Dustin L. Howett (DHowett) merged 12 commits into
masterfrom
dev/cazamor/tojson/basic
Sep 17, 2020
Merged

Dustin L. Howett (DHowett) merged 12 commits into
masterfrom
dev/cazamor/tojson/basic

Conversation

@carlos-zamora

@carlos-zamora Carlos Zamora (carlos-zamora) commented Sep 11, 2020 •

Copy link
Copy Markdown

Add ToJson() to the ConversionTraits in JsonUtils. This can be used
to serialize settings objects into JSON.

As a proof of concept, ToJson and UpdateJson were added to
ColorScheme.

Getters and setters for members and colors in the color table were added
and polished.

References

#1564 - Settings UI

ColorScheme is a particularly easy example of serialization because it
has no fallback.

Added a few tests for JSON serializers.

@carlos-zamora Carlos Zamora (carlos-zamora) added Area-Settings Issues related to settings and customizability, for console or terminal Product-Terminal The new Windows Terminal. labels Sep 11, 2020
Comment thread src/cascadia/TerminalApp/ColorScheme.h Outdated
#define GETSET_COLORTABLEPROPERTY(name) \
public: \
winrt::Windows::UI::Color name() const noexcept { return _table[##name##Index]; } \
void name(const winrt::Windows::UI::Color& value) noexcept { _table[##name##Index] = value; }

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need an observable/notifier here?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe? I'll hold off on that for when we get the UI hooked up.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

gosh i love this jsonutils stuff. good work!

Comment thread src/cascadia/ut_app/JsonUtilsTests.cpp Resolved
Comment thread src/cascadia/ut_app/JsonUtilsTests.cpp Resolved
Comment thread src/cascadia/ut_app/JsonUtilsTests.cpp Resolved
Comment thread src/cascadia/ut_app/JsonUtilsTests.cpp Resolved
Comment on lines +111 to +119
// This should only be used for color types where there's no logic in the
// getter/setter beyond just accessing/updating the value.
// This takes advantage of til::color
#define GETSET_COLORPROPERTY(name, ...) \
public: \
winrt::Windows::UI::Color name() const noexcept { return _##name; } \
void name(const winrt::Windows::UI::Color& value) noexcept { _##name = value; } \
\
private: \

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this really a generic-enough helper that it belongs in utils

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Eh? 🤷‍♂️ Yes, because WinUI::Color should be how we expose colors across layers, and we want to leverage til::color as much as we can? Only 50% confident here haha

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that some of this C++/winrt stuff might magically take care of it for us ...

so what happens if you just use GETSET_PROPERTY(til::color, Foreground) or whatever?

There's a trick to c++/winrt, and that trick is that your implementation methods don't actually need to match your signatures at all ;)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, I think that this won't automatically work because the type it's looking for is actually a struct_Windows_UI_Color and the detach_from helper does not allow for type coercion.

Comment thread src/cascadia/TerminalApp/JsonUtils.h Resolved
Comment thread src/cascadia/TerminalApp/JsonUtils.h Resolved
Comment thread src/cascadia/TerminalApp/JsonUtils.h Resolved
Comment thread src/cascadia/TerminalApp/JsonUtils.h Resolved
Comment thread src/cascadia/TerminalApp/JsonUtils.h Resolved
Co-authored-by: Dustin L. Howett <duhowett@microsoft.com>
Comment thread src/cascadia/TerminalApp/ColorScheme.h Resolved
Comment on lines +111 to +119
// This should only be used for color types where there's no logic in the
// getter/setter beyond just accessing/updating the value.
// This takes advantage of til::color
#define GETSET_COLORPROPERTY(name, ...) \
public: \
winrt::Windows::UI::Color name() const noexcept { return _##name; } \
void name(const winrt::Windows::UI::Color& value) noexcept { _##name = value; } \
\
private: \

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that some of this C++/winrt stuff might magically take care of it for us ...

so what happens if you just use GETSET_PROPERTY(til::color, Foreground) or whatever?

There's a trick to c++/winrt, and that trick is that your implementation methods don't actually need to match your signatures at all ;)

Comment thread src/cascadia/ut_app/JsonTests.cpp Resolved
Comment thread src/cascadia/ut_app/JsonUtilsTests.cpp Resolved
@ghost ghost added Needs-Author-Feedback The original author of the issue/PR needs to come back and respond to something and removed Needs-Author-Feedback The original author of the issue/PR needs to come back and respond to something labels Sep 15, 2020
Comment thread src/cascadia/ut_app/JsonUtilsTests.cpp Outdated

template<typename TExpected, typename TJson>
static void TryBasicType(TExpected&& expected, TJson&& json)
static void TryBasicType(TExpected&& expected, TJson&& json, std::optional<std::string> overrideToJsonOutput = std::nullopt)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't this be an optional json::value? so you can specify {1} or something?

then later you can use expectedJson[key] = override.value_or(jsonObject); and simplify the code?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah. I was trying to do that, but I messed up by making it a std::optional<TJson> instead of std::optional<Json::Value>. Derp!

// - json: an object which will be a serialization of a ColorScheme object.
// Return Value:
// <none>
void ColorScheme::UpdateJson(Json::Value& json)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i 100% expected you to go a different direction with this and just .. make it a function called ToJson that returned the json object.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there ever a reason for us to call UpdateJson multiple times with different color schemes? (or profiles, etc.)?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally, I could name it LayerJson with an out param because we're really just layering our values onto the Json. But I guess that isn't something we're doing yet, so yeah, renaming to ToJson as you expected haha

@DHowett

Copy link
Copy Markdown
Member

I'm going to admin override this because it's failed on #7654

@DHowett
Dustin L. Howett (DHowett) merged commit b70ffdf into master Sep 17, 2020
@DHowett
Dustin L. Howett (DHowett) deleted the dev/cazamor/tojson/basic branch September 17, 2020 18:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area-Settings Issues related to settings and customizability, for console or terminal Product-Terminal The new Windows Terminal.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants