Skip to content

Commit 2801e9a

Browse files
j4jamesDHowett
authored andcommitted
Indicate support for OSC 52 in the DA1 report (#19034)
## Summary of the Pull Request Some applications that make use of the `OSC 52` clipboard sequence will only do so if they can be certain that the terminal actually has that functionality. Indicating our support for `OSC 52` in the `DA1` report will give them an easy way to detect that. ## References and Relevant Issues `OSC 52` support was added to Windows Terminal in issue #5823, and to ConHost in issue #18949. ## Detailed Description of the Pull Request / Additional comments Support for writing to the clipboard is indicated in the primary device attributes report by the extension parameter `52`. This is obviously not a standard DEC extension, but it's one that's been agreed upon by a number of modern terminals. The extension is only reported when writing to the clipboard is actually permitted (Windows Terminal has an option to disable that). ## Validation Steps Performed I've updated the Device Attributes unit test to check that we're reporting extension `52` when clipboard access is enabled, and not reporting it when disabled. ## PR Checklist - [x] Closes #19017 - [x] Tests added/passed (cherry picked from commit 00ee884) Service-Card-Id: PVTI_lADOAF3p4s4Axadtzgbpe4g Service-Version: 1.23
1 parent dcdc213 commit 2801e9a

File tree

7 files changed

+42
-19
lines changed

7 files changed

+42
-19
lines changed

src/cascadia/TerminalCore/Terminal.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ void Terminal::UpdateSettings(ICoreSettings settings)
9393

9494
if (_stateMachine)
9595
{
96-
SetVtChecksumReportSupport(settings.AllowVtChecksumReport());
96+
SetOptionalFeatures(settings);
9797
}
9898

9999
_getTerminalInput().ForceDisableWin32InputMode(settings.ForceVTInput());
@@ -218,10 +218,13 @@ void Terminal::SetCursorStyle(const DispatchTypes::CursorStyle cursorStyle)
218218
engine.Dispatch().SetCursorStyle(cursorStyle);
219219
}
220220

221-
void Terminal::SetVtChecksumReportSupport(const bool enabled)
221+
void Terminal::SetOptionalFeatures(winrt::Microsoft::Terminal::Core::ICoreSettings settings)
222222
{
223223
auto& engine = reinterpret_cast<OutputStateMachineEngine&>(_stateMachine->Engine());
224-
engine.Dispatch().SetVtChecksumReportSupport(enabled);
224+
auto features = til::enumset<ITermDispatch::OptionalFeature>{};
225+
features.set(ITermDispatch::OptionalFeature::ChecksumReport, settings.AllowVtChecksumReport());
226+
features.set(ITermDispatch::OptionalFeature::ClipboardWrite, settings.AllowVtClipboardWrite());
227+
engine.Dispatch().SetOptionalFeatures(features);
225228
}
226229

227230
bool Terminal::IsXtermBracketedPasteModeEnabled() const noexcept

src/cascadia/TerminalCore/Terminal.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ class Microsoft::Terminal::Core::Terminal final :
9494
void UpdateAppearance(const winrt::Microsoft::Terminal::Core::ICoreAppearance& appearance);
9595
void SetFontInfo(const FontInfo& fontInfo);
9696
void SetCursorStyle(const ::Microsoft::Console::VirtualTerminal::DispatchTypes::CursorStyle cursorStyle);
97-
void SetVtChecksumReportSupport(const bool enabled);
97+
void SetOptionalFeatures(winrt::Microsoft::Terminal::Core::ICoreSettings settings);
9898
bool IsXtermBracketedPasteModeEnabled() const noexcept;
9999
std::wstring_view GetWorkingDirectory() noexcept;
100100

src/terminal/adapter/ITermDispatch.hpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,12 @@ class Microsoft::Console::VirtualTerminal::ITermDispatch
2525
public:
2626
using StringHandler = std::function<bool(const wchar_t)>;
2727

28+
enum class OptionalFeature
29+
{
30+
ChecksumReport,
31+
ClipboardWrite,
32+
};
33+
2834
#pragma warning(push)
2935
#pragma warning(disable : 26432) // suppress rule of 5 violation on interface because tampering with this is fraught with peril
3036
virtual ~ITermDispatch() = 0;
@@ -133,7 +139,6 @@ class Microsoft::Console::VirtualTerminal::ITermDispatch
133139
virtual void ScreenAlignmentPattern() = 0; // DECALN
134140

135141
virtual void SetCursorStyle(const DispatchTypes::CursorStyle cursorStyle) = 0; // DECSCUSR
136-
virtual void SetVtChecksumReportSupport(const bool enabled) = 0;
137142

138143
virtual void SetClipboard(wil::zwstring_view content) = 0; // OSCSetClipboard
139144

@@ -185,6 +190,8 @@ class Microsoft::Console::VirtualTerminal::ITermDispatch
185190
virtual StringHandler RestorePresentationState(const DispatchTypes::PresentationReportFormat format) = 0; // DECRSPS
186191

187192
virtual void PlaySounds(const VTParameters parameters) = 0; // DECPS
193+
194+
virtual void SetOptionalFeatures(const til::enumset<OptionalFeature> features) = 0;
188195
};
189196
inline Microsoft::Console::VirtualTerminal::ITermDispatch::~ITermDispatch() = default;
190197
#pragma warning(pop)

src/terminal/adapter/adaptDispatch.cpp

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1304,11 +1304,6 @@ void AdaptDispatch::SelectAttributeChangeExtent(const DispatchTypes::ChangeExten
13041304
}
13051305
}
13061306

1307-
void AdaptDispatch::SetVtChecksumReportSupport(const bool enabled) noexcept
1308-
{
1309-
_vtChecksumReportEnabled = enabled;
1310-
}
1311-
13121307
// Routine Description:
13131308
// - DECRQCRA - Computes and reports a checksum of the specified area of
13141309
// the buffer memory.
@@ -1325,7 +1320,7 @@ void AdaptDispatch::RequestChecksumRectangularArea(const VTInt id, const VTInt p
13251320
// If this feature is not enabled, we'll just report a zero checksum.
13261321
if constexpr (Feature_VtChecksumReport::IsEnabled())
13271322
{
1328-
if (_vtChecksumReportEnabled)
1323+
if (_optionalFeatures.test(OptionalFeature::ChecksumReport))
13291324
{
13301325
// If the page number is 0, then we're meant to return a checksum of all
13311326
// of the pages, but we have no need for that, so we'll just return 0.
@@ -1490,8 +1485,16 @@ void AdaptDispatch::DeviceAttributes()
14901485
// 28 = Rectangular area operations
14911486
// 32 = Text macros
14921487
// 42 = ISO Latin-2 character set
1488+
// 52 = Clipboard access
14931489

1494-
_ReturnCsiResponse(L"?61;4;6;7;14;21;22;23;24;28;32;42c");
1490+
if (_optionalFeatures.test(OptionalFeature::ClipboardWrite))
1491+
{
1492+
_ReturnCsiResponse(L"?61;4;6;7;14;21;22;23;24;28;32;42;52c");
1493+
}
1494+
else
1495+
{
1496+
_ReturnCsiResponse(L"?61;4;6;7;14;21;22;23;24;28;32;42c");
1497+
}
14951498
}
14961499

14971500
// Routine Description:
@@ -4786,3 +4789,8 @@ void AdaptDispatch::PlaySounds(const VTParameters parameters)
47864789
_api.PlayMidiNote(noteNumber, noteNumber == 71 ? 0 : velocity, duration);
47874790
});
47884791
}
4792+
4793+
void AdaptDispatch::SetOptionalFeatures(const til::enumset<OptionalFeature> features) noexcept
4794+
{
4795+
_optionalFeatures = features;
4796+
}

