Skip to content

Latest commit

 

History

History
67 lines (56 loc) · 4.1 KB

File metadata and controls

67 lines (56 loc) · 4.1 KB

Implementation Plan - File Folder Copy Replace TUI

Build a cross-platform TUI application in Rust to copy files/folders with configurable string replacements in paths and file contents.

User Review Required

Important

Library Choice: I am planning to use ratatui (the community fork of tui-rs) as it is currently the standard for Rust TUIs, along with crossterm for backend event handling. File System: The app will perform real file system operations. The "Copy Replace" action will be destructive if the destination exists (though we will prompt/warn).

Proposed Changes

Logic

[MODIFY] logic.rs

  • Update read_directory to handle partial paths:
    • If path is a directory, list contents (existing behavior).
    • If path is not a directory, try to find the parent directory.
    • If parent exists, list contents of parent that start with the file name part of the input path.

Input Handling

[MODIFY] main.rs

  • Filter key events to only process KeyEventKind::Press to prevent double input.
  • Add Event::Mouse handling to the event loop.

App Logic

[MODIFY] app.rs

  • Add Rect fields to App struct to store layout areas for mouse hit testing.
  • Implement on_mouse method in App to handle mouse clicks and update focus.
  • Update enter_char to trigger update_explorer when typing in SourceInput.

UI Rendering

[MODIFY] ui.rs

  • Change ui function signature to accept &mut App.
  • Update App's Rect fields during rendering to reflect current layout.

Verification Plan

Manual Verification

  • Double Input: Run the app and type characters. Verify only one character appears per key press.
  • Explorer Sync: Type a valid path in Source Input and verify Explorer updates immediately (or on valid path).
  • Mouse Support: Click on different sections (Source, Explorer, Destination, etc.) and verify focus changes. Click buttons to verify actions.
  • Directory Filtering: Type a partial path (e.g., C:\D) and verify that directories starting with D in C:\ are listed.
  • Explorer Mouse Click: Click on a directory in the Explorer and verify that the Source Directory input updates and the explorer refreshes.
  • Explorer Navigation: Verify Up/Down arrows scroll the list. Verify Right enters a directory, Left goes to parent.
  • Parent Directory: Verify .. appears in the list and navigating to it goes to the parent directory.
  • Files Panel: Verify a new panel appears to the right of Explorer showing files. Verify scrolling works.

Proposed Changes

Logic

[MODIFY] logic.rs

  • Update read_directory to return a tuple (Vec<PathBuf>, Vec<PathBuf>) containing (directories, files).
  • Or add a separate read_files function. Given the existing structure, modifying read_directory or returning a struct DirectoryContent might be cleaner. Let's return Result<(Vec<PathBuf>, Vec<PathBuf>)>.

App State

[MODIFY] app.rs

  • Add file_items: Vec<PathBuf> to App.
  • Add file_list_state: ListState to App.
  • Add files_area: Rect to App.
  • Add Focus::Files enum variant.
  • Update update_explorer to populate file_items.
  • Update on_key to handle Focus::Files scrolling.
  • Update next_focus/previous_focus to include Focus::Files.

UI Rendering

[MODIFY] ui.rs

  • Split the Explorer area (currently left_chunks[1]) into two horizontal chunks.
  • Render "Source Directory Explorer" (Directories) in the left chunk.
  • Render "Files in Folder" in the right chunk.
  • Use render_stateful_widget for the files list.