Terminal.Gui icon indicating copy to clipboard operation
Terminal.Gui copied to clipboard

Refactor ConsoleDrivers to remove duplicate code

Open tig opened this issue 5 years ago • 5 comments

There is a LOT of common code across the three (now four with Fake) Drivers.

I was just thinking about how to fix bugs related to non-printable chars causing rendering issues on some terminals. For example, in Windows Terminal and Fluent if AddRune gets called with \n it does this: image

The fix is to modify AddRune to look for non-printable chars like this, that may cause the underlying console to take action and replace them with the right glyph. E.g:

image

However, it's stupid to do this 4 times. Instead the base should implement the least-common-denominator functionality.

Right?

tig avatar Jun 10 '20 18:06 tig

Right. @migueldeicaza want to do all this stuff in the View, so drivers doesn't have to be magic. The View must send the right format to the AddStr and AddRune.

BDisp avatar Jun 10 '20 19:06 BDisp

What if we did this:

  • Gave View a Text property. Default Redraw would draw Text using TextAlignment
  • Refactored Label such that it was nothing more than a renaming of View
  • Refactored Button, etc... to leverage all the text handling in View.
  • Window would need to leverage this too.

???

tig avatar Jun 10 '20 20:06 tig

I agree. We also have to redirect the Driver property to the View itself in order to deviate all the call to the Driver.AddRune and Driver.AddStr to the View and avoiding the views derived from View do call Application.Driver. I think that this have to change to another way: public static ConsoleDriver Driver { get { return Application.Driver; } } to like: public static ConsoleDriver Driver { get { return View.Driver; } } But I'm still studing. More thoughts???

BDisp avatar Jun 10 '20 20:06 BDisp

I think this makes sense.

The abstract capability is more of an indicator that some holes need to be plugged by concrete implementations, but we could move common code here.

migueldeicaza avatar Jun 15 '20 16:06 migueldeicaza

I think is already fixed with your creating of the public static Rune MakePrintable (Rune c) method and the TextFormatter class. So, besides the ConsoleDriver can and must have common code, it must be abstract.

BDisp avatar Aug 03 '21 18:08 BDisp

Woo-hoo! Finally!

It ain't perfect, but this radically simplifies and improves the ability to prove quality.

tig avatar Aug 09 '23 20:08 tig