Professional bash UI/UX library providing consistent look and feel across all bash scripts.
The UI library (scripts/lib/ui.sh) provides a comprehensive set of functions for creating consistent, professional-looking terminal output with:
- Consistent color scheme across all scripts
- Box drawing for headers and footers
- Interactive prompts with standardized behavior
- Status indicators (checkmarks, crosses, bullets)
- Formatted output (key-value pairs, sections, tables)
- Error handling with helpful suggestions
#!/bin/bash
# Load the UI library
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
source "$SCRIPT_DIR/lib/ui.sh"
# Use UI functions
ui_box_header "My Script Title" 40
ui_nl
ui_step "Performing operation..."
# ... do work ...
ui_check "Operation completed"
ui_nl
ui_box_footer_success "✅ All done!" 40| Color | Variable | Usage |
|---|---|---|
| Red | UI_RED |
Errors, failures |
| Green | UI_GREEN |
Success, completions |
| Yellow | UI_YELLOW |
Warnings, prompts |
| Blue | UI_BLUE |
Information, headers |
| Cyan | UI_CYAN |
Highlights, steps |
| Gray | UI_GRAY |
Separators, muted text |
All colors automatically reset to UI_NC (no color) after use.
Creates a boxed header with centered title.
ui_box_header "My Script Title" 40
# Output:
# ╔════════════════════════════════════════╗
# ║ My Script Title ║
# ╚════════════════════════════════════════╝Creates a green success footer box.
ui_box_footer_success "✅ Build Complete!" 40Creates a red error footer box.
ui_box_footer_error "❌ Build Failed" 40Prints error message in red (to stderr).
ui_error "File not found"Prints warning message in yellow (to stderr).
ui_warn "Configuration file missing, using defaults"Prints informational message in blue.
ui_info "Processing files..."Prints success message in green.
ui_success "✓ All tests passed"Prints highlighted message in cyan.
ui_highlight "Method: AddressSanitizer (ASan)"Indicates a step in progress (
ui_step "Compiling source files..."Prints a bullet point item.
ui_bullet "main.cpp"
ui_bullet "utils.cpp"Prints an item with checkmark (✓).
ui_check "Build completed successfully"Prints an item with cross mark (✗).
ui_cross "Optional feature disabled"ui_clean "Cleaning build directory..." # 🧹
ui_inspect "Verifying output..." # 🔍
ui_config "Loading configuration..." # ⚙️
ui_launch "Starting application..." # 🚀
ui_video "Generating video..." # 🎬Asks yes/no question, returns 0 for yes, 1 for no.
if ui_confirm "Continue with build?" true; then
echo "Building..."
else
echo "Cancelled"
fi
# With default No:
if ui_confirm "Delete files?" false; then
rm -rf temp/
fiGets input from user with optional default value.
name=$(ui_input "Enter name: " "default_name")
port=$(ui_input "Enter port: ")Displays animated spinner (background process).
ui_progress "Building..." &
SPINNER_PID=$!
# ... do long-running work ...
kill $SPINNER_PID 2>/dev/nullChecks if command exists, shows installation hint if not.
if ! ui_require_command "cmake" "brew install cmake"; then
exit 1
fiChecks if file exists.
if ! ui_require_file "config.toml" "Run: cp config.example.toml config.toml"; then
exit 1
fiChecks if directory exists.
if ! ui_require_dir "build" "Run: mkdir build && cd build && cmake .."; then
exit 1
fiPrints a major section header.
ui_section "Build Configuration"
# Output:
# ═══════════════════════════════════════
# Build Configuration
# ═══════════════════════════════════════Prints a subsection header.
ui_subsection "Environment Variables"
# Output:
# ▶ Environment VariablesPrints a key-value pair with alignment.
ui_keyval "Build Type" "Debug"
ui_keyval "Compiler" "clang++"
# Output:
# Build Type: Debug
# Compiler: clang++Prints a colored key-value pair.
ui_keyval_color "Status" "Running" "$UI_GREEN"Prints error and exits with code (default: 1).
ui_die "Critical error occurred" 1Prints error with helpful suggestion.
ui_error_suggest "Build failed" "Try running: ./scripts/build.sh -c"Prints a horizontal separator line.
ui_separator # Default: ----
ui_separator "=" # Custom: ====Prints empty line(s).
ui_nl # One blank line
ui_nl 3 # Three blank linesCenters text within specified width.
ui_center "My Script Title" 80Formats help section headers.
ui_help_section "Options"Formats help option entries.
ui_help_option "-r, --release" "Build in release mode"
ui_help_option "-v, --verbose" "Verbose output"Formats help examples.
ui_help_example "./build.sh -r" "Release build"
ui_help_example "./build.sh -c -r" "Clean release build"#!/bin/bash
set -e
# Load UI library
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
source "$SCRIPT_DIR/lib/ui.sh"
# Show header
ui_box_header "🎯 My Build Script" 40
ui_nl
# Validate requirements
if ! ui_require_command "cmake" "brew install cmake"; then
exit 1
fi
# Interactive prompt
if ! ui_confirm "Start build?" true; then
ui_warn "Build cancelled"
exit 0
fi
# Show configuration
ui_section "Build Configuration"
ui_keyval "Build Type" "Debug"
ui_keyval "Generator" "Ninja"
ui_keyval "Jobs" "8"
ui_nl
# Perform build steps
ui_step "Configuring CMake..."
cmake -G Ninja -DCMAKE_BUILD_TYPE=Debug ..
ui_step "Building binaries..."
ninja -j8
ui_check "Build completed"
ui_nl
# Show results
ui_box_footer_success "✅ Build Successful!" 40
ui_nl
ui_subsection "Output"
ui_keyval "Binary" "./build/bin/myapp"
ui_nl
ui_info "Run: ./build/bin/myapp"- Consistency: All scripts use the same color scheme and formatting
- Readability: Clear visual hierarchy with boxes, sections, and bullets
- User-friendly: Interactive prompts with sensible defaults
- Professional: Clean output suitable for both interactive and CI/CD use
- Maintainable: Centralized UI logic makes updates easy
echo -e "${GREEN}Starting build...${NC}"
echo ""
if [ ! -f "$FILE" ]; then
echo -e "${RED}Error: File not found${NC}"
exit 1
fi
echo -e " ${BLUE}•${NC} Building..."
echo -e "${GREEN}✓ Done${NC}"ui_success "Starting build..."
ui_nl
if ! ui_require_file "$FILE" "Create file first"; then
exit 1
fi
ui_bullet "Building..."
ui_check "Done"The following scripts now use the UI library:
- ✅
build.sh- Main build script - ✅
quick-test.sh- Quick functionality test - ✅
test-video.sh- Video generation test - ✅
test-leaks.sh- Memory leak testing - ✅
run-hooks.sh- Pre-commit hooks runner
- Faster script writing - reusable components
- Consistent UX - users know what to expect
- Less boilerplate - no more color code duplication
- Better error handling - standardized patterns
- Professional appearance - polished terminal output
- Clear visual hierarchy - easy to scan output
- Helpful prompts - standardized yes/no questions
- Better error messages - contextual help included
Potential additions to the library:
- Progress bars for long operations
- Multi-column table formatting
- More sophisticated menu systems
- Logging to file alongside terminal output
- Theme support (dark/light modes)
- Emoji support toggle for environments that don't support them
When adding new UI functions:
- Follow the naming convention:
ui_<category>_<action> - Add documentation in this README
- Export the function at the end of
ui.sh - Keep color usage consistent with existing patterns
- Test on both macOS and Linux if possible
- Build Quick Reference - Build script usage
- Pre-commit Quickstart - Git hooks setup
- Scripts README - Overview of all scripts