Module filepicker

Source
Expand description

File picker component for browsing and selecting files in terminal applications.

This module provides a fully-functional file picker that allows users to navigate the file system, browse directories, and select files using keyboard navigation. It integrates seamlessly with bubbletea-rs applications and supports customizable styling and key bindings.

§Features

  • Directory Navigation: Browse directories with vim-style key bindings
  • File Selection: Select files using Enter key
  • Cross-platform: Works on Windows, macOS, and Linux
  • Hidden File Handling: Cross-platform hidden file detection (Windows attributes + dotfiles on Unix)
  • Customizable Styling: Configurable colors and styles for different file types
  • Keyboard Navigation: Full keyboard support with configurable key bindings
  • Sorting: Directories are automatically sorted before files alphabetically

§Basic Usage

use bubbletea_widgets::filepicker::Model;
use bubbletea_rs::{Model as BubbleTeaModel, Msg, Cmd};

// Create a new file picker
let (mut filepicker, cmd) = Model::init();

// In your application's update method
fn handle_filepicker_msg(filepicker: &mut Model, msg: Msg) -> Option<Cmd> {
    // Check if a file was selected
    let (selected, path) = filepicker.did_select_file(&msg);
    if selected {
        println!("Selected file: {:?}", path);
    }
     
    // Update the filepicker
    filepicker.update(msg)
}

§Customization

use bubbletea_widgets::filepicker::{Model, Styles, FilepickerKeyMap};
use lipgloss_extras::prelude::*;

let mut filepicker = Model::new();

// Customize styles
filepicker.styles.cursor = Style::new().foreground(Color::from("cyan"));
filepicker.styles.directory = Style::new().foreground(Color::from("blue")).bold(true);
filepicker.styles.file = Style::new().foreground(Color::from("white"));

// The keymap can also be customized if needed
// filepicker.keymap = FilepickerKeyMap::default();

§Key Bindings

The default key bindings are:

  • j/: Move cursor down
  • k/: Move cursor up
  • l//Enter: Open directory or select file
  • h//Backspace/Esc: Go back to parent directory
  • PageUp/b: Page up
  • PageDown/f: Page down

Structs§

ErrorMsg
Message type for handling errors during file system operations.
FileEntry
Represents a single file or directory entry in the file picker.
FilepickerKeyMap
Key bindings for filepicker navigation and interaction.
Model
The main file picker model containing all state and configuration.
ReadDirMsg
Message type for handling successful directory reads.
Styles
Visual styling configuration for the file picker.

Functions§

is_hidden_name
Determines whether a file is hidden based on its name.
new
Creates a new filepicker model with default styling and key bindings.