pub struct FileBrowser {
pub current_path: PathBuf,
pub entries: Vec<PathBuf>,
pub state: ListState,
/* private fields */
}Expand description
A TUI component for browsing the file system.
Allows navigation through directories, selection of files, and displaying directory contents.
Fields§
§current_path: PathBufThe current directory being displayed.
entries: Vec<PathBuf>A list of files and directories in the current_path.
state: ListStateThe state of the List widget used to render the entries.
Implementations§
Source§impl FileBrowser
impl FileBrowser
Sourcepub fn new() -> Self
pub fn new() -> Self
Creates a new FileBrowser instance, initialized to the current working directory.
It automatically lists the entries in the initial directory.
Sourcepub fn list_entries(&mut self)
pub fn list_entries(&mut self)
Lists the contents of the current_path, populating self.entries.
Directories are listed before files, and both are sorted alphabetically. A “..” entry is added if navigation upwards is possible.
Navigates the browser one level up in the directory hierarchy.
§Returns
FileBrowserEvent indicating if navigation occurred or not.
Sourcepub fn select_entry(&mut self) -> FileBrowserEvent
pub fn select_entry(&mut self) -> FileBrowserEvent
Handles the selection of the currently highlighted entry.
If a directory is selected (including “..”), it navigates into it.
If a file is selected, it returns the PathBuf of that file.
§Returns
FileBrowserEvent indicating the outcome of the selection.
Sourcepub fn selected_path(&self) -> Option<PathBuf>
pub fn selected_path(&self) -> Option<PathBuf>
Returns the PathBuf of the currently selected entry without performing any action.
§Returns
Some(PathBuf) of the selected entry, or None if no entry is selected.
Sourcepub fn handle_key(&mut self, key: KeyCode) -> FileBrowserEvent
pub fn handle_key(&mut self, key: KeyCode) -> FileBrowserEvent
pub fn get_status_message(&self) -> String
Auto Trait Implementations§
impl Freeze for FileBrowser
impl RefUnwindSafe for FileBrowser
impl Send for FileBrowser
impl Sync for FileBrowser
impl Unpin for FileBrowser
impl UnwindSafe for FileBrowser
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more