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

Patch the default profile and version into the settings template #5232

Merged
merged 4 commits into from
Apr 7, 2020

Conversation

DHowett-MSFT
Copy link
Contributor

@DHowett-MSFT DHowett-MSFT commented Apr 3, 2020

This pull request introduces unexpanded variables (%DEFAULT_PROFILE%,
%VERSION% and %PRODUCT%) to the user settings template and code to
expand them.

While doing this, I ran into a couple things that needed to widen from
accepting strings to accepting string views. I also had to move
application name and version detection up to AppLogic and expose the
AppLogic singleton.

The dynamic profile generation logic had to be moved to before we inject
the templated variables, as the new default profile depends on the
generated dynamic profiles.

References #5189, #5217 (because it has a dependency on VERSION and
PRODUCT).

PR Checklist

Validation Steps Performed

Deleted my settings and watched them regenerate.

@DHowett-MSFT
Copy link
Contributor Author

Had to move version stuff up to Logic (app level). I prefer it there, but there is some duplication in the exception handler (because we might not have an AppLogic, AND package APIs may fail).

// Throws:
// - HR E_INVALIDARG if the app isn't up and running.
const CascadiaSettings& CascadiaSettings::GetCurrentAppSettings()
static auto GetAppLogic()
Copy link
Contributor Author

Choose a reason for hiding this comment

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

an auto function

Copy link
Member

Choose a reason for hiding this comment

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

holy shit this works?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

IT IS A REVOLUTION

Comment on lines +695 to +701
auto replace{ [](std::string& haystack, std::string_view needle, std::string_view replacement) {
auto pos{ std::string::npos };
while ((pos = haystack.rfind(needle, pos)) != std::string::npos)
{
haystack.replace(pos, needle.size(), replacement);
}
} };
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I wonder how many projects have had to write this exact thing.

Copy link
Member

Choose a reason for hiding this comment

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

:laughing_but_crying_inside:

Copy link
Member

@zadjii-msft zadjii-msft left a comment

Choose a reason for hiding this comment

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

I'm really okay with this, but IIRC this has a issue that needs to be linked to it

src/cascadia/TerminalApp/CascadiaSettings.cpp Show resolved Hide resolved
Comment on lines 45 to 47
winrt::com_ptr<winrt::TerminalApp::implementation::AppLogic> appLogic;
appLogic.copy_from(appLogicPointer);
return appLogic;
Copy link
Member

Choose a reason for hiding this comment

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

Wait why are we making another winrt::com_ptr<winrt::TerminalApp::implementation::AppLogic> here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

so actually get_self returns a raw implementation::X* ☹️

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Honestly i don't know if I care to have this return a com_ptr. a bare pointer means it can't be owned, but the AppLogic should outlive ALL other lifetimes...

// Throws:
// - HR E_INVALIDARG if the app isn't up and running.
const CascadiaSettings& CascadiaSettings::GetCurrentAppSettings()
static auto GetAppLogic()
Copy link
Member

Choose a reason for hiding this comment

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

holy shit this works?

Comment on lines +695 to +701
auto replace{ [](std::string& haystack, std::string_view needle, std::string_view replacement) {
auto pos{ std::string::npos };
while ((pos = haystack.rfind(needle, pos)) != std::string::npos)
{
haystack.replace(pos, needle.size(), replacement);
}
} };
Copy link
Member

Choose a reason for hiding this comment

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

:laughing_but_crying_inside:

}

return profiles;
}

// Function Description:
// - Returns the thing it's named for.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

too cheeky?

Copy link
Member

Choose a reason for hiding this comment

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

Eh. Always nice to have a few of these sprinkled throughout haha

@DHowett-MSFT DHowett-MSFT marked this pull request as ready for review April 6, 2020 23:53
}

return profiles;
}

// Function Description:
// - Returns the thing it's named for.
Copy link
Member

Choose a reason for hiding this comment

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

Eh. Always nice to have a few of these sprinkled throughout haha

Copy link
Member

@zadjii-msft zadjii-msft left a comment

Choose a reason for hiding this comment

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

Okay sure. It's a little gross but there's not a totally better way (re: the AppLogic::Current stuff)

@zadjii-msft zadjii-msft added Area-Settings Issues related to settings and customizability, for console or terminal Product-Terminal The new Windows Terminal. labels Apr 7, 2020
@DHowett-MSFT DHowett-MSFT merged commit 52d6c03 into master Apr 7, 2020
@DHowett-MSFT DHowett-MSFT deleted the dev/duhowett/patch_settings_mode branch April 7, 2020 18:35
@ghost
Copy link

ghost commented Apr 22, 2020

🎉Windows Terminal Preview v0.11.1121.0 has been released which incorporates this pull request.:tada:

Handy links:

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.

On first launch, if Powershell Core is installed, set it as the default profile
4 participants