pub struct FileExplorer {Show 17 fields
pub current_dir: PathBuf,
pub theme_name: String,
pub editor_name: String,
pub entries: Vec<FsEntry>,
pub cursor: usize,
pub extension_filter: Vec<String>,
pub show_hidden: bool,
pub sort_mode: SortMode,
pub search_query: String,
pub search_active: bool,
pub marked: HashSet<PathBuf>,
pub mkdir_active: bool,
pub mkdir_input: String,
pub touch_active: bool,
pub touch_input: String,
pub rename_active: bool,
pub rename_input: String,
/* private fields */
}Expand description
State for the file-explorer widget.
Keep one instance in your application state and pass a mutable reference
to [crate::render] and FileExplorer::handle_key on every frame /
key event.
§Example
use tui_file_explorer::{FileExplorer, ExplorerOutcome};
use crossterm::event::{KeyCode, KeyEvent, KeyModifiers};
let mut explorer = FileExplorer::new(
std::env::current_dir().unwrap(),
vec!["iso".into(), "img".into()],
);
match explorer.handle_key(key) {
ExplorerOutcome::Selected(path) => println!("chosen: {}", path.display()),
ExplorerOutcome::Dismissed => println!("closed"),
_ => {}
}Fields§
§current_dir: PathBufThe directory currently being browsed.
theme_name: StringThe name of the currently active theme (used in the header display).
editor_name: StringThe label of the currently configured editor (used in the header display).
entries: Vec<FsEntry>Sorted, search-filtered list of visible entries (dirs first, then files).
cursor: usizeIndex of the highlighted entry.
extension_filter: Vec<String>Only files whose extension is in this list are selectable.
Directories are always shown and always navigable.
An empty Vec means all files are selectable.
Whether to show dotfiles / hidden entries.
sort_mode: SortModeCurrent sort order for directory entries.
search_query: StringCurrent incremental-search query (empty = no search active).
search_active: boolWhether the explorer is currently capturing keystrokes for search input.
marked: HashSet<PathBuf>Paths that have been space-marked for a multi-item operation.
mkdir_active: boolWhether the explorer is currently capturing keystrokes for a new folder name.
mkdir_input: StringThe folder name being typed when mkdir_active is true.
touch_active: boolWhether the explorer is currently capturing keystrokes for a new file name.
touch_input: StringThe file name being typed when touch_active is true.
rename_active: boolWhether the explorer is currently capturing keystrokes for a rename operation.
rename_input: StringThe new name being typed when rename_active is true.
Implementations§
Source§impl FileExplorer
impl FileExplorer
Sourcepub fn new(initial_dir: PathBuf, extension_filter: Vec<String>) -> FileExplorer
pub fn new(initial_dir: PathBuf, extension_filter: Vec<String>) -> FileExplorer
Create a new explorer starting at initial_dir.
extension_filter is a list of lower-case extensions without the
leading dot (e.g. vec!["iso".into(), "img".into()]).
Pass an empty Vec to allow all files.
For more configuration options use FileExplorer::builder instead.
Sourcepub fn builder(initial_dir: PathBuf) -> FileExplorerBuilder
pub fn builder(initial_dir: PathBuf) -> FileExplorerBuilder
Return a FileExplorerBuilder for constructing an explorer with
fine-grained configuration.
§Example
use tui_file_explorer::{FileExplorer, SortMode};
let explorer = FileExplorer::builder(std::env::current_dir().unwrap())
.extension_filter(vec!["rs".into(), "toml".into()])
.show_hidden(true)
.sort_mode(SortMode::SizeDesc)
.build();Navigate to path, resetting cursor, scroll, and any active search.
Accepts anything that converts into a PathBuf — a PathBuf,
&Path, &str, or String all work.
use tui_file_explorer::FileExplorer;
let mut explorer = FileExplorer::new(std::env::current_dir().unwrap(), vec![]);
explorer.navigate_to("/tmp");
explorer.navigate_to(std::path::Path::new("/home"));Sourcepub fn marked_paths(&self) -> &HashSet<PathBuf>
pub fn marked_paths(&self) -> &HashSet<PathBuf>
Process a single keyboard event and return the ExplorerOutcome.
Call this from your application’s key-handling function and act on
ExplorerOutcome::Selected / ExplorerOutcome::Dismissed.
Return the set of currently marked paths (for multi-item operations).
Sourcepub fn toggle_mark(&mut self)
pub fn toggle_mark(&mut self)
Toggle the space-mark on the currently highlighted entry and move the cursor down by one.
Sourcepub fn clear_marks(&mut self)
pub fn clear_marks(&mut self)
Clear all space-marks (called after a multi-delete or on navigation).
pub fn handle_key(&mut self, key: KeyEvent) -> ExplorerOutcome
Sourcepub fn current_entry(&self) -> Option<&FsEntry>
pub fn current_entry(&self) -> Option<&FsEntry>
The currently highlighted FsEntry, or None if the list is empty.
Sourcepub fn is_mkdir_active(&self) -> bool
pub fn is_mkdir_active(&self) -> bool
Whether the explorer is in mkdir (new-folder input) mode.
Sourcepub fn mkdir_input(&self) -> &str
pub fn mkdir_input(&self) -> &str
The folder name being typed when mkdir mode is active.
Sourcepub fn is_touch_active(&self) -> bool
pub fn is_touch_active(&self) -> bool
Whether the explorer is in touch (new-file input) mode.
Sourcepub fn touch_input(&self) -> &str
pub fn touch_input(&self) -> &str
The file name being typed when touch mode is active.
Sourcepub fn is_rename_active(&self) -> bool
pub fn is_rename_active(&self) -> bool
Whether the explorer is in rename (entry-rename input) mode.
Sourcepub fn rename_input(&self) -> &str
pub fn rename_input(&self) -> &str
The new name being typed when rename mode is active.
Sourcepub fn is_at_root(&self) -> bool
pub fn is_at_root(&self) -> bool
Returns true when the explorer is at the filesystem root and cannot
ascend any further.
use tui_file_explorer::FileExplorer;
let mut explorer = FileExplorer::new(std::path::PathBuf::from("/"), vec![]);
assert!(explorer.is_at_root());Sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Returns true when the current directory contains no visible entries.
This reflects the filtered, visible set — hidden files are excluded
unless show_hidden is true, and an active search query narrows
the set further.
Sourcepub fn entry_count(&self) -> usize
pub fn entry_count(&self) -> usize
The number of visible entries in the current directory.
Equivalent to explorer.entries.len() but reads more naturally in
condition checks.
Sourcepub fn status(&self) -> &str
pub fn status(&self) -> &str
The current human-readable status message.
The status is set by the widget when an error occurs (e.g. attempting to select a file that does not match the extension filter) and is cleared on the next successful navigation. Returns an empty string when there is nothing to report.
Sourcepub fn sort_mode(&self) -> SortMode
pub fn sort_mode(&self) -> SortMode
The current sort mode.
use tui_file_explorer::{FileExplorer, SortMode};
let explorer = FileExplorer::new(std::path::PathBuf::from("/tmp"), vec![]);
assert_eq!(explorer.sort_mode(), SortMode::Name);Sourcepub fn search_query(&self) -> &str
pub fn search_query(&self) -> &str
The current incremental-search query string.
Returns an empty string when no search is active.
Sourcepub fn is_searching(&self) -> bool
pub fn is_searching(&self) -> bool
Returns true when the explorer is actively capturing keystrokes for
incremental search input.
Set whether hidden (dot-file) entries are visible and reload the directory listing immediately.
The user can also toggle this at runtime with the . key.
use tui_file_explorer::FileExplorer;
let mut explorer = FileExplorer::new(std::env::current_dir().unwrap(), vec![]);
explorer.set_show_hidden(true);
assert!(explorer.show_hidden);Sourcepub fn set_extension_filter<I, S>(&mut self, filter: I)
pub fn set_extension_filter<I, S>(&mut self, filter: I)
Replace the extension filter and reload the directory listing immediately.
Accepts any iterable of values that convert to String — plain
&str slices, String values, and arrays all work:
use tui_file_explorer::FileExplorer;
let mut explorer = FileExplorer::new(std::env::current_dir().unwrap(), vec![]);
// Array of &str — no .into() needed
explorer.set_extension_filter(["rs", "toml"]);
// Vec<String>
explorer.set_extension_filter(vec!["iso".to_string(), "img".to_string()]);
// Empty — allow all files
explorer.set_extension_filter([] as [&str; 0]);Sourcepub fn set_sort_mode(&mut self, mode: SortMode)
pub fn set_sort_mode(&mut self, mode: SortMode)
Change the sort mode and reload the directory listing immediately.
The user can also cycle through modes at runtime with the s key.
use tui_file_explorer::{FileExplorer, SortMode};
let mut explorer = FileExplorer::new(std::env::current_dir().unwrap(), vec![]);
explorer.set_sort_mode(SortMode::SizeDesc);
assert_eq!(explorer.sort_mode(), SortMode::SizeDesc);Trait Implementations§
Auto Trait Implementations§
impl Freeze for FileExplorer
impl RefUnwindSafe for FileExplorer
impl Send for FileExplorer
impl Sync for FileExplorer
impl Unpin for FileExplorer
impl UnsafeUnpin for FileExplorer
impl UnwindSafe for FileExplorer
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> 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