Repository: segmentio/go-prompt
Branch: master
Commit: f0d19b6901ad
Files: 8
Total size: 3.5 KB
Directory structure:
gitextract_r8jliluu/
├── History.md
├── Readme.md
├── examples/
│ ├── confirm.go
│ ├── list.go
│ ├── passwords.go
│ ├── string-required.go
│ └── string.go
└── prompt.go
================================================
FILE CONTENTS
================================================
================================================
FILE: History.md
================================================
v1.2.0 / 2014-12-10
===================
* remove appending of ? to Confirm()
v1.1.0 / 2014-10-22
==================
* add passwords example
* add password docs
* Merge pull request #2 from nrmitchi/add/gopass
* Adding convenience wrappers around howeyc/gopass
================================================
FILE: Readme.md
================================================
# go-prompt
Terminal prompts for Go.
View the [docs](http://godoc.org/pkg/github.com/segmentio/go-prompt).
## Example
```go
package main
import "github.com/segmentio/go-prompt"
var langs = []string{
"c",
"c++",
"lua",
"go",
"js",
"ruby",
"python",
}
func main() {
i := prompt.Choose("What's your favorite language?", langs)
println("picked: " + langs[i])
}
```
## License
MIT
================================================
FILE: examples/confirm.go
================================================
package main
import prompt "github.com/segmentio/go-prompt"
func main() {
if ok := prompt.Confirm("launch %s?", "something"); ok {
println("launching")
} else {
println("not launching")
}
}
================================================
FILE: examples/list.go
================================================
package main
import prompt "github.com/segmentio/go-prompt"
var langs = []string{
"c",
"c++",
"lua",
"go",
"js",
"ruby",
"python",
}
func main() {
i := prompt.Choose("What's your favorite language?", langs)
println("picked: " + langs[i])
}
================================================
FILE: examples/passwords.go
================================================
package main
import prompt "github.com/segmentio/go-prompt"
func main() {
{
name := "Tobi"
pass := prompt.Password("hi %s enter your password", name)
println(pass)
}
{
pass := prompt.PasswordMasked("masked passwords are cool")
println(pass)
}
}
================================================
FILE: examples/string-required.go
================================================
package main
import (
"fmt"
prompt "github.com/segmentio/go-prompt"
)
func main() {
println("need your name!")
first := prompt.StringRequired("first")
last := prompt.StringRequired("last")
fmt.Printf("\nHello %s %s\n", first, last)
}
================================================
FILE: examples/string.go
================================================
package main
import (
"fmt"
prompt "github.com/segmentio/go-prompt"
)
func main() {
println("need your name!")
first := prompt.String("first")
last := prompt.String("last")
fmt.Printf("\nHello %s %s\n", first, last)
}
================================================
FILE: prompt.go
================================================
package prompt
import "github.com/howeyc/gopass"
import "strings"
import "strconv"
import "fmt"
// String prompt.
func String(prompt string, args ...interface{}) string {
var s string
fmt.Printf(prompt+": ", args...)
fmt.Scanln(&s)
return s
}
// String prompt (required).
func StringRequired(prompt string, args ...interface{}) (s string) {
for strings.Trim(s, " ") == "" {
s = String(prompt, args...)
}
return s
}
// Confirm continues prompting until the input is boolean-ish.
func Confirm(prompt string, args ...interface{}) bool {
for {
switch String(prompt, args...) {
case "Yes", "yes", "y", "Y":
return true
case "No", "no", "n", "N":
return false
}
}
}
// Choose prompts for a single selection from `list`, returning in the index.
func Choose(prompt string, list []string) int {
fmt.Println()
for i, val := range list {
fmt.Printf(" %d) %s\n", i+1, val)
}
fmt.Println()
i := -1
for {
s := String(prompt)
// index
n, err := strconv.Atoi(s)
if err == nil {
if n > 0 && n <= len(list) {
i = n - 1
break
} else {
continue
}
}
// value
i = indexOf(s, list)
if i != -1 {
break
}
}
return i
}
// Password prompt.
func Password(prompt string, args ...interface{}) string {
fmt.Printf(prompt+": ", args...)
password, _ := gopass.GetPasswd()
s := string(password[0:])
return s
}
// Password prompt with mask.
func PasswordMasked(prompt string, args ...interface{}) string {
fmt.Printf(prompt+": ", args...)
password, _ := gopass.GetPasswdMasked()
s := string(password[0:])
return s
}
// index of `s` in `list`.
func indexOf(s string, list []string) int {
for i, val := range list {
if val == s {
return i
}
}
return -1
}
gitextract_r8jliluu/ ├── History.md ├── Readme.md ├── examples/ │ ├── confirm.go │ ├── list.go │ ├── passwords.go │ ├── string-required.go │ └── string.go └── prompt.go
SYMBOL INDEX (12 symbols across 6 files)
FILE: examples/confirm.go
function main (line 5) | func main() {
FILE: examples/list.go
function main (line 15) | func main() {
FILE: examples/passwords.go
function main (line 5) | func main() {
FILE: examples/string-required.go
function main (line 9) | func main() {
FILE: examples/string.go
function main (line 9) | func main() {
FILE: prompt.go
function String (line 9) | func String(prompt string, args ...interface{}) string {
function StringRequired (line 17) | func StringRequired(prompt string, args ...interface{}) (s string) {
function Confirm (line 25) | func Confirm(prompt string, args ...interface{}) bool {
function Choose (line 37) | func Choose(prompt string, list []string) int {
function Password (line 71) | func Password(prompt string, args ...interface{}) string {
function PasswordMasked (line 79) | func PasswordMasked(prompt string, args ...interface{}) string {
function indexOf (line 87) | func indexOf(s string, list []string) int {
Condensed preview — 8 files, each showing path, character count, and a content snippet. Download the .json file or copy for the full structured content (4K chars).
[
{
"path": "History.md",
"chars": 270,
"preview": "\nv1.2.0 / 2014-12-10\n===================\n\n * remove appending of ? to Confirm()\n\nv1.1.0 / 2014-10-22\n=================="
},
{
"path": "Readme.md",
"chars": 406,
"preview": "\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## Exam"
},
{
"path": "examples/confirm.go",
"chars": 199,
"preview": "package main\n\nimport prompt \"github.com/segmentio/go-prompt\"\n\nfunc main() {\n\tif ok := prompt.Confirm(\"launch %s?\", \"some"
},
{
"path": "examples/list.go",
"chars": 252,
"preview": "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"
},
{
"path": "examples/passwords.go",
"chars": 262,
"preview": "package main\n\nimport prompt \"github.com/segmentio/go-prompt\"\n\nfunc main() {\n\t{\n\t\tname := \"Tobi\"\n\t\tpass := prompt.Passwor"
},
{
"path": "examples/string-required.go",
"chars": 243,
"preview": "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\tfi"
},
{
"path": "examples/string.go",
"chars": 227,
"preview": "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\tfi"
},
{
"path": "prompt.go",
"chars": 1727,
"preview": "package prompt\n\nimport \"github.com/howeyc/gopass\"\nimport \"strings\"\nimport \"strconv\"\nimport \"fmt\"\n\n// String prompt.\nfunc"
}
]
About this extraction
This page contains the full source code of the segmentio/go-prompt GitHub repository, extracted and formatted as plain text for AI agents and large language models (LLMs). The extraction includes 8 files (3.5 KB), approximately 1.2k tokens, and a symbol index with 12 extracted functions, classes, methods, constants, and types. Use this with OpenClaw, Claude, ChatGPT, Cursor, Windsurf, or any other AI tool that accepts text input. You can copy the full output to your clipboard or download it as a .txt file.
Extracted by GitExtract — free GitHub repo to text converter for AI. Built by Nikandr Surkov.