Browse Source

Initial commit

master
jimi 9 years ago
commit
8ba810d8be
  1. 0
      README.md
  2. 42
      main.go
  3. 3
      test.txt

0
README.md

42
main.go

@ -0,0 +1,42 @@
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()
}
}

3
test.txt

@ -0,0 +1,3 @@
now is the time
we are the champions
days of wine and roses
Loading…
Cancel
Save