Potato is the code-name for a small open source project that these days I am working on. I think an average programmer should be able to write this program in a day, however a more realistic estimate for me will be something between 5 days to 3 months...
One more thing: there are programs that already do what potato aims to do, however I am writing Potato will in Go, a native language that produces binaries with low startup latency -- a good fit for small CLI programs.
Anyway, as a wise man once said:
A journey of a thousand miles begins with a single step.
Writing a string in color using Go
This is a feature that Potato will gonna need. The code snippet below shows how we can print a string in color using Go:
package main;
import (
"github.com/fatih/color"
)
func main() {
color.Red("Hello world")
}
More examples at github.com/fatih/color.
And a bit more work: splitting a string into its lines, prepending a colored prefix to each line, and printing it on the screen:
package main
import (
"fmt"
"strings"
"github.com/fatih/color"
)
func main() {
input := `
This is a
multiline
string
`
for _, line := range strings.Split(input, "\n") {
fmt.Println(color.RedString("[TOMATO] ") + line)
}
for _, line := range strings.Split(input, "\n") {
fmt.Println(color.GreenString("[LETTUCE] ") + line)
}
}
Another example: an inefficient way of prepending a colorful prefix to every line of a text file:
package main
import (
"fmt"
"log"
"os"
"strings"
"github.com/fatih/color"
)
func main() {
body, err := os.ReadFile("/workspaces/lorem.txt")
if err != nil {
log.Fatal(err)
}
for _, line := range strings.Split(string(body), "\n") {
fmt.Println(color.RedString("[PREFIX] ") + line)
}
}
Possible call syntax:
$ potato --std-out-color green \
--std-out-prefix "[STDOUT] " \
--std-err-color red \
--std-err-prefix "[STDERR] " \
--command build --project ./proj1
Top comments (0)