ratatui-org / ratatui

Rust library that's all about cooking up terminal user interfaces (TUIs) 👨‍🍳🐀
https://ratatui.rs
MIT License
8.86k stars 269 forks source link

docs(examples): add widget implementation example #1147

Open joshka opened 1 month ago

joshka commented 1 month ago

This new example documents the various ways to implement widgets in Ratatui. It demonstrates how to implement the Widget trait on a type, a reference, and a mutable reference. It also shows how to use the WidgetRef trait to render boxed widgets.

joshka commented 1 month ago

I've heard and understood your concern about color_eyre.

The examples are intentionally structured in a way that helps address common scenarios that people run into in real world building Ratatui apps. I've seen evidence (from reading a significant amount of user application code on GitHub and discord) that users often grab code from the example that most matches their particular need rather than looking at all the relevant examples. Having the necessary error handling in every example helps ensure that regardless of where they grab their code from, they're getting a reasonable basis for building their app.

This is not something I'm willing to be convinced otherwise on as the benefit to the Ratatui ecosystem is much larger than the added complexity. The only thing that would make me rethink this is if there was code that was part of Ratatui that basically did the same things. Regardless, that concern is orthogonal, and until we have something that works for that, the right approach is to harmonize the various examples with boilerplate that's easily replaced by calls to that eventual support module.

kdheepak commented 1 month ago

I agree about using color_eyre (or anyhow) for examples, it's something I suspect a lot of users appreciate (I know I do) and easy to remove for those that know how to do so.