Skip to main content

FilePicker

Struct FilePicker 

Source
pub struct FilePicker { /* private fields */ }
Expand description

A file picker field for selecting files and directories.

The FilePicker field allows users to browse the filesystem and select files or directories. It can be configured to filter by file type, show/hide hidden files, and control whether files and/or directories can be selected.

§Example

use huh::FilePicker;

let picker = FilePicker::new()
    .key("config_file")
    .title("Select Configuration File")
    .description("Choose a .toml or .json file")
    .allowed_types(vec![".toml".to_string(), ".json".to_string()])
    .current_directory(".");

Implementations§

Source§

impl FilePicker

Source

pub fn new() -> Self

Creates a new file picker field.

Source

pub fn key(self, key: impl Into<String>) -> Self

Sets the field key.

Source

pub fn title(self, title: impl Into<String>) -> Self

Sets the title.

Source

pub fn description(self, description: impl Into<String>) -> Self

Sets the description.

Source

pub fn current_directory(self, dir: impl Into<String>) -> Self

Sets the starting directory.

Source

pub fn allowed_types(self, types: Vec<String>) -> Self

Sets the allowed file types (extensions).

Source

pub fn show_hidden(self, show: bool) -> Self

Sets whether to show hidden files.

Source

pub fn show_size(self, show: bool) -> Self

Sets whether to show file sizes.

Source

pub fn show_permissions(self, show: bool) -> Self

Sets whether to show file permissions.

Source

pub fn file_allowed(self, allowed: bool) -> Self

Sets whether files can be selected.

Source

pub fn dir_allowed(self, allowed: bool) -> Self

Sets whether directories can be selected.

Source

pub fn validate(self, validate: fn(&str) -> Option<String>) -> Self

Sets the validation function.

Source

pub fn height_entries(self, height: usize) -> Self

Sets the visible height (number of entries shown).

Source

pub fn get_selected_path(&self) -> Option<&str>

Gets the currently selected path.

Source

pub fn id(&self) -> usize

Returns the field ID.

Trait Implementations§

Source§

impl Default for FilePicker

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Field for FilePicker

Source§

fn get_key(&self) -> &str

Returns the field’s key.
Source§

fn get_value(&self) -> Box<dyn Any>

Returns the field’s value.
Source§

fn error(&self) -> Option<&str>

Returns the current validation error, if any.
Source§

fn init(&mut self) -> Option<Cmd>

Initializes the field.
Source§

fn update(&mut self, msg: &Message) -> Option<Cmd>

Updates the field with a message.
Source§

fn view(&self) -> String

Renders the field.
Source§

fn focus(&mut self) -> Option<Cmd>

Focuses the field.
Source§

fn blur(&mut self) -> Option<Cmd>

Blurs the field.
Source§

fn key_binds(&self) -> Vec<Binding>

Returns the help keybindings.
Source§

fn with_theme(&mut self, theme: &Theme)

Sets the theme.
Source§

fn with_keymap(&mut self, keymap: &KeyMap)

Sets the keymap.
Source§

fn with_width(&mut self, width: usize)

Sets the width.
Source§

fn with_height(&mut self, height: usize)

Sets the height.
Source§

fn with_position(&mut self, position: FieldPosition)

Sets the field position.
Source§

fn skip(&self) -> bool

Returns whether this field should be skipped.
Source§

fn zoom(&self) -> bool

Returns whether this field should zoom (take full height).

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more