build_tools.pipeline_tui.screens.file_selector

File selector screen for Pipeline TUI.

This module provides a modal screen for selecting specific files from a directory. Users can browse to a directory, see matching files, and select/deselect individual files or use select all/none for batch operations.

Features:

  • Directory tree navigation to find source folders

  • File list with checkboxes for selection

  • Select All / Select None buttons

  • File pattern filtering

  • Summary of selected files count

Example Usage:

from build_tools.pipeline_tui.screens.file_selector import FileSelectorScreen

result = await self.app.push_screen_wait(
    FileSelectorScreen(
        initial_dir=Path("_working/codex"),
        file_pattern="*.txt",
    )
)
if result:
    selected_files = result  # List[Path]
    print(f"Selected {len(selected_files)} files")

Classes

FileSelectorScreen

Modal screen for selecting multiple files from a directory.

Module Contents

class build_tools.pipeline_tui.screens.file_selector.FileSelectorScreen(initial_dir=None, file_pattern='*.txt', title='Select Files', root_dir=None)[source]

Bases: textual.screen.ModalScreen[list[pathlib.Path]| None]

Modal screen for selecting multiple files from a directory.

Displays a directory browser and a file list with checkboxes. When user navigates to a directory, shows all files matching the pattern with checkboxes for selection.

initial_dir

Starting directory for browser

file_pattern

Glob pattern for filtering files (default: “*.txt”)

current_dir

Currently browsed directory

selected_files

Set of selected file paths

Returns:

List of selected Path objects, or None if cancelled

Initialize file selector screen.

Parameters:
  • initial_dir (pathlib.Path | None) – Starting directory for browser (default: home)

  • file_pattern (str) – Glob pattern for files (default: “*.txt”)

  • title (str) – Header title for the screen

  • root_dir (pathlib.Path | None) – Root directory for tree navigation (default: home). Set higher than initial_dir to allow navigating up.

BINDINGS = [('escape', 'cancel', 'Cancel'), ('enter', 'confirm', 'Confirm'), ('a', 'select_all', 'Select...

A list of key bindings.

CSS = Multiline-String
Show Value
"""
    FileSelectorScreen {
        align: center middle;
    }

    #file-selector-container {
        width: 100;
        height: 40;
        background: $panel;
        border: thick $primary;
        padding: 1;
    }

    #selector-header {
        text-align: center;
        text-style: bold;
        color: $accent;
        margin-bottom: 1;
    }

    #main-panels {
        width: 100%;
        height: 1fr;
    }

    #dir-panel {
        width: 40%;
        height: 100%;
        border: solid $primary;
        padding: 0 1;
    }

    #file-panel {
        width: 60%;
        height: 100%;
        border: solid $primary;
        padding: 0 1;
    }

    .panel-header {
        text-style: bold;
        color: $text;
        margin-bottom: 1;
    }

    #directory-tree {
        width: 100%;
        height: 1fr;
    }

    #file-list {
        width: 100%;
        height: 1fr;
    }

    .file-checkbox {
        margin: 0;
        padding: 0;
    }

    #status-bar {
        height: 2;
        width: 100%;
        color: $text-muted;
        border-top: solid $primary;
        padding: 0 1;
        margin-top: 1;
    }

    #button-bar {
        width: 100%;
        height: auto;
        align: center middle;
        margin-top: 1;
    }

    #button-bar Button {
        margin: 0 1;
    }

    .empty-message {
        color: $text-muted;
        text-align: center;
        padding: 2;
    }
    """

Inline CSS, useful for quick scripts. Rules here take priority over CSS_PATH.

Note

This CSS applies to the whole app.

initial_dir
root_dir
file_pattern = '*.txt'
title_text = 'Select Files'
current_dir: pathlib.Path | None = None
selected_files: set[pathlib.Path]
compose()[source]

Compose the file selector UI.

async directory_selected(event)[source]

Handle directory selection in tree.

async node_expanded(event)[source]

Handle directory expansion - also load files.

checkbox_changed(event)[source]

Handle file checkbox toggle.

select_all_pressed()[source]

Select all visible files.

select_none_pressed()[source]

Deselect all visible files.

select_pressed()[source]

Confirm selection and dismiss.

cancel_pressed()[source]

Cancel and dismiss.

action_cancel()[source]

Cancel action (escape key).

action_confirm()[source]

Confirm action (enter key).

action_select_all()[source]

Select all files (a key).

action_select_none()[source]

Deselect all files (n key).

async on_mount()[source]

Handle screen mount event.

If initial_dir differs from root_dir, expand the tree to show initial_dir after a brief delay.

action_cursor_down()[source]

Move cursor down in directory tree (j key).

action_cursor_up()[source]

Move cursor up in directory tree (k key).

action_cursor_left()[source]

Collapse directory in tree (h key).

action_cursor_right()[source]

Expand directory in tree (l key).

action_toggle_node()[source]

Toggle expand/collapse of current node (space key).