src/terminal/adapter/adaptDispatch.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ namespace Microsoft::Console::VirtualTerminal
188188

189189
void PlaySounds(const VTParameters parameters) override; // DECPS
190190

191-
void SetVtChecksumReportSupport(const bool enabled) noexcept override;
191+
void SetOptionalFeatures(const til::enumset<OptionalFeature> features) noexcept override;
192192

193193
private:
194194
enum class Mode
@@ -313,7 +313,7 @@ namespace Microsoft::Console::VirtualTerminal
313313
std::unique_ptr<FontBuffer> _fontBuffer;
314314
std::shared_ptr<MacroBuffer> _macroBuffer;
315315
std::optional<unsigned int> _initialCodePage;
316-
bool _vtChecksumReportEnabled = false;
316+
til::enumset<OptionalFeature> _optionalFeatures = { OptionalFeature::ClipboardWrite };
317317

318318
// We have two instances of the saved cursor state, because we need
319319
// one for the main buffer (at index 0), and another for the alt buffer

src/terminal/adapter/termDispatch.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ class Microsoft::Console::VirtualTerminal::TermDispatch : public Microsoft::Cons
178178

179179
void PlaySounds(const VTParameters /*parameters*/) override{}; // DECPS
180180

181-
void SetVtChecksumReportSupport(const bool /*enabled*/) override{};
181+
void SetOptionalFeatures(const til::enumset<OptionalFeature> /*features*/) override{};
182182
};
183183

184184
#pragma warning(default : 26440) // Restore "can be declared noexcept" warning

src/terminal/adapter/ut_adapter/adapterTest.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,6 @@ class AdapterTest
415415
auto& renderer = _testGetSet->_renderer;
416416
auto& renderSettings = renderer._renderSettings;
417417
auto adapter = std::make_unique<AdaptDispatch>(*_testGetSet, &renderer, renderSettings, _terminalInput);
418-
adapter->SetVtChecksumReportSupport(true);
419418

420419
fSuccess = adapter.get() != nullptr;
421420
if (fSuccess)
@@ -1737,11 +1736,15 @@ class AdapterTest
17371736
Log::Comment(L"Test 1: Verify normal response.");
17381737
_testGetSet->PrepData();
17391738
_pDispatch->DeviceAttributes();
1739+
_testGetSet->ValidateInputEvent(L"\x1b[?61;4;6;7;14;21;22;23;24;28;32;42;52c");
17401740

1741-
auto pwszExpectedResponse = L"\x1b[?61;4;6;7;14;21;22;23;24;28;32;42c";
1742-
_testGetSet->ValidateInputEvent(pwszExpectedResponse);
1741+
Log::Comment(L"Test 2: Verify response with clipboard disabled.");
1742+
_testGetSet->PrepData();
1743+
_pDispatch->SetOptionalFeatures({});
1744+
_pDispatch->DeviceAttributes();
1745+
_testGetSet->ValidateInputEvent(L"\x1b[?61;4;6;7;14;21;22;23;24;28;32;42c");
17431746

1744-
Log::Comment(L"Test 2: Verify failure when ReturnResponse doesn't work.");
1747+
Log::Comment(L"Test 3: Verify failure when ReturnResponse doesn't work.");
17451748
_testGetSet->PrepData();
17461749
_testGetSet->_returnResponseResult = FALSE;
17471750

@@ -2187,6 +2190,8 @@ class AdapterTest
21872190

21882191
using namespace std::string_view_literals;
21892192

2193+
_pDispatch->SetOptionalFeatures(ITermDispatch::OptionalFeature::ChecksumReport);
2194+
21902195
Log::Comment(L"Test 1: ASCII characters");
21912196
outputText(L"A"sv);
21922197
verifyChecksumReport(L"FF4F");

0 commit comments

Comments
 (0)