Skip to content

Commit

Permalink
reset double-width / double-height lines on ED or "Clear Screen" menu
Browse files Browse the repository at this point in the history
  • Loading branch information
poderosaproject committed Dec 1, 2024
1 parent 40e6dba commit ceec928
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 26 deletions.
6 changes: 5 additions & 1 deletion Core/GLine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -985,12 +985,16 @@ private GColor24[] Duplicate24bitColors(GColor24[] reusable) {
/// </summary>
/// <param name="dec">text decoration for specifying the background color, or null for using default attributes.</param>
/// <param name="selective">if true, protected characters are retained.</param>
public void Clear(TextDecoration dec = null, bool selective = false) {
/// <param name="resetLineRenderingType">if true, LineRenderingType is reset to Normal.</param>
public void Clear(TextDecoration dec = null, bool selective = false, bool resetLineRenderingType = true) {
TextDecoration d = dec ?? TextDecoration.Default;
GAttr attr = d.Attr;
GColor24 color = d.Color24;

lock (this) {
if (resetLineRenderingType) {
_lineRenderingType = LineRenderingType.Normal;
}
if (selective) {
FillSelective(0, _cell.Length, GChar.ASCII_NUL, attr, color);
}
Expand Down
17 changes: 2 additions & 15 deletions TerminalEmulator/TerminalDocument.cs
Original file line number Diff line number Diff line change
Expand Up @@ -908,26 +908,13 @@ public void RemoveAfter(int from) {
_invalidatedRegion.InvalidatedAll = true;
}

public void ClearAfter(int from, TextDecoration dec) {
GLine l = FindLineOrNullClipTop(from);
if (l == null)
return;

while (l != null) {
l.Clear(dec);
l = l.NextLine;
}

_invalidatedRegion.InvalidatedAll = true;
}

public void ClearRange(int from, int to, TextDecoration dec, bool selective = false) {
public void ClearRange(int from, int to, TextDecoration dec, bool selective, bool resetLineRenderingType) {
GLine l = FindLineOrNullClipTop(from);
if (l == null)
return;

while (l != null && l.ID < to) {
l.Clear(dec, selective);
l.Clear(dec, selective, resetLineRenderingType);
_invalidatedRegion.InvalidateLine(l.ID);
l = l.NextLine;
}
Expand Down
31 changes: 21 additions & 10 deletions TerminalEmulator/XTerm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ protected override void FullResetInternal() { // called from the base class
_enableHorizontalMargins = false;
_rectangularAttributeChange = false;
_escapeSequenceEngine.Reset();
DoEraseInDisplay(2 /* all */, false);
DoEraseInDisplay(2 /* all */, false, true);
MoveCursorTo(new Row(1), new Col(1));
}

Expand Down Expand Up @@ -1416,40 +1416,51 @@ private void ProcessCursorPositionRelative(NumericParams p) {
[EscapeSequence(ControlCode.CSI, EscapeSequenceParamType.Numeric, 'J')] // ED
private void ProcessEraseInDisplay(NumericParams p) {
int param = p.Get(0, 0);
DoEraseInDisplay(param, false);
DoEraseInDisplay(param, false, true);
}

[EscapeSequence(ControlCode.CSI, '?', EscapeSequenceParamType.Numeric, 'J')] // DECSED
private void ProcessSelectiveEraseInDisplay(NumericParams p) {
int param = p.Get(0, 0);
DoEraseInDisplay(param, true);
DoEraseInDisplay(param, true, false);
}

private void DoEraseInDisplay(int param, bool selective) {
private void DoEraseInDisplay(int param, bool selective, bool resetLineRenderingType) {
int bottomLineNumber = Document.TopLineNumber + Document.TerminalHeight - 1;
switch (param) {
case 0: //erase below
{
if (Document.CaretColumn == 0 && Document.CurrentLineNumber == Document.TopLineNumber)
if (Document.CaretColumn == 0 && Document.CurrentLineNumber == Document.TopLineNumber) {
goto ERASE_ALL;
}

if (Document.CaretColumn == 0 && resetLineRenderingType) {
_manipulator.LineRenderingType = LineRenderingType.Normal;
}

if (selective) {
SelectiveEraseRight();
}
else {
EraseRight();
}

Document.UpdateCurrentLine(_manipulator);
Document.EnsureLine(bottomLineNumber);
Document.RemoveAfter(bottomLineNumber + 1);
Document.ClearRange(Document.CurrentLineNumber + 1, bottomLineNumber + 1, Document.CurrentDecoration, selective);
Document.ClearRange(Document.CurrentLineNumber + 1, bottomLineNumber + 1, Document.CurrentDecoration, selective, resetLineRenderingType);
_manipulator.Load(Document.CurrentLine);
}
break;
case 1: //erase above
{
if (Document.CaretColumn == Document.TerminalWidth - 1 && Document.CurrentLineNumber == bottomLineNumber)
if (Document.CaretColumn >= Document.TerminalWidth - 1 && Document.CurrentLineNumber == bottomLineNumber) {
goto ERASE_ALL;
}

if (Document.CaretColumn >= Document.TerminalWidth - 1 && resetLineRenderingType) {
_manipulator.LineRenderingType = LineRenderingType.Normal;
}

if (selective) {
SelectiveEraseLeft();
Expand All @@ -1458,7 +1469,7 @@ private void DoEraseInDisplay(int param, bool selective) {
EraseLeft();
}
Document.UpdateCurrentLine(_manipulator);
Document.ClearRange(Document.TopLineNumber, Document.CurrentLineNumber, Document.CurrentDecoration, selective);
Document.ClearRange(Document.TopLineNumber, Document.CurrentLineNumber, Document.CurrentDecoration, selective, resetLineRenderingType);
_manipulator.Load(Document.CurrentLine);
}
break;
Expand All @@ -1470,7 +1481,7 @@ private void DoEraseInDisplay(int param, bool selective) {
Document.UpdateCurrentLine(_manipulator);
Document.EnsureLine(bottomLineNumber);
Document.RemoveAfter(bottomLineNumber + 1);
Document.ClearRange(Document.TopLineNumber, bottomLineNumber + 1, Document.CurrentDecoration, selective);
Document.ClearRange(Document.TopLineNumber, bottomLineNumber + 1, Document.CurrentDecoration, selective, resetLineRenderingType);
_manipulator.Load(Document.CurrentLine);
}
break;
Expand Down Expand Up @@ -3486,7 +3497,7 @@ private void RestoreScreen(int sw) {
}

private void ClearScreen() {
DoEraseInDisplay(2, false);
DoEraseInDisplay(2, false, true);
}

[EscapeSequence(ControlCode.ESC, '7')] // DECSC
Expand Down

0 comments on commit ceec928

Please sign in to comment.