Convert Figma logo to code with AI

manifoldco logopromptui

Interactive prompt for command-line applications

6,055
336
6,055
89

Top Related Projects

Readline is a pure go(golang) implementation for GNU-Readline kind library

4,089

A golang library for building interactive and accessible prompts with full support for windows and posix terminals.

Building powerful interactive prompts in Go, inspired by python-prompt-toolkit.

4,795

✨ #PTerm is a modern Go module to easily beautify console output. Featuring charts, progressbars, tables, trees, text input, select menus and much more 🚀 It's completely configurable and 100% cross-platform compatible.

5,483

TUI components for Bubble Tea 🫧

Quick Overview

PromptUI is a Go library for building interactive command-line interfaces. It provides a set of tools to create prompts, selections, and confirmations, making it easier to develop user-friendly CLI applications with minimal effort.

Pros

  • Easy to use and integrate into existing Go projects
  • Supports various input types (text, password, select, confirm)
  • Customizable appearance and behavior
  • Cross-platform compatibility

Cons

  • Limited to command-line interfaces
  • May require additional setup for complex input validation
  • Documentation could be more comprehensive
  • Limited built-in styling options compared to some other CLI libraries

Code Examples

  1. Simple text input prompt:
prompt := promptui.Prompt{
    Label: "Enter your name",
}

result, err := prompt.Run()
if err != nil {
    fmt.Printf("Prompt failed %v\n", err)
    return
}

fmt.Printf("Hello, %s\n", result)
  1. Select prompt with options:
prompt := promptui.Select{
    Label: "Select a color",
    Items: []string{"Red", "Blue", "Green", "Yellow"},
}

_, result, err := prompt.Run()
if err != nil {
    fmt.Printf("Prompt failed %v\n", err)
    return
}

fmt.Printf("You chose %s\n", result)
  1. Confirmation prompt:
prompt := promptui.Prompt{
    Label:     "Are you sure?",
    IsConfirm: true,
}

result, err := prompt.Run()
if err != nil {
    fmt.Printf("Prompt failed %v\n", err)
    return
}

fmt.Printf("You chose %s\n", result)

Getting Started

To use PromptUI in your Go project, follow these steps:

  1. Install the library:

    go get -u github.com/manifoldco/promptui
    
  2. Import the library in your Go file:

    import "github.com/manifoldco/promptui"
    
  3. Create and run a prompt:

    prompt := promptui.Prompt{
        Label: "Enter your name",
    }
    
    result, err := prompt.Run()
    if err != nil {
        fmt.Printf("Prompt failed %v\n", err)
        return
    }
    
    fmt.Printf("Hello, %s\n", result)
    

Competitor Comparisons

Readline is a pure go(golang) implementation for GNU-Readline kind library

Pros of readline

  • Lower-level library providing more fine-grained control over input handling
  • Faster performance due to its simplicity and focus on core readline functionality
  • Closer to the standard Go library's implementation, potentially easier for Go developers to understand and extend

Cons of readline

  • Less feature-rich compared to promptui, focusing primarily on basic line editing
  • Requires more manual implementation for advanced features like input validation or custom prompts
  • May require more code to achieve the same functionality as promptui's high-level abstractions

Code Comparison

readline:

rl, err := readline.New("> ")
defer rl.Close()
line, err := rl.Readline()

promptui:

prompt := promptui.Prompt{
    Label: ">",
}
result, err := prompt.Run()

Summary

readline is a lower-level library offering more control and potentially better performance, while promptui provides a higher-level abstraction with more built-in features for creating interactive command-line interfaces. The choice between them depends on the specific requirements of your project and the level of control you need over the input handling process.

4,089

A golang library for building interactive and accessible prompts with full support for windows and posix terminals.

Pros of Survey

  • More comprehensive set of input types, including password and multiline inputs
  • Built-in validation support for user inputs
  • Supports custom prompts with icons and colors

Cons of Survey

  • Less focus on terminal UI elements compared to Promptui
  • May have a steeper learning curve for simple use cases
  • Fewer built-in styling options for prompts

Code Comparison

Survey:

prompt := &survey.Input{
    Message: "Enter your name:",
}
survey.AskOne(prompt, &name)

Promptui:

prompt := promptui.Prompt{
    Label: "Enter your name",
}
result, _ := prompt.Run()

Both libraries provide similar functionality for basic prompts, but Survey offers more advanced features for complex input scenarios. Promptui focuses on providing a simpler API with built-in terminal UI elements, while Survey emphasizes flexibility and customization options.

Survey is better suited for applications requiring diverse input types and validation, whereas Promptui excels in creating visually appealing terminal interfaces with less code. The choice between the two depends on the specific requirements of your project and the level of customization needed.

Building powerful interactive prompts in Go, inspired by python-prompt-toolkit.

Pros of go-prompt

  • More feature-rich with advanced completion and suggestion capabilities
  • Supports real-time, character-by-character input processing
  • Better suited for complex, interactive command-line interfaces

Cons of go-prompt

  • Steeper learning curve due to more complex API
  • Less suitable for simple, one-off prompts or basic user input scenarios
  • May have higher resource usage for simpler applications

Code Comparison

go-prompt example:

