|
@ -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() |
|
|
|
|
|
} |
|
|
|
|
|
} |