dodexahedron / terminal.gui Goto Github PK
View Code? Open in Web Editor NEWThis project forked from gui-cs/terminal.gui
Cross Platform Terminal UI toolkit for .NET
License: MIT License
This project forked from gui-cs/terminal.gui
Cross Platform Terminal UI toolkit for .NET
License: MIT License
The goals in https://github.com/users/dodexahedron/projects/12 and https://github.com/users/dodexahedron/projects/10 will be easier to achieve if some fundamentals are tackled early, especially with an eye toward both providing easy and open flexibility while also keeping that scope in check.
There is technical debt scattered around, both from legacy code and new code (often as a totally understandable consequence to wanting to get a given unit finished), but hey - I don't mind doing this kind of boring work, so here we go.
First, I'll just mention that this work is going to start from the branch I originally made for #22 (currently not pushed to GitHub), because problems there are what finally prompted me to confront this potential beast.
This issue will probably encompass a bit of a smorgasbord of individual changes, but we'll see what I end up actually doing as work progresses.
In the scope of this particular issue, what I'm thinking is that we can probably use both some new interfaces and members on existing types and interfaces, as well as potentially expand the capabilities and definitions of existing interfaces and abstract types.
The initial scope, which is not very likely to remain well-constrained, is the Application class and types and functionality it directly depends on.
If changes in any specific dependency seem to be getting beyond what's reasonable not to be mentioned solely in commit comments, I'll either say something on an associated issue or PR, or else I'll fire up a new issue, if something starts to grow beyond a few incidental changes.
Part of the code in question, in FileDialog.cs:
void UpdateChildren ( ) {
lock ( Parent._onlyOneSearchLock ) {
while ( !_cancel && !_finished ) {
try {
Task.Delay ( 250 ).Wait ( _token.Token );
}
catch ( OperationCanceledException ) {
_cancel = true;
}
if ( _cancel || _finished ) {
break;
}
UpdateChildrenToFound ( );
}
if ( _finished && !_cancel ) {
UpdateChildrenToFound ( );
}
Application.Invoke ( ( ) => { Parent._spinnerView.Visible = false; } );
}
}
Problems:
lock
statement carries some unfortunate restrictions and makes this even more vulnerable to deadlock.
lock
statements are turned into a try/finally block at compile-time, with a Monitor
object used as the synchronization primitive behind it.
Monitor
is a pretty expensive thing to use and is fully exclusionary, but doesn't do any good if everything touching the important stuff in the lock statement body isn't also using that same Monitor.
Exit
ed by the same object that entered it - It also has to be done on the same thread. This is the cause of the non-yielding thread blocking.lock
in one place for a particular mutex, ALL other uses of that mutex should be lock
statements or else things can get very unsafe, very quickly, very confusingly, non-deterministically, and in a very difficult to debug way.And more, but I'm done for now and want to actually get some work done.
Lots of reasons for getting rid of this type and similar types.
The main difference that actually affects anything is that it enforces values >= 0 in property setters (and also implicitly in the constructor, because of that) and throws an ArgumentException on negative values.
That alone is enough reason to at least refactor the type, but may as well just remove it.
Why?
Well, first my semi-subjective reason (though it's based on the objective stuff below):
Objectively:
Offset
method, to turn it into its equivalent all-positive-value representation, if one exists, or getting the intersection of that result with its parent's Frame or whatever if still out of bounds. This would be a good place for an extension method, if that functionality is desired.Inflate()
leaves things in a corrupted state if Width is valid but Height is not, after the multiplication, or if the assignment to X or Y result in overflow.
<exception...
XmlDoc tag, the above I think supersedes that, especially since these particular types are so basic and so simple to replace.Speaking in general and not specifically about these types:
If it's really that critical to do things like that, in that sort of situation (enforce bounds on primitives of types that also exist in the BCL), then it's more appropriate to do the following:
But this one is very arguably not an example of that kind of situation.
For reference, the current dotnet source code for the System.Drawing types I intend to replace is in these files:
Local fork issue to track work on gui-cs#3240
As I just mentioned in #13, there's an opportunity for some nice cleanup and code quality improvements around the Windows native methods we call via PInvoke and the types that support them.
The NuGet package Microsoft.Windows.CsWin32 is a source generator package that just takes a simple text file input and creates all of the methods and the types they depend on.
I've played around with it a little, already, and it is great!
Since I'm already tearing into the WindowsDriver and associated types, right now, I may as well do this opportunistically.
This issue and its associated branch are for that work.
As alluded to in #22, there are going to be a bunch of issues needed to address concurrency issues that are causing a wide variety of sporadic and nondeterministic problems at runtime and in unit tests, with increasing frequency.
The changes necessary to fix them are not terribly difficult, and they happen to also overlap to a pretty significant degree with work I am already doing on other branches, such as the event handling refactoring.
This is more critical to be tackled first, for a lot of reasons, so I'm starting with where I was already working on null fixes: the Application class and types it directly interacts with.
More to follow....
Need to take a pass over the code to find and fix any remaining null checks that are of the form x == null
or x != null
, since R# wasn't able to automatically take care of all of them in the reformat work.
The HACK_CHECK_WINCHANGED is used to conditionally compile a hack to make Windows behave better.
However, it is defined in code and thus will always be set.
Let's set it in the build configuration.
Since Rect is just a copy/paste of Rectangle, aside from slightly different ToString behavior, it's a prime candidate for removal.
To make removal smoother, I'm going to approach it in two stages. First, I'll make the behaviors it exhibits that are different from System.Drawing.Rectangle the same as in that type. That will require fixing unit tests, since the ToString output is heavily relied upon in many tests.
Once everything is working, the type can be renamed, to make the solution-wide change to Rectangle
. Then the type can be deleted and a reference added to System.Drawing.Rectangle as a type alias (rather than the entire namespace) to swap them in-place.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.