Skip to content

Latest commit

 

History

History
252 lines (195 loc) · 5.22 KB

File metadata and controls

252 lines (195 loc) · 5.22 KB

Interactive Branch Selection - Final Version ✓

The mug branches command now supports interactive selection with shell visible.

How It Works

$ mug branches

(shows beautiful branch list)

(shows interactive prompt)

Select a branch:
  1 ● feature/test (current)
  2 ○ main
  3 ○ test2

Enter branch number or name (or press Enter to skip):

You can:

  • Type a number (1, 2, 3, etc.) to select by position
  • Type a branch name (or part of it) to select by name
  • Press Enter to skip (no branch switch)

Examples

Select by Number

$ mug branches
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Branches
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
● feature/awesome (current)
○ main
○ develop

Select a branch:
  1 ● feature/awesome (current)
  2 ○ main
  3 ○ develop

Enter branch number or name (or press Enter to skip): 2
✓ success: Switched to branch: main

$ (shell prompt visible)

Select by Name

$ mug branches
(... list ...)
Enter branch number or name (or press Enter to skip): develop
✓ success: Switched to branch: develop

$ (shell prompt visible)

Partial Name Match

$ mug branches
(... list ...)
Enter branch number or name (or press Enter to skip): feat
✓ success: Switched to branch: feature/awesome

$ (shell prompt visible)

Skip (Press Enter)

$ mug branches
(... list ...)
Enter branch number or name (or press Enter to skip): 
$ (shell prompt visible, no branch switch)

Features

Beautiful Display

✨ Shows all branches with Unicode symbols:

  • bright green for current branch
  • cyan for other branches
  • Numbered list for easy selection
  • Colored header

Multiple Selection Methods

  1. By number - Type 1, 2, 3, etc.
  2. By name - Type the full or partial branch name
  3. Skip - Just press Enter

Shell-Friendly

  • ✓ Shell prompt visible after command
  • ✓ No screen clearing
  • ✓ Inline prompt
  • ✓ Works in normal shell workflow

Smart Matching

  • Exact matches
  • Partial matches (substring)
  • Case-sensitive matching

Behavior

Input Result
1 Switch to branch 1
main Switch to branch named "main"
fea Switch to first branch containing "fea"
(empty) Skip, no switch
999 Error: Invalid number
nonexistent Error: Branch not found

Visual Elements

Numbered List

Select a branch:
  1 ● feature/awesome (current)
  2 ○ main
  3 ○ develop

Prompt

Enter branch number or name (or press Enter to skip):

Success

✓ success: Switched to branch: main

Already Current

⚠ warning: Already on this branch

Error

✘ error: Failed to switch: <reason>

Real-World Usage

Workflow

$ git status
(on main)

$ mug branches
(shows branches with interactive prompt)

2
(switch to develop)

✓ success: Switched to branch: develop

$ pwd
/home/user/project

$ mug status
(shows status for develop branch)

Quick Branch Switching

$ mug branches
(quick lookup and switch)

No Friction

  • No complex keyboard navigation
  • Just type and press Enter
  • Works like familiar terminal tools
  • Shell visible and ready for next command

Implementation

File: src/ui/interactive.rs

  • BranchSelector struct
  • prompt_user() method for display and input
  • select_branch_interactive() function

Features

  • Simple stdin/stdout based input
  • No raw mode or terminal manipulation
  • Graceful error handling
  • Clean code

Integration

The Commands::Branches handler:

  1. Shows beautiful branch list (formatter)
  2. Prompts for interactive selection
  3. Switches branch if selected
  4. Shows result (success/warning/error)

Advantages

Simple - Type number or name ✅ Visual - See all branches numbered ✅ Familiar - Like terminal menus ✅ Fast - No navigation keys needed ✅ Safe - Can skip with Enter ✅ Shell-friendly - Prompt visible after ✅ Works everywhere - No special terminal features needed

Limitations

  • One selection per command (press Enter to go back to shell)
  • No multi-select
  • No branch filtering/search (but partial name matching helps)

Future Enhancements

Could add:

  • Branch search/filter
  • Show branch metadata
  • Sort branches differently
  • Delete branches from menu
  • Create new branch from menu

Compatibility

Works on:

  • ✓ All shells (bash, zsh, fish, etc.)
  • ✓ All operating systems (Linux, macOS, Windows)
  • ✓ SSH sessions
  • ✓ Piped input (for scripts)
  • ✓ CI/CD pipelines

Testing

Tested with:

  • ✓ Selection by number
  • ✓ Selection by full name
  • ✓ Selection by partial name
  • ✓ Skip (empty input)
  • ✓ Invalid number
  • ✓ Non-existent branch
  • ✓ Already on selected branch

Summary

The interactive branch selector:

  • 🎨 Shows beautiful numbered list
  • 📝 Prompts for selection
  • ✓ Switches on Enter
  • 🚀 Returns to shell immediately
  • 💡 Works like familiar terminal menus

Perfect for quick branch switching while keeping your shell workflow intact!