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

Add a Buffer::fill method #1146

Open joshka opened 1 month ago

joshka commented 1 month ago

Problem

I was playing with some ideas and CoPilot suggested that I call the non-existent Buffer::fill(area, ".", style) method This seems like it's probably a useful simple building block method to have that avoids putting that loop in the caller. I'd see this used internally for block borders, barchart, chart, scrollbars, etc. and any custom widgets that need to fill an area.

Solution

Add a fill method that accepts an area, a symbol, and a style. A naive approach runs a loop over the area and writes the symbols appropriately (taking account of unicode width). It might be possible to special case single width characters by using slice::fill

It might also be worth considering whether this allocates new cells and fills the buffer vs calling the set_symbol / set_style methods (in the same way that https://github.com/ratatui-org/ratatui/pull/1143#pullrequestreview-2079128188 needs to take this into account).

Additional context

This is an idea for discussion rather than something ready to implement.