pub struct Model {
pub current_directory: PathBuf,
pub keymap: FilepickerKeyMap,
pub styles: Styles,
pub path: Option<PathBuf>,
/* 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
Fields§
§current_directory: PathBufThe directory currently being browsed. This path is updated when navigating into subdirectories or back to parent directories.
keymap: FilepickerKeyMapKey bindings configuration for navigation and interaction. Can be customized to change keyboard shortcuts.
styles: StylesVisual styling configuration for different UI elements. Can be customized to change colors and appearance.
path: Option<PathBuf>The path of the most recently selected file, if any.
This is set when a user selects a file (not a directory) and can be checked
using the did_select_file() method.
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:
- Current directory set to “.”
- Default key bindings
- Default styling
- Empty file list (call
read_dir()or useBubbleTeaModel::init()to populate) - No file selected
§Examples
use bubbletea_widgets::filepicker::Model;
let mut picker = Model::new();
assert_eq!(picker.current_directory.as_os_str(), ".");
assert!(picker.path.is_none());Sourcepub fn did_select_file(&self, msg: &Msg) -> (bool, Option<PathBuf>)
pub fn did_select_file(&self, msg: &Msg) -> (bool, Option<PathBuf>)
Checks if a file was selected in response to the given message.
This method examines the provided message to determine if it represents a file selection event. It returns both a boolean indicating whether a file was selected and the path of the selected file (if any).
§Arguments
msg- The message to check for file selection events
§Returns
A tuple containing:
bool:trueif a file was selected,falseotherwiseOption<PathBuf>: The path of the selected file, orNoneif no file was selected
§Examples
use bubbletea_widgets::filepicker::Model;
use bubbletea_rs::{KeyMsg, Msg};
use crossterm::event::{KeyCode, KeyModifiers};
let mut picker = Model::new();
// Simulate an Enter key press
let key_msg = KeyMsg {
key: KeyCode::Enter,
modifiers: KeyModifiers::NONE,
};
let msg: Msg = Box::new(key_msg);
let (selected, path) = picker.did_select_file(&msg);
if selected {
println!("File selected: {:?}", path);
}§Note
This method only returns true if:
- The message is a key press of the Enter key
- A file path is currently stored in
self.path(i.e., a file was previously highlighted)
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