Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Two different highlight styles/introduce cursor #42

Open
dvdsk opened this issue Sep 6, 2024 · 3 comments
Open

Two different highlight styles/introduce cursor #42

dvdsk opened this issue Sep 6, 2024 · 3 comments

Comments

@dvdsk
Copy link

dvdsk commented Sep 6, 2024

Hi there, for my use case (home automation tui) I want to be able to select two or more items in the tree. I would like to have a difference between the current position in the tree and all the other selected items.

The current position is a highlighted item. By pressing or the highlighted item changes, its a sort of cursor. Using another key I can then select or unselect the currently highlighted item.

I can achieve this by rebuilding the try and styling/changing the text of different entries. That gets rather ugly as I then have to manually keep track of the selections.

I see two possible api's:

  • Add a highlight style/symbol to TreeState::select.
  • Introduce the concept of a cursor which is moved by TreeState::key_up/TreeState::key_down then add TreeState::select_current/TreeState::unselect_current to add/remove the item that is currently the cursor to the selected items.

The first API gives more freedom to users, it could be used to do other things have n-different selection's for example. This comes at the cost of requiring users to do the bookkeeping of which selected item is the cursor vs a 'normal' selected item. The second makes my usecase trivial to implement but its the only additional usecase supported.

The best, and most work, might be to implement both the concept of differently styled selected items and a cursor.

Let me know what you think.

@dvdsk
Copy link
Author

dvdsk commented Sep 6, 2024

Oh I should add that since I need this in my (hobby) project I'll have to implement it anyway. So I could do the work if this request is accepted and we settle on an API.

@EdJoPaTo
Copy link
Owner

EdJoPaTo commented Sep 6, 2024

Just as a heads-up: I can take a look on this in a few days as I don’t have that much time this weekend.

Also, TUIs are currently low on my priority until EdJoPaTo/mqttui#172 gets resolved. Until ratatui fixes the bug I am stuck at ratatui ≤ 0.26.

@dvdsk
Copy link
Author

dvdsk commented Sep 7, 2024

Just as a heads-up: I can take a look on this in a few days as I don’t have that much time this weekend.

Also, TUIs are currently low on my priority until EdJoPaTo/mqttui#172 gets resolved. Until ratatui fixes the bug I am stuck at ratatui ≤ 0.26.

No worries, its on my nice to have eventually list so its totally fine if it takes a few week or months 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants