copro

package module
Version: v0.0.0-...-005fdad Latest Latest
Warning

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

Go to latest
Published: May 10, 2017 License: MIT Imports: 4 Imported by: 0

README

Golang console interactive prompts

Copro offer you interactive console user prompts like select, password,...

Table of Contents

  1. Getting started 1. Installation 2. Basic usage
  2. Prompts
    1. Input
    2. Password
    3. Confirm
    4. Select
    5. Checkbox
  3. Examples
  4. TODOS
  5. License

Getting started

A quick overview how simple is to use copro

Install the package

go get -u github.com/julienroland/copro/prompt

Basic usage

package main

import (
    "fmt"

    "github.com/julienroland/copro/prompt"
)

func main() {
    ask := prompt.NewInput()
    ask.Question = "What's your name"
    name, _ := ask.Run()
    fmt.Println(name)
}

Prompts

Input

ask := prompt.NewInput()
ask.Question = "What's your name"
name, _ := ask.Run()
fmt.Println(name)

Password

ask := prompt.NewPassword()
ask.Question = "Enter your password"
ask.Validation = func(answer string) bool {
	return answer != "password"
}
ask.ErrorMessage = func(answer string) string {
	return "Wrong password"
}
ask.MaximumNumberOfTry = 2
result, err := ask.Run()
fmt.Println(result, err)

Confirm

ask := prompt.NewConfirm()
ask.Question = "Are you a gopher"
ask.Default = "yes"
result := ask.Run()
fmt.Println(result)

Select

ask := prompt.NewSelect()
ask.Question = "[?] Choose what you want:"
ask.Choices = []*prompt.Choice{
	{
        ID:    1,
        Label: "Apple",
	},
	{
        ID:       2,
        Label:    "Tomato",
        Selected: true,
	},
	{
        Label:       "Others",
        IsSeparator: true,
	},
	{
        ID:    3,
        Label: "Orange",
	},
	{
        ID:       4,
        Label:    "Watermelon",
        Selected: true,
	},
}
result, err := ask.Run()
fmt.Println(result, err)

Checkbox

ask := prompt.NewCheckbox()
ask.Question = "[?] Choose what you want:"
ask.Choices = []*prompt.Choice{
	{
        Label:       "List",
        IsSeparator: true,
	},
	{
        ID:    1,
        Label: "Apple",
	},
	{
        ID:       2,
        Label:    "Tomato",
        Selected: true,
	},
}
result, err := ask.Run()
fmt.Println(result, err)

Examples

You can find examples on the github repository

TODOS

  • Add custom validation for input type
  • Add password field type
  • Write tests
  • Add auto-complete type

License

MIT License

Copyright (c) 2016 Julien Roland

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Display

func Display(msg string)

func DisplayBlack

func DisplayBlack(msg string)

func DisplayBlue

func DisplayBlue(msg string)

func DisplayCyan

func DisplayCyan(msg string)

func DisplayGreen

func DisplayGreen(msg string)

func DisplayGrey

func DisplayGrey(msg string)

func DisplayMajenta

func DisplayMajenta(msg string)

func DisplayRed

func DisplayRed(msg string)

func DisplayWhite

func DisplayWhite(msg string)

func DisplayYellow

func DisplayYellow(msg string)

Types

type App

type App struct {
	Pointer       int
	SavedPointers []int

	EntryCount int

	KeyboardConfig KeyboardConfig
	Width          int
	Height         int
	// contains filtered or unexported fields
}

func NewApp

func NewApp() *App

func (*App) Renderer

func (app *App) Renderer(buffer func())

func (*App) Run

func (app *App) Run()

type Choice

type Choice struct {
	ID      int
	Label   string
	Type    string
	Pointer int
}

type KeyboardConfig

type KeyboardConfig struct {
	ValidateKey       []string
	SelectKey         []string
	UpNavigationKey   []string
	DownNavigationKey []string
	Cancelkey         []string
}

Source Files

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL