Skip to content

Commit 00ee884

Browse files
authored
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
1 parent 4cf492e commit 00ee884

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
@@ -94,7 +94,7 @@ void Terminal::UpdateSettings(ICoreSettings settings)
9494

9595
if (_stateMachine)
9696
{
97-
SetVtChecksumReportSupport(settings.AllowVtChecksumReport());
97+
SetOptionalFeatures(settings);
9898
}
9999

100100
_getTerminalInput().ForceDisableWin32InputMode(settings.ForceVTInput());
@@ -232,10 +232,13 @@ void Terminal::SetCursorStyle(const DispatchTypes::CursorStyle cursorStyle)
232232
engine.Dispatch().SetCursorStyle(cursorStyle);
233233
}
234234

235-
void Terminal::SetVtChecksumReportSupport(const bool enabled)
235+
void Terminal::SetOptionalFeatures(winrt::Microsoft::Terminal::Core::ICoreSettings settings)
236236
{
237237
auto& engine = reinterpret_cast<OutputStateMachineEngine&>(_stateMachine->Engine());
238-
engine.Dispatch().SetVtChecksumReportSupport(enabled);
238+
auto features = til::enumset<ITermDispatch::OptionalFeature>{};
239+
features.set(ITermDispatch::OptionalFeature::ChecksumReport, settings.AllowVtChecksumReport());
240+
features.set(ITermDispatch::OptionalFeature::ClipboardWrite, settings.AllowVtClipboardWrite());
241+
engine.Dispatch().SetOptionalFeatures(features);
239242
}
240243

241244
bool Terminal::IsXtermBracketedPasteModeEnabled() const noexcept

src/cascadia/TerminalCore/Terminal.hpp

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

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
@@ -1297,11 +1297,6 @@ void AdaptDispatch::SelectAttributeChangeExtent(const DispatchTypes::ChangeExten
12971297
}
12981298
}
12991299

1300-
void AdaptDispatch::SetVtChecksumReportSupport(const bool enabled) noexcept
1301-
{
1302-
_vtChecksumReportEnabled = enabled;
1303-
}
1304-
13051300
// Routine Description:
13061301
// - DECRQCRA - Computes and reports a checksum of the specified area of
13071302
// the buffer memory.
@@ -1318,7 +1313,7 @@ void AdaptDispatch::RequestChecksumRectangularArea(const VTInt id, const VTInt p
13181313
// If this feature is not enabled, we'll just report a zero checksum.
13191314
if constexpr (Feature_VtChecksumReport::IsEnabled())
13201315
{
1321-
if (_vtChecksumReportEnabled)
1316+
if (_optionalFeatures.test(OptionalFeature::ChecksumReport))
13221317
{
13231318
// If the page number is 0, then we're meant to return a checksum of all
13241319
// of the pages, but we have no need for that, so we'll just return 0.
@@ -1483,8 +1478,16 @@ void AdaptDispatch::DeviceAttributes()
14831478
// 28 = Rectangular area operations
14841479
// 32 = Text macros
14851480
// 42 = ISO Latin-2 character set
1481+
// 52 = Clipboard access
14861482

1487-
_ReturnCsiResponse(L"?61;4;6;7;14;21;22;23;24;28;32;42c");
1483+
if (_optionalFeatures.test(OptionalFeature::ClipboardWrite))
1484+
{
1485+
_ReturnCsiResponse(L"?61;4;6;7;14;21;22;23;24;28;32;42;52c");
1486+
}
1487+
else
1488+
{
1489+
_ReturnCsiResponse(L"?61;4;6;7;14;21;22;23;24;28;32;42c");
1490+
}
14881491
}
14891492

14901493
// Routine Description:
@@ -4790,3 +4793,8 @@ void AdaptDispatch::PlaySounds(const VTParameters parameters)
47904793
_api.PlayMidiNote(noteNumber, noteNumber == 71 ? 0 : velocity, duration);
47914794
});
47924795
}
4796+
4797+
void AdaptDispatch::SetOptionalFeatures(const til::enumset<OptionalFeature> features) noexcept
4798+
{
4799+
_optionalFeatures = features;
4800+
}

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)