11// SPDX-License-Identifier: Apache-2.0
2+ #include < vtbackend/Functions.h>
23#include < vtbackend/MockTerm.h>
34#include < vtbackend/SemanticBlockTracker.h>
45#include < vtbackend/ShellIntegration.h>
@@ -155,7 +156,7 @@ TEST_CASE("SemanticBlockProtocol.LineFlags")
155156 SECTION (" OutputStart and CommandEnd flags set when mode 2034 is on" )
156157 {
157158 // Enable mode 2034
158- mc.writeToScreen (" \033 [?2034h " );
159+ mc.writeToScreen (DECSM ( 2034 ) );
159160
160161 // OSC 133;C should set OutputStart on the current line
161162 mc.writeToScreen (" \033 ]133;C\033\\ " );
@@ -191,7 +192,7 @@ TEST_CASE("SemanticBlockProtocol.TrackerMetadata")
191192
192193 SECTION (" Tracker stores command line and exit code" )
193194 {
194- mc.writeToScreen (" \033 [?2034h " );
195+ mc.writeToScreen (DECSM ( 2034 ) );
195196
196197 mc.writeToScreen (" \033 ]133;A\033\\ " );
197198 mc.writeToScreen (" $ " );
@@ -209,7 +210,7 @@ TEST_CASE("SemanticBlockProtocol.TrackerMetadata")
209210
210211 SECTION (" Tracker disabled clears data" )
211212 {
212- mc.writeToScreen (" \033 [?2034h " );
213+ mc.writeToScreen (DECSM ( 2034 ) );
213214 mc.writeToScreen (" \033 ]133;A\033\\ " );
214215 mc.writeToScreen (" \033 ]133;C;cmdline_url=test\033\\ " );
215216 mc.writeToScreen (" \033 ]133;D;0\033\\ " );
@@ -218,7 +219,7 @@ TEST_CASE("SemanticBlockProtocol.TrackerMetadata")
218219 CHECK (tracker.currentBlock ().has_value ());
219220
220221 // Disable mode
221- mc.writeToScreen (" \033 [?2034l " );
222+ mc.writeToScreen (DECRM ( 2034 ) );
222223 CHECK_FALSE (tracker.currentBlock ().has_value ());
223224 CHECK (tracker.completedBlocks ().empty ());
224225 }
@@ -231,18 +232,18 @@ TEST_CASE("SemanticBlockProtocol.DECRQM")
231232 SECTION (" DECRQM reports mode 2034 as reset by default" )
232233 {
233234 mc.resetReplyData ();
234- mc.writeToScreen (" \033 [? 2034$p " );
235+ mc.writeToScreen (DECRQM ( 2034 ) );
235236 mc.terminal .flushInput ();
236237 // Response should be CSI ? 2034 ; 2 $ y (2 = reset)
237238 CHECK (mc.replyData ().find (" 2034;2$y" ) != std::string::npos);
238239 }
239240
240241 SECTION (" DECRQM reports mode 2034 as set after enabling" )
241242 {
242- mc.writeToScreen (" \033 [?2034h " );
243+ mc.writeToScreen (DECSM ( 2034 ) );
243244 mc.terminal .flushInput ();
244245 mc.resetReplyData ();
245- mc.writeToScreen (" \033 [? 2034$p " );
246+ mc.writeToScreen (DECRQM ( 2034 ) );
246247 mc.terminal .flushInput ();
247248 // Response should be CSI ? 2034 ; 1 $ y (1 = set)
248249 CHECK (mc.replyData ().find (" 2034;1$y" ) != std::string::npos);
@@ -256,8 +257,8 @@ TEST_CASE("SemanticBlockProtocol.QueryDisabled")
256257 SECTION (" Query without enabling mode returns error DCS" )
257258 {
258259 mc.resetReplyData ();
259- // CSI > 0 b (query last command)
260- mc.writeToScreen (" \033 [>0b " );
260+ // Query last command
261+ mc.writeToScreen (SBQUERY (SBQueryType::LastCommand) );
261262 mc.terminal .flushInput ();
262263 // Should get error DCS: ESC P > 0 b ESC backslash
263264 CHECK (mc.replyData ().find (" \033 P>0b\033\\ " ) != std::string::npos);
@@ -269,7 +270,7 @@ TEST_CASE("SemanticBlockProtocol.QueryLastCommand")
269270 auto mc = MockTerm { PageSize { LineCount (25 ), ColumnCount (80 ) } };
270271
271272 // Enable mode 2034
272- mc.writeToScreen (" \033 [?2034h " );
273+ mc.writeToScreen (DECSM ( 2034 ) );
273274
274275 // Simulate a complete command
275276 simulateCommand (mc, " $ " , " ls" , " file1\n file2" , 0 );
@@ -279,8 +280,8 @@ TEST_CASE("SemanticBlockProtocol.QueryLastCommand")
279280
280281 mc.terminal .flushInput ();
281282 mc.resetReplyData ();
282- // Query last command: CSI > 0 b
283- mc.writeToScreen (" \033 [>0b " );
283+ // Query last command
284+ mc.writeToScreen (SBQUERY (SBQueryType::LastCommand) );
284285 mc.terminal .flushInput ();
285286
286287 auto const & reply = mc.replyData ();
@@ -302,7 +303,7 @@ TEST_CASE("SemanticBlockProtocol.QueryLastNCommands")
302303 auto mc = MockTerm { PageSize { LineCount (25 ), ColumnCount (80 ) } };
303304
304305 // Enable mode 2034
305- mc.writeToScreen (" \033 [?2034h " );
306+ mc.writeToScreen (DECSM ( 2034 ) );
306307
307308 // Simulate two commands
308309 simulateCommand (mc, " $ " , " cmd1" , " out1" , 0 );
@@ -312,8 +313,8 @@ TEST_CASE("SemanticBlockProtocol.QueryLastNCommands")
312313 mc.writeToScreen (" \033 ]133;A\033\\ " );
313314
314315 mc.resetReplyData ();
315- // Query last 2 commands: CSI > 1 ; 2 b
316- mc.writeToScreen (" \033 [>1;2b " );
316+ // Query last 2 commands
317+ mc.writeToScreen (SBQUERY (SBQueryType::LastNumberOfCommands, 2 ) );
317318 mc.terminal .flushInput ();
318319
319320 auto const & reply = mc.replyData ();
@@ -328,7 +329,7 @@ TEST_CASE("SemanticBlockProtocol.QueryInProgress")
328329 auto mc = MockTerm { PageSize { LineCount (25 ), ColumnCount (80 ) } };
329330
330331 // Enable mode 2034
331- mc.writeToScreen (" \033 [?2034h " );
332+ mc.writeToScreen (DECSM ( 2034 ) );
332333
333334 // Start a command but don't finish it (no OSC 133;D)
334335 mc.writeToScreen (" \033 ]133;A\033\\ " );
@@ -338,8 +339,8 @@ TEST_CASE("SemanticBlockProtocol.QueryInProgress")
338339 mc.writeToScreen (" partial output" );
339340
340341 mc.resetReplyData ();
341- // Query in-progress command: CSI > 2 b
342- mc.writeToScreen (" \033 [>2b " );
342+ // Query in-progress command
343+ mc.writeToScreen (SBQUERY (SBQueryType::InProgress) );
343344 mc.terminal .flushInput ();
344345
345346 auto const & reply = mc.replyData ();
@@ -355,11 +356,11 @@ TEST_CASE("SemanticBlockProtocol.NoCompletedCommands")
355356 auto mc = MockTerm { PageSize { LineCount (25 ), ColumnCount (80 ) } };
356357
357358 // Enable mode 2034
358- mc.writeToScreen (" \033 [?2034h " );
359+ mc.writeToScreen (DECSM ( 2034 ) );
359360
360361 mc.resetReplyData ();
361362 // Query last command when none exists
362- mc.writeToScreen (" \033 [>0b " );
363+ mc.writeToScreen (SBQUERY (SBQueryType::LastCommand) );
363364 mc.terminal .flushInput ();
364365
365366 auto const & reply = mc.replyData ();
0 commit comments