ChrisBuilds / terminaltexteffects

TerminalTextEffects (TTE) is a terminal visual effects engine, application, and Python library.
https://chrisbuilds.github.io/terminaltexteffects/
MIT License
2.6k stars 43 forks source link

[enhancement] Using typed objects as arguments instead of argparse namespace object #4

Closed Navid-Means-Promise closed 4 months ago

Navid-Means-Promise commented 4 months ago

Hi. thank you for sharing this artistic project. I spent sometimes to enhance the structure of the project so as the title says instead of using an untyped generic output of "argparse" we can use a nicely typed and decorated with metadata required. I wrote some base classes and decorators so required "subparser"s and their args will be added automatically. Also using this approach can help any developer to easily and fastly use "terminaltexteffects" as a library in their projects.

It will be appretiated if you take a look at this rain effect module that i rewrote using this new approach. So if you agree with this I will rewrite all the modules and send a pull request.

https://github.com/Navid-Means-Promise/terminal-text-effects/blob/main/terminaltexteffects/effects/effect_rain.py

thank you again.

ChrisBuilds commented 4 months ago

Hey @Navid-Means-Promise , thanks for checking out the project. There are vague plans to refactor large parts of TTE to function as an importable library and enable effects within other Python projects. I would handle that refactor so as to maintain full awareness of the project's codebase, as I suspect it would require significant changes. In the event that refactor is undertaken, typed function arguments would become more important. Currently, each effect is self contained resulting in the effect developer knowing with confidence (aided by light validation handled through the utils.argtypes module) the types of the arguments. Implementing type information for parsed args would likely be offloaded to something like Typed Argument Parser to avoid the added complexity.

Your implementation, utilizing inspection, dataclasses, and decorators, while reasonably cleaning up the argument specification in each effect, adds a lot of complexity that I'm finding difficult to follow, elsewhere. This is more likely my problem than yours. I appreciate your efforts and am open to contributions in other areas such as optimization, bug fixes, new effects, new engine features, etc.

Thanks again for your interest.

Navid-Means-Promise commented 4 months ago
ChrisBuilds commented 4 months ago

I had some more time to look over your implementation of typed args. I'm assuming what you've shown was a proof of concept, given the state of the code (comments, no linting, not passing type analysis, etc.) The code should make it past ruff/mypy without any issues. If you satisfy all that, I'll pull it. Don't worry about modifying any other effects. The effect args are undergoing changes. I'll refactor them to use ArgsDataClass after I get your PR. Thanks.

As far as preserving original color. I could detect color sequences and store them to be applied at the end, assuming there is no other color data applied. Every effect has the option to colorize the final output to maintain some consistency throughout the effect. It would be pretty easy to use original colors instead, either throughout or only at the end. I'll add it to the list of things to do. It will be more involved than it seems, but that's a discussion for another issue thread.