Skip to content

Conversation

@ejacquier
Copy link
Contributor

Summary

This PR modernizes the CRE CLI's user interface by integrating the Charm ecosystem (Lipgloss, Huh, Bubble Tea). This is a view-layer only refactoring - no business logic or Cobra command structure was modified.

Why This Refactoring?

To build a world-class developer experience, we needed a better foundation. Our previous approach had limitations:

  • No terminal ownership: Simple fmt.Print calls can't handle async operations gracefully
  • Basic prompts: The old promptui library offered limited customization and no modern UX patterns
  • Inconsistent styling: Colors and formatting were applied ad-hoc across commands
  • No async feedback: Long-running operations (API calls, deployments) had no visual feedback

The Charm ecosystem solves these by owning the terminal - it manages the view layer as a proper UI framework, enabling:

  • Spinners for async operations: Visual feedback during network calls, file operations, etc.
  • Rich form inputs: Tab-completion, suggestions, themed styling
  • Consistent branding: Chainlink color palette applied uniformly
  • Graceful interruption: Users can cancel long operations with Escape/Ctrl+C

Key Changes

1. New UI Package (internal/ui/)

Centralized styling and output functions:

// Before (scattered across codebase)
fmt.Println("Operation successful")
fmt.Printf("\033[32m✓\033[0m Done\n")

// After (consistent, branded)
ui.Success("Operation successful")
ui.Error("Something went wrong")
ui.Warning("Deprecated feature")
ui.Dim("Secondary information")

2. Chainlink-Branded Theme

All interactive elements use the Chainlink color palette:

  • Blue 500 (#375BD2): Primary actions, spinners, focused elements
  • Green: Success states
  • Orange: Errors (high contrast)
  • Gray scale: Secondary text, disabled states

3. Spinner for Async Operations

Reference-counted spinner that handles concurrent operations:

spinner := ui.GlobalSpinner()
spinner.Start("Connecting to API...")
// ... async work ...
spinner.Update("Processing response...")
// ... more work ...
spinner.Stop()

4. Modern Form Inputs with Huh

Replaced promptui with huh forms featuring:

  • Tab-completion for default values
  • Chainlink-themed styling
  • Keyboard navigation (Enter to submit, Escape to cancel)
huh.NewInput().
    Title("Project name").
    Placeholder(defaultName).
    Suggestions([]string{defaultName}).
    Value(&projName)

5. Enhanced Error Handling

New helpers for actionable error messages:

ui.ErrorWithHelp("Connection failed", "Check your network connection")

ui.ErrorWithSuggestions("Invalid config", []string{
    "Run 'cre init' to create a new project",
    "Check the config file syntax",
})

6. Graceful Cancellation

Long-running operations (like cre login) now support Escape/Ctrl+C with proper cleanup and user feedback.

What's NOT Changed

  • Cobra command structure: All commands, flags, and arguments unchanged
  • Business logic: API calls, file processing, validation logic untouched
  • Command behavior: Same inputs produce same outputs
  • Configuration: Settings files and environment variables unchanged

Libraries

Library Purpose
Lipgloss Terminal styling (colors, borders, layout)
Huh Interactive forms and prompts
Bubble Tea Terminal UI framework
Bubbles Pre-built components (spinner)

Removed Dependencies

  • promptui - Replaced entirely by huh

Testing

  • All existing tests pass
  • Manual testing of all commands

  - Create internal/ui/ package with centralized Lipgloss styles (styles.go)
  - Add output helpers for consistent styling: Title, Box, Success, Dim, etc.
  - Implement Bubble Tea spinner with reference counting for async operations
  - Add GlobalSpinner singleton for seamless spinner across CLI lifecycle
  - Update PersistentPreRunE to show spinner during initialization
  - Migrate cre init and cre whoami to use shared UI package
  - Add spinner during file generation (copying, generating templates, contracts)
  - Show spinner during Go dependencies installation
  - Display dependencies in styled box after spinner completes
  - Fix Next steps box spacing and formatting
  - Refactor initializeGoModule to return deps instead of printing
  - Add styled template functions (styleTitle, styleSection, styleCommand, styleDim, styleSuccess, styleCode)
  - Update help template to use Lipgloss styling
  - Style section headers, command names, tips, and URLs
  - Improve visual hierarchy and readability
  - Add complete Blocks palette constants (Gray, Blue, Green, Red, Orange, Yellow, Teal, Purple)
  - Use high-contrast colors for dark terminal readability
  - Style titles/commands with Blue 400-500 for visibility
  - Style secondary info with Gray 500 (dimmed)
  - Create custom Huh theme with Blocks colors for forms
  - Update spinner to use Blue 500
  - Add styled title and welcome message using Chainlink theme
  - Add Bubble Tea spinner with progress states throughout auth flow:
    - Preparing authentication
    - Opening browser
    - Waiting for authentication
    - Exchanging authorization code
    - Saving credentials
  - Show styled URL fallback when browser cannot open automatically
  - Display success message with next steps in branded box
  - Update spinner message during org membership retry flow
  - Update tests to include spinner in handler instantiations
  - Add SilenceErrors: true to root command to disable Cobra's default error output
  - Display all user-facing errors with styled ui.Error() in Execute()
  - Errors now show with red color and ✗ prefix consistent with Chainlink theme
  - Internal debug logging via zerolog remains unchanged
  - Add SilenceErrors: true to disable Cobra's default error output
  - Display errors with styled ui.Error() (red with ✗ prefix)
  - Set SilenceUsage in PersistentPreRunE to hide usage for runtime errors
  - Keep usage/suggestions visible for command typos and flag errors
    - Replaced prompt.YesNoPrompt with huh.NewConfirm forms
    - Removed stdin io.Reader parameter
  2. Updated cmd/creinit/creinit.go:
    - Updated call sites to match new function signatures
  3. Updated cmd/secrets/common/handler.go:
    - Replaced ~25 fmt.Print* calls with ui.* functions
  4. Updated cmd/workflow/simulate/telemetry_writer.go:
    - Replaced fmt.Printf with ui.Printf
    - Removed unused fmt import
  5. Deleted internal/prompt/ directory:
    - Removed entire old promptui-based package
  6. Cleaned cmd/common/utils.go:
    - Removed unused MustGetUserInputWithPrompt function
    - Removed unused bufio and errors imports
  7. Dependencies cleaned (go mod tidy):
    - Removed github.com/manifoldco/promptui
    - Removed github.com/chzyer/readline
@ejacquier ejacquier requested a review from a team as a code owner January 31, 2026 15:58
@github-actions
Copy link

👋 ejacquier, thanks for creating this pull request!

To help reviewers, please consider creating future PRs as drafts first. This allows you to self-review and make any final changes before notifying the team.

Once you're ready, you can mark it as "Ready for review" to request feedback. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant