Skip to content

Commit af63923

Browse files
committed
Less diff, Less problems
1 parent eb3094d commit af63923

File tree

12 files changed

+329
-82
lines changed

12 files changed

+329
-82
lines changed

.github/actions/spelling/expect/expect.txt

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,6 @@ CREATESTRUCT
295295
CREATESTRUCTW
296296
createvpack
297297
crisman
298-
CRLFs
299298
crloew
300299
CRTLIBS
301300
csbi
@@ -597,7 +596,6 @@ ffd
597596
FFDE
598597
FFFD
599598
FFFDb
600-
FFrom
601599
fgbg
602600
FGCOLOR
603601
FGHIJ
@@ -1165,7 +1163,6 @@ NOMINMAX
11651163
NOMOVE
11661164
NONALERT
11671165
nonbreaking
1168-
noncharacter
11691166
nonclient
11701167
NONINFRINGEMENT
11711168
NONPREROTATED
@@ -1478,7 +1475,6 @@ READMODE
14781475
rectread
14791476
redef
14801477
redefinable
1481-
Redir
14821478
redist
14831479
REDSCROLL
14841480
REFCLSID
@@ -1889,7 +1885,6 @@ UPDATEDISPLAY
18891885
UPDOWN
18901886
UPKEY
18911887
upss
1892-
UPSS
18931888
uregex
18941889
URegular
18951890
usebackq
@@ -1984,7 +1979,6 @@ wchars
19841979
WCIA
19851980
WCIW
19861981
WCSHELPER
1987-
wcsicmp
19881982
wcsrev
19891983
wcswidth
19901984
wddm

src/buffer/out/Row.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -635,7 +635,7 @@ catch (...)
635635
throw;
636636
}
637637

638-
void ROW::WriteHelper::ReplaceText() noexcept
638+
[[msvc::forceinline]] void ROW::WriteHelper::ReplaceText() noexcept
639639
{
640640
// This function starts with a fast-pass for ASCII. ASCII is still predominant in technical areas.
641641
//
@@ -662,7 +662,7 @@ void ROW::WriteHelper::ReplaceText() noexcept
662662
charsConsumed = ch - chBeg;
663663
}
664664

665-
void ROW::WriteHelper::_replaceTextUnicode(size_t ch, size_t off) noexcept
665+
[[msvc::forceinline]] void ROW::WriteHelper::_replaceTextUnicode(size_t ch, size_t off) noexcept
666666
{
667667
auto& cwd = CodepointWidthDetector::Singleton();
668668
const auto len = chars.size();
@@ -849,7 +849,7 @@ catch (...)
849849
}
850850
#pragma warning(pop)
851851

852-
void ROW::WriteHelper::Finish()
852+
[[msvc::forceinline]] void ROW::WriteHelper::Finish()
853853
{
854854
colEndDirty = row._adjustForward(colEndDirty);
855855

src/host/ConsoleArguments.cpp

Lines changed: 64 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,23 @@
77
#include <shellapi.h>
88
using namespace Microsoft::Console::Utils;
99

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";
2326
static constexpr std::wstring_view GLYPH_WIDTH{ L"--textMeasurement" };
24-
static constexpr std::wstring_view COM_SERVER_ARG{ L"-Embedding" };
2527
// NOTE: Thinking about adding more commandline args that control conpty, for
2628
// the Terminal? Make sure you add them to the commandline in
2729
// 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
203205
return (hasNext) ? S_OK : E_INVALIDARG;
204206
}
205207

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+
206239
// Method Description:
207240
// Routine Description:
208241
// 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
353386
std::vector<std::wstring> args;
354387
auto hr = S_OK;
355388

389+
// Make a mutable copy of the commandline for tokenizing
390+
auto copy = _commandline;
391+
356392
// Tokenize the commandline
357393
auto argc = 0;
358394
wil::unique_hlocal_ptr<PWSTR[]> argv;
359-
argv.reset(CommandLineToArgvW(_commandline.c_str(), &argc));
395+
argv.reset(CommandLineToArgvW(copy.c_str(), &argc));
360396
RETURN_LAST_ERROR_IF(argv == nullptr);
361397

