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
75 changes: 47 additions & 28 deletions Terminal.Gui/ConsoleDrivers/CursesDriver/CursesDriver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,40 +62,59 @@ public override void AddRune (Rune rune)
Curses.move (crow, ccol);
needMove = false;
}
if (runeWidth < 2 && ccol > 0
&& Rune.ColumnWidth ((char)contents [crow, ccol - 1, 0]) > 1) {

var curAtttib = currentAttribute;
Curses.attrset (contents [crow, ccol - 1, 1]);
Curses.mvaddch (crow, ccol - 1, (int)(uint)' ');
contents [crow, ccol - 1, 0] = (int)(uint)' ';
Curses.move (crow, ccol);
Curses.attrset (curAtttib);

} else if (runeWidth < 2 && ccol <= Clip.Right - 1
&& Rune.ColumnWidth ((char)contents [crow, ccol, 0]) > 1) {

var curAtttib = currentAttribute;
Curses.attrset (contents [crow, ccol + 1, 1]);
Curses.mvaddch (crow, ccol + 1, (int)(uint)' ');
contents [crow, ccol + 1, 0] = (int)(uint)' ';
Curses.move (crow, ccol);
Curses.attrset (curAtttib);
if (runeWidth == 0 && ccol > 0) {
var r = contents [crow, ccol - 1, 0];
var s = new string (new char [] { (char)r, (char)rune });
string sn;
if (!s.IsNormalized ()) {
sn = s.Normalize ();
} else {
sn = s;
}
var c = sn [0];
Curses.mvaddch (crow, ccol - 1, (int)(uint)c);
contents [crow, ccol - 1, 0] = c;
contents [crow, ccol - 1, 1] = currentAttribute;
contents [crow, ccol - 1, 2] = 1;

}
if (runeWidth > 1 && ccol == Clip.Right - 1) {
Curses.addch ((int)(uint)' ');
contents [crow, ccol, 0] = (int)(uint)' ';
} else {
Curses.addch ((int)(uint)rune);
contents [crow, ccol, 0] = (int)(uint)rune;
if (runeWidth < 2 && ccol > 0
&& Rune.ColumnWidth ((char)contents [crow, ccol - 1, 0]) > 1) {

var curAtttib = currentAttribute;
Curses.attrset (contents [crow, ccol - 1, 1]);
Curses.mvaddch (crow, ccol - 1, (int)(uint)' ');
contents [crow, ccol - 1, 0] = (int)(uint)' ';
Curses.move (crow, ccol);
Curses.attrset (curAtttib);

} else if (runeWidth < 2 && ccol <= Clip.Right - 1
&& Rune.ColumnWidth ((char)contents [crow, ccol, 0]) > 1) {

var curAtttib = currentAttribute;
Curses.attrset (contents [crow, ccol + 1, 1]);
Curses.mvaddch (crow, ccol + 1, (int)(uint)' ');
contents [crow, ccol + 1, 0] = (int)(uint)' ';
Curses.move (crow, ccol);
Curses.attrset (curAtttib);

}
if (runeWidth > 1 && ccol == Clip.Right - 1) {
Curses.addch ((int)(uint)' ');
contents [crow, ccol, 0] = (int)(uint)' ';
} else {
Curses.addch ((int)(uint)rune);
contents [crow, ccol, 0] = (int)(uint)rune;
}
contents [crow, ccol, 1] = currentAttribute;
contents [crow, ccol, 2] = 1;
}
contents [crow, ccol, 1] = currentAttribute;
contents [crow, ccol, 2] = 1;
} else
needMove = true;

