gui-cs / Terminal.Gui

Cross Platform Terminal UI toolkit for .NET
MIT License
9.57k stars 682 forks source link

Add TrueColor support to CursesDriver #2798

Open tig opened 1 year ago

tig commented 1 year ago

Dependent on #2797

Add TrueColor support to CursesDriver

dodexahedron commented 6 months ago

While diving down the CursesDriver rabbit hole to address other issues (#3287 covers some of it), I'm now rapidly leaning toward and half talking myself into going ahead and tackling a rework of it.

While that wouldn't be directly targeted at enhancing it, such as adding more color support, I have a feeling that redoing it in the spirit of the other ConsoleDrivers will already implicitly bring at least a good portion of the necessary elements along with it, anyway, if not even straight up result in it just getting at least similar support to what the others have.

Someone either talk me out of that or push me over the edge! 😅

tig commented 6 months ago

Remember: the fact Terminal.gui relies on curses for Mac/Linux support is dumb.

Curses just provides a huge amount of complexity for very little.

If you're gonna dive in here, dive all the way. 🤪

Nutzzz commented 6 months ago

Would using notcurses help? Though I don't think they have a C# wrapper yet...

EDIT: Yeah, they don't.

BDisp commented 6 months ago

When we don't need pinvokes for Windows, they may not be necessary for Linux/Mac either. Everything is interconnected with completely different systems and only by handling them is it possible to access certain functionalities. .NET does not fully provide all these features for all systems, especially on Linux/Mac, for obvious reasons, I think.

tig commented 6 months ago

Curses (and noncurses) are not magic.

They do what we already partially do, and need to do fully on Windows (to support VTS) anyway.

We need three things on each platform:

  1. Something that outputs to the terminal.
  2. Something that receives and maps keyboard input.
  3. Something that receives and maps mouse input.

On Mac/Linux, leveraging some API that abstracts away low-level platform differences will be useful for 2 and 3. It may be curses/notcurses can be useful there. But given how these OS's have converged over time, I think we can use the bare minimum.

dodexahedron commented 6 months ago

When we don't need pinvokes for Windows, they may not be necessary for Linux/Mac either. Everything is interconnected with completely different systems and only by handling them is it possible to access certain functionalities. .NET does not fully provide all these features for all systems, especially on Linux/Mac, for obvious reasons, I think.

Spot on. Also, even Console itself is more capable in .net 8 than it was before, so we have existing code that can almost certainly be refactored to remove some pinvokes.

One of the BIG pushes they've made, in recent .net versions, however, has been explicitly to unify support and behaviors for all sorts of stuff, across platforms - linux especially.

dodexahedron commented 6 months ago

Curses (and noncurses) are not magic.

They do what we already partially do, and need to do fully on Windows (to support VTS) anyway.

We need three things on each platform:

  1. Something that outputs to the terminal.
  2. Something that receives and maps keyboard input.
  3. Something that receives and maps mouse input.

On Mac/Linux, leveraging some API that abstracts away low-level platform differences will be useful for 2 and 3. It may be curses/notcurses can be useful there. But given how these OS's have converged over time, I think we can use the bare minimum.

Yeah. That's it in a nutshell.

My approach for the purposes of the current work I'm doing, however, is not currently planned to be as drastic as an outright replacement, just yet. That is definitely a great goal, though.

Not putting specifics here, though, since some wires are getting a little crossed because the work I'm doing right now is related to several existing issues.

I'm going to try and wrap some of that up so what fixes/changes have been made can be merged and then I can hopefully triage where I focus my next effort (or at least the scope of whatever that may be) a little better.

dodexahedron commented 6 months ago

(Side note: That's another good place for a project, to organize all related work, since it's not a small endeavor.)