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

A "_random_" color scheme option. Any new window chooses randomly from those in settings.schemes. #9845

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/cascadia/TerminalApp/AppActionHandlers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,16 @@ namespace winrt::TerminalApp::implementation
activeControl.UpdateSettings();
args.Handled(true);
}
else if (realArgs.SchemeName() == winrt::to_hstring(L"_random"))
{
if (const auto scheme = _settings.GlobalSettings().ColorSchemes().TryLookup(L"Campbell"))
{
auto controlSettings = activeControl.Settings().as<TerminalSettings>();
controlSettings.ApplyColorScheme(scheme);
activeControl.UpdateSettings();
args.Handled(true);
}
}
}
}
}
Expand Down
93 changes: 51 additions & 42 deletions src/cascadia/TerminalSettingsModel/CascadiaSettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,11 @@ void CascadiaSettings::ClearWarnings()

void CascadiaSettings::AppendWarning(SettingsLoadWarnings warning)
{
_warnings.Append(warning);
warning = warning;
int i = 0;
++i;
return;
// _warnings.Append(warning);
}

winrt::Windows::Foundation::IReference<winrt::Microsoft::Terminal::Settings::Model::SettingsLoadErrors> CascadiaSettings::GetLoadingError()
Expand Down Expand Up @@ -382,15 +386,15 @@ void CascadiaSettings::_ValidateDefaultProfileExists()
}
}

if (nullDefaultProfile || defaultProfileNotInProfiles)
{
_warnings.Append(Microsoft::Terminal::Settings::Model::SettingsLoadWarnings::MissingDefaultProfile);
// Use the first profile as the new default
// if (nullDefaultProfile || defaultProfileNotInProfiles)
// {
// _warnings.Append(Microsoft::Terminal::Settings::Model::SettingsLoadWarnings::MissingDefaultProfile);
// // Use the first profile as the new default

// _temporarily_ set the default profile to the first profile. Because
// we're adding a warning, this settings change won't be re-serialized.
GlobalSettings().DefaultProfile(_allProfiles.GetAt(0).Guid());
}
// // _temporarily_ set the default profile to the first profile. Because
// // we're adding a warning, this settings change won't be re-serialized.
// GlobalSettings().DefaultProfile(_allProfiles.GetAt(0).Guid());
// }
}

// Method Description:
Expand Down Expand Up @@ -425,10 +429,10 @@ void CascadiaSettings::_ValidateNoDuplicateProfiles()
_allProfiles.RemoveAt(*iter);
}

if (foundDupe)
{
_warnings.Append(Microsoft::Terminal::Settings::Model::SettingsLoadWarnings::DuplicateProfile);
}
// if (foundDupe)
// {
// _warnings.Append(Microsoft::Terminal::Settings::Model::SettingsLoadWarnings::DuplicateProfile);
// }
}

// Method Description:
Expand Down Expand Up @@ -550,10 +554,10 @@ void CascadiaSettings::_ValidateAllSchemesExist()
}
}

if (foundInvalidScheme)
{
_warnings.Append(SettingsLoadWarnings::UnknownColorScheme);
}
// if (foundInvalidScheme)
// {
// _warnings.Append(SettingsLoadWarnings::UnknownColorScheme);
// }
}

// Method Description:
Expand Down Expand Up @@ -630,15 +634,15 @@ void CascadiaSettings::_ValidateMediaResources()
}
}

if (invalidBackground)
{
_warnings.Append(SettingsLoadWarnings::InvalidBackgroundImage);
}
// if (invalidBackground)
// {
// _warnings.Append(SettingsLoadWarnings::InvalidBackgroundImage);
// }

if (invalidIcon)
{
_warnings.Append(SettingsLoadWarnings::InvalidIcon);
}
// if (invalidIcon)
// {
// _warnings.Append(SettingsLoadWarnings::InvalidIcon);
// }
}

// Method Description:
Expand Down Expand Up @@ -758,15 +762,16 @@ std::optional<winrt::guid> CascadiaSettings::_GetProfileGuidByIndex(std::optiona
void CascadiaSettings::_ValidateKeybindings()
{
auto keybindingWarnings = _globals->KeybindingsWarnings();
return;

if (!keybindingWarnings.empty())
{
_warnings.Append(SettingsLoadWarnings::AtLeastOneKeybindingWarning);
for (auto warning : keybindingWarnings)
{
_warnings.Append(warning);
}
}
// if (!keybindingWarnings.empty())
// {
// _warnings.Append(SettingsLoadWarnings::AtLeastOneKeybindingWarning);
// for (auto warning : keybindingWarnings)
// {
// _warnings.Append(warning);
// }
// }
}

// Method Description:
Expand All @@ -789,14 +794,15 @@ void CascadiaSettings::_ValidateColorSchemesInCommands()
}
}

if (foundInvalidScheme)
{
_warnings.Append(SettingsLoadWarnings::InvalidColorSchemeInCmd);
}
// if (foundInvalidScheme)
// {
// _warnings.Append(SettingsLoadWarnings::InvalidColorSchemeInCmd);
// }
}

bool CascadiaSettings::_HasInvalidColorScheme(const Model::Command& command)
{
return false;
bool invalid{ false };
if (command.HasNestedCommands())
{
Expand Down Expand Up @@ -840,11 +846,14 @@ bool CascadiaSettings::_HasInvalidColorScheme(const Model::Command& command)
// we find any invalid background images.
void CascadiaSettings::_ValidateNoGlobalsKey()
{
// use isMember here. If you use [], you're actually injecting "globals": null.
if (_userSettings.isMember("globals"))
{
_warnings.Append(SettingsLoadWarnings::LegacyGlobalsProperty);
}
int i = 0;
++i;
return;
// // use isMember here. If you use [], you're actually injecting "globals": null.
// if (_userSettings.isMember("globals"))
// {
// _warnings.Append(SettingsLoadWarnings::LegacyGlobalsProperty);
// }
}

// Method Description
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1092,6 +1092,13 @@ winrt::com_ptr<ColorScheme> CascadiaSettings::_FindMatchingColorScheme(const Jso
{
return winrt::get_self<ColorScheme>(scheme)->get_strong();
}
else if (*schemeName == winrt::to_hstring(L"_random"))
{
if (auto scheme{ _globals->ColorSchemes().TryLookup(L"Campbell") })
{
return winrt::get_self<ColorScheme>(scheme)->get_strong();
}
}
}
return nullptr;
}
Expand Down
13 changes: 13 additions & 0 deletions src/cascadia/TerminalSettingsModel/TerminalSettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,13 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation
{
defaultSettings.ApplyColorScheme(scheme);
}
else if (newTerminalArgs.ColorScheme() == winrt::to_hstring(L"_random"))
{
if (const auto& scheme = schemes.TryLookup(L"Campbell"))
{
defaultSettings.ApplyColorScheme(scheme);
}
}
}
}

Expand All @@ -153,10 +160,16 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation
_CursorHeight = appearance.CursorHeight();
if (!appearance.ColorSchemeName().empty())
{
// TODO: Edit this scheme to apply a random scheme
if (const auto scheme = schemes.TryLookup(appearance.ColorSchemeName()))
{
ApplyColorScheme(scheme);
}
else if (appearance.ColorSchemeName() == winrt::to_hstring(L"_random"))
{
const auto scheme = schemes.TryLookup(winrt::to_hstring(L"Tango Light"));
ApplyColorScheme(scheme);
}
}
if (appearance.Foreground())
{
Expand Down