Skip to content

Commit 2f68814

Browse files
authored
Use ControlProperties macros everywhere (#12145)
When I added these macros in #11619, the real purpose was to make sure we don't forget to add new settings to these test mocks as well. However, I totally forgot to convert those. I guess that happens with a 1300 line diff ¯\\\_(ツ)_/¯ * [x] Is a codehealth thing * [x] I work here * [x] tests still pass
1 parent eb83469 commit 2f68814

File tree

5 files changed

+57
-215
lines changed

5 files changed

+57
-215
lines changed

scratch/ScratchIslandApp/SampleApp/MyPage.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ namespace winrt::SampleApp::implementation
4141
TerminalConnection::ConnectionInformation connectInfo{ myClass, connectionSettings };
4242

4343
TerminalConnection::ITerminalConnection conn{ TerminalConnection::ConnectionInformation::CreateConnection(connectInfo) };
44-
Control::TermControl control{ *settings, conn };
44+
Control::TermControl control{ *settings, *settings, conn };
4545

4646
InProcContent().Children().Append(control);
4747
}

scratch/ScratchIslandApp/SampleApp/MySettings.h

Lines changed: 12 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -5,84 +5,29 @@ Licensed under the MIT license.
55
#pragma once
66
#include "../../inc/cppwinrt_utils.h"
77
#include "../types/inc/colorTable.hpp"
8+
#include "../../inc/ControlProperties.h"
89

910
#include <DefaultSettings.h>
1011
#include <conattrs.hpp>
1112
#include "MySettings.g.h"
1213

