peterh/liner — pull request #4 by frou (2014-01-31 15:43:57+00:00)
Title: Stop prompt attempts on non-terminal stdout

Hi - thanks for the cool package. I noticed that it's assumed that standard output is a terminal if the parent has set TERM, but that doesn't hold when shell output redirection is used. Before my changes, *State.refresh will panic in case (C) due to trying to work out how to maintain the line editor in the non-existent columns of a normal file.

I don't think my changes mess anything else up, but let me know what you think.

````
Desktop $ cat x.go
package main

import (
"fmt"
"strconv"

"github.com/frou/liner"
)

func main() {
ln := liner.NewLiner()
defer ln.Close()

var accum int
for {
s, err := ln.Prompt("$ ")
if err != nil {
fmt.Println("error:", err)
return
}

n, _ := strconv.Atoi(s)
accum += n
fmt.Println(accum)
}
}

(A)
Desktop $ go run x.go
$ 2
2
$ 4
6
$ 8
14
$ error: EOF

Desktop $ cat >input.txt
3
9
27

(B)
Desktop $ go run x.go output.txt
Desktop $ cat output.txt
error: standard output is not a terminal
````