7
7
#include < shellapi.h>
8
8
using namespace Microsoft ::Console::Utils;
9
9
10
- static constexpr std::wstring_view VT_MODE_ARG{ L" --vtmode" };
11
- static constexpr std::wstring_view HEADLESS_ARG{ L" --headless" };
12
- static constexpr std::wstring_view SERVER_HANDLE_ARG{ L" --server" };
13
- static constexpr std::wstring_view SIGNAL_HANDLE_ARG{ L" --signal" };
14
- static constexpr std::wstring_view HANDLE_PREFIX{ L" 0x" };
15
- static constexpr std::wstring_view CLIENT_COMMANDLINE_ARG{ L" --" };
16
- static constexpr std::wstring_view FORCE_V1_ARG{ L" -ForceV1" };
17
- static constexpr std::wstring_view FORCE_NO_HANDOFF_ARG{ L" -ForceNoHandoff" };
18
- static constexpr std::wstring_view FILEPATH_LEADER_PREFIX{ L" \\ ??\\ " };
19
- static constexpr std::wstring_view WIDTH_ARG{ L" --width" };
20
- static constexpr std::wstring_view HEIGHT_ARG{ L" --height" };
21
- static constexpr std::wstring_view INHERIT_CURSOR_ARG{ L" --inheritcursor" };
22
- static constexpr std::wstring_view RESIZE_QUIRK{ L" --resizeQuirk" };
10
+ const std::wstring_view ConsoleArguments::VT_MODE_ARG = L" --vtmode" ;
11
+ const std::wstring_view ConsoleArguments::HEADLESS_ARG = L" --headless" ;
12
+ const std::wstring_view ConsoleArguments::SERVER_HANDLE_ARG = L" --server" ;
13
+ const std::wstring_view ConsoleArguments::SIGNAL_HANDLE_ARG = L" --signal" ;
14
+ const std::wstring_view ConsoleArguments::HANDLE_PREFIX = L" 0x" ;
15
+ const std::wstring_view ConsoleArguments::CLIENT_COMMANDLINE_ARG = L" --" ;
16
+ const std::wstring_view ConsoleArguments::FORCE_V1_ARG = L" -ForceV1" ;
17
+ const std::wstring_view ConsoleArguments::FORCE_NO_HANDOFF_ARG = L" -ForceNoHandoff" ;
18
+ const std::wstring_view ConsoleArguments::FILEPATH_LEADER_PREFIX = L" \\ ??\\ " ;
19
+ const std::wstring_view ConsoleArguments::WIDTH_ARG = L" --width" ;
20
+ const std::wstring_view ConsoleArguments::HEIGHT_ARG = L" --height" ;
21
+ const std::wstring_view ConsoleArguments::INHERIT_CURSOR_ARG = L" --inheritcursor" ;
22
+ const std::wstring_view ConsoleArguments::RESIZE_QUIRK = L" --resizeQuirk" ;
23
+ const std::wstring_view ConsoleArguments::FEATURE_ARG = L" --feature" ;
24
+ const std::wstring_view ConsoleArguments::FEATURE_PTY_ARG = L" pty" ;
25
+ const std::wstring_view ConsoleArguments::COM_SERVER_ARG = L" -Embedding" ;
23
26
static constexpr std::wstring_view GLYPH_WIDTH{ L" --textMeasurement" };
24
- static constexpr std::wstring_view COM_SERVER_ARG{ L" -Embedding" };
25
27
// NOTE: Thinking about adding more commandline args that control conpty, for
26
28
// the Terminal? Make sure you add them to the commandline in
27
29
// ConsoleEstablishHandoff. We use that to initialize the ConsoleArguments for a
@@ -203,6 +205,37 @@ void ConsoleArguments::s_ConsumeArg(_Inout_ std::vector<std::wstring>& args, _In
203
205
return (hasNext) ? S_OK : E_INVALIDARG;
204
206
}
205
207
208
+ // Routine Description:
209
+ // Similar to s_GetArgumentValue.
210
+ // Attempts to get the next arg as a "feature" arg - this can be used for
211
+ // feature detection.
212
+ // If the next arg is not recognized, then we don't support that feature.
213
+ // Currently, the only supported feature arg is `pty`, to identify pty support.
214
+ // Arguments:
215
+ // args: A collection of wstrings representing command-line arguments
216
+ // index: the index of the argument of which to get the value for. The value
217
+ // should be at (index+1). index will be decremented by one on success.
218
+ // pSetting: receives the string at index+1
219
+ // Return Value:
220
+ // S_OK if we parsed the string successfully, otherwise E_INVALIDARG indicating
221
+ // failure.
222
+ [[nodiscard]] HRESULT ConsoleArguments::s_HandleFeatureValue (_Inout_ std::vector<std::wstring>& args, _Inout_ size_t & index)
223
+ {
224
+ auto hr = E_INVALIDARG;
225
+ auto hasNext = (index + 1 ) < args.size ();
226
+ if (hasNext)
227
+ {
228
+ s_ConsumeArg (args, index);
229
+ auto value = args[index];
230
+ if (value == FEATURE_PTY_ARG)
231
+ {
232
+ hr = S_OK;
233
+ }
234
+ s_ConsumeArg (args, index);
235
+ }
236
+ return (hasNext) ? hr : E_INVALIDARG;
237
+ }
238
+
206
239
// Method Description:
207
240
// Routine Description:
208
241
// Given the commandline of tokens `args`, tries to find the argument at
@@ -353,10 +386,13 @@ void ConsoleArguments::s_ConsumeArg(_Inout_ std::vector<std::wstring>& args, _In
353
386
std::vector<std::wstring> args;
354
387
auto hr = S_OK;
355
388
389
+ // Make a mutable copy of the commandline for tokenizing
390
+ auto copy = _commandline;
391
+
356
392
// Tokenize the commandline
357
393
auto argc = 0 ;
358
394
wil::unique_hlocal_ptr<PWSTR[]> argv;
359
- argv.reset (CommandLineToArgvW (_commandline .c_str (), &argc));
395
+ argv.reset (CommandLineToArgvW (copy .c_str (), &argc));
360
396
RETURN_LAST_ERROR_IF (argv == nullptr );
361
397
362
398
for (auto i = 1 ; i < argc; ++i)
@@ -371,7 +407,7 @@ void ConsoleArguments::s_ConsumeArg(_Inout_ std::vector<std::wstring>& args, _In
371
407
{
372
408
hr = E_INVALIDARG;
373
409
374
- const std::wstring_view arg{ args[i] } ;
410
+ auto arg = args[i];
375
411
376
412
if (arg.substr (0 , HANDLE_PREFIX.length ()) == HANDLE_PREFIX ||
377
413
arg == SERVER_HANDLE_ARG)
@@ -380,7 +416,7 @@ void ConsoleArguments::s_ConsumeArg(_Inout_ std::vector<std::wstring>& args, _In
380
416
// --server 0x4 (new method)
381
417
// 0x4 (legacy method)
382
418
// If we see >1 of these, it's invalid.
383
- std::wstring serverHandleVal{ arg } ;
419
+ auto serverHandleVal = arg ;
384
420
385
421
if (arg == SERVER_HANDLE_ARG)
386
422
{
@@ -450,6 +486,10 @@ void ConsoleArguments::s_ConsumeArg(_Inout_ std::vector<std::wstring>& args, _In
450
486
{
451
487
hr = s_GetArgumentValue (args, i, &_height);
452
488
}
489
+ else if (arg == FEATURE_ARG)
490
+ {
491
+ hr = s_HandleFeatureValue (args, i);
492
+ }
453
493
else if (arg == HEADLESS_ARG)
454
494
{
455
495
_headless = true ;
@@ -580,12 +620,17 @@ HANDLE ConsoleArguments::GetVtOutHandle() const
580
620
return _vtOutHandle;
581
621
}
582
622
583
- const std::wstring& ConsoleArguments::GetClientCommandline () const
623
+ std::wstring ConsoleArguments::GetOriginalCommandLine () const
624
+ {
625
+ return _commandline;
626
+ }
627
+
628
+ std::wstring ConsoleArguments::GetClientCommandline () const
584
629
{
585
630
return _clientCommandline;
586
631
}
587
632
588
- const std::wstring& ConsoleArguments::GetVtMode () const
633
+ std::wstring ConsoleArguments::GetVtMode () const
589
634
{
590
635
return _vtMode;
591
636
}
0 commit comments