14+
using IFontFeatureMap = winrt::Windows::Foundation::Collections::IMap<winrt::hstring, uint32_t>;
15+
using IFontAxesMap = winrt::Windows::Foundation::Collections::IMap<winrt::hstring, float>;
16+
1317
namespace winrt::SampleApp::implementation
1418
{
1519
struct MySettings : MySettingsT<MySettings>
1620
{
17-
// --------------------------- Core Settings ---------------------------
18-
// All of these settings are defined in ICoreSettings.
19-
20-
WINRT_PROPERTY(til::color, DefaultForeground, DEFAULT_FOREGROUND);
21-
WINRT_PROPERTY(til::color, DefaultBackground, DEFAULT_BACKGROUND);
22-
WINRT_PROPERTY(til::color, SelectionBackground, DEFAULT_FOREGROUND);
23-
WINRT_PROPERTY(int32_t, HistorySize, DEFAULT_HISTORY_SIZE);
24-
WINRT_PROPERTY(int32_t, InitialRows, 30);
25-
WINRT_PROPERTY(int32_t, InitialCols, 80);
26-
27-
WINRT_PROPERTY(bool, SnapOnInput, true);
28-
WINRT_PROPERTY(bool, AltGrAliasing, true);
29-
WINRT_PROPERTY(til::color, CursorColor, DEFAULT_CURSOR_COLOR);
30-
WINRT_PROPERTY(winrt::Microsoft::Terminal::Core::CursorStyle, CursorShape, winrt::Microsoft::Terminal::Core::CursorStyle::Vintage);
31-
WINRT_PROPERTY(uint32_t, CursorHeight, DEFAULT_CURSOR_HEIGHT);
32-
WINRT_PROPERTY(winrt::hstring, WordDelimiters, DEFAULT_WORD_DELIMITERS);
33-
WINRT_PROPERTY(bool, CopyOnSelect, false);
34-
WINRT_PROPERTY(bool, InputServiceWarning, true);
35-
WINRT_PROPERTY(bool, FocusFollowMouse, false);
36-
37-
WINRT_PROPERTY(winrt::Windows::Foundation::IReference<winrt::Microsoft::Terminal::Core::Color>, TabColor, nullptr);
38-
39-
WINRT_PROPERTY(winrt::Windows::Foundation::IReference<winrt::Microsoft::Terminal::Core::Color>, StartingTabColor, nullptr);
40-
41-
winrt::Microsoft::Terminal::Core::ICoreAppearance UnfocusedAppearance() { return {}; };
42-
43-
WINRT_PROPERTY(bool, TrimBlockSelection, false);
44-
// ------------------------ End of Core Settings -----------------------
45-
46-
WINRT_PROPERTY(winrt::hstring, ProfileName);
47-
WINRT_PROPERTY(bool, UseAcrylic, false);
48-
WINRT_PROPERTY(double, Opacity, .5);
49-
WINRT_PROPERTY(winrt::hstring, Padding, DEFAULT_PADDING);
50-
WINRT_PROPERTY(winrt::hstring, FontFace, L"Consolas");
51-
WINRT_PROPERTY(int32_t, FontSize, DEFAULT_FONT_SIZE);
52-
53-
WINRT_PROPERTY(winrt::Windows::UI::Text::FontWeight, FontWeight);
54-
55-
WINRT_PROPERTY(winrt::hstring, BackgroundImage);
56-
WINRT_PROPERTY(double, BackgroundImageOpacity, 1.0);
57-
58-
WINRT_PROPERTY(winrt::Windows::UI::Xaml::Media::Stretch, BackgroundImageStretchMode, winrt::Windows::UI::Xaml::Media::Stretch::UniformToFill);
59-
WINRT_PROPERTY(winrt::Windows::UI::Xaml::HorizontalAlignment, BackgroundImageHorizontalAlignment, winrt::Windows::UI::Xaml::HorizontalAlignment::Center);
60-
WINRT_PROPERTY(winrt::Windows::UI::Xaml::VerticalAlignment, BackgroundImageVerticalAlignment, winrt::Windows::UI::Xaml::VerticalAlignment::Center);
61-
62-
WINRT_PROPERTY(winrt::Microsoft::Terminal::Control::IKeyBindings, KeyBindings, nullptr);
63-
64-
WINRT_PROPERTY(winrt::hstring, Commandline);
65-
WINRT_PROPERTY(winrt::hstring, StartingDirectory);
66-
WINRT_PROPERTY(winrt::hstring, StartingTitle);
67-
WINRT_PROPERTY(bool, SuppressApplicationTitle);
68-
WINRT_PROPERTY(winrt::hstring, EnvironmentVariables);
69-
70-
WINRT_PROPERTY(winrt::Microsoft::Terminal::Control::ScrollbarState, ScrollState, winrt::Microsoft::Terminal::Control::ScrollbarState::Visible);
71-
72-
WINRT_PROPERTY(winrt::Microsoft::Terminal::Control::TextAntialiasingMode, AntialiasingMode, winrt::Microsoft::Terminal::Control::TextAntialiasingMode::Grayscale);
73-
74-
WINRT_PROPERTY(bool, RetroTerminalEffect, false);
75-
WINRT_PROPERTY(bool, ForceFullRepaintRendering, false);
76-
WINRT_PROPERTY(bool, SoftwareRendering, false);
77-
WINRT_PROPERTY(bool, ForceVTInput, false);
78-
79-
WINRT_PROPERTY(winrt::hstring, PixelShaderPath);
80-
81-
WINRT_PROPERTY(bool, DetectURLs, true);
82-
83-
private:
21+
// Color Table is special because it's an array
8422
std::array<winrt::Microsoft::Terminal::Core::Color, COLOR_TABLE_SIZE> _ColorTable;
8523

24+
#define SETTINGS_GEN(type, name, ...) WINRT_PROPERTY(type, name, __VA_ARGS__);
25+
CORE_SETTINGS(SETTINGS_GEN)
26+
CORE_APPEARANCE_SETTINGS(SETTINGS_GEN)
27+
CONTROL_SETTINGS(SETTINGS_GEN)
28+
CONTROL_APPEARANCE_SETTINGS(SETTINGS_GEN)
29+
#undef SETTINGS_GEN
30+
8631
public:
8732
winrt::Microsoft::Terminal::Core::Color GetColorTableEntry(int32_t index) noexcept { return _ColorTable.at(index); }
8833
std::array<winrt::Microsoft::Terminal::Core::Color, 16> ColorTable() { return _ColorTable; }

src/cascadia/UnitTests_Control/MockControlSettings.h

Lines changed: 20 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ Licensed under the MIT license.
66

77
#include <DefaultSettings.h>
88
#include <conattrs.hpp>
9+
#include "../../inc/ControlProperties.h"
910

1011
using IFontFeatureMap = winrt::Windows::Foundation::Collections::IMap<winrt::hstring, uint32_t>;
1112
using IFontAxesMap = winrt::Windows::Foundation::Collections::IMap<winrt::hstring, float>;
@@ -14,87 +15,27 @@ namespace ControlUnitTests
1415
{
1516
class MockControlSettings : public winrt::implements<MockControlSettings, winrt::Microsoft::Terminal::Core::ICoreSettings, winrt::Microsoft::Terminal::Control::IControlSettings, winrt::Microsoft::Terminal::Core::ICoreAppearance, winrt::Microsoft::Terminal::Control::IControlAppearance>
1617
{
17-
public:
18-
MockControlSettings() = default;
19-
20-
// --------------------------- Core Settings ---------------------------
21-
// All of these settings are defined in ICoreSettings.
22-
23-
WINRT_PROPERTY(til::color, DefaultForeground, DEFAULT_FOREGROUND);
24-
WINRT_PROPERTY(til::color, DefaultBackground, DEFAULT_BACKGROUND);
25-
WINRT_PROPERTY(til::color, SelectionBackground, DEFAULT_FOREGROUND);
26-
WINRT_PROPERTY(int32_t, HistorySize, DEFAULT_HISTORY_SIZE);
27-
WINRT_PROPERTY(int32_t, InitialRows, 30);
28-
WINRT_PROPERTY(int32_t, InitialCols, 80);
29-
30-
WINRT_PROPERTY(bool, SnapOnInput, true);
31-
WINRT_PROPERTY(bool, AltGrAliasing, true);
32-
WINRT_PROPERTY(til::color, CursorColor, DEFAULT_CURSOR_COLOR);
33-
WINRT_PROPERTY(winrt::Microsoft::Terminal::Core::CursorStyle, CursorShape, winrt::Microsoft::Terminal::Core::CursorStyle::Vintage);
34-
WINRT_PROPERTY(uint32_t, CursorHeight, DEFAULT_CURSOR_HEIGHT);
35-
WINRT_PROPERTY(winrt::hstring, WordDelimiters, DEFAULT_WORD_DELIMITERS);
36-
WINRT_PROPERTY(bool, CopyOnSelect, false);
37-
WINRT_PROPERTY(bool, FocusFollowMouse, false);
38-
39-
WINRT_PROPERTY(winrt::Windows::Foundation::IReference<winrt::Microsoft::Terminal::Core::Color>, TabColor, nullptr);
40-
41-
WINRT_PROPERTY(winrt::Windows::Foundation::IReference<winrt::Microsoft::Terminal::Core::Color>, StartingTabColor, nullptr);
42-
43-
winrt::Microsoft::Terminal::Core::ICoreAppearance UnfocusedAppearance() { return {}; };
44-
45-
WINRT_PROPERTY(bool, TrimBlockSelection, false);
46-
WINRT_PROPERTY(bool, DetectURLs, true);
47-
WINRT_PROPERTY(bool, IntenseIsBright, true);
48-
WINRT_PROPERTY(bool, AdjustIndistinguishableColors, true);
49-
// ------------------------ End of Core Settings -----------------------
50-
51-
WINRT_PROPERTY(winrt::hstring, ProfileName);
52-
WINRT_PROPERTY(winrt::hstring, ProfileSource);
53-
WINRT_PROPERTY(bool, UseAcrylic, false);
54-
WINRT_PROPERTY(double, Opacity, .5);
55-
WINRT_PROPERTY(winrt::hstring, Padding, DEFAULT_PADDING);
56-
WINRT_PROPERTY(winrt::hstring, FontFace, L"Consolas");
57-
WINRT_PROPERTY(int32_t, FontSize, DEFAULT_FONT_SIZE);
58-
59-
WINRT_PROPERTY(winrt::Windows::UI::Text::FontWeight, FontWeight);
60-
61-
WINRT_PROPERTY(winrt::hstring, BackgroundImage);
62-
WINRT_PROPERTY(double, BackgroundImageOpacity, 1.0);
63-
64-
WINRT_PROPERTY(winrt::Windows::UI::Xaml::Media::Stretch, BackgroundImageStretchMode, winrt::Windows::UI::Xaml::Media::Stretch::UniformToFill);
65-
WINRT_PROPERTY(winrt::Windows::UI::Xaml::HorizontalAlignment, BackgroundImageHorizontalAlignment, winrt::Windows::UI::Xaml::HorizontalAlignment::Center);
66-
WINRT_PROPERTY(winrt::Windows::UI::Xaml::VerticalAlignment, BackgroundImageVerticalAlignment, winrt::Windows::UI::Xaml::VerticalAlignment::Center);
67-
68-
WINRT_PROPERTY(winrt::Microsoft::Terminal::Control::IKeyBindings, KeyBindings, nullptr);
69-
70-
WINRT_PROPERTY(winrt::hstring, Commandline);
71-
WINRT_PROPERTY(winrt::hstring, StartingDirectory);
72-
WINRT_PROPERTY(winrt::hstring, StartingTitle);
73-
WINRT_PROPERTY(bool, SuppressApplicationTitle);
74-
WINRT_PROPERTY(winrt::hstring, EnvironmentVariables);
75-
76-
WINRT_PROPERTY(winrt::Microsoft::Terminal::Control::ScrollbarState, ScrollState, winrt::Microsoft::Terminal::Control::ScrollbarState::Visible);
77-
WINRT_PROPERTY(bool, UseAtlasEngine, false);
78-
79-
WINRT_PROPERTY(winrt::Microsoft::Terminal::Control::TextAntialiasingMode, AntialiasingMode, winrt::Microsoft::Terminal::Control::TextAntialiasingMode::Grayscale);
80-
81-
WINRT_PROPERTY(bool, RetroTerminalEffect, false);
82-
WINRT_PROPERTY(bool, ForceFullRepaintRendering, false);
83-
WINRT_PROPERTY(bool, SoftwareRendering, false);
84-
WINRT_PROPERTY(bool, ForceVTInput, false);
85-
86-
WINRT_PROPERTY(winrt::hstring, PixelShaderPath);
87-
88-
WINRT_PROPERTY(IFontFeatureMap, FontFeatures);
89-
WINRT_PROPERTY(IFontAxesMap, FontAxes);
90-
WINRT_PROPERTY(bool, IntenseIsBold, true);
91-
92-
private:
18+
// Color Table is special because it's an array
9319
std::array<winrt::Microsoft::Terminal::Core::Color, COLOR_TABLE_SIZE> _ColorTable;
9420

21+
#define SETTINGS_GEN(type, name, ...) WINRT_PROPERTY(type, name, __VA_ARGS__);
22+
CORE_SETTINGS(SETTINGS_GEN)
23+
CORE_APPEARANCE_SETTINGS(SETTINGS_GEN)
24+
CONTROL_SETTINGS(SETTINGS_GEN)
25+
CONTROL_APPEARANCE_SETTINGS(SETTINGS_GEN)
26+
#undef SETTINGS_GEN
27+
9528
public:
96-
winrt::Microsoft::Terminal::Core::Color GetColorTableEntry(int32_t index) noexcept { return _ColorTable.at(index); }
97-
std::array<winrt::Microsoft::Terminal::Core::Color, 16> ColorTable() { return _ColorTable; }
98-
void ColorTable(std::array<winrt::Microsoft::Terminal::Core::Color, 16> /*colors*/) {}
29+
MockControlSettings() = default;
30+
31+
winrt::Microsoft::Terminal::Core::Color GetColorTableEntry(int32_t index) noexcept
32+
{
33+
return _ColorTable.at(index);
34+
}
35+
void SetColorTableEntry(int32_t index,
36+
winrt::Microsoft::Terminal::Core::Color color) noexcept
37+
{
38+
_ColorTable.at(index) = color;
39+
}
9940
};
10041
}

src/cascadia/UnitTests_TerminalCore/MockTermSettings.h

Lines changed: 21 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include <WexTestClass.h>
55

66
#include "DefaultSettings.h"
7+
#include "../../inc/ControlProperties.h"
78

89
#include <winrt/Microsoft.Terminal.Core.h>
910

@@ -13,75 +14,30 @@ namespace TerminalCoreUnitTests
1314
{
1415
class MockTermSettings : public winrt::implements<MockTermSettings, ICoreSettings, ICoreAppearance>
1516
{
17+
// Color Table is special because it's an array
18+
std::array<winrt::Microsoft::Terminal::Core::Color, COLOR_TABLE_SIZE> _ColorTable;
19+
20+
#define SETTINGS_GEN(type, name, ...) WINRT_PROPERTY(type, name, __VA_ARGS__);
21+
CORE_SETTINGS(SETTINGS_GEN)
22+
CORE_APPEARANCE_SETTINGS(SETTINGS_GEN)
23+
#undef SETTINGS_GEN
24+
1625
public:
1726
MockTermSettings(int32_t historySize, int32_t initialRows, int32_t initialCols) :
18-
_historySize(historySize),
19-
_initialRows(initialRows),
20-
_initialCols(initialCols)
27+
_HistorySize(historySize),
28+
_InitialRows(initialRows),
29+
_InitialCols(initialCols)
2130
{
2231
}
2332

24-
// property getters - all implemented
25-
int32_t HistorySize() { return _historySize; }
26-
int32_t InitialRows() { return _initialRows; }
27-
int32_t InitialCols() { return _initialCols; }
28-
til::color DefaultForeground() { return COLOR_WHITE; }
29-
til::color DefaultBackground() { return COLOR_BLACK; }
30-
bool SnapOnInput() { return false; }
31-
bool AltGrAliasing() { return true; }
32-
til::color CursorColor() { return COLOR_WHITE; }
33-
CursorStyle CursorShape() const noexcept { return CursorStyle::Vintage; }
34-
uint32_t CursorHeight() { return 42UL; }
35-
winrt::hstring WordDelimiters() { return winrt::hstring(DEFAULT_WORD_DELIMITERS); }
36-
bool CopyOnSelect() { return _copyOnSelect; }
37-
bool FocusFollowMouse() { return _focusFollowMouse; }
38-
winrt::hstring StartingTitle() { return _startingTitle; }
39-
bool SuppressApplicationTitle() { return _suppressApplicationTitle; }
40-
til::color SelectionBackground() { return COLOR_WHITE; }
41-
bool ForceVTInput() { return false; }
42-
ICoreAppearance UnfocusedAppearance() { return {}; };
43-
winrt::Windows::Foundation::IReference<winrt::Microsoft::Terminal::Core::Color> TabColor() { return nullptr; }
44-
winrt::Windows::Foundation::IReference<winrt::Microsoft::Terminal::Core::Color> StartingTabColor() { return nullptr; }
45-
bool TrimBlockSelection() { return false; }
46-
bool DetectURLs() { return true; }
47-
48-
// other implemented methods
49-
til::color GetColorTableEntry(int32_t) const { return 123; }
50-
51-
// property setters - all unimplemented
52-
void HistorySize(int32_t) {}
53-
void InitialRows(int32_t) {}
54-
void InitialCols(int32_t) {}
55-
void DefaultForeground(til::color) {}
56-
void DefaultBackground(til::color) {}
57-
void SnapOnInput(bool) {}
58-
void AltGrAliasing(bool) {}
59-
void CursorColor(til::color) {}
60-
void CursorShape(CursorStyle const&) noexcept {}
61-
void CursorHeight(uint32_t) {}
62-
void WordDelimiters(winrt::hstring) {}
63-
void CopyOnSelect(bool copyOnSelect) { _copyOnSelect = copyOnSelect; }
64-
void FocusFollowMouse(bool focusFollowMouse) { _focusFollowMouse = focusFollowMouse; }
65-
void StartingTitle(winrt::hstring const& value) { _startingTitle = value; }
66-
void SuppressApplicationTitle(bool suppressApplicationTitle) { _suppressApplicationTitle = suppressApplicationTitle; }
67-
void SelectionBackground(til::color) {}
68-
void ForceVTInput(bool) {}
69-
void UnfocusedAppearance(ICoreAppearance) {}
70-
void TabColor(const IInspectable&) {}
71-
void StartingTabColor(const IInspectable&) {}
72-
void TrimBlockSelection(bool) {}
73-
void DetectURLs(bool) {}
74-
75-
WINRT_PROPERTY(bool, IntenseIsBright, true);
76-
WINRT_PROPERTY(bool, AdjustIndistinguishableColors, true);
77-
78-
private:
79-
int32_t _historySize;
80-
int32_t _initialRows;
81-
int32_t _initialCols;
82-
bool _copyOnSelect{ false };
83-
bool _focusFollowMouse{ false };
84-
bool _suppressApplicationTitle{ false };
85-
winrt::hstring _startingTitle;
33+
winrt::Microsoft::Terminal::Core::Color GetColorTableEntry(int32_t index) noexcept
34+
{
35+
return _ColorTable.at(index);
36+
}
37+
void SetColorTableEntry(int32_t index,
38+
winrt::Microsoft::Terminal::Core::Color color) noexcept
39+
{
40+
_ColorTable.at(index) = color;
41+
}
8642
};
8743
}

src/cascadia/inc/ControlProperties.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@
4242
X(winrt::Windows::Foundation::IReference<winrt::Microsoft::Terminal::Core::Color>, TabColor, nullptr) \
4343
X(winrt::Windows::Foundation::IReference<winrt::Microsoft::Terminal::Core::Color>, StartingTabColor, nullptr) \
4444
X(bool, TrimBlockSelection, false) \
45+
X(bool, SuppressApplicationTitle) \
46+
X(bool, ForceVTInput, false) \
47+
X(winrt::hstring, StartingTitle) \
4548
X(bool, DetectURLs, true)
4649

4750
// --------------------------- Control Settings ---------------------------
@@ -59,12 +62,9 @@
5962
X(winrt::Microsoft::Terminal::Control::IKeyBindings, KeyBindings, nullptr) \
6063
X(winrt::hstring, Commandline) \
6164
X(winrt::hstring, StartingDirectory) \
62-
X(winrt::hstring, StartingTitle) \
63-
X(bool, SuppressApplicationTitle) \
6465
X(winrt::hstring, EnvironmentVariables) \
6566
X(winrt::Microsoft::Terminal::Control::ScrollbarState, ScrollState, winrt::Microsoft::Terminal::Control::ScrollbarState::Visible) \
6667
X(winrt::Microsoft::Terminal::Control::TextAntialiasingMode, AntialiasingMode, winrt::Microsoft::Terminal::Control::TextAntialiasingMode::Grayscale) \
6768
X(bool, ForceFullRepaintRendering, false) \
6869
X(bool, SoftwareRendering, false) \
69-
X(bool, ForceVTInput, false) \
7070
X(bool, UseAtlasEngine, false)

0 commit comments

Comments
 (0)