Skip to content
This repository has been archived by the owner on Apr 19, 2024. It is now read-only.

Commit

Permalink
Merge branch 'master' into fix/select-default-value
Browse files Browse the repository at this point in the history
  • Loading branch information
AlecAivazis authored Apr 21, 2017
2 parents 4364bdf + 74e3258 commit 03031b4
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 26 deletions.
10 changes: 4 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -138,11 +138,9 @@ response:
q := &survey.Question{
Prompt: &survey.Input{Message: "Hello world validation"},
Validate: func (val interface{}) error {
// since we are validating an Input, this will always succeed
if str, ok := val.(string) ; ok {
if len(str) > 10 {
return errors.New("This response cannot be longer than 10 characters.")
}
// since we are validating an Input, the assertion will always succeed
if str, ok := val.(string) ; ok && len(str) > 10 {
return errors.New("This response cannot be longer than 10 characters.")
}
}
}
Expand All @@ -162,7 +160,7 @@ validators include:

This project tries to maintain semantic GitHub releases as closely as possible. As such, services
like [gopkg.in](http://labix.org/gopkg.in) work very well to ensure non-breaking changes whenever
you build your application. For example, importing v1 of survey would look something like
you build your application. For example, importing v1 of survey could look something like

```golang
package main
Expand Down
2 changes: 1 addition & 1 deletion confirm.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ func (c *Confirm) Cleanup(rl *readline.Instance, val interface{}) error {
// go up one line
terminal.CursorPreviousLine(1)
// clear the line
terminal.EraseInLine(0)
terminal.EraseLine(terminal.ERASE_LINE_ALL)

// the string version of the answer
ans := ""
Expand Down
2 changes: 1 addition & 1 deletion input.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func (i *Input) Cleanup(rl *readline.Instance, val interface{}) error {
// go up one line
terminal.CursorPreviousLine(1)
// clear the line
terminal.EraseInLine(0)
terminal.EraseLine(terminal.ERASE_LINE_ALL)

// render the template
out, err := core.RunTemplate(
Expand Down
6 changes: 3 additions & 3 deletions multiselect.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func (m *MultiSelect) render() error {
// clean up what we left behind last time
for range m.Options {
terminal.CursorPreviousLine(1)
terminal.EraseInLine(0)
terminal.EraseLine(terminal.ERASE_LINE_ALL)
}

// render the template summarizing the current state
Expand Down Expand Up @@ -170,10 +170,10 @@ func (m *MultiSelect) Prompt(rl *readline.Instance) (interface{}, error) {
// Cleanup removes the options section, and renders the ask like a normal question.
func (m *MultiSelect) Cleanup(rl *readline.Instance, val interface{}) error {
terminal.CursorPreviousLine(1)
terminal.EraseInLine(0)
terminal.EraseLine(terminal.ERASE_LINE_ALL)
for range m.Options {
terminal.CursorPreviousLine(1)
terminal.EraseInLine(0)
terminal.EraseLine(terminal.ERASE_LINE_ALL)
}

// execute the output summary template with the answer
Expand Down
6 changes: 3 additions & 3 deletions select.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func (s *Select) OnChange(line []rune, pos int, key rune) (newLine []rune, newPo
func (s *Select) render() error {
for range s.Options {
terminal.CursorPreviousLine(1)
terminal.EraseInLine(0)
terminal.EraseLine(terminal.ERASE_LINE_ALL)
}

// the formatted response
Expand Down Expand Up @@ -163,10 +163,10 @@ func (s *Select) Prompt(rl *readline.Instance) (interface{}, error) {

func (s *Select) Cleanup(rl *readline.Instance, val interface{}) error {
terminal.CursorPreviousLine(1)
terminal.EraseInLine(0)
terminal.EraseLine(terminal.ERASE_LINE_ALL)
for range s.Options {
terminal.CursorPreviousLine(1)
terminal.EraseInLine(0)
terminal.EraseLine(terminal.ERASE_LINE_ALL)
}

// execute the output summary template with the answer
Expand Down
14 changes: 6 additions & 8 deletions terminal/display.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
// +build !windows

package terminal

import (
"fmt"
)
type EraseLineMode int

func EraseInLine(mode int) {
fmt.Printf("\x1b[%dK", mode)
}
const (
ERASE_LINE_END EraseLineMode = iota
ERASE_LINE_START
ERASE_LINE_ALL
)
11 changes: 11 additions & 0 deletions terminal/display_posix.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// +build !windows

package terminal

import (
"fmt"
)

func EraseLine(mode EraseLineMode) {
fmt.Printf("\x1b[%dK", mode)
}
8 changes: 4 additions & 4 deletions terminal/display_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"unsafe"
)

func EraseInLine(mode int) {
func EraseLine(mode EraseLineMode) {
handle := syscall.Handle(os.Stdout.Fd())

var csbi consoleScreenBufferInfo
Expand All @@ -16,11 +16,11 @@ func EraseInLine(mode int) {
var x short
cursor := csbi.cursorPosition
switch mode {
case 1:
case ERASE_LINE_END:
x = csbi.size.x
case 2:
case ERASE_LINE_START:
x = 0
case 3:
case ERASE_LINE_ALL:
cursor.x = 0
x = csbi.size.x
}
Expand Down

0 comments on commit 03031b4

Please sign in to comment.