ChrisTitusTech / linutil

Chris Titus Tech's Linux Toolbox - Linutil is a distro-agnostic toolbox designed to simplify everyday Linux tasks.
https://christitus.com
MIT License
1.75k stars 158 forks source link

refactor: Move search and filter logic to a separate module #177

Closed lj3954 closed 1 week ago

lj3954 commented 3 weeks ago

Pull Request

Title

Move filter and search logic to another module

Type of Change

Description

Move all logic related to search and filtering to a separate module, which AppState calls upon. Replace 'search.rs' with 'filter.rs' to better enumerate the logic contained within. Additionally, add the cursor to the search bar (#176), with fixes for panics with multibyte unicode characters & incorrect cursor positioning with characters taking up a non-singular amount of columns.

Testing

Search functions correctly, searchbar and cursor are rendered correctly.

Impact

Improves code structure & readability

Checklist

afonsofrancof commented 3 weeks ago

Looks good. I just have a question. Why did you choose the names filter.rs and FilterContent? I know search is used to filter items from the commands list, but it seems weird to call the whole search bar a filter, and call methods such as filter.draw(), which are actually drawing the search bar.

lj3954 commented 3 weeks ago

The logic for filtering entries, regardless of whether or not a search query is present, was moved to the file. It encapsulates significantly more than just search. Perhaps the draw() function should be renamed to draw_searchbar() or something of the like.