Skip to content
/ copro Public

Go package which add some basic interactive console user interfaces

License

Notifications You must be signed in to change notification settings

juxR/copro

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

35 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

A quick overview how simple is to use copro

go get -u github.com/julienroland/copro/prompt
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)
}
ask := prompt.NewInput()
ask.Question = "What's your name"
name, _ := ask.Run()
fmt.Println(name)
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)
ask := prompt.NewConfirm()
ask.Question = "Are you a gopher"
ask.Default = "yes"
result := ask.Run()
fmt.Println(result)
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)
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)

You can find examples on the github repository

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

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.

About

Go package which add some basic interactive console user interfaces

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Languages