Skip to content

Commit

Permalink
Support multi-line text from stdin
Browse files Browse the repository at this point in the history
  • Loading branch information
fumiyas committed Sep 8, 2014
1 parent 17858a6 commit ac226ec
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions cmd/qrc/qrc.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package main

import (
"bufio"
"code.google.com/p/rsc/qr"
"github.com/mattn/go-colorable"
"fmt"
"github.com/jessevdk/go-flags"
"github.com/mattn/go-colorable"
"io/ioutil"
"os"

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

func pErr(format string, a ...interface{}) {
fmt.Fprint(os.Stdout, os.Args[0], ": ")
fmt.Fprintf(os.Stdout, format, a...)
}

func main() {
ret := 0
defer func() { os.Exit(ret) }()
Expand All @@ -55,9 +61,12 @@ func main() {
if len(args) == 1 {
text = args[0]
} else {
// FIXME: Read all input
rd := bufio.NewReaderSize(os.Stdin, 1024)
text_bytes, _, _ := rd.ReadLine()
text_bytes, err := ioutil.ReadAll(os.Stdin)
if err != nil {
pErr("read from stdin failed: %v\n", err)
ret = 1
return
}
text = string(text_bytes)
}

Expand Down

0 comments on commit ac226ec

Please sign in to comment.