Learning the ins and outs of the bufio library...
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

42 lines
805 B

package main
import (
"bufio"
"os"
"strings"
)
// pipedInput looks for data queued up on stdin.
func pipedInput() bool {
stat, _ := os.Stdin.Stat()
if (stat.Mode() & os.ModeCharDevice) == 0 {
return true
}
return false
}
func main() {
// Process input and output with bufio
sti := bufio.NewScanner(os.Stdin)
sto := bufio.NewWriter(os.Stdout)
ste := bufio.NewWriter(os.Stderr)
// Check for existing data
if !pipedInput() {
// Prompt is there is none
// fmt.Fprintln(os.Stderr, "Feed me words!")
ste.WriteString("Feed me words!\n")
ste.Flush()
}
for sti.Scan() {
// Stop on an empty string
if sti.Text() == "" {
break
}
// Process the incoming strings
titled := strings.Title(sti.Text())
// fmt.Println(titled)
sto.WriteString(titled + "\n")
sto.Flush()
}
}