From 8ba810d8be73c5b487d8ea38872511f5039e046c Mon Sep 17 00:00:00 2001 From: jimi Date: Wed, 2 Mar 2016 16:59:28 -0600 Subject: [PATCH] Initial commit --- README.md | 0 main.go | 42 ++++++++++++++++++++++++++++++++++++++++++ test.txt | 3 +++ 3 files changed, 45 insertions(+) create mode 100644 README.md create mode 100644 main.go create mode 100644 test.txt 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