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: Automatically hides dotfiles and system hidden files
  • 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 {
        if let Some(file_path) = path {
            println!("Selected file: {:?}", file_path);
        }
    }
     
    // Update the filepicker
    filepicker.update(msg)
}

§Customization

use bubbletea_widgets::filepicker::{Model, Styles, FilepickerKeyMap};
use lipgloss::{Style, Color};

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§

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.
Styles
Visual styling configuration for the file picker.