-
Notifications
You must be signed in to change notification settings - Fork 694
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixes #666. Refactor ConsoleDriver
s to simplify and remove duplicated code
#2612
Fixes #666. Refactor ConsoleDriver
s to simplify and remove duplicated code
#2612
Conversation
@BDisp take a look... Right now, the only driver that's really using my new codepath is FakeDriver. When I read your message about working on the same thing, I was just about to refactor public override void AddRune (System.Rune systemRune)
{
var rune = new Rune (systemRune).MakePrintable ();
var runeWidth = rune.GetColumnWidth ();
var validLocation = IsValidLocation (Col, Row);
if (validLocation) {
if (rune.IsCombiningMark () && Col > 0) {
// Decode the previous rune
var previousRune = new Rune (Contents [Row, Col - 1, 0]);
var newCombo = new StringBuilder ();
ReadOnlySpan<char> remainingInput = previousRune.ToString ().AsSpan ();
while (!remainingInput.IsEmpty) {
// Decode
OperationStatus opStatus = Rune.DecodeFromUtf16 (remainingInput, out Rune result, out int charsConsumed);
if (opStatus == OperationStatus.DestinationTooSmall || opStatus == OperationStatus.InvalidData) {
result = Rune.ReplacementChar;
}
newCombo.Append (result);
// Slice and loop again
remainingInput = remainingInput.Slice (charsConsumed);
}
newCombo.Append (rune);
var combined = newCombo.ToString ();
var normalized = !combined.IsNormalized () ? combined.Normalize () : combined;
Contents [Row, Col - 1, 0] = normalized [0];// BUGBUG: This is wrong, we need to handle the case where the rune is more than one char
Contents [Row, Col - 1, 1] = CurrentAttribute;
Contents [Row, Col - 1, 2] = 1;
Col--;
} else {
Contents [Row, Col, 0] = rune.Value;
Contents [Row, Col, 1] = CurrentAttribute;
if (Col > 0) {
var left = new Rune (Contents [Row, Col - 1, 0]);
if (left.GetColumnWidth () > 1) {
Contents [Row, Col - 1, 0] = Rune.ReplacementChar.Value;
}
}
if (runeWidth > 1) {
Col++;
Contents [Row, Col, 0] = Rune.ReplacementChar.Value;
Contents [Row, Col, 1] = CurrentAttribute;
Contents [Row, Col, 2] = 1;
}
}
}
Col++;
} To enable One thing I just learned is having To address this, I propose we change the way struct ContentsCell {
string runes;
Attribute attr;
bool Dirty;
} Also, look at how I refactored things, including the |
See #2616 |
You are doing well. I think with your focused on the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@tig I only left a question. See bellow, thanks.
│これは�┌────────────┐�です。│ | ||
│これは�│ワイドルーン│�です。│ | ||
│これは�│ {CM.Glyphs.LeftBracket} 選ぶ {CM.Glyphs.RightBracket} │�です。│ | ||
│これは�└────────────┘�です。│ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Originally when a surrogate pair hasn't enough space to display I replaced it with a space. Now you are using the replacement rune. Is this temporary or you are think let it as is now? It's a matter of personal choice but I only I'm asking if it was for a test or a definitive choice.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not sure what the right thing to do is.
In some cases (e.g. when debugging), it's helpful to have the replacement char shown. But in real-world cases, it may look better to have spaces.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For now, I'm reverting to show the replacement char
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not sure what the right thing to do is.
That was controlled on the AddRune
method. I referred to surrogate pairs, but it also may be non surrogate UTF16 that has a column width of 2. Even some surrogate pairs have only one column width of 1. Well, a valid surrogate pair is composed by two surrogates (lower and high). When you are reading a surrogate pair that doesn't fit in the available space (you have only one column) you are reading the first char surrogate that isn't printable and you replace it. Before when I checked a rune that doesn't fit I replace with a space, because the user must see the right rune or none, instead of a replacement rune. The condition is the same for all drivers but each driver has it own way to replace it. Only the contents are equal.
In some cases (e.g. when debugging), it's helpful to have the replacement char shown. But in real-world cases, it may look better to have spaces.
Yes is true, I agree. The only driver that is dealing with surrogate pairs with a column width of 1 is the NetDriver because it use a String.Builder list, but I think the FakeDriver may use it too.
Fixes #666 - Include a terse summary of the change or which issue is fixed.
For v2, and as part of #2606, I'm tackling this. Todo:
Move()
andAddStr()
- there's almost no difference in each of the 4 driver's implementation, and the code is complex and hard to understand.AddStr
is the wrong place to do it and will investigate how to move that logic intoUpdateScreen
_ccol
and_crow
and_contents
the same and uses them in the same way. These should be moved intoConsoleDriver
./Drawning
These issues are NOT fixed in this PR and need to be addressed separately:
Pull Request checklist:
CTRL-K-D
to automatically reformat your files before committing.dotnet test
before commit///
style comments)