## Summary of the Pull Request This adds a new setting `intenseTextStyle`. It's a per-appearance, control setting, defaulting to `"all"`. * When set to `"all"` or `["bold", "bright"]`, then we'll render text as both **bold** and bright (1.10 behavior) * When set to `"bold"`, `["bold"]`, we'll render text formatted with `^[[1m` as **bold**, but not bright * When set to `"bright"`, `["bright"]`, we'll render text formatted with `^[[1m` as bright, but not bold. This is the pre 1.10 behavior * When set to `"none"`, we won't do anything special for it at all. ## references * I last did this in #10648. This time it's an enum, so we can add bright in the future. It's got positive wording this time. * ~We will want to add `"bright"` as a value in the future, to disable the auto intense->bright conversion.~ I just did that now. * #5682 is related ## PR Checklist * [x] Closes #10576 * [x] I seriously don't think we have an issue for "disable intense is bright", but I'm not crazy, people wanted that, right? https://github.com/microsoft/terminal/issues/2916#issuecomment-544880423 was the closest * [x] I work here * [x] Tests added/passed * [x] https://github.com/MicrosoftDocs/terminal/pull/381 ## Validation Steps Performed <!-- ![image](https://user-images.githubusercontent.com/18356694/125480327-07f6b711-6bca-4c1b-9a76-75fc978c702d.png) --> ![image](https://user-images.githubusercontent.com/18356694/128929228-504933ee-cf50-43a2-9982-55110ba39191.png) Yea that works. Printed some bold text, toggled it on, the text was no longer bold. hooray. ### EDIT, 10 Aug ```json "intenseTextStyle": "none", "intenseTextStyle": "bold", "intenseTextStyle": "bright", "intenseTextStyle": "all", "intenseTextStyle": ["bold", "bright"], ``` all work now. Repro script: ```sh printf "\e[1m[bold]\e[m[normal]\e[34m[blue]\e[1m[bold blue]\e[m\n" ```
148 lines
7.6 KiB
C++
148 lines
7.6 KiB
C++
// Copyright (c) Microsoft Corporation.
|
|
// Licensed under the MIT license.
|
|
|
|
#include "pch.h"
|
|
#include "AppearanceConfig.h"
|
|
#include "AppearanceConfig.g.cpp"
|
|
#include "TerminalSettingsSerializationHelpers.h"
|
|
#include "JsonUtils.h"
|
|
|
|
using namespace winrt::Microsoft::Terminal::Control;
|
|
using namespace Microsoft::Terminal::Settings::Model;
|
|
using namespace winrt::Windows::UI::Xaml;
|
|
using namespace winrt::Microsoft::Terminal::Settings::Model::implementation;
|
|
|
|
static constexpr std::string_view ForegroundKey{ "foreground" };
|
|
static constexpr std::string_view BackgroundKey{ "background" };
|
|
static constexpr std::string_view SelectionBackgroundKey{ "selectionBackground" };
|
|
static constexpr std::string_view CursorColorKey{ "cursorColor" };
|
|
static constexpr std::string_view CursorShapeKey{ "cursorShape" };
|
|
static constexpr std::string_view CursorHeightKey{ "cursorHeight" };
|
|
static constexpr std::string_view BackgroundImageKey{ "backgroundImage" };
|
|
static constexpr std::string_view ColorSchemeKey{ "colorScheme" };
|
|
static constexpr std::string_view BackgroundImageOpacityKey{ "backgroundImageOpacity" };
|
|
static constexpr std::string_view BackgroundImageStretchModeKey{ "backgroundImageStretchMode" };
|
|
static constexpr std::string_view BackgroundImageAlignmentKey{ "backgroundImageAlignment" };
|
|
static constexpr std::string_view RetroTerminalEffectKey{ "experimental.retroTerminalEffect" };
|
|
static constexpr std::string_view PixelShaderPathKey{ "experimental.pixelShaderPath" };
|
|
static constexpr std::string_view IntenseTextStyleKey{ "intenseTextStyle" };
|
|
|
|
winrt::Microsoft::Terminal::Settings::Model::implementation::AppearanceConfig::AppearanceConfig(const winrt::weak_ref<Profile> sourceProfile) :
|
|
_sourceProfile(sourceProfile)
|
|
{
|
|
}
|
|
|
|
winrt::com_ptr<AppearanceConfig> AppearanceConfig::CopyAppearance(const winrt::com_ptr<AppearanceConfig> source, const winrt::weak_ref<Profile> sourceProfile)
|
|
{
|
|
auto appearance{ winrt::make_self<AppearanceConfig>(sourceProfile) };
|
|
auto const sourceAppearance = source.try_as<AppearanceConfig>();
|
|
appearance->_BackgroundImagePath = sourceAppearance->_BackgroundImagePath;
|
|
appearance->_BackgroundImageOpacity = sourceAppearance->_BackgroundImageOpacity;
|
|
appearance->_BackgroundImageStretchMode = sourceAppearance->_BackgroundImageStretchMode;
|
|
appearance->_ColorSchemeName = sourceAppearance->_ColorSchemeName;
|
|
appearance->_Foreground = sourceAppearance->_Foreground;
|
|
appearance->_Background = sourceAppearance->_Background;
|
|
appearance->_SelectionBackground = sourceAppearance->_SelectionBackground;
|
|
appearance->_CursorColor = sourceAppearance->_CursorColor;
|
|
appearance->_CursorShape = sourceAppearance->_CursorShape;
|
|
appearance->_CursorHeight = sourceAppearance->_CursorHeight;
|
|
appearance->_BackgroundImageAlignment = sourceAppearance->_BackgroundImageAlignment;
|
|
appearance->_RetroTerminalEffect = sourceAppearance->_RetroTerminalEffect;
|
|
appearance->_PixelShaderPath = sourceAppearance->_PixelShaderPath;
|
|
appearance->_IntenseTextStyle = sourceAppearance->_IntenseTextStyle;
|
|
return appearance;
|
|
}
|
|
|
|
Json::Value AppearanceConfig::ToJson() const
|
|
{
|
|
Json::Value json{ Json::ValueType::objectValue };
|
|
|
|
JsonUtils::SetValueForKey(json, ForegroundKey, _Foreground);
|
|
JsonUtils::SetValueForKey(json, BackgroundKey, _Background);
|
|
JsonUtils::SetValueForKey(json, SelectionBackgroundKey, _SelectionBackground);
|
|
JsonUtils::SetValueForKey(json, CursorColorKey, _CursorColor);
|
|
JsonUtils::SetValueForKey(json, ColorSchemeKey, _ColorSchemeName);
|
|
JsonUtils::SetValueForKey(json, CursorHeightKey, _CursorHeight);
|
|
JsonUtils::SetValueForKey(json, CursorShapeKey, _CursorShape);
|
|
JsonUtils::SetValueForKey(json, BackgroundImageKey, _BackgroundImagePath);
|
|
JsonUtils::SetValueForKey(json, BackgroundImageOpacityKey, _BackgroundImageOpacity);
|
|
JsonUtils::SetValueForKey(json, BackgroundImageStretchModeKey, _BackgroundImageStretchMode);
|
|
JsonUtils::SetValueForKey(json, BackgroundImageAlignmentKey, _BackgroundImageAlignment);
|
|
JsonUtils::SetValueForKey(json, RetroTerminalEffectKey, _RetroTerminalEffect);
|
|
JsonUtils::SetValueForKey(json, PixelShaderPathKey, _PixelShaderPath);
|
|
JsonUtils::SetValueForKey(json, IntenseTextStyleKey, _IntenseTextStyle);
|
|
|
|
return json;
|
|
}
|
|
|
|
// Method Description:
|
|
// - Layer values from the given json object on top of the existing properties
|
|
// of this object. For any keys we're expecting to be able to parse in the
|
|
// given object, we'll parse them and replace our settings with values from
|
|
// the new json object. Properties that _aren't_ in the json object will _not_
|
|
// be replaced.
|
|
// - Optional values that are set to `null` in the json object
|
|
// will be set to nullopt.
|
|
// - This is similar to Profile::LayerJson but for AppearanceConfig
|
|
// Arguments:
|
|
// - json: an object which should be a partial serialization of an AppearanceConfig object.
|
|
void AppearanceConfig::LayerJson(const Json::Value& json)
|
|
{
|
|
JsonUtils::GetValueForKey(json, ForegroundKey, _Foreground);
|
|
JsonUtils::GetValueForKey(json, BackgroundKey, _Background);
|
|
JsonUtils::GetValueForKey(json, SelectionBackgroundKey, _SelectionBackground);
|
|
JsonUtils::GetValueForKey(json, CursorColorKey, _CursorColor);
|
|
JsonUtils::GetValueForKey(json, CursorHeightKey, _CursorHeight);
|
|
JsonUtils::GetValueForKey(json, ColorSchemeKey, _ColorSchemeName);
|
|
JsonUtils::GetValueForKey(json, CursorShapeKey, _CursorShape);
|
|
JsonUtils::GetValueForKey(json, BackgroundImageKey, _BackgroundImagePath);
|
|
JsonUtils::GetValueForKey(json, BackgroundImageOpacityKey, _BackgroundImageOpacity);
|
|
JsonUtils::GetValueForKey(json, BackgroundImageStretchModeKey, _BackgroundImageStretchMode);
|
|
JsonUtils::GetValueForKey(json, BackgroundImageAlignmentKey, _BackgroundImageAlignment);
|
|
JsonUtils::GetValueForKey(json, RetroTerminalEffectKey, _RetroTerminalEffect);
|
|
JsonUtils::GetValueForKey(json, PixelShaderPathKey, _PixelShaderPath);
|
|
JsonUtils::GetValueForKey(json, IntenseTextStyleKey, _IntenseTextStyle);
|
|
}
|
|
|
|
winrt::Microsoft::Terminal::Settings::Model::Profile AppearanceConfig::SourceProfile()
|
|
{
|
|
return _sourceProfile.get();
|
|
}
|
|
|
|
// Method Description:
|
|
// - Returns this AppearanceConfig's background image path, if one is set, expanding
|
|
// any environment variables in the path, if there are any.
|
|
// - Or if "DesktopWallpaper" is set, then gets the path to the desktops wallpaper.
|
|
// - This is the same as Profile::ExpandedBackgroundImagePath, but for AppearanceConfig
|
|
// - NOTE: This is just placeholder for now, eventually the path will no longer be expanded in the settings model
|
|
// Return Value:
|
|
// - This profile's expanded background image path / desktops's wallpaper path /the empty string.
|
|
winrt::hstring AppearanceConfig::ExpandedBackgroundImagePath()
|
|
{
|
|
const auto path{ BackgroundImagePath() };
|
|
if (path.empty())
|
|
{
|
|
return path;
|
|
}
|
|
// checks if the user would like to copy their desktop wallpaper
|
|
// if so, replaces the path with the desktop wallpaper's path
|
|
else if (path == L"desktopWallpaper")
|
|
{
|
|
WCHAR desktopWallpaper[MAX_PATH];
|
|
|
|
// "The returned string will not exceed MAX_PATH characters" as of 2020
|
|
if (SystemParametersInfo(SPI_GETDESKWALLPAPER, MAX_PATH, desktopWallpaper, SPIF_UPDATEINIFILE))
|
|
{
|
|
return winrt::hstring{ (desktopWallpaper) };
|
|
}
|
|
else
|
|
{
|
|
return winrt::hstring{ L"" };
|
|
}
|
|
}
|
|
else
|
|
{
|
|
return winrt::hstring{ wil::ExpandEnvironmentStringsW<std::wstring>(path.c_str()) };
|
|
}
|
|
}
|