uiutil

package module
v0.0.0-...-5c68245 Latest Latest
Warning

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

Go to latest
Published: Dec 16, 2015 License: MIT Imports: 5 Imported by: 0

README

uiutil GoDoc Build Status

uiutil is a go library that provides a set of helpers to improve readbility in terminal applications.

Features

  • Hidden Prompts: Provides a prompter for capturing sensitive data (passwords).
  • Buffered Printer: Printer object to buffer UI components that can be flushed.
  • Title Decorator: Decorator for formating titles.

Usage Example

Hidden Prompts
var pass string
uiutil.PromptHiddenString(&pass, "Password: ")
fmt.Println("Password is", pass)

Renders: example

Full source for above example is available at example/prompt/prompt.go

Installation

$ go get github.com/gosuri/uiutil/...

Documentation

Index

Examples

Constants

This section is empty.

Variables

View Source
var DefaultPrompter = New()

DefaultPrompter is the default prompter for the package

View Source
var Out = os.Stdout

Out is the default out

View Source
var TitleUnderliner = "="

TitleUnderliner is the underline character for the title

Functions

func PromptHiddenString

func PromptHiddenString(str *string, prompt string) error

PromptHiddenString uses the default prompter to prompt the user for input and hides the input when the string is missing. It is used for capturing sensitive data (passwords). Will not prompt when no interactive is true

Types

type Component

type Component interface {
	Bytes() []byte
}

Component in the interface that UI components need to implement

type Printer

type Printer struct {
	// contains filtered or unexported fields
}

Printer represents a buffered container for components that can be flushed

func NewPrinter

func NewPrinter(out io.Writer) *Printer

NewPrinter returns a pointer to a new printer object

func (*Printer) Add

func (p *Printer) Add(c Component) *Printer

Add adds the components to the printer

func (*Printer) AddTitle

func (p *Printer) AddTitle(title string) *Printer

AddTitle Adds a Title to the printer

func (*Printer) Bytes

func (p *Printer) Bytes() []byte

Bytes returns the formmated string of the output

func (*Printer) Flush

func (p *Printer) Flush() error

Flush prints the output to the writer and clears the buffer

type Prompter

type Prompter struct {
	// Reader is the input reader to read user input from
	Reader io.Reader

	// Writer is the output writer to present the prompt
	Writer io.Writer

	// NoInteractive when enabled disables prompting user
	NoInteractive bool
}

Prompter represent an interactive prompter that captures inputs from the user

func New

func New() *Prompter

NewPrompter returns a new instance of a prompter

func (*Prompter) PromptHiddenString

func (a *Prompter) PromptHiddenString(str *string, prompt string) error

PromptHiddenString prompts the user for input and hides the input capture. It used for capturing sensitive data (passwords). Will not prompt when no interactive is true

Example
package main

import (
	"fmt"

	"github.com/gosuri/uiutil"
)

func main() {
	var pass string
	uiutil.PromptHiddenString(&pass, "Password: ")
	fmt.Println("Password is", pass)
}

type Title

type Title struct {
	// contains filtered or unexported fields
}

Title is a UI component that renders a title

func NewTitle

func NewTitle(text string) *Title

func (*Title) Bytes

func (t *Title) Bytes() []byte

String returns the formated string of the title

Directories

Path Synopsis
_vendor
example
prompt command

Jump to

Keyboard shortcuts

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