commit 8ba810d8be73c5b487d8ea38872511f5039e046c Author: jimi Date: Wed Mar 2 16:59:28 2016 -0600 Initial commit diff --git a/README.md b/README.md new file mode 100644 index 0000000..e69de29 diff --git a/main.go b/main.go new file mode 100644 index 0000000..6478ba4 --- /dev/null +++ b/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() + } +} diff --git a/test.txt b/test.txt new file mode 100644 index 0000000..457931c --- /dev/null +++ b/test.txt @@ -0,0 +1,3 @@ +now is the time +we are the champions +days of wine and roses