362398
for (auto i = 1; i < argc; ++i)
@@ -371,7 +407,7 @@ void ConsoleArguments::s_ConsumeArg(_Inout_ std::vector<std::wstring>& args, _In
371407
{
372408
hr = E_INVALIDARG;
373409

374-
const std::wstring_view arg{ args[i] };
410+
auto arg = args[i];
375411

376412
if (arg.substr(0, HANDLE_PREFIX.length()) == HANDLE_PREFIX ||
377413
arg == SERVER_HANDLE_ARG)
@@ -380,7 +416,7 @@ void ConsoleArguments::s_ConsumeArg(_Inout_ std::vector<std::wstring>& args, _In
380416
// --server 0x4 (new method)
381417
// 0x4 (legacy method)
382418
// If we see >1 of these, it's invalid.
383-
std::wstring serverHandleVal{ arg };
419+
auto serverHandleVal = arg;
384420

385421
if (arg == SERVER_HANDLE_ARG)
386422
{
@@ -450,6 +486,10 @@ void ConsoleArguments::s_ConsumeArg(_Inout_ std::vector<std::wstring>& args, _In
450486
{
451487
hr = s_GetArgumentValue(args, i, &_height);
452488
}
489+
else if (arg == FEATURE_ARG)
490+
{
491+
hr = s_HandleFeatureValue(args, i);
492+
}
453493
else if (arg == HEADLESS_ARG)
454494
{
455495
_headless = true;
@@ -580,12 +620,17 @@ HANDLE ConsoleArguments::GetVtOutHandle() const
580620
return _vtOutHandle;
581621
}
582622

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
584629
{
585630
return _clientCommandline;
586631
}
587632

588-
const std::wstring& ConsoleArguments::GetVtMode() const
633+
std::wstring ConsoleArguments::GetVtMode() const
589634
{
590635
return _vtMode;
591636
}

src/host/ConsoleArguments.hpp

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,9 @@ class ConsoleArguments
4444
bool HasSignalHandle() const;
4545
HANDLE GetSignalHandle() const;
4646

47-
const std::wstring& GetClientCommandline() const;
48-
const std::wstring& GetVtMode() const;
47+
std::wstring GetOriginalCommandLine() const;
48+
std::wstring GetClientCommandline() const;
49+
std::wstring GetVtMode() const;
4950
const std::wstring& GetTextMeasurement() const;
5051
bool GetForceV1() const;
5152
bool GetForceNoHandoff() const;
@@ -59,6 +60,23 @@ class ConsoleArguments
5960
void EnableConptyModeForTests();
6061
#endif
6162

63+
static const std::wstring_view VT_MODE_ARG;
64+
static const std::wstring_view HEADLESS_ARG;
65+
static const std::wstring_view SERVER_HANDLE_ARG;
66+
static const std::wstring_view SIGNAL_HANDLE_ARG;
67+
static const std::wstring_view HANDLE_PREFIX;
68+
static const std::wstring_view CLIENT_COMMANDLINE_ARG;
69+
static const std::wstring_view FORCE_V1_ARG;
70+
static const std::wstring_view FORCE_NO_HANDOFF_ARG;
71+
static const std::wstring_view FILEPATH_LEADER_PREFIX;
72+
static const std::wstring_view WIDTH_ARG;
73+
static const std::wstring_view HEIGHT_ARG;
74+
static const std::wstring_view INHERIT_CURSOR_ARG;
75+
static const std::wstring_view RESIZE_QUIRK;
76+
static const std::wstring_view FEATURE_ARG;
77+
static const std::wstring_view FEATURE_PTY_ARG;
78+
static const std::wstring_view COM_SERVER_ARG;
79+
6280
private:
6381
#ifdef UNIT_TESTING
6482
// This accessor used to create a copy of this class for unit testing comparison ease.
@@ -134,6 +152,8 @@ class ConsoleArguments
134152
[[nodiscard]] static HRESULT s_GetArgumentValue(_Inout_ std::vector<std::wstring>& args,
135153
_Inout_ size_t& index,
136154
_Out_opt_ short* const pSetting);
155+
[[nodiscard]] static HRESULT s_HandleFeatureValue(_Inout_ std::vector<std::wstring>& args,
156+
_Inout_ size_t& index);
137157

138158
[[nodiscard]] static HRESULT s_ParseHandleArg(const std::wstring& handleAsText,
139159
_Inout_ DWORD& handleAsVal);

src/host/VtIo.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@
99
#include "../renderer/vt/Xterm256Engine.hpp"
1010

1111
#include "../renderer/base/renderer.hpp"
12+
#include "../types/inc/CodepointWidthDetector.hpp"
1213
#include "../types/inc/utils.hpp"
1314
#include "handle.h" // LockConsole
1415
#include "input.h" // ProcessCtrlEvents
1516
#include "output.h" // CloseConsoleProcessState
16-
#include "../types/inc/CodepointWidthDetector.hpp"
1717

1818
using namespace Microsoft::Console;
1919
using namespace Microsoft::Console::Render;

src/host/inputBuffer.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -810,8 +810,7 @@ bool InputBuffer::_CoalesceEvent(const INPUT_RECORD& inEvent) noexcept
810810
// You can't update the repeat count of such a A,B pair, because they're stored as A,A,B,B (down-down, up-up).
811811
// I believe the proper approach is to store pairs of characters as pairs, update their combined
812812
// repeat count and only when they're being read de-coalesce them into their alternating form.
813-
// TODO:GH#8000 IsGlyphFullWidth was replaced with til::is_surrogate to get rid off the former. Neither approach is fully correct.
814-
!til::is_surrogate(inKey.uChar.UnicodeChar))
813+
!IsGlyphFullWidth(inKey.uChar.UnicodeChar))
815814
{
816815
lastKey.wRepeatCount += inKey.wRepeatCount;
817816
return true;

src/host/stream.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,18 @@
22
// Licensed under the MIT license.
33

44
#include "precomp.h"
5+
6+
#include "_stream.h"
57
#include "stream.h"
68

79
#include "handle.h"
810
#include "misc.h"
911
#include "readDataRaw.hpp"
12+
13+
#include "ApiRoutines.h"
14+
15+
#include "../types/inc/GlyphWidth.hpp"
16+
1017
#include "../interactivity/inc/ServiceLocator.hpp"
1118

1219
using Microsoft::Console::Interactivity::ServiceLocator;

0 commit comments

Comments
 (0)