enricozb / intuitive

A library for building declarative text-based user interfaces
213 stars 3 forks source link

Fix integer underflow bug in section.rs #2

Open philippeitis opened 2 years ago

philippeitis commented 2 years ago

This would cause watch.rs to crash when build using debug mode. Considering that integer underflow is a problem in release mode, I used saturating_sub / saturating_add to avoid this problem, and included a link to the relevant source code.

On an another note, I myself am also building a TUI for my own application, and have been flowing moving towards this exact style. I'd like to contribute a few of the widgets I've built - infinitely scrolling lists, text-widgets with selection, copy/paste/cut, backwards / forwards deletion. I've also implemented additional scroll features based on keyboard input.

I'd also be interested in a focus-grabbing system for widgets (so that all input goes by default to a text entry widget, for example, and commands "bubble" up the stack) - I've implemented a basic version of this, but a more powerful version would allow assigning a deeply nested widget focus by default.

All of this can be found here: https://github.com/philippeitis/bookworm/tree/master/bookworm-tui/src/ui/widgets

enricozb commented 2 years ago

Thanks for the PR! This looks safe to me, I'll probably remove the comment though. Please feel free to make PRs for any widgets you'd like to add! If they're general enough I'll merge them.

I'll take a look at your UI as well, very interested in how you've implemented copy/paste. I have some ideas on how to do focusing, but haven't added any widgets yet. I'm imagining something like Modal, and it would have a function use_focus similar to use_modal, that would return something that could change focus.