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

Add suppressApplicationTitle as boolean #2814

Merged
merged 20 commits into from
Nov 22, 2019
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/cascadia/SettingsSchema.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ Properties listed below are specific to each unique profile.
| `foreground` | Optional | String | | Sets the foreground color of the profile. Overrides `foreground` set in color scheme if `colorscheme` is set. Uses hex color format: `"#rrggbb"`. |
| `icon` | Optional | String | | Image file location of the icon used in the profile. Displays within the tab and the dropdown menu. See [Background Images and Icons](./SettingsSchema.md#background-images-and-icons) below for help on specifying your own icons |
| `scrollbarState` | Optional | String | | Defines the visibility of the scrollbar. Possible values: `"visible"`, `"hidden"` |
| `suppressApplicationTitle` | Optional | Boolean | | When set to `true`, `tabTitle` overrides the default title of the tab. When set to `false`, `tabTitle` behaves as normal. |
| `tabTitle` | Optional | String | | If set, will replace the `name` as the title to pass to the shell on startup. Some shells (like `bash`) may choose to ignore this initial value, while others (`cmd`, `powershell`) may use this value over the lifetime of the application. |

## Schemes
Expand Down
22 changes: 22 additions & 0 deletions src/cascadia/TerminalApp/Profile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ static constexpr std::string_view ForegroundKey{ "foreground" };
static constexpr std::string_view BackgroundKey{ "background" };
static constexpr std::string_view ColorTableKey{ "colorTable" };
static constexpr std::string_view TabTitleKey{ "tabTitle" };
static constexpr std::string_view SuppressApplicationTitleKey{ "suppressApplicationTitle" };
static constexpr std::string_view HistorySizeKey{ "historySize" };
static constexpr std::string_view SnapOnInputKey{ "snapOnInput" };
static constexpr std::string_view CursorColorKey{ "cursorColor" };
Expand Down Expand Up @@ -91,6 +92,7 @@ Profile::Profile(const std::optional<GUID>& guid) :
_defaultBackground{},
_colorTable{},
_tabTitle{},
_suppressApplicationTitle{},
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
_suppressApplicationTitle{},
_suppressApplicationTitle{ false },

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Isn't this only if it's set false as default?

_historySize{ DEFAULT_HISTORY_SIZE },
_snapOnInput{ true },
_cursorColor{ DEFAULT_CURSOR_COLOR },
Expand Down Expand Up @@ -674,6 +676,11 @@ void Profile::LayerJson(const Json::Value& json)
auto useAcrylic{ json[JsonKey(UseAcrylicKey)] };
_useAcrylic = useAcrylic.asBool();
}
if (json.isMember(JsonKey(SuppressApplicationTitleKey)))
{
auto suppressApplicationTitle{ json[JsonKey(SuppressApplicationTitleKey)] };
_suppressApplicationTitle = suppressApplicationTitle.asBool();
}
if (json.isMember(JsonKey(CloseOnExitKey)))
{
auto closeOnExit{ json[JsonKey(CloseOnExitKey)] };
Expand Down Expand Up @@ -806,6 +813,21 @@ std::wstring_view Profile::GetName() const noexcept
return _name;
}

// Method Description:
// - Returns the tab title, if one is set. Otherwise returns the empty string.
// Return Value:
// - this profile's tab title, if one is set. Otherwise returns the empty string.
std::wstring_view Profile::GetTabTitle() const noexcept
{
return _tabTitle.has_value() ? std::wstring_view{ _tabTitle.value().c_str(), _tabTitle.value().size() } :
std::wstring_view{ L"", 0 };
}

bool Profile::GetSuppressApplicationTitle() const noexcept
{
return _suppressApplicationTitle;
}

bool Profile::HasConnectionType() const noexcept
{
return _connectionType.has_value();
Expand Down
3 changes: 3 additions & 0 deletions src/cascadia/TerminalApp/Profile.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ class TerminalApp::Profile final
bool HasGuid() const noexcept;
bool HasSource() const noexcept;
GUID GetGuid() const noexcept;
std::wstring_view GetTabTitle() const noexcept;
void SetSource(std::wstring_view sourceNamespace) noexcept;
std::wstring_view GetName() const noexcept;
bool HasConnectionType() const noexcept;
Expand All @@ -81,6 +82,7 @@ class TerminalApp::Profile final
void SetIconPath(std::wstring_view path);

bool GetCloseOnExit() const noexcept;
bool GetSuppressApplicationTitle() const noexcept;
bool IsHidden() const noexcept;

void GenerateGuidIfNecessary() noexcept;
Expand Down Expand Up @@ -116,6 +118,7 @@ class TerminalApp::Profile final
std::optional<uint32_t> _defaultBackground;
std::array<uint32_t, COLOR_TABLE_SIZE> _colorTable;
std::optional<std::wstring> _tabTitle;
bool _suppressApplicationTitle;
int32_t _historySize;
bool _snapOnInput;
uint32_t _cursorColor;
Expand Down
14 changes: 13 additions & 1 deletion src/cascadia/TerminalApp/TerminalPage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -563,7 +563,19 @@ namespace winrt::TerminalApp::implementation
void TerminalPage::_UpdateTitle(std::shared_ptr<Tab> tab)
{
auto newTabTitle = tab->GetFocusedTitle();
tab->SetTabText(newTabTitle);
const auto lastFocusedProfile = tab->GetFocusedProfile().value();

auto matchingProfile = _settings->FindProfile(lastFocusedProfile);
if (matchingProfile)
{
if (matchingProfile->GetSuppressApplicationTitle())
{
auto profileTabTitle = matchingProfile->GetTabTitle();
newTabTitle = profileTabTitle.empty() ? matchingProfile->GetName() : profileTabTitle;
}
}

tab->SetTabText(winrt::to_hstring(newTabTitle));

if (_settings->GlobalSettings().GetShowTitleInTitlebar() &&
tab->IsFocused())
Expand Down
10 changes: 10 additions & 0 deletions src/cascadia/TerminalSettings/TerminalSettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,16 @@ namespace winrt::Microsoft::Terminal::Settings::implementation
_startingTitle = value;
}

bool TerminalSettings::SuppressApplicationTitle()
{
return _suppressApplicationTitle;
}

void TerminalSettings::SuppressApplicationTitle(bool value)
{
_suppressApplicationTitle = value;
}

hstring TerminalSettings::EnvironmentVariables()
{
return _envVars;
Expand Down
4 changes: 4 additions & 0 deletions src/cascadia/TerminalSettings/terminalsettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,9 @@ namespace winrt::Microsoft::Terminal::Settings::implementation
hstring StartingTitle();
void StartingTitle(hstring const& value);

bool SuppressApplicationTitle();
void SuppressApplicationTitle(bool value);

hstring EnvironmentVariables();
void EnvironmentVariables(hstring const& value);

Expand Down Expand Up @@ -122,6 +125,7 @@ namespace winrt::Microsoft::Terminal::Settings::implementation
hstring _commandline;
hstring _startingDir;
hstring _startingTitle;
bool _suppressApplicationTitle;
hstring _envVars;
Settings::IKeyBindings _keyBindings;
Settings::ScrollbarState _scrollbarState;
Expand Down