[
  {
    "path": "History.md",
    "content": "\nv1.2.0 / 2014-12-10\n===================\n\n  * remove appending of ? to Confirm()\n\nv1.1.0 / 2014-10-22\n==================\n\n * add passwords example\n * add password docs\n * Merge pull request #2 from nrmitchi/add/gopass\n * Adding convenience wrappers around howeyc/gopass\n"
  },
  {
    "path": "Readme.md",
    "content": "\n# go-prompt\n\n Terminal prompts for Go.\n\n View the [docs](http://godoc.org/pkg/github.com/segmentio/go-prompt).\n\n## Example\n\n```go\npackage main\n\nimport \"github.com/segmentio/go-prompt\"\n\nvar langs = []string{\n  \"c\",\n  \"c++\",\n  \"lua\",\n  \"go\",\n  \"js\",\n  \"ruby\",\n  \"python\",\n}\n\nfunc main() {\n  i := prompt.Choose(\"What's your favorite language?\", langs)\n  println(\"picked: \" + langs[i])\n}\n```\n\n## License\n\n MIT"
  },
  {
    "path": "examples/confirm.go",
    "content": "package main\n\nimport prompt \"github.com/segmentio/go-prompt\"\n\nfunc main() {\n\tif ok := prompt.Confirm(\"launch %s?\", \"something\"); ok {\n\t\tprintln(\"launching\")\n\t} else {\n\t\tprintln(\"not launching\")\n\t}\n}\n"
  },
  {
    "path": "examples/list.go",
    "content": "package main\n\nimport prompt \"github.com/segmentio/go-prompt\"\n\nvar langs = []string{\n\t\"c\",\n\t\"c++\",\n\t\"lua\",\n\t\"go\",\n\t\"js\",\n\t\"ruby\",\n\t\"python\",\n}\n\nfunc main() {\n\ti := prompt.Choose(\"What's your favorite language?\", langs)\n\tprintln(\"picked: \" + langs[i])\n}\n"
  },
  {
    "path": "examples/passwords.go",
    "content": "package main\n\nimport prompt \"github.com/segmentio/go-prompt\"\n\nfunc main() {\n\t{\n\t\tname := \"Tobi\"\n\t\tpass := prompt.Password(\"hi %s enter your password\", name)\n\t\tprintln(pass)\n\t}\n\n\t{\n\t\tpass := prompt.PasswordMasked(\"masked passwords are cool\")\n\t\tprintln(pass)\n\t}\n}\n"
  },
  {
    "path": "examples/string-required.go",
    "content": "package main\n\nimport (\n\t\"fmt\"\n\n\tprompt \"github.com/segmentio/go-prompt\"\n)\n\nfunc main() {\n\tprintln(\"need your name!\")\n\tfirst := prompt.StringRequired(\"first\")\n\tlast := prompt.StringRequired(\"last\")\n\tfmt.Printf(\"\\nHello %s %s\\n\", first, last)\n}\n"
  },
  {
    "path": "examples/string.go",
    "content": "package main\n\nimport (\n\t\"fmt\"\n\n\tprompt \"github.com/segmentio/go-prompt\"\n)\n\nfunc main() {\n\tprintln(\"need your name!\")\n\tfirst := prompt.String(\"first\")\n\tlast := prompt.String(\"last\")\n\tfmt.Printf(\"\\nHello %s %s\\n\", first, last)\n}\n"
  },
  {
    "path": "prompt.go",
    "content": "package prompt\n\nimport \"github.com/howeyc/gopass\"\nimport \"strings\"\nimport \"strconv\"\nimport \"fmt\"\n\n// String prompt.\nfunc String(prompt string, args ...interface{}) string {\n\tvar s string\n\tfmt.Printf(prompt+\": \", args...)\n\tfmt.Scanln(&s)\n\treturn s\n}\n\n// String prompt (required).\nfunc StringRequired(prompt string, args ...interface{}) (s string) {\n\tfor strings.Trim(s, \" \") == \"\" {\n\t\ts = String(prompt, args...)\n\t}\n\treturn s\n}\n\n// Confirm continues prompting until the input is boolean-ish.\nfunc Confirm(prompt string, args ...interface{}) bool {\n\tfor {\n\t\tswitch String(prompt, args...) {\n\t\tcase \"Yes\", \"yes\", \"y\", \"Y\":\n\t\t\treturn true\n\t\tcase \"No\", \"no\", \"n\", \"N\":\n\t\t\treturn false\n\t\t}\n\t}\n}\n\n// Choose prompts for a single selection from `list`, returning in the index.\nfunc Choose(prompt string, list []string) int {\n\tfmt.Println()\n\tfor i, val := range list {\n\t\tfmt.Printf(\"  %d) %s\\n\", i+1, val)\n\t}\n\n\tfmt.Println()\n\ti := -1\n\n\tfor {\n\t\ts := String(prompt)\n\n\t\t// index\n\t\tn, err := strconv.Atoi(s)\n\t\tif err == nil {\n\t\t\tif n > 0 && n <= len(list) {\n\t\t\t\ti = n - 1\n\t\t\t\tbreak\n\t\t\t} else {\n\t\t\t\tcontinue\n\t\t\t}\n\t\t}\n\n\t\t// value\n\t\ti = indexOf(s, list)\n\t\tif i != -1 {\n\t\t\tbreak\n\t\t}\n\t}\n\n\treturn i\n}\n\n// Password prompt.\nfunc Password(prompt string, args ...interface{}) string {\n\tfmt.Printf(prompt+\": \", args...)\n\tpassword, _ := gopass.GetPasswd()\n\ts := string(password[0:])\n\treturn s\n}\n\n// Password prompt with mask.\nfunc PasswordMasked(prompt string, args ...interface{}) string {\n\tfmt.Printf(prompt+\": \", args...)\n\tpassword, _ := gopass.GetPasswdMasked()\n\ts := string(password[0:])\n\treturn s\n}\n\n// index of `s` in `list`.\nfunc indexOf(s string, list []string) int {\n\tfor i, val := range list {\n\t\tif val == s {\n\t\t\treturn i\n\t\t}\n\t}\n\treturn -1\n}\n"
  }
]