Skip to content

Commit

Permalink
fix erase commands to respect SGR values (fixes weird buffer corrupti…
Browse files Browse the repository at this point in the history
…on from vim)
  • Loading branch information
doubleyewdee committed Nov 27, 2018
1 parent 9d10e5e commit 4b17588
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
15 changes: 12 additions & 3 deletions src/ConsoleBuffer/Buffer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,9 @@ private void HandleEraseCharacter(Commands.EraseCharacter ech)
var x = this.cursorX;
for (var c = 0; c < ech.Count; ++c)
{
this.lines[y].SetGlyph(x, 0x20);
var eraseChar = this.characterTemplate;
eraseChar.Glyph = 0x20;
this.lines[y].Set(x, eraseChar);
++x;
if (x == this.Width)
{
Expand Down Expand Up @@ -332,9 +334,14 @@ private void HandleEraseInDisplay(Commands.EraseIn eid)
return;
}

var eraseChar = this.characterTemplate;
eraseChar.Glyph = 0x20;
for (var y = startY; y <= endY; ++y)
{
this.lines[y].Clear();
for (var x = 0; x < this.lines[y].Length; ++x)
{
this.lines[y].Set(x, eraseChar);
}
}
}

Expand All @@ -359,9 +366,11 @@ private void HandleEraseInLine(Commands.EraseIn eil)
return;
}

var eraseChar = this.characterTemplate;
eraseChar.Glyph = 0x20;
for (var x = startX; x <= endX; ++x)
{
this.lines[this.CurrentLine].SetGlyph(x, 0x20);
this.lines[this.CurrentLine].Set(x, eraseChar);
}
}

Expand Down
10 changes: 2 additions & 8 deletions src/ConsoleBuffer/Line.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ public sealed class Line : IEnumerable<Character>
{
private readonly List<Character> chars;

public int Length => this.chars.Count;

public Line()
{
var hintSize = 80;
Expand Down Expand Up @@ -54,14 +56,6 @@ public void SetGlyph(int pos, int glyph)
this.chars[pos] = current;
}

public void Clear()
{
for (var x = 0; x < this.chars.Count; ++x)
{
this.SetGlyph(x, 0x20);
}
}

private void Extend(int pos)
{
while (this.chars.Count <= pos)
Expand Down

0 comments on commit 4b17588

Please sign in to comment.