pub struct Model {Show 15 fields
pub path: String,
pub current_directory: PathBuf,
pub allowed_types: Vec<String>,
pub keymap: FilepickerKeyMap,
pub show_permissions: bool,
pub show_size: bool,
pub show_hidden: bool,
pub dir_allowed: bool,
pub file_allowed: bool,
pub file_selected: String,
pub height: usize,
pub auto_height: bool,
pub cursor: String,
pub error: Option<String>,
pub styles: Styles,
/* private fields */
}Expand description
The main file picker model containing all state and configuration.
This struct represents the complete state of the file picker, including the current directory, file list, selection state, and styling configuration. It implements the BubbleTeaModel trait for integration with bubbletea-rs applications.
§Examples
use bubbletea_widgets::filepicker::Model;
use bubbletea_rs::Model as BubbleTeaModel;
// Create a new file picker
let mut picker = Model::new();
// Or use the BubbleTeaModel::init() method
let (picker, cmd) = Model::init();§State Management
The model maintains:
- Current directory being browsed
- List of files and directories in the current location
- Currently selected item index
- Last selected file path (if any)
- Styling and key binding configuration
- Navigation history and viewport state
Fields§
§path: StringPath is the path which the user has selected with the file picker.
current_directory: PathBufThe directory currently being browsed. This path is updated when navigating into subdirectories or back to parent directories.
allowed_types: Vec<String>AllowedTypes specifies which file types the user may select. If empty the user may select any file.
keymap: FilepickerKeyMapKey bindings configuration for navigation and interaction. Can be customized to change keyboard shortcuts.
show_permissions: boolWhether to show file permissions in the display.
show_size: boolWhether to show file sizes in the display.
Whether to show hidden files (dotfiles on Unix, Windows FILE_ATTRIBUTE_HIDDEN + dotfiles).
dir_allowed: boolWhether directories can be selected.
file_allowed: boolWhether files can be selected.
file_selected: StringThe name of the most recently selected file.
height: usizeHeight of the picker.
auto_height: boolWhether height should automatically adjust to terminal size.
cursor: StringThe cursor string to display (e.g., “> “).
error: Option<String>Error message to display when directory operations fail.
styles: StylesVisual styling configuration for different UI elements. Can be customized to change colors and appearance.
Implementations§
Source§impl Model
impl Model
Sourcepub fn new() -> Self
pub fn new() -> Self
Creates a new file picker model with default settings.
The file picker starts in the current working directory (“.”) and uses default key bindings and styles. The file list is initially empty and will be populated when the model is initialized or when directories are navigated.
§Returns
A new Model instance with default settings matching the Go implementation.
§Examples
use bubbletea_widgets::filepicker::Model;
let mut picker = Model::new();
assert_eq!(picker.current_directory.as_os_str(), ".");
assert!(picker.path.is_empty());Sourcepub fn set_height(&mut self, height: usize)
pub fn set_height(&mut self, height: usize)
Sets the height of the filepicker viewport.
This controls how many file entries are visible at once. The viewport automatically adjusts to show the selected item within the visible range.
§Arguments
height- The number of lines to show in the file list
§Examples
use bubbletea_widgets::filepicker::Model;
let mut picker = Model::new();
picker.set_height(10); // Show 10 files at a timeSourcepub fn did_select_file(&self, msg: &Msg) -> (bool, String)
pub fn did_select_file(&self, msg: &Msg) -> (bool, String)
Returns whether a user has selected a file with the given message.
This function checks if the message represents a file selection action
and if the selected file is allowed based on the current configuration.
It only returns true for files that can actually be selected.
§Arguments
msg- The message to check for file selection
§Returns
A tuple containing:
bool: Whether a valid file was selectedString: The path of the selected file (empty if no selection)
§Examples
use bubbletea_widgets::filepicker::Model;
use bubbletea_rs::Msg;
let picker = Model::new();
// In your application's update loop:
// let (selected, path) = picker.did_select_file(&msg);
// if selected {
// println!("User selected: {}", path);
// }Sourcepub fn did_select_disabled_file(&self, msg: &Msg) -> (bool, String)
pub fn did_select_disabled_file(&self, msg: &Msg) -> (bool, String)
Returns whether a user tried to select a disabled file with the given message.
This function is useful for providing feedback when users attempt to select
files that are not allowed based on the current allowed_types configuration.
Use this to show warning messages or provide helpful feedback.
§Arguments
msg- The message to check for disabled file selection attempts
§Returns
A tuple containing:
bool: Whether a disabled file selection was attemptedString: The path of the disabled file (empty if no disabled selection)
§Examples
use bubbletea_widgets::filepicker::Model;
use bubbletea_rs::Msg;
let mut picker = Model::new();
picker.allowed_types = vec![".txt".to_string()];
// In your application's update loop:
// let (tried_disabled, path) = picker.did_select_disabled_file(&msg);
// if tried_disabled {
// eprintln!("Cannot select {}: file type not allowed", path);
// }Sourcepub fn read_dir(&mut self)
pub fn read_dir(&mut self)
Reads the current directory and populates the files list. Clears any existing files and error state before reading.
Sourcepub fn read_dir_cmd(&self) -> Cmd
pub fn read_dir_cmd(&self) -> Cmd
Creates a command to read the current directory.
This method allows external code to trigger a directory read without
directly calling the private read_dir method. It’s useful for
initializing the filepicker with a specific directory.
§Returns
A command that will trigger a ReadDirMsg when executed
§Examples
use bubbletea_widgets::filepicker::Model;
let mut picker = Model::new();
picker.current_directory = std::path::PathBuf::from("/home/user");
let cmd = picker.read_dir_cmd();
// This command can be returned from init() or update()Trait Implementations§
Auto Trait Implementations§
impl Freeze for Model
impl !RefUnwindSafe for Model
impl Send for Model
impl Sync for Model
impl Unpin for Model
impl !UnwindSafe for Model
Blanket Implementations§
Source§impl<S, D, Swp, Dwp, T> AdaptInto<D, Swp, Dwp, T> for Swhere
T: Real + Zero + Arithmetics + Clone,
Swp: WhitePoint<T>,
Dwp: WhitePoint<T>,
D: AdaptFrom<S, Swp, Dwp, T>,
impl<S, D, Swp, Dwp, T> AdaptInto<D, Swp, Dwp, T> for Swhere
T: Real + Zero + Arithmetics + Clone,
Swp: WhitePoint<T>,
Dwp: WhitePoint<T>,
D: AdaptFrom<S, Swp, Dwp, T>,
Source§fn adapt_into_using<M>(self, method: M) -> Dwhere
M: TransformMatrix<T>,
fn adapt_into_using<M>(self, method: M) -> Dwhere
M: TransformMatrix<T>,
Source§fn adapt_into(self) -> D
fn adapt_into(self) -> D
Source§impl<T, C> ArraysFrom<C> for Twhere
C: IntoArrays<T>,
impl<T, C> ArraysFrom<C> for Twhere
C: IntoArrays<T>,
Source§fn arrays_from(colors: C) -> T
fn arrays_from(colors: C) -> T
Source§impl<T, C> ArraysInto<C> for Twhere
C: FromArrays<T>,
impl<T, C> ArraysInto<C> for Twhere
C: FromArrays<T>,
Source§fn arrays_into(self) -> C
fn arrays_into(self) -> C
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<WpParam, T, U> Cam16IntoUnclamped<WpParam, T> for Uwhere
T: FromCam16Unclamped<WpParam, U>,
impl<WpParam, T, U> Cam16IntoUnclamped<WpParam, T> for Uwhere
T: FromCam16Unclamped<WpParam, U>,
Source§type Scalar = <T as FromCam16Unclamped<WpParam, U>>::Scalar
type Scalar = <T as FromCam16Unclamped<WpParam, U>>::Scalar
parameters when converting.Source§fn cam16_into_unclamped(
self,
parameters: BakedParameters<WpParam, <U as Cam16IntoUnclamped<WpParam, T>>::Scalar>,
) -> T
fn cam16_into_unclamped( self, parameters: BakedParameters<WpParam, <U as Cam16IntoUnclamped<WpParam, T>>::Scalar>, ) -> T
self into C, using the provided parameters.Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T, C> ComponentsFrom<C> for Twhere
C: IntoComponents<T>,
impl<T, C> ComponentsFrom<C> for Twhere
C: IntoComponents<T>,
Source§fn components_from(colors: C) -> T
fn components_from(colors: C) -> T
Source§impl<T> FromAngle<T> for T
impl<T> FromAngle<T> for T
Source§fn from_angle(angle: T) -> T
fn from_angle(angle: T) -> T
angle.Source§impl<T, U> FromStimulus<U> for Twhere
U: IntoStimulus<T>,
impl<T, U> FromStimulus<U> for Twhere
U: IntoStimulus<T>,
Source§fn from_stimulus(other: U) -> T
fn from_stimulus(other: U) -> T
other into Self, while performing the appropriate scaling,
rounding and clamping.Source§impl<T, U> IntoAngle<U> for Twhere
U: FromAngle<T>,
impl<T, U> IntoAngle<U> for Twhere
U: FromAngle<T>,
Source§fn into_angle(self) -> U
fn into_angle(self) -> U
T.Source§impl<WpParam, T, U> IntoCam16Unclamped<WpParam, T> for Uwhere
T: Cam16FromUnclamped<WpParam, U>,
impl<WpParam, T, U> IntoCam16Unclamped<WpParam, T> for Uwhere
T: Cam16FromUnclamped<WpParam, U>,
Source§type Scalar = <T as Cam16FromUnclamped<WpParam, U>>::Scalar
type Scalar = <T as Cam16FromUnclamped<WpParam, U>>::Scalar
parameters when converting.Source§fn into_cam16_unclamped(
self,
parameters: BakedParameters<WpParam, <U as IntoCam16Unclamped<WpParam, T>>::Scalar>,
) -> T
fn into_cam16_unclamped( self, parameters: BakedParameters<WpParam, <U as IntoCam16Unclamped<WpParam, T>>::Scalar>, ) -> T
self into C, using the provided parameters.Source§impl<T, U> IntoColor<U> for Twhere
U: FromColor<T>,
impl<T, U> IntoColor<U> for Twhere
U: FromColor<T>,
Source§fn into_color(self) -> U
fn into_color(self) -> U
Source§impl<T, U> IntoColorUnclamped<U> for Twhere
U: FromColorUnclamped<T>,
impl<T, U> IntoColorUnclamped<U> for Twhere
U: FromColorUnclamped<T>,
Source§fn into_color_unclamped(self) -> U
fn into_color_unclamped(self) -> U
Source§impl<T> IntoStimulus<T> for T
impl<T> IntoStimulus<T> for T
Source§fn into_stimulus(self) -> T
fn into_stimulus(self) -> T
self into T, while performing the appropriate scaling,
rounding and clamping.Source§impl<T, C> TryComponentsInto<C> for Twhere
C: TryFromComponents<T>,
impl<T, C> TryComponentsInto<C> for Twhere
C: TryFromComponents<T>,
Source§type Error = <C as TryFromComponents<T>>::Error
type Error = <C as TryFromComponents<T>>::Error
try_into_colors fails to cast.Source§fn try_components_into(self) -> Result<C, <T as TryComponentsInto<C>>::Error>
fn try_components_into(self) -> Result<C, <T as TryComponentsInto<C>>::Error>
Source§impl<T, U> TryIntoColor<U> for Twhere
U: TryFromColor<T>,
impl<T, U> TryIntoColor<U> for Twhere
U: TryFromColor<T>,
Source§fn try_into_color(self) -> Result<U, OutOfBounds<U>>
fn try_into_color(self) -> Result<U, OutOfBounds<U>>
OutOfBounds error is returned which contains
the unclamped color. Read more