Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deduplicate identical inbox color schemes to heal user settings #12800

Merged
merged 23 commits into from
Feb 27, 2024

Conversation

DHowett
Copy link
Member

@DHowett DHowett commented Mar 31, 2022

Up until now, we have treated inbox, fragment and user color schemes the
same: we load them all into one big map and when we save the settings
file we write them all out. It's been a big annoyance pretty much
forever.

In addition to cluttering the user's settings file, it prevents us from
making changes to the stock color schemes (like to change the cursor
color, or to adjust the colors in Tango Dark, or what have you) because
they're already copied in full in the user settings. It also means that
we need some special UI affordances for color schemes that you are
allowed to view but not to delete or rename.

We also have a funny hardcoded list of color scheme names and we use
that to determine whether they're "inbox" for UI purposes.

Because of all that, we are hesitant to add more color schemes to the
default set.

This pull request resolves all of those issues at once.

It:

  • Adds an "origin" to color schemes indicating where they're from
    (Inbox, Fragment, User, ...)
  • Replaces the Edit UI with a much simpler version that pretty much only
    has a "duplicate this color scheme to start editing it" button
  • Deletes color schemes that we consider to be equivalent to inbox ones;
    this allows us to finally disentangle the user's preferences from the
    terminal's.
  • Migrates all user settings that referred to schemes they may have
    modified (even implicitly!) to their modified versions.

The equivalence check intentionally leaves out the cursor and selection
colors, so that we have the freedom to change them in the future.

The Origin is part of a new interface, ISettingsModelObject, which we
can use in the future for things like Themes and Actions.

@github-actions

This comment was marked as resolved.

Json::Value schemes{ Json::ValueType::arrayValue };
for (const auto& entry : _globals->ColorSchemes())
{
const auto scheme{ winrt::get_self<ColorScheme>(entry.Value()) };
schemes.append(scheme->ToJson());
if (scheme->Origin() == OriginTag::User)
Copy link
Member Author

Choose a reason for hiding this comment

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

is this bodgy i can't tell

@DHowett
Copy link
Member Author

DHowett commented Apr 18, 2022

I'll include this in Leonard's new "Fix User Settings" code :)

@DHowett DHowett force-pushed the dev/duhowett/fhl-202203/color-scheme-healing branch from 073540b to a31b089 Compare April 24, 2022 22:04
@github-actions

This comment has been minimized.

@DHowett DHowett mentioned this pull request Jul 7, 2022
12 tasks
@zadjii-msft zadjii-msft mentioned this pull request Jul 7, 2022
20 tasks
@zadjii-msft zadjii-msft mentioned this pull request Feb 20, 2023
@github-actions

This comment has been minimized.

@zadjii-msft
Copy link
Member

Notes from team sync today (post hackathon)

  • The SUI still needs updates
  • Instead of making the builtin schemes read-only, just sneaky save them as the (Modified) version

@github-actions

This comment has been minimized.

This comment has been minimized.

@DHowett
Copy link
Member Author

DHowett commented Feb 23, 2024

I am noodling on what the UI looks like when you try to edit one of these. We don't need to fun disclaimer text any more (woo), but we do need a call to action.

image

@zadjii-msft
Copy link
Member

I'm gonna say :shipit:. I'd maybe make it an InfoBar but that's basically the same UX

@DHowett
Copy link
Member Author

DHowett commented Feb 23, 2024

Okay, this works pretty well.

image

This comment has been minimized.

@Machine391

This comment was marked as off-topic.

Copy link
Member

@lhecker lhecker left a comment

Choose a reason for hiding this comment

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

The fmt::format calls throughout the PR could use FMT_COMPILE IMO.

@DHowett
Copy link
Member Author

DHowett commented Feb 27, 2024

The one risk I am aware of is that we will delete user color schemes that ONLY change the cursor or selection colors.

I can add checks to avoid this, but the risk seems fairly low overall.

@lhecker
Copy link
Member

lhecker commented Feb 27, 2024

I think that's an acceptable risk.

@DHowett
Copy link
Member Author

DHowett commented Feb 27, 2024

@lhecker any blockers left?

@DHowett
Copy link
Member Author

DHowett commented Feb 27, 2024

Body updated

@lhecker
Copy link
Member

lhecker commented Feb 27, 2024

I still don't quite understand how _addOrMergeUserColorScheme works without returning a bool fixup flag. It potentially renames the user's scheme, so why don't we need to trigger a save of the new (fixed) config?

@DHowett
Copy link
Member Author

DHowett commented Feb 27, 2024

So! Because _addOrMerge is called during settings loading and we don't have a place to store "I did fixups" outside of FixupUserSettings, I opted to instead track the observable effects of merging.

This line in CascadiaSettingsSerialization ensures that we write out the settings if we renamed a user color scheme. Because renaming adds a remapping entry, the condition will always reflect whether there have been any renames.

The one case this does not cover is when a user had an identical color scheme which we deleted, but no other settings changes. Honestly, I don't mind that terribly. If they go save their settings again it will disappear, and it is not harming anyone much by being there.

I can plumb through a "made changes" flag if we want to force a flush to disk when we delete schemes.

@DHowett DHowett changed the title "Heal" user settings by deduplicating identical inbox color schemes Deduplicate identical inbox color schemes to heal user settings Feb 27, 2024
@DHowett DHowett enabled auto-merge (squash) February 27, 2024 19:01
@DHowett DHowett merged commit de0f702 into main Feb 27, 2024
18 of 20 checks passed
@DHowett DHowett deleted the dev/duhowett/fhl-202203/color-scheme-healing branch February 27, 2024 19:07
@@ -10,6 +10,7 @@

using namespace Microsoft::Console;
using namespace winrt::Microsoft::Terminal;
using namespace winrt::Microsoft::Terminal::Settings;

Choose a reason for hiding this comment

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

Added
Continue script

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants