charmbracelet / charmbracelet/bubbles

get highlighted DirEntry in filepicker

Open
#580 0 comments 0 reactions 0 assignees View on GitHub
enhancement
Dominant language
Go
Stars
8.9k
Forks
457
Avg merge
1d 18h
Merged PRs (30d)
5

Description

**Is your feature request related to a problem? Please describe.**
I'd like to get the DirEntry that is currently highlighted by the user (ie: on which items the cursor currently is).
The name would not be enough as I want to do something if it's a directory and another thing if it's a file

**Describe the solution you'd like**
A method on the filepicker bubble that would return the current dirEntry.
Smething probaby close to this :

```go
func (m Model) GetCurrentFile() fs.DirEntry {
if m.selected < len(m.files) {
return m.files[m.selected]
}
return nil
}
```

**Describe alternatives you've considered**
create my own bubble by copy/pasting the code of the filepicker.

**Additional context**
the hardest part might be on how to use this kind of method because this kind of call would be done in an `Update(msg tea.Msg)` method, when the cursor might change from user input. So the function above could take a modifier as an argument ie :
```go
func (m Model) GetCurrentFile(modifier int) fs.DirEntry {
newCursor := m.selected + modifier
if newCursor < len(m.files) {
return m.files[newCursor]
}
return nil
}
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.