p := prompt.New(
    executor,
    completer,
    prompt.OptionPrefix(">>> "),
    prompt.OptionTitle("My CLI"),
)
p.Run()

promptui example:

prompt := promptui.Select{
    Label: "Select Day",
    Items: []string{"Monday", "Tuesday", "Wednesday", "Thursday", "Friday"},
}
_, result, err := prompt.Run()

Key Differences

  1. Input handling: go-prompt processes input in real-time, while promptui typically handles input after submission.
  2. Customization: go-prompt offers more granular control over input processing and suggestions, while promptui provides simpler, pre-built prompt types.
  3. Use case: go-prompt is better for building complex CLIs, while promptui excels at creating quick, user-friendly prompts.
  4. Performance: go-prompt may have higher resource usage for simple tasks, but offers better performance for complex scenarios.
  5. Learning curve: promptui is generally easier to learn and implement for basic use cases, while go-prompt requires more time to master its advanced features.
4,795

✨ #PTerm is a modern Go module to easily beautify console output. Featuring charts, progressbars, tables, trees, text input, select menus and much more 🚀 It's completely configurable and 100% cross-platform compatible.

Pros of pterm

  • More comprehensive terminal UI toolkit with a wider range of features
  • Supports cross-platform color and style rendering
  • Offers advanced components like progress bars, spinners, and tables

Cons of pterm

  • Steeper learning curve due to more extensive API
  • May be overkill for simple CLI applications
  • Less focused on interactive prompts compared to promptui

Code Comparison

pterm example:

pterm.DefaultHeader.WithBackgroundStyle(pterm.NewStyle(pterm.BgLightBlue)).WithMargin(10).Println("Hello, World!")
pterm.Info.Println("This is a simple info message")
pterm.Success.Println("This is a success message")

promptui example:

prompt := promptui.Select{
    Label: "Select Day",
    Items: []string{"Monday", "Tuesday", "Wednesday", "Thursday", "Friday"},
}
_, result, err := prompt.Run()

Summary

pterm is a more feature-rich terminal UI toolkit, offering a wide range of components and styling options. It's ideal for creating complex CLI applications with advanced visual elements. promptui, on the other hand, focuses primarily on interactive prompts and is simpler to use for basic CLI input scenarios. The choice between the two depends on the specific requirements of your project and the level of UI complexity you need.

5,483

TUI components for Bubble Tea 🫧

Pros of Bubbles

  • More comprehensive UI toolkit with a wider range of components
  • Built on top of the Bubble Tea framework, offering a cohesive ecosystem
  • Highly customizable and extensible

Cons of Bubbles

  • Steeper learning curve due to its more complex architecture
  • May be overkill for simple CLI applications

Code Comparison

Bubbles:

progress := progress.New(progress.WithDefaultGradient())
spinner := spinner.New()
spinner.Style = lipgloss.NewStyle().Foreground(lipgloss.Color("205"))

Promptui:

prompt := promptui.Select{
    Label: "Select Day",
    Items: []string{"Monday", "Tuesday", "Wednesday"},
}
_, result, err := prompt.Run()

Summary

Bubbles offers a more comprehensive set of UI components and is part of a larger ecosystem, making it suitable for complex CLI applications. It provides greater customization options but comes with a steeper learning curve.

Promptui, on the other hand, is more focused on providing simple prompts and selections, making it easier to use for basic CLI interactions. It has a simpler API but lacks the extensive features and customization options of Bubbles.

Choose Bubbles for feature-rich, highly customizable CLI applications, and Promptui for straightforward, quick-to-implement CLI prompts and selections.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

promptui

Interactive prompt for command-line applications.

We built Promptui because we wanted to make it easy and fun to explore cloud services with manifold cli.

Code of Conduct | Contribution Guidelines

GitHub release GoDoc Travis Go Report Card License

Overview

promptui

Promptui is a library providing a simple interface to create command-line prompts for go. It can be easily integrated into spf13/cobra, urfave/cli or any cli go application.

Promptui has two main input modes:

  • Prompt provides a single line for user input. Prompt supports optional live validation, confirmation and masking the input.

  • Select provides a list of options to choose from. Select supports pagination, search, detailed view and custom templates.

For a full list of options check GoDoc.

Basic Usage

Prompt

package main

import (
	"errors"
	"fmt"
	"strconv"

	"github.com/manifoldco/promptui"
)

func main() {
	validate := func(input string) error {
		_, err := strconv.ParseFloat(input, 64)
		if err != nil {
			return errors.New("Invalid number")
		}
		return nil
	}

	prompt := promptui.Prompt{
		Label:    "Number",
		Validate: validate,
	}

	result, err := prompt.Run()

	if err != nil {
		fmt.Printf("Prompt failed %v\n", err)
		return
	}

	fmt.Printf("You choose %q\n", result)
}

Select

package main

import (
	"fmt"

	"github.com/manifoldco/promptui"
)

func main() {
	prompt := promptui.Select{
		Label: "Select Day",
		Items: []string{"Monday", "Tuesday", "Wednesday", "Thursday", "Friday",
			"Saturday", "Sunday"},
	}

	_, result, err := prompt.Run()

	if err != nil {
		fmt.Printf("Prompt failed %v\n", err)
		return
	}

	fmt.Printf("You choose %q\n", result)
}

More Examples

See full list of examples