Skip to content

Commit ac226ec

Browse files
committed
Support multi-line text from stdin
1 parent 17858a6 commit ac226ec

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

cmd/qrc/qrc.go

+14-5
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
package main
22

33
import (
4-
"bufio"
54
"code.google.com/p/rsc/qr"
6-
"github.com/mattn/go-colorable"
5+
"fmt"
76
"github.com/jessevdk/go-flags"
7+
"github.com/mattn/go-colorable"
8+
"io/ioutil"
89
"os"
910

1011
"github.com/fumiyas/qrc/lib"
@@ -34,6 +35,11 @@ Text examples:
3435
os.Stderr.Write([]byte(v))
3536
}
3637

38+
func pErr(format string, a ...interface{}) {
39+
fmt.Fprint(os.Stdout, os.Args[0], ": ")
40+
fmt.Fprintf(os.Stdout, format, a...)
41+
}
42+
3743
func main() {
3844
ret := 0
3945
defer func() { os.Exit(ret) }()
@@ -55,9 +61,12 @@ func main() {
5561
if len(args) == 1 {
5662
text = args[0]
5763
} else {
58-
// FIXME: Read all input
59-
rd := bufio.NewReaderSize(os.Stdin, 1024)
60-
text_bytes, _, _ := rd.ReadLine()
64+
text_bytes, err := ioutil.ReadAll(os.Stdin)
65+
if err != nil {
66+
pErr("read from stdin failed: %v\n", err)
67+
ret = 1
68+
return
69+
}
6170
text = string(text_bytes)
6271
}
6372

0 commit comments

Comments
 (0)