Add a --colorScheme
param to new-tab
, split-pane
(#9602)
This is entirely self-serving. In my go-to config, I like having some of the panes for a given profile in a different color scheme. This will let a user pass `--colorScheme <scheme name>` to manually override the scheme for that profile. Neat!
This commit is contained in:
parent
ba543c0696
commit
eac3eea484
|
@ -227,6 +227,10 @@
|
|||
"type": "boolean",
|
||||
"default": "false",
|
||||
"description": "When set to true, tabTitle overrides the default title of the tab and any title change messages from the application will be suppressed. When set to false, tabTitle behaves as normal"
|
||||
},
|
||||
"colorScheme": {
|
||||
"description": "The name of a color scheme to use, instead of the one specified by the profile",
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"type": "object"
|
||||
|
|
|
@ -458,6 +458,7 @@ namespace TerminalAppLocalTests
|
|||
VERIFY_IS_NULL(myArgs.TerminalArgs().TabColor());
|
||||
VERIFY_IS_NULL(myArgs.TerminalArgs().ProfileIndex());
|
||||
VERIFY_IS_TRUE(myArgs.TerminalArgs().Profile().empty());
|
||||
VERIFY_IS_TRUE(myArgs.TerminalArgs().ColorScheme().empty());
|
||||
}
|
||||
{
|
||||
AppCommandlineArgs appArgs{};
|
||||
|
@ -479,6 +480,7 @@ namespace TerminalAppLocalTests
|
|||
VERIFY_IS_NULL(myArgs.TerminalArgs().ProfileIndex());
|
||||
VERIFY_IS_FALSE(myArgs.TerminalArgs().Profile().empty());
|
||||
VERIFY_ARE_EQUAL(L"cmd", myArgs.TerminalArgs().Profile());
|
||||
VERIFY_IS_TRUE(myArgs.TerminalArgs().ColorScheme().empty());
|
||||
}
|
||||
{
|
||||
AppCommandlineArgs appArgs{};
|
||||
|
@ -500,6 +502,7 @@ namespace TerminalAppLocalTests
|
|||
VERIFY_IS_NULL(myArgs.TerminalArgs().ProfileIndex());
|
||||
VERIFY_IS_TRUE(myArgs.TerminalArgs().Profile().empty());
|
||||
VERIFY_ARE_EQUAL(L"c:\\Foo", myArgs.TerminalArgs().StartingDirectory());
|
||||
VERIFY_IS_TRUE(myArgs.TerminalArgs().ColorScheme().empty());
|
||||
}
|
||||
{
|
||||
AppCommandlineArgs appArgs{};
|
||||
|
@ -521,6 +524,7 @@ namespace TerminalAppLocalTests
|
|||
VERIFY_IS_NULL(myArgs.TerminalArgs().ProfileIndex());
|
||||
VERIFY_IS_TRUE(myArgs.TerminalArgs().Profile().empty());
|
||||
VERIFY_ARE_EQUAL(L"powershell.exe", myArgs.TerminalArgs().Commandline());
|
||||
VERIFY_IS_TRUE(myArgs.TerminalArgs().ColorScheme().empty());
|
||||
}
|
||||
{
|
||||
AppCommandlineArgs appArgs{};
|
||||
|
@ -543,6 +547,7 @@ namespace TerminalAppLocalTests
|
|||
VERIFY_IS_TRUE(myArgs.TerminalArgs().Profile().empty());
|
||||
auto myCommand = myArgs.TerminalArgs().Commandline();
|
||||
VERIFY_ARE_EQUAL(L"powershell.exe \"This is an arg with spaces\"", myCommand);
|
||||
VERIFY_IS_TRUE(myArgs.TerminalArgs().ColorScheme().empty());
|
||||
}
|
||||
{
|
||||
AppCommandlineArgs appArgs{};
|
||||
|
@ -565,6 +570,7 @@ namespace TerminalAppLocalTests
|
|||
VERIFY_IS_TRUE(myArgs.TerminalArgs().Profile().empty());
|
||||
auto myCommand = myArgs.TerminalArgs().Commandline();
|
||||
VERIFY_ARE_EQUAL(L"powershell.exe \"This is an arg with spaces\" another-arg \"more spaces in this one\"", myCommand);
|
||||
VERIFY_IS_TRUE(myArgs.TerminalArgs().ColorScheme().empty());
|
||||
}
|
||||
{
|
||||
AppCommandlineArgs appArgs{};
|
||||
|
@ -586,6 +592,7 @@ namespace TerminalAppLocalTests
|
|||
VERIFY_IS_NULL(myArgs.TerminalArgs().ProfileIndex());
|
||||
VERIFY_IS_FALSE(myArgs.TerminalArgs().Profile().empty());
|
||||
VERIFY_ARE_EQUAL(L"Windows PowerShell", myArgs.TerminalArgs().Profile());
|
||||
VERIFY_IS_TRUE(myArgs.TerminalArgs().ColorScheme().empty());
|
||||
}
|
||||
{
|
||||
AppCommandlineArgs appArgs{};
|
||||
|
@ -606,6 +613,7 @@ namespace TerminalAppLocalTests
|
|||
VERIFY_IS_NULL(myArgs.TerminalArgs().ProfileIndex());
|
||||
VERIFY_IS_TRUE(myArgs.TerminalArgs().Profile().empty());
|
||||
VERIFY_ARE_EQUAL(L"wsl -d Alpine", myArgs.TerminalArgs().Commandline());
|
||||
VERIFY_IS_TRUE(myArgs.TerminalArgs().ColorScheme().empty());
|
||||
}
|
||||
{
|
||||
AppCommandlineArgs appArgs{};
|
||||
|
@ -628,6 +636,7 @@ namespace TerminalAppLocalTests
|
|||
VERIFY_IS_FALSE(myArgs.TerminalArgs().Profile().empty());
|
||||
VERIFY_ARE_EQUAL(L"wsl -d Alpine", myArgs.TerminalArgs().Commandline());
|
||||
VERIFY_ARE_EQUAL(L"1", myArgs.TerminalArgs().Profile());
|
||||
VERIFY_IS_TRUE(myArgs.TerminalArgs().ColorScheme().empty());
|
||||
}
|
||||
{
|
||||
AppCommandlineArgs appArgs{};
|
||||
|
@ -651,6 +660,31 @@ namespace TerminalAppLocalTests
|
|||
VERIFY_ARE_EQUAL(til::color(myArgs.TerminalArgs().TabColor().Value()), expectedColor);
|
||||
VERIFY_IS_NULL(myArgs.TerminalArgs().ProfileIndex());
|
||||
VERIFY_IS_TRUE(myArgs.TerminalArgs().Profile().empty());
|
||||
VERIFY_IS_TRUE(myArgs.TerminalArgs().ColorScheme().empty());
|
||||
}
|
||||
{
|
||||
AppCommandlineArgs appArgs{};
|
||||
std::vector<const wchar_t*> rawCommands{ L"wt.exe", subcommand, L"--colorScheme", L"Vintage" };
|
||||
const winrt::hstring expectedScheme{ L"Vintage" };
|
||||
|
||||
_buildCommandlinesHelper(appArgs, 1u, rawCommands);
|
||||
|
||||
VERIFY_ARE_EQUAL(1u, appArgs._startupActions.size());
|
||||
|
||||
auto actionAndArgs = appArgs._startupActions.at(0);
|
||||
VERIFY_ARE_EQUAL(ShortcutAction::NewTab, actionAndArgs.Action());
|
||||
VERIFY_IS_NOT_NULL(actionAndArgs.Args());
|
||||
auto myArgs = actionAndArgs.Args().try_as<NewTabArgs>();
|
||||
VERIFY_IS_NOT_NULL(myArgs);
|
||||
VERIFY_IS_NOT_NULL(myArgs.TerminalArgs());
|
||||
VERIFY_IS_TRUE(myArgs.TerminalArgs().Commandline().empty());
|
||||
VERIFY_IS_TRUE(myArgs.TerminalArgs().StartingDirectory().empty());
|
||||
VERIFY_IS_TRUE(myArgs.TerminalArgs().TabTitle().empty());
|
||||
VERIFY_IS_NULL(myArgs.TerminalArgs().TabColor());
|
||||
VERIFY_IS_NULL(myArgs.TerminalArgs().ProfileIndex());
|
||||
VERIFY_IS_TRUE(myArgs.TerminalArgs().Profile().empty());
|
||||
VERIFY_IS_FALSE(myArgs.TerminalArgs().ColorScheme().empty());
|
||||
VERIFY_ARE_EQUAL(expectedScheme, myArgs.TerminalArgs().ColorScheme());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -749,6 +783,7 @@ namespace TerminalAppLocalTests
|
|||
VERIFY_IS_FALSE(myArgs.TerminalArgs().Profile().empty());
|
||||
VERIFY_ARE_EQUAL(L"wsl -d Alpine", myArgs.TerminalArgs().Commandline());
|
||||
VERIFY_ARE_EQUAL(L"1", myArgs.TerminalArgs().Profile());
|
||||
VERIFY_IS_TRUE(myArgs.TerminalArgs().ColorScheme().empty());
|
||||
}
|
||||
{
|
||||
AppCommandlineArgs appArgs{};
|
||||
|
@ -777,6 +812,7 @@ namespace TerminalAppLocalTests
|
|||
VERIFY_IS_FALSE(myArgs.TerminalArgs().Profile().empty());
|
||||
VERIFY_ARE_EQUAL(L"wsl -d Alpine", myArgs.TerminalArgs().Commandline());
|
||||
VERIFY_ARE_EQUAL(L"1", myArgs.TerminalArgs().Profile());
|
||||
VERIFY_IS_TRUE(myArgs.TerminalArgs().ColorScheme().empty());
|
||||
}
|
||||
{
|
||||
AppCommandlineArgs appArgs{};
|
||||
|
@ -805,6 +841,7 @@ namespace TerminalAppLocalTests
|
|||
VERIFY_IS_FALSE(myArgs.TerminalArgs().Profile().empty());
|
||||
VERIFY_ARE_EQUAL(L"wsl -d Alpine -H", myArgs.TerminalArgs().Commandline());
|
||||
VERIFY_ARE_EQUAL(L"1", myArgs.TerminalArgs().Profile());
|
||||
VERIFY_IS_TRUE(myArgs.TerminalArgs().ColorScheme().empty());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -422,6 +422,9 @@ void AppCommandlineArgs::_addNewTerminalArgs(AppCommandlineArgs::NewTerminalSubc
|
|||
_suppressApplicationTitle,
|
||||
RS_A(L"CmdSuppressApplicationTitleDesc"));
|
||||
|
||||
subcommand.colorSchemeOption = subcommand.subcommand->add_option("--colorScheme",
|
||||
_startingColorScheme,
|
||||
RS_A(L"CmdColorSchemeArgDesc"));
|
||||
// Using positionals_at_end allows us to support "wt new-tab -d wsl -d Ubuntu"
|
||||
// without CLI11 thinking that we've specified -d twice.
|
||||
// There's an alternate construction where we make all subcommands "prefix commands",
|
||||
|
@ -494,6 +497,11 @@ NewTerminalArgs AppCommandlineArgs::_getNewTerminalArgs(AppCommandlineArgs::NewT
|
|||
args.SuppressApplicationTitle(_suppressApplicationTitle);
|
||||
}
|
||||
|
||||
if (*subcommand.colorSchemeOption)
|
||||
{
|
||||
args.ColorScheme(winrt::to_hstring(_startingColorScheme));
|
||||
}
|
||||
|
||||
return args;
|
||||
}
|
||||
|
||||
|
|
|
@ -63,6 +63,7 @@ private:
|
|||
CLI::Option* titleOption;
|
||||
CLI::Option* tabColorOption;
|
||||
CLI::Option* suppressApplicationTitleOption;
|
||||
CLI::Option* colorSchemeOption;
|
||||
};
|
||||
|
||||
struct NewPaneSubcommand : public NewTerminalSubcommand
|
||||
|
@ -87,6 +88,7 @@ private:
|
|||
std::string _startingDirectory;
|
||||
std::string _startingTitle;
|
||||
std::string _startingTabColor;
|
||||
std::string _startingColorScheme;
|
||||
bool _suppressApplicationTitle{ false };
|
||||
|
||||
winrt::Microsoft::Terminal::Settings::Model::FocusDirection _moveFocusDirection{ winrt::Microsoft::Terminal::Settings::Model::FocusDirection::None };
|
||||
|
|
|
@ -323,6 +323,10 @@
|
|||
<value>Open the tab with tabTitle overriding default title and suppressing title change messages from the application</value>
|
||||
<comment>{Locked="\"tabTitle\""}</comment>
|
||||
</data>
|
||||
<data name="CmdColorSchemeArgDesc" xml:space="preserve">
|
||||
<value>Open the tab with the specified color scheme, instead of the profile's set "colorScheme"</value>
|
||||
<comment>{Locked="\"colorScheme\""}</comment>
|
||||
</data>
|
||||
<data name="CmdVersionDesc" xml:space="preserve">
|
||||
<value>Display the application version</value>
|
||||
</data>
|
||||
|
|
|
@ -68,6 +68,10 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation
|
|||
const til::color tabColor{ _TabColor.Value() };
|
||||
ss << fmt::format(L"tabColor: {}, ", tabColor.ToHexString(true));
|
||||
}
|
||||
if (!_ColorScheme.empty())
|
||||
{
|
||||
ss << fmt::format(L"colorScheme: {}, ", _ColorScheme);
|
||||
}
|
||||
|
||||
if (_SuppressApplicationTitle)
|
||||
{
|
||||
|
@ -135,6 +139,11 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation
|
|||
}
|
||||
}
|
||||
|
||||
if (!_ColorScheme.empty())
|
||||
{
|
||||
ss << fmt::format(L"--colorScheme \"{}\" ", _ColorScheme);
|
||||
}
|
||||
|
||||
if (!_Commandline.empty())
|
||||
{
|
||||
ss << fmt::format(L"-- \"{}\" ", _Commandline);
|
||||
|
|
|
@ -70,6 +70,7 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation
|
|||
WINRT_PROPERTY(Windows::Foundation::IReference<int32_t>, ProfileIndex, nullptr);
|
||||
WINRT_PROPERTY(winrt::hstring, Profile, L"");
|
||||
WINRT_PROPERTY(Windows::Foundation::IReference<bool>, SuppressApplicationTitle, nullptr);
|
||||
WINRT_PROPERTY(winrt::hstring, ColorScheme);
|
||||
|
||||
static constexpr std::string_view CommandlineKey{ "commandline" };
|
||||
static constexpr std::string_view StartingDirectoryKey{ "startingDirectory" };
|
||||
|
@ -78,6 +79,7 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation
|
|||
static constexpr std::string_view ProfileIndexKey{ "index" };
|
||||
static constexpr std::string_view ProfileKey{ "profile" };
|
||||
static constexpr std::string_view SuppressApplicationTitleKey{ "suppressApplicationTitle" };
|
||||
static constexpr std::string_view ColorSchemeKey{ "colorScheme" };
|
||||
|
||||
public:
|
||||
hstring GenerateName() const;
|
||||
|
@ -91,7 +93,8 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation
|
|||
other.TabColor() == _TabColor &&
|
||||
other.ProfileIndex() == _ProfileIndex &&
|
||||
other.Profile() == _Profile &&
|
||||
other.SuppressApplicationTitle() == _SuppressApplicationTitle;
|
||||
other.SuppressApplicationTitle() == _SuppressApplicationTitle &&
|
||||
other.ColorScheme() == _ColorScheme;
|
||||
};
|
||||
static Model::NewTerminalArgs FromJson(const Json::Value& json)
|
||||
{
|
||||
|
@ -104,6 +107,7 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation
|
|||
JsonUtils::GetValueForKey(json, ProfileKey, args->_Profile);
|
||||
JsonUtils::GetValueForKey(json, TabColorKey, args->_TabColor);
|
||||
JsonUtils::GetValueForKey(json, SuppressApplicationTitleKey, args->_SuppressApplicationTitle);
|
||||
JsonUtils::GetValueForKey(json, ColorSchemeKey, args->_ColorScheme);
|
||||
return *args;
|
||||
}
|
||||
Model::NewTerminalArgs Copy() const
|
||||
|
@ -116,6 +120,7 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation
|
|||
copy->_ProfileIndex = _ProfileIndex;
|
||||
copy->_Profile = _Profile;
|
||||
copy->_SuppressApplicationTitle = _SuppressApplicationTitle;
|
||||
copy->_ColorScheme = _ColorScheme;
|
||||
return *copy;
|
||||
}
|
||||
};
|
||||
|
|
|
@ -100,6 +100,8 @@ namespace Microsoft.Terminal.Settings.Model
|
|||
|
||||
Windows.Foundation.IReference<Boolean> SuppressApplicationTitle;
|
||||
|
||||
String ColorScheme;
|
||||
|
||||
Boolean Equals(NewTerminalArgs other);
|
||||
String GenerateName();
|
||||
String ToCommandline();
|
||||
|
|
|
@ -118,6 +118,14 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation
|
|||
{
|
||||
settings.SuppressApplicationTitle(newTerminalArgs.SuppressApplicationTitle().Value());
|
||||
}
|
||||
if (!newTerminalArgs.ColorScheme().empty())
|
||||
{
|
||||
const auto schemes = appSettings.GlobalSettings().ColorSchemes();
|
||||
if (const auto& scheme = schemes.TryLookup(newTerminalArgs.ColorScheme()))
|
||||
{
|
||||
settings.ApplyColorScheme(scheme);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return settings;
|
||||
|
|
Loading…
Reference in a new issue