Skip to content

Commit

Permalink
Fix windows support
Browse files Browse the repository at this point in the history
  • Loading branch information
angrybrad committed Apr 30, 2020
1 parent 8312818 commit cf8f965
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 13 deletions.
4 changes: 2 additions & 2 deletions ask.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func (i *UI) Ask(query string, opts *Options) (string, error) {
break
}

fmt.Fprintf(i.Writer, "Input must not be empty.\n\n")
fmt.Fprintf(i.Writer, "Input must not be empty.")
continue
}

Expand All @@ -74,7 +74,7 @@ func (i *UI) Ask(query string, opts *Options) (string, error) {
break
}

fmt.Fprintf(i.Writer, "Failed to validate input string: %s\n\n", err)
fmt.Fprintf(i.Writer, "Failed to validate input string: %s", err)
continue
}

Expand Down
4 changes: 2 additions & 2 deletions read.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ func (i *UI) read(opts *readOptions) (string, error) {
resultErr = fmt.Errorf("failed to read the input: %s", err)
}

resultStr = strings.TrimSuffix(line, LineSep)
resultStr = strings.Trim(line, LineSep)
// brute force for the moment
resultStr = strings.TrimSuffix(line, "\n")
resultStr = strings.TrimSuffix(resultStr, "\n")
}
}()

Expand Down
14 changes: 10 additions & 4 deletions read_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,18 @@ package input

import (
"bytes"
"fmt"
"io"
"io/ioutil"
"testing"
)

func TestRead(t *testing.T) {
var stringWithSpace = fmt.Sprintf("taichi nakashima%s", LineSep)
var expectedWithSpace = "taichi nakashima"
var stringNoSpace = fmt.Sprintf("passw0rd%s", LineSep)
var expectedNoSpace = "passw0rd"

cases := []struct {
opts *readOptions
userInput io.Reader
Expand All @@ -18,17 +24,17 @@ func TestRead(t *testing.T) {
mask: false,
maskVal: "",
},
userInput: bytes.NewBufferString("passw0rd"),
expect: "passw0rd",
userInput: bytes.NewBufferString(stringNoSpace),
expect: expectedNoSpace,
},

{
opts: &readOptions{
mask: false,
maskVal: "",
},
userInput: bytes.NewBufferString("taichi nakashima"),
expect: "taichi nakashima",
userInput: bytes.NewBufferString(stringWithSpace),
expect: expectedWithSpace,
},

// No good way to test masking...
Expand Down
10 changes: 5 additions & 5 deletions select.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func (i *UI) Select(query string, list []string, opts *Options) (string, error)

// Construct the query & display it to user
var buf bytes.Buffer
buf.WriteString(fmt.Sprintf("%s\n\n", query))
buf.WriteString(fmt.Sprintf("%s", query))
for i, item := range list {
buf.WriteString(fmt.Sprintf("%d. %s\n", i+1, item))
}
Expand Down Expand Up @@ -87,7 +87,7 @@ func (i *UI) Select(query string, list []string, opts *Options) (string, error)
break
}

fmt.Fprintf(i.Writer, "Input must not be empty. Answer by a number.\n\n")
fmt.Fprintf(i.Writer, "Input must not be empty. Answer by a number.")
continue
}

Expand All @@ -100,7 +100,7 @@ func (i *UI) Select(query string, list []string, opts *Options) (string, error)
}

fmt.Fprintf(i.Writer,
"%q is not a valid input. Answer by a number.\n\n", line)
"%q is not a valid input. Answer by a number.", line)
continue
}

Expand All @@ -112,7 +112,7 @@ func (i *UI) Select(query string, list []string, opts *Options) (string, error)
}

fmt.Fprintf(i.Writer,
"%q is not a valid choice. Choose a number from 1 to %d.\n\n",
"%q is not a valid choice. Choose a number from 1 to %d.",
line, len(list))
continue
}
Expand All @@ -125,7 +125,7 @@ func (i *UI) Select(query string, list []string, opts *Options) (string, error)
break
}

fmt.Fprintf(i.Writer, "Failed to validate input string: %s\n\n", err)
fmt.Fprintf(i.Writer, "Failed to validate input string: %s", err)
continue
}

Expand Down

0 comments on commit cf8f965

Please sign in to comment.