Skip to content
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

Post-V2: Rewrite TextFormatter #3617

Open
tig opened this issue Jul 17, 2024 · 1 comment
Open

Post-V2: Rewrite TextFormatter #3617

tig opened this issue Jul 17, 2024 · 1 comment
Labels
design Issues regarding Terminal.Gui design (bugs, guidelines, debates, etc...)

Comments

@tig
Copy link
Collaborator

tig commented Jul 17, 2024

We've discussed all of the cruft in the current TextFormatter design and implementation many times.

This Issue is to collect all of the issues and track a re-design an re-implementation.

This Issue is marked as POST-v2 as the current implementation actually works fine for the most part and we have much bigger fish to fry. but post V2 we should tackle this.

Problems with Current TextFormatter

  • Format and Draw are decoupled - Draw does a significant amount of "formatting". The impact of this is getting the size of the formatted text (e.g. FormatAndGetSize() is error prone. This is critical for Dim.Auto(Text)... and means the current implementation of that has a bunch of hacks.

  • TextFormatter.AutoSize is completely useless (and no longer used by the core View class). This is because it couples width and height (and because of the aformentioned Draw/Format decoupling).

  • Performance - The current implementation is horribly inefficient and the design is such that Format gets called many-many times during operations like LayoutSubviews/SetRelativeLayout.

  • We now have a simple, robust, alignment engine: Aligner. The current implementation has a very complex, spaghetti-code, alignment/justification implementation - It is now well tested, but the unit tests for it are actually unit tests of higher-level functions, like View.Draw.

  • Poor extensibility and no replicability - As @tznind noted in Gradients - From Terminal Text Effects #3586, adding gradient formatting will be a ton of work given the nature of the current code. This is an example of poor extensibility. For replicability, a possible path for addressing Support TUI apps running in the browser - aka Add HTML5 rendering support #1642 would be to have multiple TextFormatter implementations. E.g. one for "Attributed Text" and one for "HTML".

  • TextFormatter.WordWrap is fragile and confusing.

  • (Please feel to add more!)

Great things about the current TextFormatter

  • It is actually a magnificent example of a poor-design applied to a very complex problem where ingenuity and hard-core-brute-force-work has led to something that actually, shockingly, works very well for most use-cases. The TextFormatterDemo Scenario illustrates just how powerful the current engine is.
    • Horizontal & vertical text alignment, including Fill/Justification.
    • Horizontal & vertical text direction.
    • WordWrap.
    • Wide char support.
  • Code coverage with unit tests is actually pretty good. Most of the testing is via higher-level constructs (e.g. View, Label, etc...), but it's not bad.

Issues & PRs with valid context

@tig tig added the design Issues regarding Terminal.Gui design (bugs, guidelines, debates, etc...) label Jul 17, 2024
@dodexahedron
Copy link
Collaborator

To be fair to all who have battled that beast, Unicode isn't easy.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
design Issues regarding Terminal.Gui design (bugs, guidelines, debates, etc...)
Projects
Status: No status
Development

No branches or pull requests

2 participants