ccol++;
if (runeWidth < 0 || runeWidth > 0) {
ccol++;
}
if (runeWidth > 1) {
if (validClip && ccol < Clip.Right) {
contents [crow, ccol, 1] = currentAttribute;
Expand Down
52 changes: 35 additions & 17 deletions Terminal.Gui/ConsoleDrivers/FakeDriver/FakeDriver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public Behaviors (bool useFakeClipboard = false, bool fakeClipboardAlwaysThrowsN
UseFakeClipboard = useFakeClipboard;
FakeClipboardAlwaysThrowsNotSupportedException = fakeClipboardAlwaysThrowsNotSupportedException;
FakeClipboardIsSupportedAlwaysFalse = fakeClipboardIsSupportedAlwaysTrue;

// double check usage is correct
Debug.Assert (useFakeClipboard == false && fakeClipboardAlwaysThrowsNotSupportedException == false);
Debug.Assert (useFakeClipboard == false && fakeClipboardIsSupportedAlwaysTrue == false);
Expand Down Expand Up @@ -131,31 +131,49 @@ public override void AddRune (Rune rune)
//MockConsole.CursorTop = crow;
needMove = false;
}
if (runeWidth < 2 && ccol > 0
if (runeWidth == 0 && ccol > 0) {
var r = contents [crow, ccol - 1, 0];
var s = new string (new char [] { (char)r, (char)rune });
string sn;
if (!s.IsNormalized ()) {
sn = s.Normalize ();
} else {
sn = s;
}
var c = sn [0];
contents [crow, ccol - 1, 0] = c;
contents [crow, ccol - 1, 1] = currentAttribute;
contents [crow, ccol - 1, 2] = 1;

} else {
if (runeWidth < 2 && ccol > 0
&& Rune.ColumnWidth ((Rune)contents [crow, ccol - 1, 0]) > 1) {

contents [crow, ccol - 1, 0] = (int)(uint)' ';
contents [crow, ccol - 1, 0] = (int)(uint)' ';

} else if (runeWidth < 2 && ccol <= Clip.Right - 1
&& Rune.ColumnWidth ((Rune)contents [crow, ccol, 0]) > 1) {
} else if (runeWidth < 2 && ccol <= Clip.Right - 1
&& Rune.ColumnWidth ((Rune)contents [crow, ccol, 0]) > 1) {

contents [crow, ccol + 1, 0] = (int)(uint)' ';
contents [crow, ccol + 1, 2] = 1;
contents [crow, ccol + 1, 0] = (int)(uint)' ';
contents [crow, ccol + 1, 2] = 1;

}
if (runeWidth > 1 && ccol == Clip.Right - 1) {
contents [crow, ccol, 0] = (int)(uint)' ';
} else {
contents [crow, ccol, 0] = (int)(uint)rune;
}
contents [crow, ccol, 1] = currentAttribute;
contents [crow, ccol, 2] = 1;
}
if (runeWidth > 1 && ccol == Clip.Right - 1) {
contents [crow, ccol, 0] = (int)(uint)' ';
} else {
contents [crow, ccol, 0] = (int)(uint)rune;
}
contents [crow, ccol, 1] = currentAttribute;
contents [crow, ccol, 2] = 1;

dirtyLine [crow] = true;
dirtyLine [crow] = true;
}
} else
needMove = true;

ccol++;
if (runeWidth < 0 || runeWidth > 0) {
ccol++;
}
if (runeWidth > 1) {
if (validClip && ccol < Clip.Right) {
contents [crow, ccol, 1] = currentAttribute;
Expand Down
52 changes: 35 additions & 17 deletions Terminal.Gui/ConsoleDrivers/NetDriver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1241,30 +1241,48 @@ public override void AddRune (Rune rune)
var validClip = IsValidContent (ccol, crow, Clip);

if (validClip) {
if (runeWidth < 2 && ccol > 0
&& Rune.ColumnWidth ((char)contents [crow, ccol - 1, 0]) > 1) {
if (runeWidth == 0 && ccol > 0) {
var r = contents [crow, ccol - 1, 0];
var s = new string (new char [] { (char)r, (char)rune });
string sn;
if (!s.IsNormalized ()) {
sn = s.Normalize ();
} else {
sn = s;
}
var c = sn [0];
contents [crow, ccol - 1, 0] = c;
contents [crow, ccol - 1, 1] = currentAttribute;
contents [crow, ccol - 1, 2] = 1;

contents [crow, ccol - 1, 0] = (int)(uint)' ';
} else {
if (runeWidth < 2 && ccol > 0
&& Rune.ColumnWidth ((char)contents [crow, ccol - 1, 0]) > 1) {

} else if (runeWidth < 2 && ccol <= Clip.Right - 1
&& Rune.ColumnWidth ((char)contents [crow, ccol, 0]) > 1) {
contents [crow, ccol - 1, 0] = (int)(uint)' ';

contents [crow, ccol + 1, 0] = (int)(uint)' ';
contents [crow, ccol + 1, 2] = 1;
} else if (runeWidth < 2 && ccol <= Clip.Right - 1
&& Rune.ColumnWidth ((char)contents [crow, ccol, 0]) > 1) {

}
if (runeWidth > 1 && ccol == Clip.Right - 1) {
contents [crow, ccol, 0] = (int)(uint)' ';
} else {
contents [crow, ccol, 0] = (int)(uint)rune;
}
contents [crow, ccol, 1] = currentAttribute;
contents [crow, ccol, 2] = 1;
contents [crow, ccol + 1, 0] = (int)(uint)' ';
contents [crow, ccol + 1, 2] = 1;

}
if (runeWidth > 1 && ccol == Clip.Right - 1) {
contents [crow, ccol, 0] = (int)(uint)' ';
} else {
contents [crow, ccol, 0] = (int)(uint)rune;
}
contents [crow, ccol, 1] = currentAttribute;
contents [crow, ccol, 2] = 1;

}
dirtyLine [crow] = true;
}

ccol++;
if (runeWidth < 0 || runeWidth > 0) {
ccol++;
}
if (runeWidth > 1) {
if (validClip && ccol < Clip.Right) {
contents [crow, ccol, 1] = currentAttribute;
Expand Down Expand Up @@ -1485,7 +1503,7 @@ public override void UpdateScreen ()
outputWidth++;
var rune = contents [row, col, 0];
char [] spair;
if (Rune.DecodeSurrogatePair((uint) rune, out spair)) {
if (Rune.DecodeSurrogatePair ((uint)rune, out spair)) {
output.Append (spair);
} else {
output.Append ((char)rune);
Expand Down
65 changes: 43 additions & 22 deletions Terminal.Gui/ConsoleDrivers/WindowsDriver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1517,35 +1517,56 @@ public override void AddRune (Rune rune)
var validClip = IsValidContent (ccol, crow, Clip);

if (validClip) {
if (runeWidth < 2 && ccol > 0
&& Rune.ColumnWidth ((char)contents [crow, ccol - 1, 0]) > 1) {

if (runeWidth == 0 && ccol > 0) {
var r = contents [crow, ccol - 1, 0];
var s = new string (new char [] { (char)r, (char)rune });
string sn;
if (!s.IsNormalized ()) {
sn = s.Normalize ();
} else {
sn = s;
}
var c = sn [0];
var prevPosition = crow * Cols + (ccol - 1);
OutputBuffer [prevPosition].Char.UnicodeChar = ' ';
contents [crow, ccol - 1, 0] = (int)(uint)' ';
OutputBuffer [prevPosition].Char.UnicodeChar = c;
contents [crow, ccol - 1, 0] = c;
OutputBuffer [prevPosition].Attributes = (ushort)currentAttribute;
contents [crow, ccol - 1, 1] = currentAttribute;
contents [crow, ccol - 1, 2] = 1;
WindowsConsole.SmallRect.Update (ref damageRegion, (short)(ccol - 1), (short)crow);
} else {
if (runeWidth < 2 && ccol > 0
&& Rune.ColumnWidth ((char)contents [crow, ccol - 1, 0]) > 1) {

} else if (runeWidth < 2 && ccol <= Clip.Right - 1
&& Rune.ColumnWidth ((char)contents [crow, ccol, 0]) > 1) {
var prevPosition = crow * Cols + (ccol - 1);
OutputBuffer [prevPosition].Char.UnicodeChar = ' ';
contents [crow, ccol - 1, 0] = (int)(uint)' ';

var prevPosition = GetOutputBufferPosition () + 1;
OutputBuffer [prevPosition].Char.UnicodeChar = (char)' ';
contents [crow, ccol + 1, 0] = (int)(uint)' ';
} else if (runeWidth < 2 && ccol <= Clip.Right - 1
&& Rune.ColumnWidth ((char)contents [crow, ccol, 0]) > 1) {

var prevPosition = GetOutputBufferPosition () + 1;
OutputBuffer [prevPosition].Char.UnicodeChar = (char)' ';
contents [crow, ccol + 1, 0] = (int)(uint)' ';

}
if (runeWidth > 1 && ccol == Clip.Right - 1) {
OutputBuffer [position].Char.UnicodeChar = (char)' ';
contents [crow, ccol, 0] = (int)(uint)' ';
} else {
OutputBuffer [position].Char.UnicodeChar = (char)rune;
contents [crow, ccol, 0] = (int)(uint)rune;
}
OutputBuffer [position].Attributes = (ushort)currentAttribute;
contents [crow, ccol, 1] = currentAttribute;
contents [crow, ccol, 2] = 1;
WindowsConsole.SmallRect.Update (ref damageRegion, (short)ccol, (short)crow);
}
if (runeWidth > 1 && ccol == Clip.Right - 1) {
OutputBuffer [position].Char.UnicodeChar = (char)' ';
contents [crow, ccol, 0] = (int)(uint)' ';
} else {
OutputBuffer [position].Char.UnicodeChar = (char)rune;
contents [crow, ccol, 0] = (int)(uint)rune;
}
OutputBuffer [position].Attributes = (ushort)currentAttribute;
contents [crow, ccol, 1] = currentAttribute;
contents [crow, ccol, 2] = 1;
WindowsConsole.SmallRect.Update (ref damageRegion, (short)ccol, (short)crow);
}

ccol++;
if (runeWidth < 0 || runeWidth > 0) {
ccol++;
}
if (runeWidth > 1) {
if (validClip && ccol < Clip.Right) {
position = GetOutputBufferPosition ();
Expand Down
4 changes: 2 additions & 2 deletions UnitTests/Views/TabViewTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -719,7 +719,7 @@ public void ShowTopLine_True_TabsOnBottom_False_With_Unicode ()

TestHelpers.AssertDriverContentsWithFrameAre (@"
┌──────────────┐
│Les Misérables
│Les Misérables
◄ └───┐
│hi2 │
└──────────────────┘", output);
Expand Down Expand Up @@ -756,7 +756,7 @@ public void ShowTopLine_True_TabsOnBottom_True_With_Unicode ()
┌──────────────────┐
│hi2 │
◄ ┌───┘
│Les Misérables
│Les Misérables
└──────────────┘ ", output);
}

Expand Down