Skip to content

Commit

Permalink
working on some bad ideas. This broke ConptyRoundtripTests::Passthrou…
Browse files Browse the repository at this point in the history
…ghHardReset
  • Loading branch information
zadjii-msft committed Jul 12, 2022
1 parent f194402 commit 3e40ee1
Show file tree
Hide file tree
Showing 2 changed files with 134 additions and 5 deletions.
118 changes: 115 additions & 3 deletions src/cascadia/UnitTests_TerminalCore/ConptyRoundtripTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ class TerminalCoreUnitTests::ConptyRoundtripTests final
TEST_METHOD(PassthroughClearScrollback);

TEST_METHOD(PassthroughClearAll);
TEST_METHOD(ClearAllInTheMiddleOfAString);

TEST_METHOD(PassthroughHardReset);

Expand Down Expand Up @@ -985,6 +986,8 @@ void ConptyRoundtripTests::PassthroughClearScrollback()
Log::Comment(NoThrowString().Format(
L"Write more lines of output than there are lines in the viewport. Clear the scrollback with ^[[3J"));

WEX::TestExecution::SetVerifyOutput settings(WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);

auto& g = ServiceLocator::LocateGlobals();
auto& renderer = *g.pRender;
auto& gci = g.getConsoleInformation();
Expand Down Expand Up @@ -1030,12 +1033,11 @@ void ConptyRoundtripTests::PassthroughClearScrollback()
TestUtils::VerifyExpectedString(termTb, L"X ", { 0, y });
}

_checkConptyOutput = false;

// Write a Erase Scrollback VT sequence to the host, it should come through to the Terminal
expectedOutput.push_back("\x1b[3J");
hostSm.ProcessString(L"\x1b[3J");

_checkConptyOutput = false;

VERIFY_SUCCEEDED(renderer.PaintFrame());

const auto termSecondView = term->GetViewport();
Expand Down Expand Up @@ -1063,6 +1065,9 @@ void ConptyRoundtripTests::PassthroughClearAll()
L"all the _current_ buffer contents are moved to scrollback. "
L"We shouldn't just paint over the current viewport with spaces.");

WEX::TestExecution::SetVerifyOutput settings(WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
const WEX::TestExecution::DisableVerifyExceptions disableExceptionsScope;

auto& g = ServiceLocator::LocateGlobals();
auto& renderer = *g.pRender;
auto& gci = g.getConsoleInformation();
Expand Down Expand Up @@ -1123,6 +1128,7 @@ void ConptyRoundtripTests::PassthroughClearAll()

// Here, we'll emit the 2J to EraseAll, and move the viewport contents into
// the scrollback.
Log::Comment(L"Send the EraseAll");
sm.ProcessString(L"\x1b[2J");

Log::Comment(L"Painting the frame");
Expand All @@ -1143,6 +1149,112 @@ void ConptyRoundtripTests::PassthroughClearAll()
verifyBuffer(*termTb, newTerminalView, true);
}

