terminal/src/cascadia/TerminalSettings/TerminalSettings.cpp

354 lines
8.4 KiB
C++
Raw Normal View History

// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
#include "pch.h"
#include "TerminalSettings.h"
#include <DefaultSettings.h>
#include "TerminalSettings.g.cpp"
namespace winrt::Microsoft::Terminal::Settings::implementation
{
TerminalSettings::TerminalSettings() :
_defaultForeground{ DEFAULT_FOREGROUND_WITH_ALPHA },
_defaultBackground{ DEFAULT_BACKGROUND_WITH_ALPHA },
Add Selection Background Color as a setting to Profiles and Col… (#3471) <!-- Enter a brief description/summary of your PR here. What does it fix/what does it change/how was it tested (even manually, if necessary)? --> ## Summary of the Pull Request This introduces a setting to both Profiles and ColorSchemes called <code>selectionBackground</code> that allows you to change the selection background color to what's specified. If <code>selectionBackground</code> isn't set in either the profile or color scheme, it'll default to what it was before - white. <!-- Please review the items on the PR checklist before submitting--> ## PR Checklist * [x] Closes #3326 * [x] CLA signed. If not, go over [here](https://cla.opensource.microsoft.com/microsoft/Terminal) and sign the CLA * [x] Tests added/passed * [x] Requires documentation to be updated <!-- Describe how you validated the behavior. Add automated tests wherever possible, but list manual validation steps taken as well --> ## Validation Steps Performed - Added selectionBackground to existing profile and colorscheme tests. - Verified that the color does change to what I expect it to be when I add "selectionBackground" to either/both a profile and a color scheme. <hr> * adding selectionBackground to ColorScheme and TerminalSettings * Changing PaintSelection inside the renderers to take a SelectionBackground COLORREF * changes to conhost and terminal renderdata, and to terminal settings and core * IT WORKS * modification of unit tests, json schemas, reordering of functions * more movement * changed a couple of unit tests to add selectionBackground, added the setting to schemas, also added the optional setting to profiles * default selection background should be slightly offwhite like the default foreground is * reverting changes to .sln * cleaning up * adding comment * oops * added clangformat to my vs hehe * moving selectionBackground to IControlSettings and removing from ICoreSettings * trying to figure out why the WHOLE FILE LOOKS LIKE ITS CHANGED * here it goes again * pls * adding default foreground as the default for selection background in dx
2019-11-13 19:17:39 +01:00
_selectionBackground{ DEFAULT_FOREGROUND },
_colorTable{},
_historySize{ DEFAULT_HISTORY_SIZE },
_initialRows{ 30 },
_initialCols{ 80 },
_snapOnInput{ true },
_cursorColor{ DEFAULT_CURSOR_COLOR },
_cursorShape{ CursorStyle::Vintage },
_cursorHeight{ DEFAULT_CURSOR_HEIGHT },
_wordDelimiters{ DEFAULT_WORD_DELIMITERS },
_copyOnSelect{ false },
_useAcrylic{ false },
_tintOpacity{ 0.5 },
_padding{ DEFAULT_PADDING },
_fontFace{ DEFAULT_FONT_FACE },
_fontSize{ DEFAULT_FONT_SIZE },
_backgroundImage{},
_backgroundImageOpacity{ 1.0 },
_backgroundImageStretchMode{ winrt::Windows::UI::Xaml::Media::Stretch::UniformToFill },
Add support for background image alignment (as one setting) (#1959) * Implement base background image alignment settings TerminalSettings now has two new properties: * BackgroundImageHorizontalAlignment * BackgroundImageVerticalAlignment These properties are used in TermControl::_InitializeBackgroundBrush to specify the alignment for TermControl::_bgImageLayer. This is a base commit that will split into two possible branches: * Use one setting in profiles.json: "backgroundImageAlignment" * Use two settings in profiles.json: "backgroundImageHorizontal/VerticalAlignment" * Implement background image alignment profile setting Implement background image alignment as one profile setting. * This has the benefit of acting as a single setting when the user would likely want to change both horizontal and vertical alignment. * HorizontalAlignment and VerticalAlignment are still stored as a tuple in Profile because they are an optional field. And thus, it would not make sense for one of the alignments to be left unused while the other is not. * Cons are that the tuple signature is quite long, but it is only used in a small number of locations. The Serialize method is also a little mishapen with the nested switch statements. Empty lines have been added between base-level cases to improve readability. * Fix capitalization typo for BackgroundImageStretchModeKey In Profiles.cpp, the key for the image stretch mode json property had a lowercase 'i' in "Backgroundimage", not following proper UpperCamelCase. The "i" has been capitalized and the two usages of the constant have been updated as well. * Document Background Image settings * Adds entries SettingsSchema.md for the original 3 backgroundImage settings in addition to the new backgroundImageAlignment setting. * Fix setting capitalization error in UsingJsonSettings.md * The background image example in UsingJsonSettings.md listing a backgroundImageStretchMode of "Fill" has been corrected to "fill". Fixes #1949.
2019-07-25 06:47:06 +02:00
_backgroundImageHorizontalAlignment{ winrt::Windows::UI::Xaml::HorizontalAlignment::Center },
_backgroundImageVerticalAlignment{ winrt::Windows::UI::Xaml::VerticalAlignment::Center },
_keyBindings{ nullptr },
_scrollbarState{ ScrollbarState::Visible }
{
}
uint32_t TerminalSettings::DefaultForeground()
{
return _defaultForeground;
}
void TerminalSettings::DefaultForeground(uint32_t value)
{
_defaultForeground = value;
}
uint32_t TerminalSettings::DefaultBackground()
{
return _defaultBackground;
}
void TerminalSettings::DefaultBackground(uint32_t value)
{
_defaultBackground = value;
}
Add Selection Background Color as a setting to Profiles and Col… (#3471) <!-- Enter a brief description/summary of your PR here. What does it fix/what does it change/how was it tested (even manually, if necessary)? --> ## Summary of the Pull Request This introduces a setting to both Profiles and ColorSchemes called <code>selectionBackground</code> that allows you to change the selection background color to what's specified. If <code>selectionBackground</code> isn't set in either the profile or color scheme, it'll default to what it was before - white. <!-- Please review the items on the PR checklist before submitting--> ## PR Checklist * [x] Closes #3326 * [x] CLA signed. If not, go over [here](https://cla.opensource.microsoft.com/microsoft/Terminal) and sign the CLA * [x] Tests added/passed * [x] Requires documentation to be updated <!-- Describe how you validated the behavior. Add automated tests wherever possible, but list manual validation steps taken as well --> ## Validation Steps Performed - Added selectionBackground to existing profile and colorscheme tests. - Verified that the color does change to what I expect it to be when I add "selectionBackground" to either/both a profile and a color scheme. <hr> * adding selectionBackground to ColorScheme and TerminalSettings * Changing PaintSelection inside the renderers to take a SelectionBackground COLORREF * changes to conhost and terminal renderdata, and to terminal settings and core * IT WORKS * modification of unit tests, json schemas, reordering of functions * more movement * changed a couple of unit tests to add selectionBackground, added the setting to schemas, also added the optional setting to profiles * default selection background should be slightly offwhite like the default foreground is * reverting changes to .sln * cleaning up * adding comment * oops * added clangformat to my vs hehe * moving selectionBackground to IControlSettings and removing from ICoreSettings * trying to figure out why the WHOLE FILE LOOKS LIKE ITS CHANGED * here it goes again * pls * adding default foreground as the default for selection background in dx
2019-11-13 19:17:39 +01:00
uint32_t TerminalSettings::SelectionBackground()
{
return _selectionBackground;
}
void TerminalSettings::SelectionBackground(uint32_t value)
{
_selectionBackground = value;
}
uint32_t TerminalSettings::GetColorTableEntry(int32_t index) const
{
return _colorTable[index];
}
void TerminalSettings::SetColorTableEntry(int32_t index, uint32_t value)
{
auto const colorTableCount = gsl::narrow_cast<decltype(index)>(_colorTable.size());
THROW_HR_IF(E_INVALIDARG, index >= colorTableCount);
_colorTable[index] = value;
}
int32_t TerminalSettings::HistorySize()
{
return _historySize;
}
void TerminalSettings::HistorySize(int32_t value)
{
_historySize = value;
}
int32_t TerminalSettings::InitialRows()
{
return _initialRows;
}
void TerminalSettings::InitialRows(int32_t value)
{
_initialRows = value;
}
int32_t TerminalSettings::InitialCols()
{
return _initialCols;
}
void TerminalSettings::InitialCols(int32_t value)
{
_initialCols = value;
}
bool TerminalSettings::SnapOnInput()
{
return _snapOnInput;
}
void TerminalSettings::SnapOnInput(bool value)
{
_snapOnInput = value;
}
uint32_t TerminalSettings::CursorColor()
{
return _cursorColor;
}
void TerminalSettings::CursorColor(uint32_t value)
{
_cursorColor = value;
}
Settings::CursorStyle TerminalSettings::CursorShape() const noexcept
{
return _cursorShape;
}
void TerminalSettings::CursorShape(Settings::CursorStyle const& value) noexcept
{
_cursorShape = value;
}
uint32_t TerminalSettings::CursorHeight()
{
return _cursorHeight;
}
void TerminalSettings::CursorHeight(uint32_t value)
{
_cursorHeight = value;
}
hstring TerminalSettings::WordDelimiters()
{
return _wordDelimiters;
}
void TerminalSettings::WordDelimiters(hstring const& value)
{
_wordDelimiters = value;
}
bool TerminalSettings::CopyOnSelect()
{
return _copyOnSelect;
}
void TerminalSettings::CopyOnSelect(bool value)
{
_copyOnSelect = value;
}
bool TerminalSettings::UseAcrylic()
{
return _useAcrylic;
}
void TerminalSettings::UseAcrylic(bool value)
{
_useAcrylic = value;
}
double TerminalSettings::TintOpacity()
{
return _tintOpacity;
}
void TerminalSettings::TintOpacity(double value)
{
_tintOpacity = value;
}
hstring TerminalSettings::Padding()
{
return _padding;
}
void TerminalSettings::Padding(hstring value)
{
_padding = value;
}
hstring TerminalSettings::FontFace()
{
return _fontFace;
}
void TerminalSettings::FontFace(hstring const& value)
{
_fontFace = value;
}
int32_t TerminalSettings::FontSize()
{
return _fontSize;
}
void TerminalSettings::FontSize(int32_t value)
{
_fontSize = value;
}
void TerminalSettings::BackgroundImage(hstring const& value)
{
_backgroundImage = value;
}
hstring TerminalSettings::BackgroundImage()
{
return _backgroundImage;
}
void TerminalSettings::BackgroundImageOpacity(double value)
{
_backgroundImageOpacity = value;
}
double TerminalSettings::BackgroundImageOpacity()
{
return _backgroundImageOpacity;
}
winrt::Windows::UI::Xaml::Media::Stretch TerminalSettings::BackgroundImageStretchMode()
{
return _backgroundImageStretchMode;
}
void TerminalSettings::BackgroundImageStretchMode(winrt::Windows::UI::Xaml::Media::Stretch value)
{
_backgroundImageStretchMode = value;
}
Add support for background image alignment (as one setting) (#1959) * Implement base background image alignment settings TerminalSettings now has two new properties: * BackgroundImageHorizontalAlignment * BackgroundImageVerticalAlignment These properties are used in TermControl::_InitializeBackgroundBrush to specify the alignment for TermControl::_bgImageLayer. This is a base commit that will split into two possible branches: * Use one setting in profiles.json: "backgroundImageAlignment" * Use two settings in profiles.json: "backgroundImageHorizontal/VerticalAlignment" * Implement background image alignment profile setting Implement background image alignment as one profile setting. * This has the benefit of acting as a single setting when the user would likely want to change both horizontal and vertical alignment. * HorizontalAlignment and VerticalAlignment are still stored as a tuple in Profile because they are an optional field. And thus, it would not make sense for one of the alignments to be left unused while the other is not. * Cons are that the tuple signature is quite long, but it is only used in a small number of locations. The Serialize method is also a little mishapen with the nested switch statements. Empty lines have been added between base-level cases to improve readability. * Fix capitalization typo for BackgroundImageStretchModeKey In Profiles.cpp, the key for the image stretch mode json property had a lowercase 'i' in "Backgroundimage", not following proper UpperCamelCase. The "i" has been capitalized and the two usages of the constant have been updated as well. * Document Background Image settings * Adds entries SettingsSchema.md for the original 3 backgroundImage settings in addition to the new backgroundImageAlignment setting. * Fix setting capitalization error in UsingJsonSettings.md * The background image example in UsingJsonSettings.md listing a backgroundImageStretchMode of "Fill" has been corrected to "fill". Fixes #1949.
2019-07-25 06:47:06 +02:00
winrt::Windows::UI::Xaml::HorizontalAlignment TerminalSettings::BackgroundImageHorizontalAlignment()
{
return _backgroundImageHorizontalAlignment;
}
void TerminalSettings::BackgroundImageHorizontalAlignment(winrt::Windows::UI::Xaml::HorizontalAlignment value)
{
_backgroundImageHorizontalAlignment = value;
}
winrt::Windows::UI::Xaml::VerticalAlignment TerminalSettings::BackgroundImageVerticalAlignment()
{
return _backgroundImageVerticalAlignment;
}
void TerminalSettings::BackgroundImageVerticalAlignment(winrt::Windows::UI::Xaml::VerticalAlignment value)
{
_backgroundImageVerticalAlignment = value;
}
Settings::IKeyBindings TerminalSettings::KeyBindings()
{
return _keyBindings;
}
void TerminalSettings::KeyBindings(Settings::IKeyBindings const& value)
{
_keyBindings = value;
}
hstring TerminalSettings::Commandline()
{
return _commandline;
}
void TerminalSettings::Commandline(hstring const& value)
{
_commandline = value;
}
hstring TerminalSettings::StartingDirectory()
{
return _startingDir;
}
void TerminalSettings::StartingDirectory(hstring const& value)
{
_startingDir = value;
}
A better fix for #tab-titles-are-too-long (#2373) ### User Stories: 1. A user wants to be able to use the executable path as their starting title - Does anyone want this? 2. A user wants to be able to set a custom starting title, but have that title be overridable 3. A user wants to be able to set an overridable starting title, different from the profile name - Presumably someone will want this 4. A user totally wants to ignore the VT title and use something else - This will make more sense in the post [#1320] "Support runtime variables in the custom user title" settings ### Solutions: 1. `name`, `startingTitle`, `tabTitle` * a. `name` is only ever used as the profile name. * b. If `startingTitle` isn't set, then the executable path is used * c. If `startingTitle` is set, it's used as the initial title * d. If `tabTitle` is set, it overrides the title from the terminal * e. Current users of `tabTitle` need to manually update to the new behavior. 2. `name` as starting title, `tabTitle` as a different starting title * a. `name` is used as the starting title and the profile name in the dropdown * b. If `tabTitle` is set, we'll use that as the overridable starting title instead. * c. In the future, `dynamicTabTitle` or `tabTitleOverride` could be added to support [#1320] * d. Current users of `tabTitle` automatically get the new (different!) behavior. * e. User Story 1 is impossible - Does anyone want the behavior _ever_? Perhaps making that scenario impossible is good? 3. `name` unchanged, `tabTitle` as the starting title * a. `name` is only ever used as the profile name. * b. If `tabTitle` is set, we'll use that as the overridable starting title. * c. In the future, `dynamicTabTitle` or `tabTitleOverride` could be added to support [#1320] * d. Current users of `tabTitle` automatically get the new (different!) behavior. 4. `name` as starting title, `tabTitle` as different starting title, `suppressApplicationTitle` Boolean to force it to override * a. `name`, `tabTitle` work as in Solution 2. * b. When someone wants to be able to statically totally override that title (story 4), they can use `suppressApplicationTitle` * c. `suppressApplicationTitle` name is WIP * d. We'll add `suppressApplicationTitle` when someone complains * e. If you really want story 1, use `tabTitle: c:\path\to\foo.exe` and `suppressApplicationTitle`. [#1320]: https://github.com/microsoft/terminal/issues/1320 We've decided to pursue path 4.
2019-08-15 01:16:38 +02:00
hstring TerminalSettings::StartingTitle()
{
return _startingTitle;
}
void TerminalSettings::StartingTitle(hstring const& value)
{
_startingTitle = value;
}
bool TerminalSettings::SuppressApplicationTitle()
{
return _suppressApplicationTitle;
}
void TerminalSettings::SuppressApplicationTitle(bool value)
{
_suppressApplicationTitle = value;
}
hstring TerminalSettings::EnvironmentVariables()
{
return _envVars;
}
void TerminalSettings::EnvironmentVariables(hstring const& value)
{
_envVars = value;
}
Settings::ScrollbarState TerminalSettings::ScrollState() const noexcept
{
return _scrollbarState;
}
void TerminalSettings::ScrollState(Settings::ScrollbarState const& value) noexcept
{
_scrollbarState = value;
}
bool TerminalSettings::RetroTerminalEffect()
{
return _retroTerminalEffect;
}
void TerminalSettings::RetroTerminalEffect(bool value)
{
_retroTerminalEffect = value;
}
}