Skip to content

Commit d34b999

Browse files
committed
fix reset
1 parent b9fa0bb commit d34b999

2 files changed

Lines changed: 95 additions & 2 deletions

File tree

src/XTerm.NET.Tests/TerminalTests.cs

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using XTerm;
2+
using XTerm.Buffer;
23
using XTerm.Options;
34

45
namespace XTerm.Tests;
@@ -891,4 +892,89 @@ public void GetLine_WithScrollback_ReturnsCorrectContent()
891892
}
892893

893894
#endregion
895+
896+
[Fact]
897+
public void Reset_ClearsLineAttributes()
898+
{
899+
// Arrange
900+
var terminal = new Terminal();
901+
902+
// Set some lines to double-height mode using ESC # 3 (top) and ESC # 4 (bottom)
903+
terminal.Write("Line 0\n");
904+
terminal.Write("\x1B#3"); // ESC # 3 - Double-height top
905+
terminal.Write("Line 1 Top\n");
906+
terminal.Write("\x1B#4"); // ESC # 4 - Double-height bottom
907+
terminal.Write("Line 2 Bottom\n");
908+
terminal.Write("\x1B#6"); // ESC # 6 - Double-width
909+
terminal.Write("Line 3 Wide\n");
910+
911+
// Verify line attributes are set
912+
Assert.Equal(LineAttribute.DoubleHeightTop, terminal.Buffer.Lines[1]?.LineAttribute);
913+
Assert.Equal(LineAttribute.DoubleHeightBottom, terminal.Buffer.Lines[2]?.LineAttribute);
914+
Assert.Equal(LineAttribute.DoubleWidth, terminal.Buffer.Lines[3]?.LineAttribute);
915+
916+
// Act - Reset the terminal (simulates 'reset' command which sends ESC c / RIS)
917+
terminal.Reset();
918+
919+
// Assert - All line attributes should be reset to Normal
920+
for (int i = 0; i < terminal.Rows; i++)
921+
{
922+
var line = terminal.Buffer.Lines[i];
923+
if (line != null)
924+
{
925+
Assert.Equal(LineAttribute.Normal, line.LineAttribute);
926+
}
927+
}
928+
}
929+
930+
[Fact]
931+
public void Reset_ClearsLineAttributesInScrollback()
932+
{
933+
// Arrange
934+
var terminal = new Terminal(new TerminalOptions { Rows = 5, Cols = 80, Scrollback = 100 });
935+
936+
// Write lines with double-height attributes
937+
for (int i = 0; i < 10; i++)
938+
{
939+
if (i % 2 == 0)
940+
{
941+
terminal.Write("\x1B#3"); // ESC # 3 - Double-height top
942+
}
943+
else
944+
{
945+
terminal.Write("\x1B#6"); // ESC # 6 - Double-width
946+
}
947+
terminal.Write($"Line {i}\n");
948+
}
949+
950+
// Verify some line attributes are set (check a few lines in scrollback)
951+
bool foundDoubleHeight = false;
952+
bool foundDoubleWidth = false;
953+
for (int i = 0; i < terminal.Buffer.Lines.Length; i++)
954+
{
955+
var line = terminal.Buffer.Lines[i];
956+
if (line != null)
957+
{
958+
if (line.LineAttribute == LineAttribute.DoubleHeightTop)
959+
foundDoubleHeight = true;
960+
if (line.LineAttribute == LineAttribute.DoubleWidth)
961+
foundDoubleWidth = true;
962+
}
963+
}
964+
Assert.True(foundDoubleHeight || foundDoubleWidth, "Expected to find at least one line with non-normal attribute");
965+
966+
// Act - Reset the terminal (simulates 'reset' command which sends ESC c / RIS)
967+
terminal.Reset();
968+
969+
// Assert - All lines in the buffer (including scrollback) should have Normal line attributes
970+
for (int i = 0; i < terminal.Buffer.Lines.Length; i++)
971+
{
972+
var line = terminal.Buffer.Lines[i];
973+
if (line != null)
974+
{
975+
Assert.Equal(LineAttribute.Normal, line.LineAttribute);
976+
}
977+
}
978+
}
894979
}
980+

src/XTerm.NET/Terminal.cs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,7 @@ public void Reset()
296296
{
297297
_buffer = _normalBuffer!;
298298
_usingAltBuffer = false;
299+
_inputHandler.SetBuffer(_buffer);
299300
}
300301

301302
// Reset parser
@@ -334,10 +335,16 @@ public void Clear()
334335

335336
private void ClearBuffer()
336337
{
337-
for (int i = 0; i < Rows; i++)
338+
// Clear all lines in the buffer (including scrollback)
339+
// and reset line attributes (double-width/double-height) to normal
340+
for (int i = 0; i < _buffer.Lines.Length; i++)
338341
{
339342
var line = _buffer.Lines[i];
340-
line?.Fill(BufferCell.Space);
343+
if (line != null)
344+
{
345+
line.Fill(BufferCell.Space);
346+
line.LineAttribute = LineAttribute.Normal;
347+
}
341348
}
342349
_buffer.SetCursor(0, 0);
343350
}

0 commit comments

Comments
 (0)