Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/SharpMUTerm.Core/Session/WorldSession.cs
Original file line number Diff line number Diff line change
Expand Up @@ -312,15 +312,22 @@ private void OnOutputReceived(object? sender, TelnetOutputEventArgs e)
return;
}

var emitted = false;
foreach (var completed in _parser.Feed(e.Text))
{
ProcessOutputLine(completed);
emitted = true;
}

var tail = _parser.Flush();
if (tail is not null)
{
ProcessOutputLine(tail);
emitted = true;
}
else if (!emitted)
{
ProcessOutputLine(StyledLine.Empty);
}
}

Expand Down
30 changes: 30 additions & 0 deletions tests/SharpMUTerm.Core.Tests/Session/WorldSessionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,36 @@ public async Task OutputLine_IsAppendedToScrollbackAndRaisesEvent()
await Assert.That(printed).IsNotNull();
}

[Test]
public async Task EmptyOutputLine_IsAppendedAsBlankLine()
{
var (session, telnet) = Create(World());
await session.ConnectAsync();
var before = session.Scrollback.Snapshot().Count;

telnet.EmitLine(string.Empty);

var after = session.Scrollback.Snapshot();
await Assert.That(after.Count).IsEqualTo(before + 1);
await Assert.That(after[^1].IsEmpty).IsTrue();
}

[Test]
public async Task SameFrame_OutputPreservesAnEmptyMiddleLine()
{
var (session, telnet) = Create(World());
await session.ConnectAsync();
var before = session.Scrollback.Snapshot().Count;

telnet.EmitLine("Line one\n\nThis line three, previous line was empty, this is valid output. It came from the same received frame.");

var after = session.Scrollback.Snapshot();
await Assert.That(after.Count).IsEqualTo(before + 3);
await Assert.That(after[before].Text).IsEqualTo("Line one");
await Assert.That(after[before + 1].IsEmpty).IsTrue();
await Assert.That(after[before + 2].Text).IsEqualTo("This line three, previous line was empty, this is valid output. It came from the same received frame.");
}

[Test]
public async Task AnsiColor_InOutput_IsParsedIntoStyledSpans()
{
Expand Down
Loading