void ConptyRoundtripTests::ClearAllInTheMiddleOfAString()
{
// see TODO!
Log::Comment(L"TODO!");

WEX::TestExecution::SetVerifyOutput settings(WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
const WEX::TestExecution::DisableVerifyExceptions disableExceptionsScope;

auto& g = ServiceLocator::LocateGlobals();
auto& renderer = *g.pRender;
auto& gci = g.getConsoleInformation();
auto& si = gci.GetActiveOutputBuffer();
auto* hostTb = &si.GetTextBuffer();
auto* termTb = term->_mainBuffer.get();

auto& sm = si.GetStateMachine();

_flushFirstFrame();

_checkConptyOutput = false;
_logConpty = true;

const auto hostView = si.GetViewport();
const auto end = 2 * hostView.Height();
for (auto i = 0; i < end; i++)
{
if (i > 0)
{
sm.ProcessString(L"\r\n");
}

sm.ProcessString(L"~");
}

auto verifyBuffer = [&](const TextBuffer& tb, const til::rect& viewport, const bool afterClear = false) {
const auto width = viewport.width();

// "~" rows
for (til::CoordType row = 0; row < viewport.bottom; row++)
{
Log::Comment(NoThrowString().Format(L"Checking row %d", row));
VERIFY_IS_FALSE(tb.GetRowByOffset(row).WasWrapForced());
auto iter = tb.GetCellDataAt({ 0, row });
if (afterClear && row >= viewport.top)
{
if (row == viewport.bottom - 1)
{
TestUtils::VerifyExpectedString(L" ", iter);
TestUtils::VerifyExpectedString(L"bar", iter);
TestUtils::VerifySpanOfText(L" ", iter, 0, width - 8);
}
else
{
TestUtils::VerifySpanOfText(L" ", iter, 0, width);
}
}
else
{
TestUtils::VerifySpanOfText(L"~", iter, 0, 1);
if (afterClear && row == viewport.top - 1)
{
TestUtils::VerifyExpectedString(L"foo", iter);
TestUtils::VerifySpanOfText(L" ", iter, 0, width - 4);
}
else
{
TestUtils::VerifySpanOfText(L" ", iter, 0, width - 1);
}
}
}
};

Log::Comment(L"========== Checking the host buffer state (before) ==========");
verifyBuffer(*hostTb, si.GetViewport().ToExclusive());

Log::Comment(L"Painting the frame");
VERIFY_SUCCEEDED(renderer.PaintFrame());

Log::Comment(L"========== Checking the terminal buffer state (before) ==========");
verifyBuffer(*termTb, term->_mutableViewport.ToExclusive());

const til::rect originalTerminalView{ term->_mutableViewport.ToInclusive() };

// Here, we'll emit the 2J to EraseAll, and move the viewport contents into
// the scrollback.
Log::Comment(L"Send the EraseAll between foo and bar");
sm.ProcessString(L"foo\x1b[2Jbar");

Log::Comment(L"Painting the frame");
VERIFY_SUCCEEDED(renderer.PaintFrame());

// Make sure that the terminal's new viewport is actually just lower than it
// used to be.
const til::rect newTerminalView{ term->_mutableViewport.ToInclusive() };
VERIFY_ARE_EQUAL(end, newTerminalView.top);
VERIFY_IS_GREATER_THAN(newTerminalView.top, originalTerminalView.top);

Log::Comment(L"========== Checking the host buffer state (after) ==========");
verifyBuffer(*hostTb, si.GetViewport().ToExclusive(), true);

Log::Comment(L"Painting the frame");
VERIFY_SUCCEEDED(renderer.PaintFrame());
Log::Comment(L"========== Checking the terminal buffer state (after) ==========");
verifyBuffer(*termTb, newTerminalView, true);
}

void ConptyRoundtripTests::PassthroughHardReset()
{
// This test is highly similar to PassthroughClearScrollback.
Expand Down
21 changes: 19 additions & 2 deletions src/terminal/adapter/adaptDispatch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -606,23 +606,40 @@ bool AdaptDispatch::EraseInDisplay(const DispatchTypes::EraseType eraseType)
// by moving the current contents of the viewport into the scrollback.
if (eraseType == DispatchTypes::EraseType::Scrollback)
{
_renderer.TriggerFlush(false);

_EraseScrollback();
// GH#2715 - If this succeeded, but we're in a conpty, return `false` to
// make the state machine propagate this ED sequence to the connected
// terminal application. While we're in conpty mode, we don't really
// have a scrollback, but the attached terminal might.
return !_api.IsConsolePty();

if (_api.IsConsolePty())
{
_api.GetStateMachine().Engine().ActionPassThroughString(L"\x1b[3J");
}

return true; // !_api.IsConsolePty();
}
else if (eraseType == DispatchTypes::EraseType::All)
{
_renderer.TriggerFlush(false);

// GH#5683 - If this succeeded, but we're in a conpty, return `false` to
// make the state machine propagate this ED sequence to the connected
// terminal application. While we're in conpty mode, when the client
// requests a Erase All operation, we need to manually tell the
// connected terminal to do the same thing, so that the terminal will
// move it's own buffer contents into the scrollback.
_EraseAll();
return !_api.IsConsolePty();

if (_api.IsConsolePty())
{
// TODO! HardReset I guess also relied on this code path. Yikes.
_api.GetStateMachine().Engine().ActionPassThroughString(L"\x1b[2J");
}

return true; // !_api.IsConsolePty();
}

const auto viewport = _api.GetViewport();
Expand Down

1 comment on commit 3e40ee1

@github-actions
Copy link

@github-actions github-actions bot commented on 3e40ee1 Jul 12, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@check-spelling-bot Report

Unrecognized words, please review:

  • AString
  • Jbar
Previously acknowledged words that are now absent ansicode appconsult askubuntu aspx azuredevopspodcast azurewebsites biblioscape bitsavers charlespetzold Checkin ckuehl cla cliutils codeproject colororacle condev Consolescreen cppreference css cxcy DCompile debolden deconstructed DECRST DECRSTS decstandar devblogs devicefamily devops dostips DWMWA dwriteglyphrundescriptionclustermap dxp easyrgb ecma edu errno fabricbot FARPROC fcb fdopen fixterms freedesktop GETKEYSTATE guardxfg halfwidth HOWTO HPAINTBUFFER HPROPSHEETPAGE htm icch iconify ietf intptr inwap ipa issuecomment iwch kayla kovidgoyal leonerd linkid LLVM locstudio lparen LPCHARSETINFO manpage MAPVIRTUALKEY mscorlib MSDL mspartners myignite ned newcursor nlength NOWAIT ocf opensource openxmlformats osfhandle pdp PENDTASKMSG pgorepro pgort PGU php Poli ppci PPORT PSMALL QWERTYUIOP rapidtables RDONLY rdpartysource redistributable referencesource restrictedcapabilities Rexx rfc robertelder rosettacode rparen runasradio scm SOURCESDIRECTORY stackoverflow stdio stgm techcommunity technet testmddefinition Timeline timelines tldp toolbars Toolset ucdxml unintense universaltest UWA UWAs uwaterloo uwspace viewtopic VKKEYSCAN vstudio wddmconrenderer wdx wfdopen wfstream wikia wikipedia windev windowsdeveloper winfx wline wlinestream workitem WResult WSpace xfg Xzn ycombinator
Some files were were automatically ignored

These sample patterns would exclude them:

^samples/ConPTY/EchoCon/EchoCon/EchoCon\.vcxproj\.filters$
^src/host/exe/Host\.EXE\.vcxproj\.filters$
^src/tools/closetest/CloseTest\.vcxproj\.filters$

You should consider adding them to:

.github/actions/spelling/excludes.txt

File matching is via Perl regular expressions.

To check these files, more of their words need to be in the dictionary than not. You can use patterns.txt to exclude portions, add items to the dictionary (e.g. by adding them to allow.txt), or fix typos.

To accept these unrecognized words as correct (and remove the previously acknowledged and now absent words), run the following commands

... in a clone of the git@github.com:microsoft/terminal.git repository
on the dev/migrie/b/8698-YOURE-OUT-OF-ORDER branch:

update_files() {
perl -e '
my @expect_files=qw('".github/actions/spelling/expect/alphabet.txt
.github/actions/spelling/expect/expect.txt
.github/actions/spelling/expect/web.txt"');
@ARGV=@expect_files;
my @stale=qw('"$patch_remove"');
my $re=join "|", @stale;
my $suffix=".".time();
my $previous="";
sub maybe_unlink { unlink($_[0]) if $_[0]; }
while (<>) {
if ($ARGV ne $old_argv) { maybe_unlink($previous); $previous="$ARGV$suffix"; rename($ARGV, $previous); open(ARGV_OUT, ">$ARGV"); select(ARGV_OUT); $old_argv = $ARGV; }
next if /^(?:$re)(?:(?:\r|\n)*$| .*)/; print;
}; maybe_unlink($previous);'
perl -e '
my $new_expect_file=".github/actions/spelling/expect/3e40ee1458eb5002a7047f42463ec86d49aa479f.txt";
use File::Path qw(make_path);
use File::Basename qw(dirname);
make_path (dirname($new_expect_file));
open FILE, q{<}, $new_expect_file; chomp(my @words = <FILE>); close FILE;
my @add=qw('"$patch_add"');
my %items; @items{@words} = @words x (1); @items{@add} = @add x (1);
@words = sort {lc($a)."-".$a cmp lc($b)."-".$b} keys %items;
open FILE, q{>}, $new_expect_file; for my $word (@words) { print FILE "$word\n" if $word =~ /\w/; };
close FILE;
system("git", "add", $new_expect_file);
'
(cat '.github/actions/spelling/excludes.txt' - <<EOF
$should_exclude_patterns
EOF
) |grep .|
sort -f |
uniq > '.github/actions/spelling/excludes.txt.temp' &&
mv '.github/actions/spelling/excludes.txt.temp' '.github/actions/spelling/excludes.txt'
}

comment_json=$(mktemp)
curl -L -s -S \
  --header "Content-Type: application/json" \
  "https://api.github.com/repos/microsoft/terminal/comments/78340397" > "$comment_json"
comment_body=$(mktemp)
jq -r .body < "$comment_json" > $comment_body
rm $comment_json

patch_remove=$(perl -ne 'next unless s{^</summary>(.*)</details>$}{$1}; print' < "$comment_body")
  

patch_add=$(perl -e '$/=undef;
$_=<>;
s{<details>.*}{}s;
s{^#.*}{};
s{\n##.*}{};
s{(?:^|\n)\s*\*}{}g;
s{\s+}{ }g;
print' < "$comment_body")
  

should_exclude_patterns=$(perl -e '$/=undef;
$_=<>;
exit unless s{(?:You should consider excluding directory paths|You should consider adding them to).*}{}s;
s{.*These sample patterns would exclude them:}{}s;
s{.*\`\`\`([^`]*)\`\`\`.*}{$1}m;
print' < "$comment_body" | grep . || true)

update_files
rm $comment_body
git add -u
✏️ Contributor please read this

By default the command suggestion will generate a file named based on your commit. That's generally ok as long as you add the file to your commit. Someone can reorganize it later.

⚠️ The command is written for posix shells. You can copy the contents of each perl command excluding the outer ' marks and dropping any '"/"' quotation mark pairs into a file and then run perl file.pl from the root of the repository to run the code. Alternatively, you can manually insert the items...

If the listed items are:

  • ... misspelled, then please correct them instead of using the command.
  • ... names, please add them to .github/actions/spelling/allow/names.txt.
  • ... APIs, you can add them to a file in .github/actions/spelling/allow/.
  • ... just things you're using, please add them to an appropriate file in .github/actions/spelling/expect/.
  • ... tokens you only need in one place and shouldn't generally be used, you can add an item in an appropriate file in .github/actions/spelling/patterns/.

See the README.md in each directory for more information.

🔬 You can test your commits without appending to a PR by creating a new branch with that extra change and pushing it to your fork. The check-spelling action will run in response to your push -- it doesn't require an open pull request. By using such a branch, you can limit the number of typos your peers see you make. 😉

🗜️ If you see a bunch of garbage

If it relates to a ...

well-formed pattern

See if there's a pattern that would match it.

If not, try writing one and adding it to a patterns/{file}.txt.

Patterns are Perl 5 Regular Expressions - you can test yours before committing to verify it will match your lines.

Note that patterns can't match multiline strings.

binary-ish string

Please add a file path to the excludes.txt file instead of just accepting the garbage.

File paths are Perl 5 Regular Expressions - you can test yours before committing to verify it will match your files.

^ refers to the file's path from the root of the repository, so ^README\.md$ would exclude README.md (on whichever branch you're using).

Please sign in to comment.