promptio

package
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 31, 2024 License: MPL-2.0 Imports: 2 Imported by: 0

Documentation

Overview

package promptio wraps a test IOStream to make it safe to use the input with promptui.

Example
package main

import (
	"io"

	"github.com/hashicorp/hcp/internal/pkg/iostreams"
	"github.com/hashicorp/hcp/internal/pkg/testing/promptio"
	"github.com/manifoldco/promptui"
)

func main() {
	// Write to the stream input buffer to simulate interaction with the prompt
	stream := iostreams.Test()

	// Write down and then enter
	_, _ = stream.Input.WriteRune(promptui.KeyNext)
	_, _ = stream.Input.WriteRune(promptui.KeyEnter)

	promptIO := promptio.Wrap(stream)
	prompt := promptui.Select{
		Label: "Your prompt",
		Items: []string{"test", "other"},
		Stdin: io.NopCloser(promptIO.In()),
	}

	// Run the prompt
	_, _, _ = prompt.Run() //nolint:dogsled
}
Output:

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type PromptIO

type PromptIO struct {
	*iostreams.Testing
}

PromptIO wraps a testing iostream to make it safe to test promptui.

func Wrap

func Wrap(t *iostreams.Testing) *PromptIO

Wrap wraps the testing iostreams and returns an iostream safe for use with promptui.

func (*PromptIO) In

func (p *PromptIO) In() io.Reader

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL