mirror of
https://github.com/Threnklyn/jira.git
synced 2026-06-07 13:33:32 +02:00
running dep prune
This commit is contained in:
-46
@@ -1,46 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"gopkg.in/AlecAivazis/survey.v1"
|
||||
)
|
||||
|
||||
// the questions to ask
|
||||
var simpleQs = []*survey.Question{
|
||||
{
|
||||
Name: "letter",
|
||||
Prompt: &survey.Select{
|
||||
Message: "Choose a letter:",
|
||||
Options: []string{
|
||||
"a",
|
||||
"b",
|
||||
"c",
|
||||
"d",
|
||||
"e",
|
||||
"f",
|
||||
"g",
|
||||
"h",
|
||||
"i",
|
||||
"j",
|
||||
},
|
||||
},
|
||||
Validate: survey.Required,
|
||||
},
|
||||
}
|
||||
|
||||
func main() {
|
||||
answers := struct {
|
||||
Letter string
|
||||
}{}
|
||||
|
||||
// ask the question
|
||||
err := survey.Ask(simpleQs, &answers)
|
||||
|
||||
if err != nil {
|
||||
fmt.Println(err.Error())
|
||||
return
|
||||
}
|
||||
// print the answers
|
||||
fmt.Printf("you chose %s.\n", answers.Letter)
|
||||
}
|
||||
-40
@@ -1,40 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"gopkg.in/AlecAivazis/survey.v1"
|
||||
)
|
||||
|
||||
// the questions to ask
|
||||
var simpleQs = []*survey.Question{
|
||||
{
|
||||
Name: "name",
|
||||
Prompt: &survey.Input{
|
||||
Message: "What is your name?",
|
||||
},
|
||||
Validate: survey.Required,
|
||||
},
|
||||
{
|
||||
Name: "color",
|
||||
Prompt: &survey.Select{
|
||||
Message: "Choose a color:",
|
||||
Options: []string{"red", "blue", "green"},
|
||||
},
|
||||
Validate: survey.Required,
|
||||
},
|
||||
}
|
||||
|
||||
func main() {
|
||||
ansmap := make(map[string]string)
|
||||
|
||||
// ask the question
|
||||
err := survey.Ask(simpleQs, &ansmap)
|
||||
|
||||
if err != nil {
|
||||
fmt.Println(err.Error())
|
||||
return
|
||||
}
|
||||
// print the answers
|
||||
fmt.Printf("%s chose %s.\n", ansmap["name"], ansmap["color"])
|
||||
}
|
||||
-43
@@ -1,43 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"gopkg.in/AlecAivazis/survey.v1"
|
||||
)
|
||||
|
||||
// the questions to ask
|
||||
var simpleQs = []*survey.Question{
|
||||
{
|
||||
Name: "name",
|
||||
Prompt: &survey.Input{
|
||||
Message: "What is your name?",
|
||||
},
|
||||
Validate: survey.Required,
|
||||
},
|
||||
{
|
||||
Name: "color",
|
||||
Prompt: &survey.Select{
|
||||
Message: "Choose a color:",
|
||||
Options: []string{"red", "blue", "green"},
|
||||
},
|
||||
Validate: survey.Required,
|
||||
},
|
||||
}
|
||||
|
||||
func main() {
|
||||
answers := struct {
|
||||
Name string
|
||||
Color string
|
||||
}{}
|
||||
|
||||
// ask the question
|
||||
err := survey.Ask(simpleQs, &answers)
|
||||
|
||||
if err != nil {
|
||||
fmt.Println(err.Error())
|
||||
return
|
||||
}
|
||||
// print the answers
|
||||
fmt.Printf("%s chose %s.\n", answers.Name, answers.Color)
|
||||
}
|
||||
-41
@@ -1,41 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"gopkg.in/AlecAivazis/survey.v1"
|
||||
)
|
||||
|
||||
// the questions to ask
|
||||
var validationQs = []*survey.Question{
|
||||
{
|
||||
Name: "name",
|
||||
Prompt: &survey.Input{Message: "What is your name?"},
|
||||
Validate: survey.Required,
|
||||
},
|
||||
{
|
||||
Name: "valid",
|
||||
Prompt: &survey.Input{Message: "Enter 'foo':", Default: "not foo"},
|
||||
Validate: func(val interface{}) error {
|
||||
// if the input matches the expectation
|
||||
if str := val.(string); str != "foo" {
|
||||
return fmt.Errorf("You entered %s, not 'foo'.", str)
|
||||
}
|
||||
// nothing was wrong
|
||||
return nil
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
func main() {
|
||||
// the place to hold the answers
|
||||
answers := struct {
|
||||
Name string
|
||||
Valid string
|
||||
}{}
|
||||
err := survey.Ask(validationQs, &answers)
|
||||
|
||||
if err != nil {
|
||||
fmt.Println("\n", err.Error())
|
||||
}
|
||||
}
|
||||
-6
@@ -1,6 +0,0 @@
|
||||
# survey/tests
|
||||
|
||||
Because of the nature of this library, I was having a hard time finding a reliable
|
||||
way to run unit tests, therefore I decided to try to create a suite
|
||||
of integration tests which must be run successfully before a PR can be merged.
|
||||
I will try to add to this suite as new edge cases are known.
|
||||
-60
@@ -1,60 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"gopkg.in/AlecAivazis/survey.v1"
|
||||
)
|
||||
|
||||
// the questions to ask
|
||||
var simpleQs = []*survey.Question{
|
||||
{
|
||||
Name: "name",
|
||||
Prompt: &survey.Input{
|
||||
Message: "What is your name?",
|
||||
Default: "Johnny Appleseed",
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "color",
|
||||
Prompt: &survey.Select{
|
||||
Message: "Choose a color:",
|
||||
Options: []string{"red", "blue", "green", "yellow"},
|
||||
Default: "yellow",
|
||||
},
|
||||
Validate: survey.Required,
|
||||
},
|
||||
}
|
||||
|
||||
func main() {
|
||||
|
||||
fmt.Println("Asking many.")
|
||||
// a place to store the answers
|
||||
ans := struct {
|
||||
Name string
|
||||
Color string
|
||||
}{}
|
||||
err := survey.Ask(simpleQs, &ans)
|
||||
if err != nil {
|
||||
fmt.Println(err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Println("Asking one.")
|
||||
answer := ""
|
||||
err = survey.AskOne(simpleQs[0].Prompt, &answer, nil)
|
||||
if err != nil {
|
||||
fmt.Println(err.Error())
|
||||
return
|
||||
}
|
||||
fmt.Printf("Answered with %v.\n", answer)
|
||||
|
||||
fmt.Println("Asking one with validation.")
|
||||
vAns := ""
|
||||
err = survey.AskOne(&survey.Input{Message: "What is your name?"}, &vAns, survey.Required)
|
||||
if err != nil {
|
||||
fmt.Println(err.Error())
|
||||
return
|
||||
}
|
||||
fmt.Printf("Answered with %v.\n", vAns)
|
||||
}
|
||||
-180
@@ -1,180 +0,0 @@
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// DO NOT MODIFY THIS FILE!
|
||||
//
|
||||
// This file was automatically generated via the commands:
|
||||
//
|
||||
// go get github.com/coryb/autoplay
|
||||
// autoplay -n autoplay/ask.go go run ask.go
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
package main
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"fmt"
|
||||
"github.com/kr/pty"
|
||||
"os"
|
||||
"os/exec"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
const (
|
||||
RED = "\033[31m"
|
||||
RESET = "\033[0m"
|
||||
)
|
||||
|
||||
func main() {
|
||||
fh, tty, _ := pty.Open()
|
||||
defer tty.Close()
|
||||
defer fh.Close()
|
||||
c := exec.Command("go", "run", "ask.go")
|
||||
c.Stdin = tty
|
||||
c.Stdout = tty
|
||||
c.Stderr = tty
|
||||
c.Start()
|
||||
buf := bufio.NewReaderSize(fh, 1024)
|
||||
|
||||
expect("Asking many.\r\n", buf)
|
||||
expect("\x1b[0G\x1b[2K\x1b[1;92m? \x1b[0m\x1b[1;99mWhat is your name? \x1b[0m\x1b[37m(Johnny Appleseed) \x1b[0m", buf)
|
||||
fh.Write([]byte("L"))
|
||||
expect("L", buf)
|
||||
fh.Write([]byte("a"))
|
||||
expect("a", buf)
|
||||
fh.Write([]byte("r"))
|
||||
expect("r", buf)
|
||||
fh.Write([]byte("r"))
|
||||
expect("r", buf)
|
||||
fh.Write([]byte("y"))
|
||||
expect("y", buf)
|
||||
fh.Write([]byte(" "))
|
||||
expect(" ", buf)
|
||||
fh.Write([]byte("B"))
|
||||
expect("B", buf)
|
||||
fh.Write([]byte("i"))
|
||||
expect("i", buf)
|
||||
fh.Write([]byte("r"))
|
||||
expect("r", buf)
|
||||
fh.Write([]byte("d"))
|
||||
expect("d", buf)
|
||||
fh.Write([]byte("\r"))
|
||||
expect("\r\r\n", buf)
|
||||
expect("\x1b[1F\x1b[0G\x1b[2K\x1b[1;92m? \x1b[0m\x1b[1;99mWhat is your name? \x1b[0m\x1b[36mLarry Bird\x1b[0m\r\n", buf)
|
||||
expect("\x1b[0G\x1b[2K\x1b[1;92m? \x1b[0m\x1b[1;99mChoose a color:\x1b[0m\r\n", buf)
|
||||
expect("\x1b[1;99m red\x1b[0m\r\n", buf)
|
||||
expect("\x1b[1;99m blue\x1b[0m\r\n", buf)
|
||||
expect("\x1b[1;99m green\x1b[0m\r\n", buf)
|
||||
expect("\x1b[1;36m❯ yellow\x1b[0m\r\n", buf)
|
||||
expect("\x1b[?25l", buf)
|
||||
fh.Write([]byte("\x1b"))
|
||||
fh.Write([]byte("["))
|
||||
fh.Write([]byte("A"))
|
||||
expect("\x1b[0G\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1;92m? \x1b[0m\x1b[1;99mChoose a color:\x1b[0m\r\n", buf)
|
||||
expect("\x1b[1;99m red\x1b[0m\r\n", buf)
|
||||
expect("\x1b[1;99m blue\x1b[0m\r\n", buf)
|
||||
expect("\x1b[1;36m❯ green\x1b[0m\r\n", buf)
|
||||
expect("\x1b[1;99m yellow\x1b[0m\r\n", buf)
|
||||
fh.Write([]byte("\x1b"))
|
||||
fh.Write([]byte("["))
|
||||
fh.Write([]byte("A"))
|
||||
expect("\x1b[0G\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1;92m? \x1b[0m\x1b[1;99mChoose a color:\x1b[0m\r\n", buf)
|
||||
expect("\x1b[1;99m red\x1b[0m\r\n", buf)
|
||||
expect("\x1b[1;36m❯ blue\x1b[0m\r\n", buf)
|
||||
expect("\x1b[1;99m green\x1b[0m\r\n", buf)
|
||||
expect("\x1b[1;99m yellow\x1b[0m\r\n", buf)
|
||||
fh.Write([]byte("\r"))
|
||||
expect("\x1b[?25h\x1b[0G\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1;92m? \x1b[0m\x1b[1;99mChoose a color:\x1b[0m\x1b[36m blue\x1b[0m\r\n", buf)
|
||||
expect("Asking one.\r\n", buf)
|
||||
expect("\x1b[0G\x1b[2K\x1b[1F\x1b[2K\x1b[1;92m? \x1b[0m\x1b[1;99mWhat is your name? \x1b[0m\x1b[37m(Johnny Appleseed) \x1b[0m", buf)
|
||||
fh.Write([]byte("L"))
|
||||
expect("L", buf)
|
||||
fh.Write([]byte("a"))
|
||||
expect("a", buf)
|
||||
fh.Write([]byte("r"))
|
||||
expect("r", buf)
|
||||
fh.Write([]byte("r"))
|
||||
expect("r", buf)
|
||||
fh.Write([]byte("y"))
|
||||
expect("y", buf)
|
||||
fh.Write([]byte(" "))
|
||||
expect(" ", buf)
|
||||
fh.Write([]byte("K"))
|
||||
expect("K", buf)
|
||||
fh.Write([]byte("i"))
|
||||
expect("i", buf)
|
||||
fh.Write([]byte("n"))
|
||||
expect("n", buf)
|
||||
fh.Write([]byte("g"))
|
||||
expect("g", buf)
|
||||
fh.Write([]byte("\r"))
|
||||
expect("\r\r\n", buf)
|
||||
expect("\x1b[1F\x1b[0G\x1b[2K\x1b[1;92m? \x1b[0m\x1b[1;99mWhat is your name? \x1b[0m\x1b[36mLarry King\x1b[0m\r\n", buf)
|
||||
expect("Answered with Larry King.\r\n", buf)
|
||||
expect("Asking one with validation.\r\n", buf)
|
||||
expect("\x1b[0G\x1b[2K\x1b[1;92m? \x1b[0m\x1b[1;99mWhat is your name? \x1b[0m", buf)
|
||||
fh.Write([]byte("\r"))
|
||||
expect("\r\r\n", buf)
|
||||
expect("\x1b[1F\x1b[0G\x1b[2K\x1b[31m✘ Sorry, your reply was invalid: Value is required\x1b[0m\r\n", buf)
|
||||
expect("\x1b[0G\x1b[2K\x1b[1;92m? \x1b[0m\x1b[1;99mWhat is your name? \x1b[0m", buf)
|
||||
fh.Write([]byte("L"))
|
||||
expect("L", buf)
|
||||
fh.Write([]byte("a"))
|
||||
expect("a", buf)
|
||||
fh.Write([]byte("r"))
|
||||
expect("r", buf)
|
||||
fh.Write([]byte("r"))
|
||||
expect("r", buf)
|
||||
fh.Write([]byte("y"))
|
||||
expect("y", buf)
|
||||
fh.Write([]byte(" "))
|
||||
expect(" ", buf)
|
||||
fh.Write([]byte("W"))
|
||||
expect("W", buf)
|
||||
fh.Write([]byte("a"))
|
||||
expect("a", buf)
|
||||
fh.Write([]byte("l"))
|
||||
expect("l", buf)
|
||||
fh.Write([]byte("l"))
|
||||
expect("l", buf)
|
||||
fh.Write([]byte("\r"))
|
||||
expect("\r\r\n", buf)
|
||||
expect("\x1b[1F\x1b[0G\x1b[2K\x1b[1;92m? \x1b[0m\x1b[1;99mWhat is your name? \x1b[0m\x1b[36mLarry Wall\x1b[0m\r\n", buf)
|
||||
expect("Answered with Larry Wall.\r\n", buf)
|
||||
|
||||
c.Wait()
|
||||
tty.Close()
|
||||
fh.Close()
|
||||
}
|
||||
|
||||
func expect(expected string, buf *bufio.Reader) {
|
||||
sofar := []rune{}
|
||||
for _, r := range expected {
|
||||
got, _, _ := buf.ReadRune()
|
||||
sofar = append(sofar, got)
|
||||
if got != r {
|
||||
fmt.Fprintln(os.Stderr, RESET)
|
||||
|
||||
// we want to quote the string but we also want to make the unexpected character RED
|
||||
// so we use the strconv.Quote function but trim off the quoted characters so we can
|
||||
// merge multiple quoted strings into one.
|
||||
expStart := strings.TrimSuffix(strconv.Quote(expected[:len(sofar)-1]), "\"")
|
||||
expMiss := strings.TrimSuffix(strings.TrimPrefix(strconv.Quote(string(expected[len(sofar)-1])), "\""), "\"")
|
||||
expEnd := strings.TrimPrefix(strconv.Quote(expected[len(sofar):]), "\"")
|
||||
|
||||
fmt.Fprintf(os.Stderr, "Expected: %s%s%s%s%s\n", expStart, RED, expMiss, RESET, expEnd)
|
||||
|
||||
// read the rest of the buffer
|
||||
p := make([]byte, buf.Buffered())
|
||||
buf.Read(p)
|
||||
|
||||
gotStart := strings.TrimSuffix(strconv.Quote(string(sofar[:len(sofar)-1])), "\"")
|
||||
gotMiss := strings.TrimSuffix(strings.TrimPrefix(strconv.Quote(string(sofar[len(sofar)-1])), "\""), "\"")
|
||||
gotEnd := strings.TrimPrefix(strconv.Quote(string(p)), "\"")
|
||||
|
||||
fmt.Fprintf(os.Stderr, "Got: %s%s%s%s%s\n", gotStart, RED, gotMiss, RESET, gotEnd)
|
||||
panic(fmt.Errorf("Unexpected Rune %q, Expected %q\n", got, r))
|
||||
} else {
|
||||
fmt.Printf("%c", r)
|
||||
}
|
||||
}
|
||||
}
|
||||
-132
@@ -1,132 +0,0 @@
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// DO NOT MODIFY THIS FILE!
|
||||
//
|
||||
// This file was automatically generated via the commands:
|
||||
//
|
||||
// go get github.com/coryb/autoplay
|
||||
// autoplay -n autoplay/confirm.go go run confirm.go
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
package main
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"fmt"
|
||||
"github.com/kr/pty"
|
||||
"os"
|
||||
"os/exec"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
const (
|
||||
RED = "\033[31m"
|
||||
RESET = "\033[0m"
|
||||
)
|
||||
|
||||
func main() {
|
||||
fh, tty, _ := pty.Open()
|
||||
defer tty.Close()
|
||||
defer fh.Close()
|
||||
c := exec.Command("go", "run", "confirm.go")
|
||||
c.Stdin = tty
|
||||
c.Stdout = tty
|
||||
c.Stderr = tty
|
||||
c.Start()
|
||||
buf := bufio.NewReaderSize(fh, 1024)
|
||||
|
||||
expect("Enter 'yes'\r\n", buf)
|
||||
expect("\x1b[0G\x1b[2K\x1b[1;92m? \x1b[0m\x1b[1;99myes: \x1b[0m\x1b[37m(y/N) \x1b[0m", buf)
|
||||
fh.Write([]byte("y"))
|
||||
expect("y", buf)
|
||||
fh.Write([]byte("e"))
|
||||
expect("e", buf)
|
||||
fh.Write([]byte("s"))
|
||||
expect("s", buf)
|
||||
fh.Write([]byte("\r"))
|
||||
expect("\r\r\n", buf)
|
||||
expect("\x1b[1F\x1b[0G\x1b[2K\x1b[1;92m? \x1b[0m\x1b[1;99myes: \x1b[0m\x1b[36mYes\x1b[0m\r\n", buf)
|
||||
expect("Answered true.\r\n", buf)
|
||||
expect("---------------------\r\n", buf)
|
||||
expect("Enter 'no'\r\n", buf)
|
||||
expect("\x1b[0G\x1b[2K\x1b[1;92m? \x1b[0m\x1b[1;99myes: \x1b[0m\x1b[37m(y/N) \x1b[0m", buf)
|
||||
fh.Write([]byte("n"))
|
||||
expect("n", buf)
|
||||
fh.Write([]byte("o"))
|
||||
expect("o", buf)
|
||||
fh.Write([]byte("\r"))
|
||||
expect("\r\r\n", buf)
|
||||
expect("\x1b[1F\x1b[0G\x1b[2K\x1b[1;92m? \x1b[0m\x1b[1;99myes: \x1b[0m\x1b[36mNo\x1b[0m\r\n", buf)
|
||||
expect("Answered false.\r\n", buf)
|
||||
expect("---------------------\r\n", buf)
|
||||
expect("default\r\n", buf)
|
||||
expect("\x1b[0G\x1b[2K\x1b[1;92m? \x1b[0m\x1b[1;99myes: \x1b[0m\x1b[37m(Y/n) \x1b[0m", buf)
|
||||
fh.Write([]byte("\r"))
|
||||
expect("\r\r\n", buf)
|
||||
expect("\x1b[1F\x1b[0G\x1b[2K\x1b[1;92m? \x1b[0m\x1b[1;99myes: \x1b[0m\x1b[36mYes\x1b[0m\r\n", buf)
|
||||
expect("Answered true.\r\n", buf)
|
||||
expect("---------------------\r\n", buf)
|
||||
expect("not recognized (enter random letter)\r\n", buf)
|
||||
expect("\x1b[0G\x1b[2K\x1b[1;92m? \x1b[0m\x1b[1;99myes: \x1b[0m\x1b[37m(Y/n) \x1b[0m", buf)
|
||||
fh.Write([]byte("x"))
|
||||
expect("x", buf)
|
||||
fh.Write([]byte("\r"))
|
||||
expect("\r\r\n", buf)
|
||||
expect("\x1b[1F\x1b[0G\x1b[2K\x1b[31m✘ Sorry, your reply was invalid: \"x\" is not a valid answer, please try again.\x1b[0m\r\n", buf)
|
||||
expect("\x1b[0G\x1b[2K\x1b[1;92m? \x1b[0m\x1b[1;99myes: \x1b[0m\x1b[37m(Y/n) \x1b[0m", buf)
|
||||
fh.Write([]byte("\r"))
|
||||
expect("\r\r\n", buf)
|
||||
expect("\x1b[1F\x1b[0G\x1b[2K\x1b[1;92m? \x1b[0m\x1b[1;99myes: \x1b[0m\x1b[36mYes\x1b[0m\r\n", buf)
|
||||
expect("Answered true.\r\n", buf)
|
||||
expect("---------------------\r\n", buf)
|
||||
expect("no help - type '?'\r\n", buf)
|
||||
expect("\x1b[0G\x1b[2K\x1b[1;92m? \x1b[0m\x1b[1;99myes: \x1b[0m\x1b[37m(Y/n) \x1b[0m", buf)
|
||||
fh.Write([]byte("?"))
|
||||
expect("?", buf)
|
||||
fh.Write([]byte("\r"))
|
||||
expect("\r\r\n", buf)
|
||||
expect("\x1b[1F\x1b[0G\x1b[2K\x1b[31m✘ Sorry, your reply was invalid: \"?\" is not a valid answer, please try again.\x1b[0m\r\n", buf)
|
||||
expect("\x1b[0G\x1b[2K\x1b[1;92m? \x1b[0m\x1b[1;99myes: \x1b[0m\x1b[37m(Y/n) \x1b[0m", buf)
|
||||
fh.Write([]byte("\r"))
|
||||
expect("\r\r\n", buf)
|
||||
expect("\x1b[1F\x1b[0G\x1b[2K\x1b[1;92m? \x1b[0m\x1b[1;99myes: \x1b[0m\x1b[36mYes\x1b[0m\r\n", buf)
|
||||
expect("Answered true.\r\n", buf)
|
||||
expect("---------------------\r\n", buf)
|
||||
|
||||
c.Wait()
|
||||
tty.Close()
|
||||
fh.Close()
|
||||
}
|
||||
|
||||
func expect(expected string, buf *bufio.Reader) {
|
||||
sofar := []rune{}
|
||||
for _, r := range expected {
|
||||
got, _, _ := buf.ReadRune()
|
||||
sofar = append(sofar, got)
|
||||
if got != r {
|
||||
fmt.Fprintln(os.Stderr, RESET)
|
||||
|
||||
// we want to quote the string but we also want to make the unexpected character RED
|
||||
// so we use the strconv.Quote function but trim off the quoted characters so we can
|
||||
// merge multiple quoted strings into one.
|
||||
expStart := strings.TrimSuffix(strconv.Quote(expected[:len(sofar)-1]), "\"")
|
||||
expMiss := strings.TrimSuffix(strings.TrimPrefix(strconv.Quote(string(expected[len(sofar)-1])), "\""), "\"")
|
||||
expEnd := strings.TrimPrefix(strconv.Quote(expected[len(sofar):]), "\"")
|
||||
|
||||
fmt.Fprintf(os.Stderr, "Expected: %s%s%s%s%s\n", expStart, RED, expMiss, RESET, expEnd)
|
||||
|
||||
// read the rest of the buffer
|
||||
p := make([]byte, buf.Buffered())
|
||||
buf.Read(p)
|
||||
|
||||
gotStart := strings.TrimSuffix(strconv.Quote(string(sofar[:len(sofar)-1])), "\"")
|
||||
gotMiss := strings.TrimSuffix(strings.TrimPrefix(strconv.Quote(string(sofar[len(sofar)-1])), "\""), "\"")
|
||||
gotEnd := strings.TrimPrefix(strconv.Quote(string(p)), "\"")
|
||||
|
||||
fmt.Fprintf(os.Stderr, "Got: %s%s%s%s%s\n", gotStart, RED, gotMiss, RESET, gotEnd)
|
||||
panic(fmt.Errorf("Unexpected Rune %q, Expected %q\n", got, r))
|
||||
} else {
|
||||
fmt.Printf("%c", r)
|
||||
}
|
||||
}
|
||||
}
|
||||
-104
@@ -1,104 +0,0 @@
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// DO NOT MODIFY THIS FILE!
|
||||
//
|
||||
// This file was automatically generated via the commands:
|
||||
//
|
||||
// go get github.com/coryb/autoplay
|
||||
// autoplay -n autoplay/doubleSelect.go go run doubleSelect.go
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
package main
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"fmt"
|
||||
"github.com/kr/pty"
|
||||
"os"
|
||||
"os/exec"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
const (
|
||||
RED = "\033[31m"
|
||||
RESET = "\033[0m"
|
||||
)
|
||||
|
||||
func main() {
|
||||
fh, tty, _ := pty.Open()
|
||||
defer tty.Close()
|
||||
defer fh.Close()
|
||||
c := exec.Command("go", "run", "doubleSelect.go")
|
||||
c.Stdin = tty
|
||||
c.Stdout = tty
|
||||
c.Stderr = tty
|
||||
c.Start()
|
||||
buf := bufio.NewReaderSize(fh, 1024)
|
||||
|
||||
expect("\x1b[0G\x1b[2K\x1b[1;92m? \x1b[0m\x1b[1;99mselect1:\x1b[0m\r\n", buf)
|
||||
expect("\x1b[1;36m❯ red\x1b[0m\r\n", buf)
|
||||
expect("\x1b[1;99m blue\x1b[0m\r\n", buf)
|
||||
expect("\x1b[1;99m green\x1b[0m\r\n", buf)
|
||||
expect("\x1b[?25l", buf)
|
||||
fh.Write([]byte("\x1b"))
|
||||
fh.Write([]byte("["))
|
||||
fh.Write([]byte("B"))
|
||||
expect("\x1b[0G\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1;92m? \x1b[0m\x1b[1;99mselect1:\x1b[0m\r\n", buf)
|
||||
expect("\x1b[1;99m red\x1b[0m\r\n", buf)
|
||||
expect("\x1b[1;36m❯ blue\x1b[0m\r\n", buf)
|
||||
expect("\x1b[1;99m green\x1b[0m\r\n", buf)
|
||||
fh.Write([]byte("\r"))
|
||||
expect("\x1b[?25h\x1b[0G\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1;92m? \x1b[0m\x1b[1;99mselect1:\x1b[0m\x1b[36m blue\x1b[0m\r\n", buf)
|
||||
expect("\x1b[0G\x1b[2K\x1b[1;92m? \x1b[0m\x1b[1;99mselect2:\x1b[0m\r\n", buf)
|
||||
expect("\x1b[1;36m❯ red\x1b[0m\r\n", buf)
|
||||
expect("\x1b[1;99m blue\x1b[0m\r\n", buf)
|
||||
expect("\x1b[1;99m green\x1b[0m\r\n", buf)
|
||||
expect("\x1b[?25l", buf)
|
||||
fh.Write([]byte("\x1b"))
|
||||
fh.Write([]byte("["))
|
||||
fh.Write([]byte("B"))
|
||||
expect("\x1b[0G\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1;92m? \x1b[0m\x1b[1;99mselect2:\x1b[0m\r\n", buf)
|
||||
expect("\x1b[1;99m red\x1b[0m\r\n", buf)
|
||||
expect("\x1b[1;36m❯ blue\x1b[0m\r\n", buf)
|
||||
expect("\x1b[1;99m green\x1b[0m\r\n", buf)
|
||||
fh.Write([]byte("\r"))
|
||||
expect("\x1b[?25h\x1b[0G\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1;92m? \x1b[0m\x1b[1;99mselect2:\x1b[0m\x1b[36m blue\x1b[0m\r\n", buf)
|
||||
expect("blue and blue.\r\n", buf)
|
||||
|
||||
c.Wait()
|
||||
tty.Close()
|
||||
fh.Close()
|
||||
}
|
||||
|
||||
func expect(expected string, buf *bufio.Reader) {
|
||||
sofar := []rune{}
|
||||
for _, r := range expected {
|
||||
got, _, _ := buf.ReadRune()
|
||||
sofar = append(sofar, got)
|
||||
if got != r {
|
||||
fmt.Fprintln(os.Stderr, RESET)
|
||||
|
||||
// we want to quote the string but we also want to make the unexpected character RED
|
||||
// so we use the strconv.Quote function but trim off the quoted characters so we can
|
||||
// merge multiple quoted strings into one.
|
||||
expStart := strings.TrimSuffix(strconv.Quote(expected[:len(sofar)-1]), "\"")
|
||||
expMiss := strings.TrimSuffix(strings.TrimPrefix(strconv.Quote(string(expected[len(sofar)-1])), "\""), "\"")
|
||||
expEnd := strings.TrimPrefix(strconv.Quote(expected[len(sofar):]), "\"")
|
||||
|
||||
fmt.Fprintf(os.Stderr, "Expected: %s%s%s%s%s\n", expStart, RED, expMiss, RESET, expEnd)
|
||||
|
||||
// read the rest of the buffer
|
||||
p := make([]byte, buf.Buffered())
|
||||
buf.Read(p)
|
||||
|
||||
gotStart := strings.TrimSuffix(strconv.Quote(string(sofar[:len(sofar)-1])), "\"")
|
||||
gotMiss := strings.TrimSuffix(strings.TrimPrefix(strconv.Quote(string(sofar[len(sofar)-1])), "\""), "\"")
|
||||
gotEnd := strings.TrimPrefix(strconv.Quote(string(p)), "\"")
|
||||
|
||||
fmt.Fprintf(os.Stderr, "Got: %s%s%s%s%s\n", gotStart, RED, gotMiss, RESET, gotEnd)
|
||||
panic(fmt.Errorf("Unexpected Rune %q, Expected %q\n", got, r))
|
||||
} else {
|
||||
fmt.Printf("%c", r)
|
||||
}
|
||||
}
|
||||
}
|
||||
-236
@@ -1,236 +0,0 @@
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// DO NOT MODIFY THIS FILE!
|
||||
//
|
||||
// This file was automatically generated via the commands:
|
||||
//
|
||||
// go get github.com/coryb/autoplay
|
||||
// autoplay -n autoplay/help.go go run help.go
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
package main
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"fmt"
|
||||
"github.com/kr/pty"
|
||||
"os"
|
||||
"os/exec"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
const (
|
||||
RED = "\033[31m"
|
||||
RESET = "\033[0m"
|
||||
)
|
||||
|
||||
func main() {
|
||||
fh, tty, _ := pty.Open()
|
||||
defer tty.Close()
|
||||
defer fh.Close()
|
||||
c := exec.Command("go", "run", "help.go")
|
||||
c.Stdin = tty
|
||||
c.Stdout = tty
|
||||
c.Stderr = tty
|
||||
c.Start()
|
||||
buf := bufio.NewReaderSize(fh, 1024)
|
||||
|
||||
expect("confirm\r\n", buf)
|
||||
expect("\x1b[0G\x1b[2K\x1b[1;92m? \x1b[0m\x1b[1;99mIs it raining? \x1b[0m\x1b[36m[? for help]\x1b[0m \x1b[37m(y/N) \x1b[0m", buf)
|
||||
fh.Write([]byte("?"))
|
||||
expect("?", buf)
|
||||
fh.Write([]byte("\r"))
|
||||
expect("\r\r\n", buf)
|
||||
expect("\x1b[1F\x1b[0G\x1b[2K\x1b[36mⓘ Go outside, if your head becomes wet the answer is probably 'yes'\x1b[0m\r\n", buf)
|
||||
expect("\x1b[1;92m? \x1b[0m\x1b[1;99mIs it raining? \x1b[0m\x1b[37m(y/N) \x1b[0m", buf)
|
||||
fh.Write([]byte("y"))
|
||||
expect("y", buf)
|
||||
fh.Write([]byte("e"))
|
||||
expect("e", buf)
|
||||
fh.Write([]byte("s"))
|
||||
expect("s", buf)
|
||||
fh.Write([]byte("\r"))
|
||||
expect("\r\r\n", buf)
|
||||
expect("\x1b[1F\x1b[0G\x1b[2K\x1b[1F\x1b[2K\x1b[1;92m? \x1b[0m\x1b[1;99mIs it raining? \x1b[0m\x1b[36mYes\x1b[0m\r\n", buf)
|
||||
expect("Answered true.\r\n", buf)
|
||||
expect("---------------------\r\n", buf)
|
||||
expect("input\r\n", buf)
|
||||
expect("\x1b[0G\x1b[2K\x1b[1;92m? \x1b[0m\x1b[1;99mWhat is your phone number: \x1b[0m\x1b[36m[? for help]\x1b[0m ", buf)
|
||||
fh.Write([]byte("?"))
|
||||
expect("?", buf)
|
||||
fh.Write([]byte("\r"))
|
||||
expect("\r\r\n", buf)
|
||||
expect("\x1b[1F\x1b[0G\x1b[2K\x1b[36mⓘ Phone number should include the area code, parentheses optional\x1b[0m\r\n", buf)
|
||||
expect("\x1b[1;92m? \x1b[0m\x1b[1;99mWhat is your phone number: \x1b[0m", buf)
|
||||
fh.Write([]byte("1"))
|
||||
expect("1", buf)
|
||||
fh.Write([]byte("2"))
|
||||
expect("2", buf)
|
||||
fh.Write([]byte("3"))
|
||||
expect("3", buf)
|
||||
fh.Write([]byte("-"))
|
||||
expect("-", buf)
|
||||
fh.Write([]byte("1"))
|
||||
expect("1", buf)
|
||||
fh.Write([]byte("2"))
|
||||
expect("2", buf)
|
||||
fh.Write([]byte("3"))
|
||||
expect("3", buf)
|
||||
fh.Write([]byte("-"))
|
||||
expect("-", buf)
|
||||
fh.Write([]byte("1"))
|
||||
expect("1", buf)
|
||||
fh.Write([]byte("2"))
|
||||
expect("2", buf)
|
||||
fh.Write([]byte("3"))
|
||||
expect("3", buf)
|
||||
fh.Write([]byte("4"))
|
||||
expect("4", buf)
|
||||
fh.Write([]byte("\r"))
|
||||
expect("\r\r\n", buf)
|
||||
expect("\x1b[1F\x1b[0G\x1b[2K\x1b[1F\x1b[2K\x1b[1;92m? \x1b[0m\x1b[1;99mWhat is your phone number: \x1b[0m\x1b[36m123-123-1234\x1b[0m\r\n", buf)
|
||||
expect("Answered 123-123-1234.\r\n", buf)
|
||||
expect("---------------------\r\n", buf)
|
||||
expect("select\r\n", buf)
|
||||
expect("\x1b[?25l\x1b[0G\x1b[2K\x1b[1;92m? \x1b[0m\x1b[1;99mWhat days are you available:\x1b[0m \x1b[36m[? for help]\x1b[0m\r\n", buf)
|
||||
expect("\x1b[36m❯\x1b[0m\x1b[32m ◉ \x1b[0m Monday\r\n", buf)
|
||||
expect(" \x1b[32m ◉ \x1b[0m Tuesday\r\n", buf)
|
||||
expect(" \x1b[1;99m ◯ \x1b[0m Wednesday\r\n", buf)
|
||||
expect(" \x1b[32m ◉ \x1b[0m Thursday\r\n", buf)
|
||||
expect(" \x1b[32m ◉ \x1b[0m Friday\r\n", buf)
|
||||
fh.Write([]byte("?"))
|
||||
expect("\x1b[0G\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[36mⓘ We are closed weekends and avaibility is limited on Wednesday\x1b[0m\r\n", buf)
|
||||
expect("\x1b[1;92m? \x1b[0m\x1b[1;99mWhat days are you available:\x1b[0m\r\n", buf)
|
||||
expect("\x1b[36m❯\x1b[0m\x1b[32m ◉ \x1b[0m Monday\r\n", buf)
|
||||
expect(" \x1b[32m ◉ \x1b[0m Tuesday\r\n", buf)
|
||||
expect(" \x1b[1;99m ◯ \x1b[0m Wednesday\r\n", buf)
|
||||
expect(" \x1b[32m ◉ \x1b[0m Thursday\r\n", buf)
|
||||
expect(" \x1b[32m ◉ \x1b[0m Friday\r\n", buf)
|
||||
fh.Write([]byte("\x1b"))
|
||||
fh.Write([]byte("["))
|
||||
fh.Write([]byte("B"))
|
||||
expect("\x1b[0G\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[36mⓘ We are closed weekends and avaibility is limited on Wednesday\x1b[0m\r\n", buf)
|
||||
expect("\x1b[1;92m? \x1b[0m\x1b[1;99mWhat days are you available:\x1b[0m\r\n", buf)
|
||||
expect(" \x1b[32m ◉ \x1b[0m Monday\r\n", buf)
|
||||
expect("\x1b[36m❯\x1b[0m\x1b[32m ◉ \x1b[0m Tuesday\r\n", buf)
|
||||
expect(" \x1b[1;99m ◯ \x1b[0m Wednesday\r\n", buf)
|
||||
expect(" \x1b[32m ◉ \x1b[0m Thursday\r\n", buf)
|
||||
expect(" \x1b[32m ◉ \x1b[0m Friday\r\n", buf)
|
||||
fh.Write([]byte(" "))
|
||||
expect("\x1b[0G\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[36mⓘ We are closed weekends and avaibility is limited on Wednesday\x1b[0m\r\n", buf)
|
||||
expect("\x1b[1;92m? \x1b[0m\x1b[1;99mWhat days are you available:\x1b[0m\r\n", buf)
|
||||
expect(" \x1b[32m ◉ \x1b[0m Monday\r\n", buf)
|
||||
expect("\x1b[36m❯\x1b[0m\x1b[1;99m ◯ \x1b[0m Tuesday\r\n", buf)
|
||||
expect(" \x1b[1;99m ◯ \x1b[0m Wednesday\r\n", buf)
|
||||
expect(" \x1b[32m ◉ \x1b[0m Thursday\r\n", buf)
|
||||
expect(" \x1b[32m ◉ \x1b[0m Friday\r\n", buf)
|
||||
fh.Write([]byte("\x1b"))
|
||||
fh.Write([]byte("["))
|
||||
fh.Write([]byte("B"))
|
||||
expect("\x1b[0G\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[36mⓘ We are closed weekends and avaibility is limited on Wednesday\x1b[0m\r\n", buf)
|
||||
expect("\x1b[1;92m? \x1b[0m\x1b[1;99mWhat days are you available:\x1b[0m\r\n", buf)
|
||||
expect(" \x1b[32m ◉ \x1b[0m Monday\r\n", buf)
|
||||
expect(" \x1b[1;99m ◯ \x1b[0m Tuesday\r\n", buf)
|
||||
expect("\x1b[36m❯\x1b[0m\x1b[1;99m ◯ \x1b[0m Wednesday\r\n", buf)
|
||||
expect(" \x1b[32m ◉ \x1b[0m Thursday\r\n", buf)
|
||||
expect(" \x1b[32m ◉ \x1b[0m Friday\r\n", buf)
|
||||
fh.Write([]byte("\x1b"))
|
||||
fh.Write([]byte("["))
|
||||
fh.Write([]byte("B"))
|
||||
expect("\x1b[0G\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[36mⓘ We are closed weekends and avaibility is limited on Wednesday\x1b[0m\r\n", buf)
|
||||
expect("\x1b[1;92m? \x1b[0m\x1b[1;99mWhat days are you available:\x1b[0m\r\n", buf)
|
||||
expect(" \x1b[32m ◉ \x1b[0m Monday\r\n", buf)
|
||||
expect(" \x1b[1;99m ◯ \x1b[0m Tuesday\r\n", buf)
|
||||
expect(" \x1b[1;99m ◯ \x1b[0m Wednesday\r\n", buf)
|
||||
expect("\x1b[36m❯\x1b[0m\x1b[32m ◉ \x1b[0m Thursday\r\n", buf)
|
||||
expect(" \x1b[32m ◉ \x1b[0m Friday\r\n", buf)
|
||||
fh.Write([]byte(" "))
|
||||
expect("\x1b[0G\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[36mⓘ We are closed weekends and avaibility is limited on Wednesday\x1b[0m\r\n", buf)
|
||||
expect("\x1b[1;92m? \x1b[0m\x1b[1;99mWhat days are you available:\x1b[0m\r\n", buf)
|
||||
expect(" \x1b[32m ◉ \x1b[0m Monday\r\n", buf)
|
||||
expect(" \x1b[1;99m ◯ \x1b[0m Tuesday\r\n", buf)
|
||||
expect(" \x1b[1;99m ◯ \x1b[0m Wednesday\r\n", buf)
|
||||
expect("\x1b[36m❯\x1b[0m\x1b[1;99m ◯ \x1b[0m Thursday\r\n", buf)
|
||||
expect(" \x1b[32m ◉ \x1b[0m Friday\r\n", buf)
|
||||
fh.Write([]byte("\r"))
|
||||
expect("\x1b[?25h\x1b[0G\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1;92m? \x1b[0m\x1b[1;99mWhat days are you available:\x1b[0m\x1b[36m Monday, Friday\x1b[0m\r\n", buf)
|
||||
expect("Answered [Monday Friday].\r\n", buf)
|
||||
expect("---------------------\r\n", buf)
|
||||
expect("select\r\n", buf)
|
||||
expect("\x1b[0G\x1b[2K\x1b[1;92m? \x1b[0m\x1b[1;99mChoose a color:\x1b[0m \x1b[36m[? for help]\x1b[0m\r\n", buf)
|
||||
expect("\x1b[1;99m red\x1b[0m\r\n", buf)
|
||||
expect("\x1b[1;36m❯ blue\x1b[0m\r\n", buf)
|
||||
expect("\x1b[1;99m green\x1b[0m\r\n", buf)
|
||||
expect("\x1b[?25l", buf)
|
||||
fh.Write([]byte("?"))
|
||||
expect("\x1b[0G\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[36mⓘ Blue is the best color, but it is your choice\x1b[0m\r\n", buf)
|
||||
expect("\x1b[1;92m? \x1b[0m\x1b[1;99mChoose a color:\x1b[0m\r\n", buf)
|
||||
expect("\x1b[1;99m red\x1b[0m\r\n", buf)
|
||||
expect("\x1b[1;36m❯ blue\x1b[0m\r\n", buf)
|
||||
expect("\x1b[1;99m green\x1b[0m\r\n", buf)
|
||||
fh.Write([]byte("\r"))
|
||||
expect("\x1b[?25h\x1b[0G\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1;92m? \x1b[0m\x1b[1;99mChoose a color:\x1b[0m\x1b[36m blue\x1b[0m\r\n", buf)
|
||||
expect("Answered blue.\r\n", buf)
|
||||
expect("---------------------\r\n", buf)
|
||||
expect("password\r\n", buf)
|
||||
expect("\x1b[1;92m? \x1b[0m\x1b[1;99mEnter a secret: \x1b[0m\x1b[36m[? for help]\x1b[0m ", buf)
|
||||
fh.Write([]byte("?"))
|
||||
expect("*", buf)
|
||||
fh.Write([]byte("\r"))
|
||||
expect("\r\r\n", buf)
|
||||
expect("\x1b[1F\x1b[0G\x1b[2K\x1b[36mⓘ Don't really enter a secret, this is just for testing\x1b[0m\r\n", buf)
|
||||
expect("\x1b[1;92m? \x1b[0m\x1b[1;99mEnter a secret: \x1b[0m", buf)
|
||||
fh.Write([]byte("f"))
|
||||
expect("*", buf)
|
||||
fh.Write([]byte("o"))
|
||||
expect("*", buf)
|
||||
fh.Write([]byte("o"))
|
||||
expect("*", buf)
|
||||
fh.Write([]byte("b"))
|
||||
expect("*", buf)
|
||||
fh.Write([]byte("a"))
|
||||
expect("*", buf)
|
||||
fh.Write([]byte("r"))
|
||||
expect("*", buf)
|
||||
fh.Write([]byte("\r"))
|
||||
expect("\r\r\n", buf)
|
||||
expect("Answered foobar.\r\n", buf)
|
||||
expect("---------------------\r\n", buf)
|
||||
|
||||
c.Wait()
|
||||
tty.Close()
|
||||
fh.Close()
|
||||
}
|
||||
|
||||
func expect(expected string, buf *bufio.Reader) {
|
||||
sofar := []rune{}
|
||||
for _, r := range expected {
|
||||
got, _, _ := buf.ReadRune()
|
||||
sofar = append(sofar, got)
|
||||
if got != r {
|
||||
fmt.Fprintln(os.Stderr, RESET)
|
||||
|
||||
// we want to quote the string but we also want to make the unexpected character RED
|
||||
// so we use the strconv.Quote function but trim off the quoted characters so we can
|
||||
// merge multiple quoted strings into one.
|
||||
expStart := strings.TrimSuffix(strconv.Quote(expected[:len(sofar)-1]), "\"")
|
||||
expMiss := strings.TrimSuffix(strings.TrimPrefix(strconv.Quote(string(expected[len(sofar)-1])), "\""), "\"")
|
||||
expEnd := strings.TrimPrefix(strconv.Quote(expected[len(sofar):]), "\"")
|
||||
|
||||
fmt.Fprintf(os.Stderr, "Expected: %s%s%s%s%s\n", expStart, RED, expMiss, RESET, expEnd)
|
||||
|
||||
// read the rest of the buffer
|
||||
p := make([]byte, buf.Buffered())
|
||||
buf.Read(p)
|
||||
|
||||
gotStart := strings.TrimSuffix(strconv.Quote(string(sofar[:len(sofar)-1])), "\"")
|
||||
gotMiss := strings.TrimSuffix(strings.TrimPrefix(strconv.Quote(string(sofar[len(sofar)-1])), "\""), "\"")
|
||||
gotEnd := strings.TrimPrefix(strconv.Quote(string(p)), "\"")
|
||||
|
||||
fmt.Fprintf(os.Stderr, "Got: %s%s%s%s%s\n", gotStart, RED, gotMiss, RESET, gotEnd)
|
||||
panic(fmt.Errorf("Unexpected Rune %q, Expected %q\n", got, r))
|
||||
} else {
|
||||
fmt.Printf("%c", r)
|
||||
}
|
||||
}
|
||||
}
|
||||
-176
@@ -1,176 +0,0 @@
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// DO NOT MODIFY THIS FILE!
|
||||
//
|
||||
// This file was automatically generated via the commands:
|
||||
//
|
||||
// go get github.com/coryb/autoplay
|
||||
// autoplay -n autoplay/input.go go run input.go
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
package main
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"fmt"
|
||||
"github.com/kr/pty"
|
||||
"os"
|
||||
"os/exec"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
const (
|
||||
RED = "\033[31m"
|
||||
RESET = "\033[0m"
|
||||
)
|
||||
|
||||
func main() {
|
||||
fh, tty, _ := pty.Open()
|
||||
defer tty.Close()
|
||||
defer fh.Close()
|
||||
c := exec.Command("go", "run", "input.go")
|
||||
c.Stdin = tty
|
||||
c.Stdout = tty
|
||||
c.Stderr = tty
|
||||
c.Start()
|
||||
buf := bufio.NewReaderSize(fh, 1024)
|
||||
|
||||
expect("no default\r\n", buf)
|
||||
expect("\x1b[0G\x1b[2K\x1b[1;92m? \x1b[0m\x1b[1;99mHello world \x1b[0m", buf)
|
||||
fh.Write([]byte("a"))
|
||||
expect("a", buf)
|
||||
fh.Write([]byte("l"))
|
||||
expect("l", buf)
|
||||
fh.Write([]byte("e"))
|
||||
expect("e", buf)
|
||||
fh.Write([]byte("c"))
|
||||
expect("c", buf)
|
||||
fh.Write([]byte("\r"))
|
||||
expect("\r\r\n", buf)
|
||||
expect("\x1b[1F\x1b[0G\x1b[2K\x1b[1;92m? \x1b[0m\x1b[1;99mHello world \x1b[0m\x1b[36malec\x1b[0m\r\n", buf)
|
||||
expect("Answered alec.\r\n", buf)
|
||||
expect("---------------------\r\n", buf)
|
||||
expect("default\r\n", buf)
|
||||
expect("\x1b[0G\x1b[2K\x1b[1;92m? \x1b[0m\x1b[1;99mHello world \x1b[0m\x1b[37m(default) \x1b[0m", buf)
|
||||
fh.Write([]byte("\r"))
|
||||
expect("\r\r\n", buf)
|
||||
expect("\x1b[1F\x1b[0G\x1b[2K\x1b[1;92m? \x1b[0m\x1b[1;99mHello world \x1b[0m\x1b[36mdefault\x1b[0m\r\n", buf)
|
||||
expect("Answered default.\r\n", buf)
|
||||
expect("---------------------\r\n", buf)
|
||||
expect("no help, send '?'\r\n", buf)
|
||||
expect("\x1b[0G\x1b[2K\x1b[1;92m? \x1b[0m\x1b[1;99mHello world \x1b[0m", buf)
|
||||
fh.Write([]byte("?"))
|
||||
expect("?", buf)
|
||||
fh.Write([]byte("\r"))
|
||||
expect("\r\r\n", buf)
|
||||
expect("\x1b[1F\x1b[0G\x1b[2K\x1b[1;92m? \x1b[0m\x1b[1;99mHello world \x1b[0m\x1b[36m?\x1b[0m\r\n", buf)
|
||||
expect("Answered ?.\r\n", buf)
|
||||
expect("---------------------\r\n", buf)
|
||||
expect("input text in random location\r\n", buf)
|
||||
expect("\x1b[0G\x1b[2K\x1b[1;92m? \x1b[0m\x1b[1;99mHello \x1b[0m", buf)
|
||||
fh.Write([]byte("h"))
|
||||
expect("h", buf)
|
||||
fh.Write([]byte("e"))
|
||||
expect("e", buf)
|
||||
fh.Write([]byte("l"))
|
||||
expect("l", buf)
|
||||
fh.Write([]byte("l"))
|
||||
expect("l", buf)
|
||||
fh.Write([]byte("o"))
|
||||
expect("o", buf)
|
||||
fh.Write([]byte(" "))
|
||||
expect(" ", buf)
|
||||
fh.Write([]byte("w"))
|
||||
expect("w", buf)
|
||||
fh.Write([]byte("o"))
|
||||
expect("o", buf)
|
||||
fh.Write([]byte("r"))
|
||||
expect("r", buf)
|
||||
fh.Write([]byte("l"))
|
||||
expect("l", buf)
|
||||
fh.Write([]byte("d"))
|
||||
expect("d", buf)
|
||||
fh.Write([]byte("\x1b"))
|
||||
fh.Write([]byte("["))
|
||||
fh.Write([]byte("D"))
|
||||
expect("\x1b[1D", buf)
|
||||
fh.Write([]byte("\x1b"))
|
||||
fh.Write([]byte("["))
|
||||
fh.Write([]byte("B"))
|
||||
fh.Write([]byte("a"))
|
||||
expect("\x1b[0Kad\x1b[1D", buf)
|
||||
fh.Write([]byte("\x1b"))
|
||||
fh.Write([]byte("["))
|
||||
fh.Write([]byte("D"))
|
||||
expect("\x1b[1D", buf)
|
||||
fh.Write([]byte("\x1b"))
|
||||
fh.Write([]byte("["))
|
||||
fh.Write([]byte("D"))
|
||||
expect("\x1b[1D", buf)
|
||||
fh.Write([]byte("a"))
|
||||
expect("\x1b[0Kalad\x1b[3D", buf)
|
||||
fh.Write([]byte("\x1b"))
|
||||
fh.Write([]byte("["))
|
||||
fh.Write([]byte("D"))
|
||||
expect("\x1b[1D", buf)
|
||||
fh.Write([]byte("\x1b"))
|
||||
fh.Write([]byte("["))
|
||||
fh.Write([]byte("D"))
|
||||
expect("\x1b[1D", buf)
|
||||
fh.Write([]byte("\x1b"))
|
||||
fh.Write([]byte("["))
|
||||
fh.Write([]byte("D"))
|
||||
expect("\x1b[1D", buf)
|
||||
fh.Write([]byte("\x1b"))
|
||||
fh.Write([]byte("["))
|
||||
fh.Write([]byte("D"))
|
||||
expect("\x1b[1D", buf)
|
||||
fh.Write([]byte("\u007f"))
|
||||
expect("\x1b[1D\x1b[0Kworalad\x1b[7D", buf)
|
||||
fh.Write([]byte("\u007f"))
|
||||
expect("\x1b[1D\x1b[0Kworalad\x1b[7D", buf)
|
||||
fh.Write([]byte("\u007f"))
|
||||
expect("\x1b[1D\x1b[0Kworalad\x1b[7D", buf)
|
||||
fh.Write([]byte("\r"))
|
||||
expect("\r\r\n", buf)
|
||||
expect("\x1b[1F\x1b[0G\x1b[2K\x1b[1;92m? \x1b[0m\x1b[1;99mHello \x1b[0m\x1b[36mhelworalad\x1b[0m\r\n", buf)
|
||||
expect("Answered helworalad.\r\n", buf)
|
||||
expect("---------------------\r\n", buf)
|
||||
|
||||
c.Wait()
|
||||
tty.Close()
|
||||
fh.Close()
|
||||
}
|
||||
|
||||
func expect(expected string, buf *bufio.Reader) {
|
||||
sofar := []rune{}
|
||||
for _, r := range expected {
|
||||
got, _, _ := buf.ReadRune()
|
||||
sofar = append(sofar, got)
|
||||
if got != r {
|
||||
fmt.Fprintln(os.Stderr, RESET)
|
||||
|
||||
// we want to quote the string but we also want to make the unexpected character RED
|
||||
// so we use the strconv.Quote function but trim off the quoted characters so we can
|
||||
// merge multiple quoted strings into one.
|
||||
expStart := strings.TrimSuffix(strconv.Quote(expected[:len(sofar)-1]), "\"")
|
||||
expMiss := strings.TrimSuffix(strings.TrimPrefix(strconv.Quote(string(expected[len(sofar)-1])), "\""), "\"")
|
||||
expEnd := strings.TrimPrefix(strconv.Quote(expected[len(sofar):]), "\"")
|
||||
|
||||
fmt.Fprintf(os.Stderr, "Expected: %s%s%s%s%s\n", expStart, RED, expMiss, RESET, expEnd)
|
||||
|
||||
// read the rest of the buffer
|
||||
p := make([]byte, buf.Buffered())
|
||||
buf.Read(p)
|
||||
|
||||
gotStart := strings.TrimSuffix(strconv.Quote(string(sofar[:len(sofar)-1])), "\"")
|
||||
gotMiss := strings.TrimSuffix(strings.TrimPrefix(strconv.Quote(string(sofar[len(sofar)-1])), "\""), "\"")
|
||||
gotEnd := strings.TrimPrefix(strconv.Quote(string(p)), "\"")
|
||||
|
||||
fmt.Fprintf(os.Stderr, "Got: %s%s%s%s%s\n", gotStart, RED, gotMiss, RESET, gotEnd)
|
||||
panic(fmt.Errorf("Unexpected Rune %q, Expected %q\n", got, r))
|
||||
} else {
|
||||
fmt.Printf("%c", r)
|
||||
}
|
||||
}
|
||||
}
|
||||
-446
@@ -1,446 +0,0 @@
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// DO NOT MODIFY THIS FILE!
|
||||
//
|
||||
// This file was automatically generated via the commands:
|
||||
//
|
||||
// go get github.com/coryb/autoplay
|
||||
// autoplay -n autoplay/multiselect.go go run multiselect.go
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
package main
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"fmt"
|
||||
"github.com/kr/pty"
|
||||
"os"
|
||||
"os/exec"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
const (
|
||||
RED = "\033[31m"
|
||||
RESET = "\033[0m"
|
||||
)
|
||||
|
||||
func main() {
|
||||
fh, tty, _ := pty.Open()
|
||||
defer tty.Close()
|
||||
defer fh.Close()
|
||||
c := exec.Command("go", "run", "multiselect.go")
|
||||
c.Stdin = tty
|
||||
c.Stdout = tty
|
||||
c.Stderr = tty
|
||||
c.Start()
|
||||
buf := bufio.NewReaderSize(fh, 1024)
|
||||
|
||||
expect("standard\r\n", buf)
|
||||
expect("\x1b[?25l\x1b[0G\x1b[2K\x1b[1;92m? \x1b[0m\x1b[1;99mWhat days do you prefer:\x1b[0m\r\n", buf)
|
||||
expect("\x1b[36m❯\x1b[0m\x1b[1;99m ◯ \x1b[0m Sunday\r\n", buf)
|
||||
expect(" \x1b[1;99m ◯ \x1b[0m Monday\r\n", buf)
|
||||
expect(" \x1b[1;99m ◯ \x1b[0m Tuesday\r\n", buf)
|
||||
expect(" \x1b[1;99m ◯ \x1b[0m Wednesday\r\n", buf)
|
||||
expect(" \x1b[1;99m ◯ \x1b[0m Thursday\r\n", buf)
|
||||
expect(" \x1b[1;99m ◯ \x1b[0m Friday\r\n", buf)
|
||||
expect(" \x1b[1;99m ◯ \x1b[0m Saturday\r\n", buf)
|
||||
fh.Write([]byte("\x1b"))
|
||||
fh.Write([]byte("["))
|
||||
fh.Write([]byte("B"))
|
||||
expect("\x1b[0G\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1;92m? \x1b[0m\x1b[1;99mWhat days do you prefer:\x1b[0m\r\n", buf)
|
||||
expect(" \x1b[1;99m ◯ \x1b[0m Sunday\r\n", buf)
|
||||
expect("\x1b[36m❯\x1b[0m\x1b[1;99m ◯ \x1b[0m Monday\r\n", buf)
|
||||
expect(" \x1b[1;99m ◯ \x1b[0m Tuesday\r\n", buf)
|
||||
expect(" \x1b[1;99m ◯ \x1b[0m Wednesday\r\n", buf)
|
||||
expect(" \x1b[1;99m ◯ \x1b[0m Thursday\r\n", buf)
|
||||
expect(" \x1b[1;99m ◯ \x1b[0m Friday\r\n", buf)
|
||||
expect(" \x1b[1;99m ◯ \x1b[0m Saturday\r\n", buf)
|
||||
fh.Write([]byte(" "))
|
||||
expect("\x1b[0G\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1;92m? \x1b[0m\x1b[1;99mWhat days do you prefer:\x1b[0m\r\n", buf)
|
||||
expect(" \x1b[1;99m ◯ \x1b[0m Sunday\r\n", buf)
|
||||
expect("\x1b[36m❯\x1b[0m\x1b[32m ◉ \x1b[0m Monday\r\n", buf)
|
||||
expect(" \x1b[1;99m ◯ \x1b[0m Tuesday\r\n", buf)
|
||||
expect(" \x1b[1;99m ◯ \x1b[0m Wednesday\r\n", buf)
|
||||
expect(" \x1b[1;99m ◯ \x1b[0m Thursday\r\n", buf)
|
||||
expect(" \x1b[1;99m ◯ \x1b[0m Friday\r\n", buf)
|
||||
expect(" \x1b[1;99m ◯ \x1b[0m Saturday\r\n", buf)
|
||||
fh.Write([]byte("\x1b"))
|
||||
fh.Write([]byte("["))
|
||||
fh.Write([]byte("B"))
|
||||
expect("\x1b[0G\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1;92m? \x1b[0m\x1b[1;99mWhat days do you prefer:\x1b[0m\r\n", buf)
|
||||
expect(" \x1b[1;99m ◯ \x1b[0m Sunday\r\n", buf)
|
||||
expect(" \x1b[32m ◉ \x1b[0m Monday\r\n", buf)
|
||||
expect("\x1b[36m❯\x1b[0m\x1b[1;99m ◯ \x1b[0m Tuesday\r\n", buf)
|
||||
expect(" \x1b[1;99m ◯ \x1b[0m Wednesday\r\n", buf)
|
||||
expect(" \x1b[1;99m ◯ \x1b[0m Thursday\r\n", buf)
|
||||
expect(" \x1b[1;99m ◯ \x1b[0m Friday\r\n", buf)
|
||||
expect(" \x1b[1;99m ◯ \x1b[0m Saturday\r\n", buf)
|
||||
fh.Write([]byte("\x1b"))
|
||||
fh.Write([]byte("["))
|
||||
fh.Write([]byte("B"))
|
||||
expect("\x1b[0G\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1;92m? \x1b[0m\x1b[1;99mWhat days do you prefer:\x1b[0m\r\n", buf)
|
||||
expect(" \x1b[1;99m ◯ \x1b[0m Sunday\r\n", buf)
|
||||
expect(" \x1b[32m ◉ \x1b[0m Monday\r\n", buf)
|
||||
expect(" \x1b[1;99m ◯ \x1b[0m Tuesday\r\n", buf)
|
||||
expect("\x1b[36m❯\x1b[0m\x1b[1;99m ◯ \x1b[0m Wednesday\r\n", buf)
|
||||
expect(" \x1b[1;99m ◯ \x1b[0m Thursday\r\n", buf)
|
||||
expect(" \x1b[1;99m ◯ \x1b[0m Friday\r\n", buf)
|
||||
expect(" \x1b[1;99m ◯ \x1b[0m Saturday\r\n", buf)
|
||||
fh.Write([]byte("\x1b"))
|
||||
fh.Write([]byte("["))
|
||||
fh.Write([]byte("B"))
|
||||
expect("\x1b[0G\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1;92m? \x1b[0m\x1b[1;99mWhat days do you prefer:\x1b[0m\r\n", buf)
|
||||
expect(" \x1b[1;99m ◯ \x1b[0m Sunday\r\n", buf)
|
||||
expect(" \x1b[32m ◉ \x1b[0m Monday\r\n", buf)
|
||||
expect(" \x1b[1;99m ◯ \x1b[0m Tuesday\r\n", buf)
|
||||
expect(" \x1b[1;99m ◯ \x1b[0m Wednesday\r\n", buf)
|
||||
expect("\x1b[36m❯\x1b[0m\x1b[1;99m ◯ \x1b[0m Thursday\r\n", buf)
|
||||
expect(" \x1b[1;99m ◯ \x1b[0m Friday\r\n", buf)
|
||||
expect(" \x1b[1;99m ◯ \x1b[0m Saturday\r\n", buf)
|
||||
fh.Write([]byte("\x1b"))
|
||||
fh.Write([]byte("["))
|
||||
fh.Write([]byte("B"))
|
||||
expect("\x1b[0G\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1;92m? \x1b[0m\x1b[1;99mWhat days do you prefer:\x1b[0m\r\n", buf)
|
||||
expect(" \x1b[1;99m ◯ \x1b[0m Sunday\r\n", buf)
|
||||
expect(" \x1b[32m ◉ \x1b[0m Monday\r\n", buf)
|
||||
expect(" \x1b[1;99m ◯ \x1b[0m Tuesday\r\n", buf)
|
||||
expect(" \x1b[1;99m ◯ \x1b[0m Wednesday\r\n", buf)
|
||||
expect(" \x1b[1;99m ◯ \x1b[0m Thursday\r\n", buf)
|
||||
expect("\x1b[36m❯\x1b[0m\x1b[1;99m ◯ \x1b[0m Friday\r\n", buf)
|
||||
expect(" \x1b[1;99m ◯ \x1b[0m Saturday\r\n", buf)
|
||||
fh.Write([]byte(" "))
|
||||
expect("\x1b[0G\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1;92m? \x1b[0m\x1b[1;99mWhat days do you prefer:\x1b[0m\r\n", buf)
|
||||
expect(" \x1b[1;99m ◯ \x1b[0m Sunday\r\n", buf)
|
||||
expect(" \x1b[32m ◉ \x1b[0m Monday\r\n", buf)
|
||||
expect(" \x1b[1;99m ◯ \x1b[0m Tuesday\r\n", buf)
|
||||
expect(" \x1b[1;99m ◯ \x1b[0m Wednesday\r\n", buf)
|
||||
expect(" \x1b[1;99m ◯ \x1b[0m Thursday\r\n", buf)
|
||||
expect("\x1b[36m❯\x1b[0m\x1b[32m ◉ \x1b[0m Friday\r\n", buf)
|
||||
expect(" \x1b[1;99m ◯ \x1b[0m Saturday\r\n", buf)
|
||||
fh.Write([]byte("\r"))
|
||||
expect("\x1b[?25h\x1b[0G\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1;92m? \x1b[0m\x1b[1;99mWhat days do you prefer:\x1b[0m\x1b[36m Monday, Friday\x1b[0m\r\n", buf)
|
||||
expect("Answered [Monday Friday].\r\n", buf)
|
||||
expect("---------------------\r\n", buf)
|
||||
expect("default (sunday, tuesday)\r\n", buf)
|
||||
expect("\x1b[?25l\x1b[0G\x1b[2K\x1b[1;92m? \x1b[0m\x1b[1;99mWhat days do you prefer:\x1b[0m\r\n", buf)
|
||||
expect("\x1b[36m❯\x1b[0m\x1b[32m ◉ \x1b[0m Sunday\r\n", buf)
|
||||
expect(" \x1b[1;99m ◯ \x1b[0m Monday\r\n", buf)
|
||||
expect(" \x1b[32m ◉ \x1b[0m Tuesday\r\n", buf)
|
||||
expect(" \x1b[1;99m ◯ \x1b[0m Wednesday\r\n", buf)
|
||||
expect(" \x1b[1;99m ◯ \x1b[0m Thursday\r\n", buf)
|
||||
expect(" \x1b[1;99m ◯ \x1b[0m Friday\r\n", buf)
|
||||
expect(" \x1b[1;99m ◯ \x1b[0m Saturday\r\n", buf)
|
||||
fh.Write([]byte(" "))
|
||||
expect("\x1b[0G\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1;92m? \x1b[0m\x1b[1;99mWhat days do you prefer:\x1b[0m\r\n", buf)
|
||||
expect("\x1b[36m❯\x1b[0m\x1b[1;99m ◯ \x1b[0m Sunday\r\n", buf)
|
||||
expect(" \x1b[1;99m ◯ \x1b[0m Monday\r\n", buf)
|
||||
expect(" \x1b[32m ◉ \x1b[0m Tuesday\r\n", buf)
|
||||
expect(" \x1b[1;99m ◯ \x1b[0m Wednesday\r\n", buf)
|
||||
expect(" \x1b[1;99m ◯ \x1b[0m Thursday\r\n", buf)
|
||||
expect(" \x1b[1;99m ◯ \x1b[0m Friday\r\n", buf)
|
||||
expect(" \x1b[1;99m ◯ \x1b[0m Saturday\r\n", buf)
|
||||
fh.Write([]byte("\x1b"))
|
||||
fh.Write([]byte("["))
|
||||
fh.Write([]byte("B"))
|
||||
expect("\x1b[0G\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1;92m? \x1b[0m\x1b[1;99mWhat days do you prefer:\x1b[0m\r\n", buf)
|
||||
expect(" \x1b[1;99m ◯ \x1b[0m Sunday\r\n", buf)
|
||||
expect("\x1b[36m❯\x1b[0m\x1b[1;99m ◯ \x1b[0m Monday\r\n", buf)
|
||||
expect(" \x1b[32m ◉ \x1b[0m Tuesday\r\n", buf)
|
||||
expect(" \x1b[1;99m ◯ \x1b[0m Wednesday\r\n", buf)
|
||||
expect(" \x1b[1;99m ◯ \x1b[0m Thursday\r\n", buf)
|
||||
expect(" \x1b[1;99m ◯ \x1b[0m Friday\r\n", buf)
|
||||
expect(" \x1b[1;99m ◯ \x1b[0m Saturday\r\n", buf)
|
||||
fh.Write([]byte(" "))
|
||||
expect("\x1b[0G\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1;92m? \x1b[0m\x1b[1;99mWhat days do you prefer:\x1b[0m\r\n", buf)
|
||||
expect(" \x1b[1;99m ◯ \x1b[0m Sunday\r\n", buf)
|
||||
expect("\x1b[36m❯\x1b[0m\x1b[32m ◉ \x1b[0m Monday\r\n", buf)
|
||||
expect(" \x1b[32m ◉ \x1b[0m Tuesday\r\n", buf)
|
||||
expect(" \x1b[1;99m ◯ \x1b[0m Wednesday\r\n", buf)
|
||||
expect(" \x1b[1;99m ◯ \x1b[0m Thursday\r\n", buf)
|
||||
expect(" \x1b[1;99m ◯ \x1b[0m Friday\r\n", buf)
|
||||
expect(" \x1b[1;99m ◯ \x1b[0m Saturday\r\n", buf)
|
||||
fh.Write([]byte("\x1b"))
|
||||
fh.Write([]byte("["))
|
||||
fh.Write([]byte("B"))
|
||||
expect("\x1b[0G\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1;92m? \x1b[0m\x1b[1;99mWhat days do you prefer:\x1b[0m\r\n", buf)
|
||||
expect(" \x1b[1;99m ◯ \x1b[0m Sunday\r\n", buf)
|
||||
expect(" \x1b[32m ◉ \x1b[0m Monday\r\n", buf)
|
||||
expect("\x1b[36m❯\x1b[0m\x1b[32m ◉ \x1b[0m Tuesday\r\n", buf)
|
||||
expect(" \x1b[1;99m ◯ \x1b[0m Wednesday\r\n", buf)
|
||||
expect(" \x1b[1;99m ◯ \x1b[0m Thursday\r\n", buf)
|
||||
expect(" \x1b[1;99m ◯ \x1b[0m Friday\r\n", buf)
|
||||
expect(" \x1b[1;99m ◯ \x1b[0m Saturday\r\n", buf)
|
||||
fh.Write([]byte(" "))
|
||||
expect("\x1b[0G\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1;92m? \x1b[0m\x1b[1;99mWhat days do you prefer:\x1b[0m\r\n", buf)
|
||||
expect(" \x1b[1;99m ◯ \x1b[0m Sunday\r\n", buf)
|
||||
expect(" \x1b[32m ◉ \x1b[0m Monday\r\n", buf)
|
||||
expect("\x1b[36m❯\x1b[0m\x1b[1;99m ◯ \x1b[0m Tuesday\r\n", buf)
|
||||
expect(" \x1b[1;99m ◯ \x1b[0m Wednesday\r\n", buf)
|
||||
expect(" \x1b[1;99m ◯ \x1b[0m Thursday\r\n", buf)
|
||||
expect(" \x1b[1;99m ◯ \x1b[0m Friday\r\n", buf)
|
||||
expect(" \x1b[1;99m ◯ \x1b[0m Saturday\r\n", buf)
|
||||
fh.Write([]byte("\x1b"))
|
||||
fh.Write([]byte("["))
|
||||
fh.Write([]byte("B"))
|
||||
expect("\x1b[0G\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1;92m? \x1b[0m\x1b[1;99mWhat days do you prefer:\x1b[0m\r\n", buf)
|
||||
expect(" \x1b[1;99m ◯ \x1b[0m Sunday\r\n", buf)
|
||||
expect(" \x1b[32m ◉ \x1b[0m Monday\r\n", buf)
|
||||
expect(" \x1b[1;99m ◯ \x1b[0m Tuesday\r\n", buf)
|
||||
expect("\x1b[36m❯\x1b[0m\x1b[1;99m ◯ \x1b[0m Wednesday\r\n", buf)
|
||||
expect(" \x1b[1;99m ◯ \x1b[0m Thursday\r\n", buf)
|
||||
expect(" \x1b[1;99m ◯ \x1b[0m Friday\r\n", buf)
|
||||
expect(" \x1b[1;99m ◯ \x1b[0m Saturday\r\n", buf)
|
||||
fh.Write([]byte("\x1b"))
|
||||
fh.Write([]byte("["))
|
||||
fh.Write([]byte("B"))
|
||||
expect("\x1b[0G\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1;92m? \x1b[0m\x1b[1;99mWhat days do you prefer:\x1b[0m\r\n", buf)
|
||||
expect(" \x1b[1;99m ◯ \x1b[0m Sunday\r\n", buf)
|
||||
expect(" \x1b[32m ◉ \x1b[0m Monday\r\n", buf)
|
||||
expect(" \x1b[1;99m ◯ \x1b[0m Tuesday\r\n", buf)
|
||||
expect(" \x1b[1;99m ◯ \x1b[0m Wednesday\r\n", buf)
|
||||
expect("\x1b[36m❯\x1b[0m\x1b[1;99m ◯ \x1b[0m Thursday\r\n", buf)
|
||||
expect(" \x1b[1;99m ◯ \x1b[0m Friday\r\n", buf)
|
||||
expect(" \x1b[1;99m ◯ \x1b[0m Saturday\r\n", buf)
|
||||
fh.Write([]byte("\x1b"))
|
||||
fh.Write([]byte("["))
|
||||
fh.Write([]byte("B"))
|
||||
expect("\x1b[0G\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1;92m? \x1b[0m\x1b[1;99mWhat days do you prefer:\x1b[0m\r\n", buf)
|
||||
expect(" \x1b[1;99m ◯ \x1b[0m Sunday\r\n", buf)
|
||||
expect(" \x1b[32m ◉ \x1b[0m Monday\r\n", buf)
|
||||
expect(" \x1b[1;99m ◯ \x1b[0m Tuesday\r\n", buf)
|
||||
expect(" \x1b[1;99m ◯ \x1b[0m Wednesday\r\n", buf)
|
||||
expect(" \x1b[1;99m ◯ \x1b[0m Thursday\r\n", buf)
|
||||
expect("\x1b[36m❯\x1b[0m\x1b[1;99m ◯ \x1b[0m Friday\r\n", buf)
|
||||
expect(" \x1b[1;99m ◯ \x1b[0m Saturday\r\n", buf)
|
||||
fh.Write([]byte(" "))
|
||||
expect("\x1b[0G\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1;92m? \x1b[0m\x1b[1;99mWhat days do you prefer:\x1b[0m\r\n", buf)
|
||||
expect(" \x1b[1;99m ◯ \x1b[0m Sunday\r\n", buf)
|
||||
expect(" \x1b[32m ◉ \x1b[0m Monday\r\n", buf)
|
||||
expect(" \x1b[1;99m ◯ \x1b[0m Tuesday\r\n", buf)
|
||||
expect(" \x1b[1;99m ◯ \x1b[0m Wednesday\r\n", buf)
|
||||
expect(" \x1b[1;99m ◯ \x1b[0m Thursday\r\n", buf)
|
||||
expect("\x1b[36m❯\x1b[0m\x1b[32m ◉ \x1b[0m Friday\r\n", buf)
|
||||
expect(" \x1b[1;99m ◯ \x1b[0m Saturday\r\n", buf)
|
||||
fh.Write([]byte("\r"))
|
||||
expect("\x1b[?25h\x1b[0G\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1;92m? \x1b[0m\x1b[1;99mWhat days do you prefer:\x1b[0m\x1b[36m Monday, Friday\x1b[0m\r\n", buf)
|
||||
expect("Answered [Monday Friday].\r\n", buf)
|
||||
expect("---------------------\r\n", buf)
|
||||
expect("default not found\r\n", buf)
|
||||
expect("\x1b[?25l\x1b[0G\x1b[2K\x1b[1;92m? \x1b[0m\x1b[1;99mWhat days do you prefer:\x1b[0m\r\n", buf)
|
||||
expect("\x1b[36m❯\x1b[0m\x1b[1;99m ◯ \x1b[0m Sunday\r\n", buf)
|
||||
expect(" \x1b[1;99m ◯ \x1b[0m Monday\r\n", buf)
|
||||
expect(" \x1b[1;99m ◯ \x1b[0m Tuesday\r\n", buf)
|
||||
expect(" \x1b[1;99m ◯ \x1b[0m Wednesday\r\n", buf)
|
||||
expect(" \x1b[1;99m ◯ \x1b[0m Thursday\r\n", buf)
|
||||
expect(" \x1b[1;99m ◯ \x1b[0m Friday\r\n", buf)
|
||||
expect(" \x1b[1;99m ◯ \x1b[0m Saturday\r\n", buf)
|
||||
fh.Write([]byte("\x1b"))
|
||||
fh.Write([]byte("["))
|
||||
fh.Write([]byte("B"))
|
||||
expect("\x1b[0G\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1;92m? \x1b[0m\x1b[1;99mWhat days do you prefer:\x1b[0m\r\n", buf)
|
||||
expect(" \x1b[1;99m ◯ \x1b[0m Sunday\r\n", buf)
|
||||
expect("\x1b[36m❯\x1b[0m\x1b[1;99m ◯ \x1b[0m Monday\r\n", buf)
|
||||
expect(" \x1b[1;99m ◯ \x1b[0m Tuesday\r\n", buf)
|
||||
expect(" \x1b[1;99m ◯ \x1b[0m Wednesday\r\n", buf)
|
||||
expect(" \x1b[1;99m ◯ \x1b[0m Thursday\r\n", buf)
|
||||
expect(" \x1b[1;99m ◯ \x1b[0m Friday\r\n", buf)
|
||||
expect(" \x1b[1;99m ◯ \x1b[0m Saturday\r\n", buf)
|
||||
fh.Write([]byte(" "))
|
||||
expect("\x1b[0G\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1;92m? \x1b[0m\x1b[1;99mWhat days do you prefer:\x1b[0m\r\n", buf)
|
||||
expect(" \x1b[1;99m ◯ \x1b[0m Sunday\r\n", buf)
|
||||
expect("\x1b[36m❯\x1b[0m\x1b[32m ◉ \x1b[0m Monday\r\n", buf)
|
||||
expect(" \x1b[1;99m ◯ \x1b[0m Tuesday\r\n", buf)
|
||||
expect(" \x1b[1;99m ◯ \x1b[0m Wednesday\r\n", buf)
|
||||
expect(" \x1b[1;99m ◯ \x1b[0m Thursday\r\n", buf)
|
||||
expect(" \x1b[1;99m ◯ \x1b[0m Friday\r\n", buf)
|
||||
expect(" \x1b[1;99m ◯ \x1b[0m Saturday\r\n", buf)
|
||||
fh.Write([]byte("\x1b"))
|
||||
fh.Write([]byte("["))
|
||||
fh.Write([]byte("B"))
|
||||
expect("\x1b[0G\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1;92m? \x1b[0m\x1b[1;99mWhat days do you prefer:\x1b[0m\r\n", buf)
|
||||
expect(" \x1b[1;99m ◯ \x1b[0m Sunday\r\n", buf)
|
||||
expect(" \x1b[32m ◉ \x1b[0m Monday\r\n", buf)
|
||||
expect("\x1b[36m❯\x1b[0m\x1b[1;99m ◯ \x1b[0m Tuesday\r\n", buf)
|
||||
expect(" \x1b[1;99m ◯ \x1b[0m Wednesday\r\n", buf)
|
||||
expect(" \x1b[1;99m ◯ \x1b[0m Thursday\r\n", buf)
|
||||
expect(" \x1b[1;99m ◯ \x1b[0m Friday\r\n", buf)
|
||||
expect(" \x1b[1;99m ◯ \x1b[0m Saturday\r\n", buf)
|
||||
fh.Write([]byte("\x1b"))
|
||||
fh.Write([]byte("["))
|
||||
fh.Write([]byte("B"))
|
||||
expect("\x1b[0G\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1;92m? \x1b[0m\x1b[1;99mWhat days do you prefer:\x1b[0m\r\n", buf)
|
||||
expect(" \x1b[1;99m ◯ \x1b[0m Sunday\r\n", buf)
|
||||
expect(" \x1b[32m ◉ \x1b[0m Monday\r\n", buf)
|
||||
expect(" \x1b[1;99m ◯ \x1b[0m Tuesday\r\n", buf)
|
||||
expect("\x1b[36m❯\x1b[0m\x1b[1;99m ◯ \x1b[0m Wednesday\r\n", buf)
|
||||
expect(" \x1b[1;99m ◯ \x1b[0m Thursday\r\n", buf)
|
||||
expect(" \x1b[1;99m ◯ \x1b[0m Friday\r\n", buf)
|
||||
expect(" \x1b[1;99m ◯ \x1b[0m Saturday\r\n", buf)
|
||||
fh.Write([]byte("\x1b"))
|
||||
fh.Write([]byte("["))
|
||||
fh.Write([]byte("B"))
|
||||
expect("\x1b[0G\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1;92m? \x1b[0m\x1b[1;99mWhat days do you prefer:\x1b[0m\r\n", buf)
|
||||
expect(" \x1b[1;99m ◯ \x1b[0m Sunday\r\n", buf)
|
||||
expect(" \x1b[32m ◉ \x1b[0m Monday\r\n", buf)
|
||||
expect(" \x1b[1;99m ◯ \x1b[0m Tuesday\r\n", buf)
|
||||
expect(" \x1b[1;99m ◯ \x1b[0m Wednesday\r\n", buf)
|
||||
expect("\x1b[36m❯\x1b[0m\x1b[1;99m ◯ \x1b[0m Thursday\r\n", buf)
|
||||
expect(" \x1b[1;99m ◯ \x1b[0m Friday\r\n", buf)
|
||||
expect(" \x1b[1;99m ◯ \x1b[0m Saturday\r\n", buf)
|
||||
fh.Write([]byte("\x1b"))
|
||||
fh.Write([]byte("["))
|
||||
fh.Write([]byte("B"))
|
||||
expect("\x1b[0G\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1;92m? \x1b[0m\x1b[1;99mWhat days do you prefer:\x1b[0m\r\n", buf)
|
||||
expect(" \x1b[1;99m ◯ \x1b[0m Sunday\r\n", buf)
|
||||
expect(" \x1b[32m ◉ \x1b[0m Monday\r\n", buf)
|
||||
expect(" \x1b[1;99m ◯ \x1b[0m Tuesday\r\n", buf)
|
||||
expect(" \x1b[1;99m ◯ \x1b[0m Wednesday\r\n", buf)
|
||||
expect(" \x1b[1;99m ◯ \x1b[0m Thursday\r\n", buf)
|
||||
expect("\x1b[36m❯\x1b[0m\x1b[1;99m ◯ \x1b[0m Friday\r\n", buf)
|
||||
expect(" \x1b[1;99m ◯ \x1b[0m Saturday\r\n", buf)
|
||||
fh.Write([]byte(" "))
|
||||
expect("\x1b[0G\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1;92m? \x1b[0m\x1b[1;99mWhat days do you prefer:\x1b[0m\r\n", buf)
|
||||
expect(" \x1b[1;99m ◯ \x1b[0m Sunday\r\n", buf)
|
||||
expect(" \x1b[32m ◉ \x1b[0m Monday\r\n", buf)
|
||||
expect(" \x1b[1;99m ◯ \x1b[0m Tuesday\r\n", buf)
|
||||
expect(" \x1b[1;99m ◯ \x1b[0m Wednesday\r\n", buf)
|
||||
expect(" \x1b[1;99m ◯ \x1b[0m Thursday\r\n", buf)
|
||||
expect("\x1b[36m❯\x1b[0m\x1b[32m ◉ \x1b[0m Friday\r\n", buf)
|
||||
expect(" \x1b[1;99m ◯ \x1b[0m Saturday\r\n", buf)
|
||||
fh.Write([]byte("\r"))
|
||||
expect("\x1b[?25h\x1b[0G\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1;92m? \x1b[0m\x1b[1;99mWhat days do you prefer:\x1b[0m\x1b[36m Monday, Friday\x1b[0m\r\n", buf)
|
||||
expect("Answered [Monday Friday].\r\n", buf)
|
||||
expect("---------------------\r\n", buf)
|
||||
expect("no help - type ?\r\n", buf)
|
||||
expect("\x1b[?25l\x1b[0G\x1b[2K\x1b[1;92m? \x1b[0m\x1b[1;99mWhat days do you prefer:\x1b[0m\r\n", buf)
|
||||
expect("\x1b[36m❯\x1b[0m\x1b[1;99m ◯ \x1b[0m Sunday\r\n", buf)
|
||||
expect(" \x1b[1;99m ◯ \x1b[0m Monday\r\n", buf)
|
||||
expect(" \x1b[1;99m ◯ \x1b[0m Tuesday\r\n", buf)
|
||||
expect(" \x1b[1;99m ◯ \x1b[0m Wednesday\r\n", buf)
|
||||
expect(" \x1b[1;99m ◯ \x1b[0m Thursday\r\n", buf)
|
||||
expect(" \x1b[1;99m ◯ \x1b[0m Friday\r\n", buf)
|
||||
expect(" \x1b[1;99m ◯ \x1b[0m Saturday\r\n", buf)
|
||||
fh.Write([]byte("?"))
|
||||
expect("\x1b[0G\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1;92m? \x1b[0m\x1b[1;99mWhat days do you prefer:\x1b[0m\r\n", buf)
|
||||
expect("\x1b[36m❯\x1b[0m\x1b[1;99m ◯ \x1b[0m Sunday\r\n", buf)
|
||||
expect(" \x1b[1;99m ◯ \x1b[0m Monday\r\n", buf)
|
||||
expect(" \x1b[1;99m ◯ \x1b[0m Tuesday\r\n", buf)
|
||||
expect(" \x1b[1;99m ◯ \x1b[0m Wednesday\r\n", buf)
|
||||
expect(" \x1b[1;99m ◯ \x1b[0m Thursday\r\n", buf)
|
||||
expect(" \x1b[1;99m ◯ \x1b[0m Friday\r\n", buf)
|
||||
expect(" \x1b[1;99m ◯ \x1b[0m Saturday\r\n", buf)
|
||||
fh.Write([]byte("\x1b"))
|
||||
fh.Write([]byte("["))
|
||||
fh.Write([]byte("B"))
|
||||
expect("\x1b[0G\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1;92m? \x1b[0m\x1b[1;99mWhat days do you prefer:\x1b[0m\r\n", buf)
|
||||
expect(" \x1b[1;99m ◯ \x1b[0m Sunday\r\n", buf)
|
||||
expect("\x1b[36m❯\x1b[0m\x1b[1;99m ◯ \x1b[0m Monday\r\n", buf)
|
||||
expect(" \x1b[1;99m ◯ \x1b[0m Tuesday\r\n", buf)
|
||||
expect(" \x1b[1;99m ◯ \x1b[0m Wednesday\r\n", buf)
|
||||
expect(" \x1b[1;99m ◯ \x1b[0m Thursday\r\n", buf)
|
||||
expect(" \x1b[1;99m ◯ \x1b[0m Friday\r\n", buf)
|
||||
expect(" \x1b[1;99m ◯ \x1b[0m Saturday\r\n", buf)
|
||||
fh.Write([]byte(" "))
|
||||
expect("\x1b[0G\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1;92m? \x1b[0m\x1b[1;99mWhat days do you prefer:\x1b[0m\r\n", buf)
|
||||
expect(" \x1b[1;99m ◯ \x1b[0m Sunday\r\n", buf)
|
||||
expect("\x1b[36m❯\x1b[0m\x1b[32m ◉ \x1b[0m Monday\r\n", buf)
|
||||
expect(" \x1b[1;99m ◯ \x1b[0m Tuesday\r\n", buf)
|
||||
expect(" \x1b[1;99m ◯ \x1b[0m Wednesday\r\n", buf)
|
||||
expect(" \x1b[1;99m ◯ \x1b[0m Thursday\r\n", buf)
|
||||
expect(" \x1b[1;99m ◯ \x1b[0m Friday\r\n", buf)
|
||||
expect(" \x1b[1;99m ◯ \x1b[0m Saturday\r\n", buf)
|
||||
fh.Write([]byte("\x1b"))
|
||||
fh.Write([]byte("["))
|
||||
fh.Write([]byte("B"))
|
||||
expect("\x1b[0G\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1;92m? \x1b[0m\x1b[1;99mWhat days do you prefer:\x1b[0m\r\n", buf)
|
||||
expect(" \x1b[1;99m ◯ \x1b[0m Sunday\r\n", buf)
|
||||
expect(" \x1b[32m ◉ \x1b[0m Monday\r\n", buf)
|
||||
expect("\x1b[36m❯\x1b[0m\x1b[1;99m ◯ \x1b[0m Tuesday\r\n", buf)
|
||||
expect(" \x1b[1;99m ◯ \x1b[0m Wednesday\r\n", buf)
|
||||
expect(" \x1b[1;99m ◯ \x1b[0m Thursday\r\n", buf)
|
||||
expect(" \x1b[1;99m ◯ \x1b[0m Friday\r\n", buf)
|
||||
expect(" \x1b[1;99m ◯ \x1b[0m Saturday\r\n", buf)
|
||||
fh.Write([]byte("\x1b"))
|
||||
fh.Write([]byte("["))
|
||||
fh.Write([]byte("B"))
|
||||
expect("\x1b[0G\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1;92m? \x1b[0m\x1b[1;99mWhat days do you prefer:\x1b[0m\r\n", buf)
|
||||
expect(" \x1b[1;99m ◯ \x1b[0m Sunday\r\n", buf)
|
||||
expect(" \x1b[32m ◉ \x1b[0m Monday\r\n", buf)
|
||||
expect(" \x1b[1;99m ◯ \x1b[0m Tuesday\r\n", buf)
|
||||
expect("\x1b[36m❯\x1b[0m\x1b[1;99m ◯ \x1b[0m Wednesday\r\n", buf)
|
||||
expect(" \x1b[1;99m ◯ \x1b[0m Thursday\r\n", buf)
|
||||
expect(" \x1b[1;99m ◯ \x1b[0m Friday\r\n", buf)
|
||||
expect(" \x1b[1;99m ◯ \x1b[0m Saturday\r\n", buf)
|
||||
fh.Write([]byte("\x1b"))
|
||||
fh.Write([]byte("["))
|
||||
fh.Write([]byte("B"))
|
||||
expect("\x1b[0G\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1;92m? \x1b[0m\x1b[1;99mWhat days do you prefer:\x1b[0m\r\n", buf)
|
||||
expect(" \x1b[1;99m ◯ \x1b[0m Sunday\r\n", buf)
|
||||
expect(" \x1b[32m ◉ \x1b[0m Monday\r\n", buf)
|
||||
expect(" \x1b[1;99m ◯ \x1b[0m Tuesday\r\n", buf)
|
||||
expect(" \x1b[1;99m ◯ \x1b[0m Wednesday\r\n", buf)
|
||||
expect("\x1b[36m❯\x1b[0m\x1b[1;99m ◯ \x1b[0m Thursday\r\n", buf)
|
||||
expect(" \x1b[1;99m ◯ \x1b[0m Friday\r\n", buf)
|
||||
expect(" \x1b[1;99m ◯ \x1b[0m Saturday\r\n", buf)
|
||||
fh.Write([]byte("\x1b"))
|
||||
fh.Write([]byte("["))
|
||||
fh.Write([]byte("B"))
|
||||
expect("\x1b[0G\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1;92m? \x1b[0m\x1b[1;99mWhat days do you prefer:\x1b[0m\r\n", buf)
|
||||
expect(" \x1b[1;99m ◯ \x1b[0m Sunday\r\n", buf)
|
||||
expect(" \x1b[32m ◉ \x1b[0m Monday\r\n", buf)
|
||||
expect(" \x1b[1;99m ◯ \x1b[0m Tuesday\r\n", buf)
|
||||
expect(" \x1b[1;99m ◯ \x1b[0m Wednesday\r\n", buf)
|
||||
expect(" \x1b[1;99m ◯ \x1b[0m Thursday\r\n", buf)
|
||||
expect("\x1b[36m❯\x1b[0m\x1b[1;99m ◯ \x1b[0m Friday\r\n", buf)
|
||||
expect(" \x1b[1;99m ◯ \x1b[0m Saturday\r\n", buf)
|
||||
fh.Write([]byte(" "))
|
||||
expect("\x1b[0G\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1;92m? \x1b[0m\x1b[1;99mWhat days do you prefer:\x1b[0m\r\n", buf)
|
||||
expect(" \x1b[1;99m ◯ \x1b[0m Sunday\r\n", buf)
|
||||
expect(" \x1b[32m ◉ \x1b[0m Monday\r\n", buf)
|
||||
expect(" \x1b[1;99m ◯ \x1b[0m Tuesday\r\n", buf)
|
||||
expect(" \x1b[1;99m ◯ \x1b[0m Wednesday\r\n", buf)
|
||||
expect(" \x1b[1;99m ◯ \x1b[0m Thursday\r\n", buf)
|
||||
expect("\x1b[36m❯\x1b[0m\x1b[32m ◉ \x1b[0m Friday\r\n", buf)
|
||||
expect(" \x1b[1;99m ◯ \x1b[0m Saturday\r\n", buf)
|
||||
fh.Write([]byte("\r"))
|
||||
expect("\x1b[?25h\x1b[0G\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1;92m? \x1b[0m\x1b[1;99mWhat days do you prefer:\x1b[0m\x1b[36m Monday, Friday\x1b[0m\r\n", buf)
|
||||
expect("Answered [Monday Friday].\r\n", buf)
|
||||
expect("---------------------\r\n", buf)
|
||||
|
||||
c.Wait()
|
||||
tty.Close()
|
||||
fh.Close()
|
||||
}
|
||||
|
||||
func expect(expected string, buf *bufio.Reader) {
|
||||
sofar := []rune{}
|
||||
for _, r := range expected {
|
||||
got, _, _ := buf.ReadRune()
|
||||
sofar = append(sofar, got)
|
||||
if got != r {
|
||||
fmt.Fprintln(os.Stderr, RESET)
|
||||
|
||||
// we want to quote the string but we also want to make the unexpected character RED
|
||||
// so we use the strconv.Quote function but trim off the quoted characters so we can
|
||||
// merge multiple quoted strings into one.
|
||||
expStart := strings.TrimSuffix(strconv.Quote(expected[:len(sofar)-1]), "\"")
|
||||
expMiss := strings.TrimSuffix(strings.TrimPrefix(strconv.Quote(string(expected[len(sofar)-1])), "\""), "\"")
|
||||
expEnd := strings.TrimPrefix(strconv.Quote(expected[len(sofar):]), "\"")
|
||||
|
||||
fmt.Fprintf(os.Stderr, "Expected: %s%s%s%s%s\n", expStart, RED, expMiss, RESET, expEnd)
|
||||
|
||||
// read the rest of the buffer
|
||||
p := make([]byte, buf.Buffered())
|
||||
buf.Read(p)
|
||||
|
||||
gotStart := strings.TrimSuffix(strconv.Quote(string(sofar[:len(sofar)-1])), "\"")
|
||||
gotMiss := strings.TrimSuffix(strings.TrimPrefix(strconv.Quote(string(sofar[len(sofar)-1])), "\""), "\"")
|
||||
gotEnd := strings.TrimPrefix(strconv.Quote(string(p)), "\"")
|
||||
|
||||
fmt.Fprintf(os.Stderr, "Got: %s%s%s%s%s\n", gotStart, RED, gotMiss, RESET, gotEnd)
|
||||
panic(fmt.Errorf("Unexpected Rune %q, Expected %q\n", got, r))
|
||||
} else {
|
||||
fmt.Printf("%c", r)
|
||||
}
|
||||
}
|
||||
}
|
||||
-114
@@ -1,114 +0,0 @@
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// DO NOT MODIFY THIS FILE!
|
||||
//
|
||||
// This file was automatically generated via the commands:
|
||||
//
|
||||
// go get github.com/coryb/autoplay
|
||||
// autoplay -n autoplay/password.go go run password.go
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
package main
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"fmt"
|
||||
"github.com/kr/pty"
|
||||
"os"
|
||||
"os/exec"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
const (
|
||||
RED = "\033[31m"
|
||||
RESET = "\033[0m"
|
||||
)
|
||||
|
||||
func main() {
|
||||
fh, tty, _ := pty.Open()
|
||||
defer tty.Close()
|
||||
defer fh.Close()
|
||||
c := exec.Command("go", "run", "password.go")
|
||||
c.Stdin = tty
|
||||
c.Stdout = tty
|
||||
c.Stderr = tty
|
||||
c.Start()
|
||||
buf := bufio.NewReaderSize(fh, 1024)
|
||||
|
||||
expect("standard\r\n", buf)
|
||||
expect("\x1b[1;92m? \x1b[0m\x1b[1;99mPlease type your password: \x1b[0m", buf)
|
||||
fh.Write([]byte("f"))
|
||||
expect("*", buf)
|
||||
fh.Write([]byte("o"))
|
||||
expect("*", buf)
|
||||
fh.Write([]byte("o"))
|
||||
expect("*", buf)
|
||||
fh.Write([]byte("b"))
|
||||
expect("*", buf)
|
||||
fh.Write([]byte("a"))
|
||||
expect("*", buf)
|
||||
fh.Write([]byte("r"))
|
||||
expect("*", buf)
|
||||
fh.Write([]byte("\r"))
|
||||
expect("\r\r\n", buf)
|
||||
expect("Answered foobar.\r\n", buf)
|
||||
expect("---------------------\r\n", buf)
|
||||
expect("please make sure paste works\r\n", buf)
|
||||
expect("\x1b[1;92m? \x1b[0m\x1b[1;99mPlease paste your password: \x1b[0m", buf)
|
||||
fh.Write([]byte("f"))
|
||||
fh.Write([]byte("o"))
|
||||
fh.Write([]byte("o"))
|
||||
fh.Write([]byte("b"))
|
||||
fh.Write([]byte("a"))
|
||||
fh.Write([]byte("r"))
|
||||
expect("******", buf)
|
||||
fh.Write([]byte("\r"))
|
||||
expect("\r\r\n", buf)
|
||||
expect("Answered foobar.\r\n", buf)
|
||||
expect("---------------------\r\n", buf)
|
||||
expect("no help, send '?'\r\n", buf)
|
||||
expect("\x1b[1;92m? \x1b[0m\x1b[1;99mPlease type your password: \x1b[0m", buf)
|
||||
fh.Write([]byte("?"))
|
||||
expect("*", buf)
|
||||
fh.Write([]byte("\r"))
|
||||
expect("\r\r\n", buf)
|
||||
expect("Answered ?.\r\n", buf)
|
||||
expect("---------------------\r\n", buf)
|
||||
|
||||
c.Wait()
|
||||
tty.Close()
|
||||
fh.Close()
|
||||
}
|
||||
|
||||
func expect(expected string, buf *bufio.Reader) {
|
||||
sofar := []rune{}
|
||||
for _, r := range expected {
|
||||
got, _, _ := buf.ReadRune()
|
||||
sofar = append(sofar, got)
|
||||
if got != r {
|
||||
fmt.Fprintln(os.Stderr, RESET)
|
||||
|
||||
// we want to quote the string but we also want to make the unexpected character RED
|
||||
// so we use the strconv.Quote function but trim off the quoted characters so we can
|
||||
// merge multiple quoted strings into one.
|
||||
expStart := strings.TrimSuffix(strconv.Quote(expected[:len(sofar)-1]), "\"")
|
||||
expMiss := strings.TrimSuffix(strings.TrimPrefix(strconv.Quote(string(expected[len(sofar)-1])), "\""), "\"")
|
||||
expEnd := strings.TrimPrefix(strconv.Quote(expected[len(sofar):]), "\"")
|
||||
|
||||
fmt.Fprintf(os.Stderr, "Expected: %s%s%s%s%s\n", expStart, RED, expMiss, RESET, expEnd)
|
||||
|
||||
// read the rest of the buffer
|
||||
p := make([]byte, buf.Buffered())
|
||||
buf.Read(p)
|
||||
|
||||
gotStart := strings.TrimSuffix(strconv.Quote(string(sofar[:len(sofar)-1])), "\"")
|
||||
gotMiss := strings.TrimSuffix(strings.TrimPrefix(strconv.Quote(string(sofar[len(sofar)-1])), "\""), "\"")
|
||||
gotEnd := strings.TrimPrefix(strconv.Quote(string(p)), "\"")
|
||||
|
||||
fmt.Fprintf(os.Stderr, "Got: %s%s%s%s%s\n", gotStart, RED, gotMiss, RESET, gotEnd)
|
||||
panic(fmt.Errorf("Unexpected Rune %q, Expected %q\n", got, r))
|
||||
} else {
|
||||
fmt.Printf("%c", r)
|
||||
}
|
||||
}
|
||||
}
|
||||
-158
@@ -1,158 +0,0 @@
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// DO NOT MODIFY THIS FILE!
|
||||
//
|
||||
// This file was automatically generated via the commands:
|
||||
//
|
||||
// go get github.com/coryb/autoplay
|
||||
// autoplay -n autoplay/select.go go run select.go
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
package main
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"fmt"
|
||||
"github.com/kr/pty"
|
||||
"os"
|
||||
"os/exec"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
const (
|
||||
RED = "\033[31m"
|
||||
RESET = "\033[0m"
|
||||
)
|
||||
|
||||
func main() {
|
||||
fh, tty, _ := pty.Open()
|
||||
defer tty.Close()
|
||||
defer fh.Close()
|
||||
c := exec.Command("go", "run", "select.go")
|
||||
c.Stdin = tty
|
||||
c.Stdout = tty
|
||||
c.Stderr = tty
|
||||
c.Start()
|
||||
buf := bufio.NewReaderSize(fh, 1024)
|
||||
|
||||
expect("standard\r\n", buf)
|
||||
expect("\x1b[0G\x1b[2K\x1b[1;92m? \x1b[0m\x1b[1;99mChoose a color:\x1b[0m\r\n", buf)
|
||||
expect("\x1b[1;36m❯ red\x1b[0m\r\n", buf)
|
||||
expect("\x1b[1;99m blue\x1b[0m\r\n", buf)
|
||||
expect("\x1b[1;99m green\x1b[0m\r\n", buf)
|
||||
expect("\x1b[?25l", buf)
|
||||
fh.Write([]byte("\r"))
|
||||
expect("\x1b[?25h\x1b[0G\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1;92m? \x1b[0m\x1b[1;99mChoose a color:\x1b[0m\x1b[36m red\x1b[0m\r\n", buf)
|
||||
expect("Answered red.\r\n", buf)
|
||||
expect("---------------------\r\n", buf)
|
||||
expect("short\r\n", buf)
|
||||
expect("\x1b[0G\x1b[2K\x1b[1;92m? \x1b[0m\x1b[1;99mChoose a color:\x1b[0m\r\n", buf)
|
||||
expect("\x1b[1;36m❯ red\x1b[0m\r\n", buf)
|
||||
expect("\x1b[1;99m blue\x1b[0m\r\n", buf)
|
||||
expect("\x1b[?25l", buf)
|
||||
fh.Write([]byte("\r"))
|
||||
expect("\x1b[?25h\x1b[0G\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1;92m? \x1b[0m\x1b[1;99mChoose a color:\x1b[0m\x1b[36m red\x1b[0m\r\n", buf)
|
||||
expect("Answered red.\r\n", buf)
|
||||
expect("---------------------\r\n", buf)
|
||||
expect("default\r\n", buf)
|
||||
expect("\x1b[0G\x1b[2K\x1b[1;92m? \x1b[0m\x1b[1;99mChoose a color (should default blue):\x1b[0m\r\n", buf)
|
||||
expect("\x1b[1;99m red\x1b[0m\r\n", buf)
|
||||
expect("\x1b[1;36m❯ blue\x1b[0m\r\n", buf)
|
||||
expect("\x1b[1;99m green\x1b[0m\r\n", buf)
|
||||
expect("\x1b[?25l", buf)
|
||||
fh.Write([]byte("\r"))
|
||||
expect("\x1b[?25h\x1b[0G\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1;92m? \x1b[0m\x1b[1;99mChoose a color (should default blue):\x1b[0m\x1b[36m blue\x1b[0m\r\n", buf)
|
||||
expect("Answered blue.\r\n", buf)
|
||||
expect("---------------------\r\n", buf)
|
||||
expect("one\r\n", buf)
|
||||
expect("\x1b[0G\x1b[2K\x1b[1;92m? \x1b[0m\x1b[1;99mChoose one:\x1b[0m\r\n", buf)
|
||||
expect("\x1b[1;36m❯ hello\x1b[0m\r\n", buf)
|
||||
expect("\x1b[?25l", buf)
|
||||
fh.Write([]byte("\r"))
|
||||
expect("\x1b[?25h\x1b[0G\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1;92m? \x1b[0m\x1b[1;99mChoose one:\x1b[0m\x1b[36m hello\x1b[0m\r\n", buf)
|
||||
expect("Answered hello.\r\n", buf)
|
||||
expect("---------------------\r\n", buf)
|
||||
expect("no help, type ?\r\n", buf)
|
||||
expect("\x1b[0G\x1b[2K\x1b[1;92m? \x1b[0m\x1b[1;99mChoose a color:\x1b[0m\r\n", buf)
|
||||
expect("\x1b[1;36m❯ red\x1b[0m\r\n", buf)
|
||||
expect("\x1b[1;99m blue\x1b[0m\r\n", buf)
|
||||
expect("\x1b[?25l", buf)
|
||||
fh.Write([]byte("\r"))
|
||||
expect("\x1b[?25h\x1b[0G\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1;92m? \x1b[0m\x1b[1;99mChoose a color:\x1b[0m\x1b[36m red\x1b[0m\r\n", buf)
|
||||
expect("Answered red.\r\n", buf)
|
||||
expect("---------------------\r\n", buf)
|
||||
expect("passes through bottom\r\n", buf)
|
||||
expect("\x1b[0G\x1b[2K\x1b[1;92m? \x1b[0m\x1b[1;99mChoose one:\x1b[0m\r\n", buf)
|
||||
expect("\x1b[1;36m❯ red\x1b[0m\r\n", buf)
|
||||
expect("\x1b[1;99m blue\x1b[0m\r\n", buf)
|
||||
expect("\x1b[?25l", buf)
|
||||
fh.Write([]byte("\x1b"))
|
||||
fh.Write([]byte("["))
|
||||
fh.Write([]byte("B"))
|
||||
expect("\x1b[0G\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1;92m? \x1b[0m\x1b[1;99mChoose one:\x1b[0m\r\n", buf)
|
||||
expect("\x1b[1;99m red\x1b[0m\r\n", buf)
|
||||
expect("\x1b[1;36m❯ blue\x1b[0m\r\n", buf)
|
||||
fh.Write([]byte("\x1b"))
|
||||
fh.Write([]byte("["))
|
||||
fh.Write([]byte("B"))
|
||||
expect("\x1b[0G\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1;92m? \x1b[0m\x1b[1;99mChoose one:\x1b[0m\r\n", buf)
|
||||
expect("\x1b[1;36m❯ red\x1b[0m\r\n", buf)
|
||||
expect("\x1b[1;99m blue\x1b[0m\r\n", buf)
|
||||
fh.Write([]byte("\r"))
|
||||
expect("\x1b[?25h\x1b[0G\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1;92m? \x1b[0m\x1b[1;99mChoose one:\x1b[0m\x1b[36m red\x1b[0m\r\n", buf)
|
||||
expect("Answered red.\r\n", buf)
|
||||
expect("---------------------\r\n", buf)
|
||||
expect("passes through top\r\n", buf)
|
||||
expect("\x1b[0G\x1b[2K\x1b[1;92m? \x1b[0m\x1b[1;99mChoose one:\x1b[0m\r\n", buf)
|
||||
expect("\x1b[1;36m❯ red\x1b[0m\r\n", buf)
|
||||
expect("\x1b[1;99m blue\x1b[0m\r\n", buf)
|
||||
expect("\x1b[?25l", buf)
|
||||
fh.Write([]byte("\x1b"))
|
||||
fh.Write([]byte("["))
|
||||
fh.Write([]byte("A"))
|
||||
expect("\x1b[0G\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1;92m? \x1b[0m\x1b[1;99mChoose one:\x1b[0m\r\n", buf)
|
||||
expect("\x1b[1;99m red\x1b[0m\r\n", buf)
|
||||
expect("\x1b[1;36m❯ blue\x1b[0m\r\n", buf)
|
||||
fh.Write([]byte("\r"))
|
||||
expect("\x1b[?25h\x1b[0G\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1;92m? \x1b[0m\x1b[1;99mChoose one:\x1b[0m\x1b[36m blue\x1b[0m\r\n", buf)
|
||||
expect("Answered blue.\r\n", buf)
|
||||
expect("---------------------\r\n", buf)
|
||||
expect("no options\r\n", buf)
|
||||
|
||||
c.Wait()
|
||||
tty.Close()
|
||||
fh.Close()
|
||||
}
|
||||
|
||||
func expect(expected string, buf *bufio.Reader) {
|
||||
sofar := []rune{}
|
||||
for _, r := range expected {
|
||||
got, _, _ := buf.ReadRune()
|
||||
sofar = append(sofar, got)
|
||||
if got != r {
|
||||
fmt.Fprintln(os.Stderr, RESET)
|
||||
|
||||
// we want to quote the string but we also want to make the unexpected character RED
|
||||
// so we use the strconv.Quote function but trim off the quoted characters so we can
|
||||
// merge multiple quoted strings into one.
|
||||
expStart := strings.TrimSuffix(strconv.Quote(expected[:len(sofar)-1]), "\"")
|
||||
expMiss := strings.TrimSuffix(strings.TrimPrefix(strconv.Quote(string(expected[len(sofar)-1])), "\""), "\"")
|
||||
expEnd := strings.TrimPrefix(strconv.Quote(expected[len(sofar):]), "\"")
|
||||
|
||||
fmt.Fprintf(os.Stderr, "Expected: %s%s%s%s%s\n", expStart, RED, expMiss, RESET, expEnd)
|
||||
|
||||
// read the rest of the buffer
|
||||
p := make([]byte, buf.Buffered())
|
||||
buf.Read(p)
|
||||
|
||||
gotStart := strings.TrimSuffix(strconv.Quote(string(sofar[:len(sofar)-1])), "\"")
|
||||
gotMiss := strings.TrimSuffix(strings.TrimPrefix(strconv.Quote(string(sofar[len(sofar)-1])), "\""), "\"")
|
||||
gotEnd := strings.TrimPrefix(strconv.Quote(string(p)), "\"")
|
||||
|
||||
fmt.Fprintf(os.Stderr, "Got: %s%s%s%s%s\n", gotStart, RED, gotMiss, RESET, gotEnd)
|
||||
panic(fmt.Errorf("Unexpected Rune %q, Expected %q\n", got, r))
|
||||
} else {
|
||||
fmt.Printf("%c", r)
|
||||
}
|
||||
}
|
||||
}
|
||||
-114
@@ -1,114 +0,0 @@
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// DO NOT MODIFY THIS FILE!
|
||||
//
|
||||
// This file was automatically generated via the commands:
|
||||
//
|
||||
// go get github.com/coryb/autoplay
|
||||
// autoplay -n autoplay/selectThenInput.go go run selectThenInput.go
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
package main
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"fmt"
|
||||
"github.com/kr/pty"
|
||||
"os"
|
||||
"os/exec"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
const (
|
||||
RED = "\033[31m"
|
||||
RESET = "\033[0m"
|
||||
)
|
||||
|
||||
func main() {
|
||||
fh, tty, _ := pty.Open()
|
||||
defer tty.Close()
|
||||
defer fh.Close()
|
||||
c := exec.Command("go", "run", "selectThenInput.go")
|
||||
c.Stdin = tty
|
||||
c.Stdout = tty
|
||||
c.Stderr = tty
|
||||
c.Start()
|
||||
buf := bufio.NewReaderSize(fh, 1024)
|
||||
|
||||
expect("\x1b[0G\x1b[2K\x1b[1;92m? \x1b[0m\x1b[1;99mChoose a color:\x1b[0m\r\n", buf)
|
||||
expect("\x1b[1;36m❯ red\x1b[0m\r\n", buf)
|
||||
expect("\x1b[1;99m blue\x1b[0m\r\n", buf)
|
||||
expect("\x1b[1;99m green\x1b[0m\r\n", buf)
|
||||
expect("\x1b[?25l", buf)
|
||||
fh.Write([]byte("\x1b"))
|
||||
fh.Write([]byte("["))
|
||||
fh.Write([]byte("B"))
|
||||
expect("\x1b[0G\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1;92m? \x1b[0m\x1b[1;99mChoose a color:\x1b[0m\r\n", buf)
|
||||
expect("\x1b[1;99m red\x1b[0m\r\n", buf)
|
||||
expect("\x1b[1;36m❯ blue\x1b[0m\r\n", buf)
|
||||
expect("\x1b[1;99m green\x1b[0m\r\n", buf)
|
||||
fh.Write([]byte("\r"))
|
||||
expect("\x1b[?25h\x1b[0G\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1F\x1b[2K\x1b[1;92m? \x1b[0m\x1b[1;99mChoose a color:\x1b[0m\x1b[36m blue\x1b[0m\r\n", buf)
|
||||
expect("\x1b[0G\x1b[2K\x1b[1;92m? \x1b[0m\x1b[1;99mWhat is your name? \x1b[0m", buf)
|
||||
fh.Write([]byte("L"))
|
||||
expect("L", buf)
|
||||
fh.Write([]byte("a"))
|
||||
expect("a", buf)
|
||||
fh.Write([]byte("r"))
|
||||
expect("r", buf)
|
||||
fh.Write([]byte("r"))
|
||||
expect("r", buf)
|
||||
fh.Write([]byte("y"))
|
||||
expect("y", buf)
|
||||
fh.Write([]byte(" "))
|
||||
expect(" ", buf)
|
||||
fh.Write([]byte("W"))
|
||||
expect("W", buf)
|
||||
fh.Write([]byte("a"))
|
||||
expect("a", buf)
|
||||
fh.Write([]byte("l"))
|
||||
expect("l", buf)
|
||||
fh.Write([]byte("l"))
|
||||
expect("l", buf)
|
||||
fh.Write([]byte("\r"))
|
||||
expect("\r\r\n", buf)
|
||||
expect("\x1b[1F\x1b[0G\x1b[2K\x1b[1;92m? \x1b[0m\x1b[1;99mWhat is your name? \x1b[0m\x1b[36mLarry Wall\x1b[0m\r\n", buf)
|
||||
expect("Larry Wall chose blue.\r\n", buf)
|
||||
|
||||
c.Wait()
|
||||
tty.Close()
|
||||
fh.Close()
|
||||
}
|
||||
|
||||
func expect(expected string, buf *bufio.Reader) {
|
||||
sofar := []rune{}
|
||||
for _, r := range expected {
|
||||
got, _, _ := buf.ReadRune()
|
||||
sofar = append(sofar, got)
|
||||
if got != r {
|
||||
fmt.Fprintln(os.Stderr, RESET)
|
||||
|
||||
// we want to quote the string but we also want to make the unexpected character RED
|
||||
// so we use the strconv.Quote function but trim off the quoted characters so we can
|
||||
// merge multiple quoted strings into one.
|
||||
expStart := strings.TrimSuffix(strconv.Quote(expected[:len(sofar)-1]), "\"")
|
||||
expMiss := strings.TrimSuffix(strings.TrimPrefix(strconv.Quote(string(expected[len(sofar)-1])), "\""), "\"")
|
||||
expEnd := strings.TrimPrefix(strconv.Quote(expected[len(sofar):]), "\"")
|
||||
|
||||
fmt.Fprintf(os.Stderr, "Expected: %s%s%s%s%s\n", expStart, RED, expMiss, RESET, expEnd)
|
||||
|
||||
// read the rest of the buffer
|
||||
p := make([]byte, buf.Buffered())
|
||||
buf.Read(p)
|
||||
|
||||
gotStart := strings.TrimSuffix(strconv.Quote(string(sofar[:len(sofar)-1])), "\"")
|
||||
gotMiss := strings.TrimSuffix(strings.TrimPrefix(strconv.Quote(string(sofar[len(sofar)-1])), "\""), "\"")
|
||||
gotEnd := strings.TrimPrefix(strconv.Quote(string(p)), "\"")
|
||||
|
||||
fmt.Fprintf(os.Stderr, "Got: %s%s%s%s%s\n", gotStart, RED, gotMiss, RESET, gotEnd)
|
||||
panic(fmt.Errorf("Unexpected Rune %q, Expected %q\n", got, r))
|
||||
} else {
|
||||
fmt.Printf("%c", r)
|
||||
}
|
||||
}
|
||||
}
|
||||
-43
@@ -1,43 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"gopkg.in/AlecAivazis/survey.v1"
|
||||
"gopkg.in/AlecAivazis/survey.v1/tests/util"
|
||||
)
|
||||
|
||||
var answer = false
|
||||
|
||||
var goodTable = []TestUtil.TestTableEntry{
|
||||
{
|
||||
"Enter 'yes'", &survey.Confirm{
|
||||
Message: "yes:",
|
||||
}, &answer,
|
||||
},
|
||||
{
|
||||
"Enter 'no'", &survey.Confirm{
|
||||
Message: "yes:",
|
||||
}, &answer,
|
||||
},
|
||||
{
|
||||
"default", &survey.Confirm{
|
||||
Message: "yes:",
|
||||
Default: true,
|
||||
}, &answer,
|
||||
},
|
||||
{
|
||||
"not recognized (enter random letter)", &survey.Confirm{
|
||||
Message: "yes:",
|
||||
Default: true,
|
||||
}, &answer,
|
||||
},
|
||||
{
|
||||
"no help - type '?'", &survey.Confirm{
|
||||
Message: "yes:",
|
||||
Default: true,
|
||||
}, &answer,
|
||||
},
|
||||
}
|
||||
|
||||
func main() {
|
||||
TestUtil.RunTable(goodTable)
|
||||
}
|
||||
-42
@@ -1,42 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"gopkg.in/AlecAivazis/survey.v1"
|
||||
)
|
||||
|
||||
var simpleQs = []*survey.Question{
|
||||
{
|
||||
Name: "color",
|
||||
Prompt: &survey.Select{
|
||||
Message: "select1:",
|
||||
Options: []string{"red", "blue", "green"},
|
||||
},
|
||||
Validate: survey.Required,
|
||||
},
|
||||
{
|
||||
Name: "color2",
|
||||
Prompt: &survey.Select{
|
||||
Message: "select2:",
|
||||
Options: []string{"red", "blue", "green"},
|
||||
},
|
||||
Validate: survey.Required,
|
||||
},
|
||||
}
|
||||
|
||||
func main() {
|
||||
answers := struct {
|
||||
Color string
|
||||
Color2 string
|
||||
}{}
|
||||
// ask the question
|
||||
err := survey.Ask(simpleQs, &answers)
|
||||
|
||||
if err != nil {
|
||||
fmt.Println(err.Error())
|
||||
return
|
||||
}
|
||||
// print the answers
|
||||
fmt.Printf("%s and %s.\n", answers.Color, answers.Color2)
|
||||
}
|
||||
-26
@@ -1,26 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/AlecAivazis/survey"
|
||||
"github.com/AlecAivazis/survey/tests/util"
|
||||
)
|
||||
|
||||
var answer = ""
|
||||
|
||||
var goodTable = []TestUtil.TestTableEntry{
|
||||
{
|
||||
"should open in editor", &survey.Editor{
|
||||
Message: "should open",
|
||||
}, &answer,
|
||||
},
|
||||
{
|
||||
"has help", &survey.Editor{
|
||||
Message: "press ? to see message",
|
||||
Help: "Does this work?",
|
||||
}, &answer,
|
||||
},
|
||||
}
|
||||
|
||||
func main() {
|
||||
TestUtil.RunTable(goodTable)
|
||||
}
|
||||
-55
@@ -1,55 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"gopkg.in/AlecAivazis/survey.v1"
|
||||
"gopkg.in/AlecAivazis/survey.v1/tests/util"
|
||||
)
|
||||
|
||||
var (
|
||||
confirmAns = false
|
||||
inputAns = ""
|
||||
multiselectAns = []string{}
|
||||
selectAns = ""
|
||||
passwordAns = ""
|
||||
)
|
||||
|
||||
var goodTable = []TestUtil.TestTableEntry{
|
||||
{
|
||||
"confirm", &survey.Confirm{
|
||||
Message: "Is it raining?",
|
||||
Help: "Go outside, if your head becomes wet the answer is probably 'yes'",
|
||||
}, &confirmAns,
|
||||
},
|
||||
{
|
||||
"input", &survey.Input{
|
||||
Message: "What is your phone number:",
|
||||
Help: "Phone number should include the area code, parentheses optional",
|
||||
}, &inputAns,
|
||||
},
|
||||
{
|
||||
"select", &survey.MultiSelect{
|
||||
Message: "What days are you available:",
|
||||
Help: "We are closed weekends and avaibility is limited on Wednesday",
|
||||
Options: []string{"Monday", "Tuesday", "Wednesday", "Thursday", "Friday"},
|
||||
Default: []string{"Monday", "Tuesday", "Thursday", "Friday"},
|
||||
}, &multiselectAns,
|
||||
},
|
||||
{
|
||||
"select", &survey.Select{
|
||||
Message: "Choose a color:",
|
||||
Help: "Blue is the best color, but it is your choice",
|
||||
Options: []string{"red", "blue", "green"},
|
||||
Default: "blue",
|
||||
}, &selectAns,
|
||||
},
|
||||
{
|
||||
"password", &survey.Password{
|
||||
Message: "Enter a secret:",
|
||||
Help: "Don't really enter a secret, this is just for testing",
|
||||
}, &passwordAns,
|
||||
},
|
||||
}
|
||||
|
||||
func main() {
|
||||
TestUtil.RunTable(goodTable)
|
||||
}
|
||||
-27
@@ -1,27 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"gopkg.in/AlecAivazis/survey.v1"
|
||||
"gopkg.in/AlecAivazis/survey.v1/tests/util"
|
||||
)
|
||||
|
||||
var val = ""
|
||||
|
||||
var table = []TestUtil.TestTableEntry{
|
||||
{
|
||||
"no default", &survey.Input{Message: "Hello world"}, &val,
|
||||
},
|
||||
{
|
||||
"default", &survey.Input{Message: "Hello world", Default: "default"}, &val,
|
||||
},
|
||||
{
|
||||
"no help, send '?'", &survey.Input{Message: "Hello world"}, &val,
|
||||
},
|
||||
{
|
||||
"input text in random location", &survey.Input{Message: "Hello"}, &val,
|
||||
},
|
||||
}
|
||||
|
||||
func main() {
|
||||
TestUtil.RunTable(table)
|
||||
}
|
||||
-23
@@ -1,23 +0,0 @@
|
||||
package main
|
||||
|
||||
import "gopkg.in/AlecAivazis/survey.v1"
|
||||
|
||||
func main() {
|
||||
color := ""
|
||||
prompt := &survey.Select{
|
||||
Message: "Choose a color:",
|
||||
Options: []string{
|
||||
"a",
|
||||
"b",
|
||||
"c",
|
||||
"d",
|
||||
"e",
|
||||
"f",
|
||||
"g",
|
||||
"h",
|
||||
"i",
|
||||
"j",
|
||||
},
|
||||
}
|
||||
survey.AskOne(prompt, &color, nil)
|
||||
}
|
||||
-42
@@ -1,42 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"gopkg.in/AlecAivazis/survey.v1"
|
||||
"gopkg.in/AlecAivazis/survey.v1/tests/util"
|
||||
)
|
||||
|
||||
var answer = []string{}
|
||||
|
||||
var table = []TestUtil.TestTableEntry{
|
||||
{
|
||||
"standard", &survey.MultiSelect{
|
||||
Message: "What days do you prefer:",
|
||||
Options: []string{"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"},
|
||||
}, &answer,
|
||||
},
|
||||
{
|
||||
"default (sunday, tuesday)", &survey.MultiSelect{
|
||||
Message: "What days do you prefer:",
|
||||
Options: []string{"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"},
|
||||
Default: []string{"Sunday", "Tuesday"},
|
||||
}, &answer,
|
||||
},
|
||||
{
|
||||
"default not found", &survey.MultiSelect{
|
||||
Message: "What days do you prefer:",
|
||||
Options: []string{"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"},
|
||||
Default: []string{"Sundayaa"},
|
||||
}, &answer,
|
||||
},
|
||||
{
|
||||
"no help - type ?", &survey.MultiSelect{
|
||||
Message: "What days do you prefer:",
|
||||
Options: []string{"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"},
|
||||
Default: []string{"Sundayaa"},
|
||||
}, &answer,
|
||||
},
|
||||
}
|
||||
|
||||
func main() {
|
||||
TestUtil.RunTable(table)
|
||||
}
|
||||
-24
@@ -1,24 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"gopkg.in/AlecAivazis/survey.v1"
|
||||
"gopkg.in/AlecAivazis/survey.v1/tests/util"
|
||||
)
|
||||
|
||||
var value = ""
|
||||
|
||||
var table = []TestUtil.TestTableEntry{
|
||||
{
|
||||
"standard", &survey.Password{Message: "Please type your password:"}, &value,
|
||||
},
|
||||
{
|
||||
"please make sure paste works", &survey.Password{Message: "Please paste your password:"}, &value,
|
||||
},
|
||||
{
|
||||
"no help, send '?'", &survey.Password{Message: "Please type your password:"}, &value,
|
||||
},
|
||||
}
|
||||
|
||||
func main() {
|
||||
TestUtil.RunTable(table)
|
||||
}
|
||||
-67
@@ -1,67 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"gopkg.in/AlecAivazis/survey.v1"
|
||||
"gopkg.in/AlecAivazis/survey.v1/tests/util"
|
||||
)
|
||||
|
||||
var answer = ""
|
||||
|
||||
var goodTable = []TestUtil.TestTableEntry{
|
||||
{
|
||||
"standard", &survey.Select{
|
||||
Message: "Choose a color:",
|
||||
Options: []string{"red", "blue", "green"},
|
||||
}, &answer,
|
||||
},
|
||||
{
|
||||
"short", &survey.Select{
|
||||
Message: "Choose a color:",
|
||||
Options: []string{"red", "blue"},
|
||||
}, &answer,
|
||||
},
|
||||
{
|
||||
"default", &survey.Select{
|
||||
Message: "Choose a color (should default blue):",
|
||||
Options: []string{"red", "blue", "green"},
|
||||
Default: "blue",
|
||||
}, &answer,
|
||||
},
|
||||
{
|
||||
"one", &survey.Select{
|
||||
Message: "Choose one:",
|
||||
Options: []string{"hello"},
|
||||
}, &answer,
|
||||
},
|
||||
{
|
||||
"no help, type ?", &survey.Select{
|
||||
Message: "Choose a color:",
|
||||
Options: []string{"red", "blue"},
|
||||
}, &answer,
|
||||
},
|
||||
{
|
||||
"passes through bottom", &survey.Select{
|
||||
Message: "Choose one:",
|
||||
Options: []string{"red", "blue"},
|
||||
}, &answer,
|
||||
},
|
||||
{
|
||||
"passes through top", &survey.Select{
|
||||
Message: "Choose one:",
|
||||
Options: []string{"red", "blue"},
|
||||
}, &answer,
|
||||
},
|
||||
}
|
||||
|
||||
var badTable = []TestUtil.TestTableEntry{
|
||||
{
|
||||
"no options", &survey.Select{
|
||||
Message: "Choose one:",
|
||||
}, &answer,
|
||||
},
|
||||
}
|
||||
|
||||
func main() {
|
||||
TestUtil.RunTable(goodTable)
|
||||
TestUtil.RunErrorTable(badTable)
|
||||
}
|
||||
-42
@@ -1,42 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"gopkg.in/AlecAivazis/survey.v1"
|
||||
)
|
||||
|
||||
// the questions to ask
|
||||
var simpleQs = []*survey.Question{
|
||||
{
|
||||
Name: "color",
|
||||
Prompt: &survey.Select{
|
||||
Message: "Choose a color:",
|
||||
Options: []string{"red", "blue", "green"},
|
||||
},
|
||||
Validate: survey.Required,
|
||||
},
|
||||
{
|
||||
Name: "name",
|
||||
Prompt: &survey.Input{
|
||||
Message: "What is your name?",
|
||||
},
|
||||
Validate: survey.Required,
|
||||
},
|
||||
}
|
||||
|
||||
func main() {
|
||||
answers := struct {
|
||||
Color string
|
||||
Name string
|
||||
}{}
|
||||
// ask the question
|
||||
err := survey.Ask(simpleQs, &answers)
|
||||
|
||||
if err != nil {
|
||||
fmt.Println(err.Error())
|
||||
return
|
||||
}
|
||||
// print the answers
|
||||
fmt.Printf("%s chose %s.\n", answers.Name, answers.Color)
|
||||
}
|
||||
-50
@@ -1,50 +0,0 @@
|
||||
package TestUtil
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"reflect"
|
||||
|
||||
"gopkg.in/AlecAivazis/survey.v1"
|
||||
)
|
||||
|
||||
type TestTableEntry struct {
|
||||
Name string
|
||||
Prompt survey.Prompt
|
||||
Value interface{}
|
||||
}
|
||||
|
||||
func formatAnswer(ans interface{}) {
|
||||
// show the answer to the user
|
||||
fmt.Printf("Answered %v.\n", reflect.ValueOf(ans).Elem())
|
||||
fmt.Println("---------------------")
|
||||
}
|
||||
|
||||
func RunTable(table []TestTableEntry) {
|
||||
// go over every entry in the table
|
||||
for _, entry := range table {
|
||||
// tell the user what we are going to ask them
|
||||
fmt.Println(entry.Name)
|
||||
// perform the ask
|
||||
err := survey.AskOne(entry.Prompt, entry.Value, nil)
|
||||
if err != nil {
|
||||
fmt.Printf("AskOne on %v's prompt failed: %v.", entry.Name, err.Error())
|
||||
break
|
||||
}
|
||||
// show the answer to the user
|
||||
formatAnswer(entry.Value)
|
||||
}
|
||||
}
|
||||
|
||||
func RunErrorTable(table []TestTableEntry) {
|
||||
// go over every entry in the table
|
||||
for _, entry := range table {
|
||||
// tell the user what we are going to ask them
|
||||
fmt.Println(entry.Name)
|
||||
// perform the ask
|
||||
err := survey.AskOne(entry.Prompt, entry.Value, nil)
|
||||
if err == nil {
|
||||
fmt.Printf("AskOne on %v's prompt didn't fail.", entry.Name)
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user