Skip to content

Instantly share code, notes, and snippets.

@shinshin86
Created January 14, 2017 00:02
Show Gist options
  • Save shinshin86/45a1b0015ddea91bae744f67b3362078 to your computer and use it in GitHub Desktop.
Save shinshin86/45a1b0015ddea91bae744f67b3362078 to your computer and use it in GitHub Desktop.
"cf" display a color text of standard output.
// Usage:
// cf {color} {text}
// colors => black, red, green, yellow, blue, magenta, cyan, white
package main
import (
"fmt"
"flag"
)
func main() {
flag.Parse()
if(flag.NArg() == 2){
switch color := flag.Args()[0]; color {
case "black":
fmt.Printf("\x1b[30m%s\x1b[0m\n", flag.Args()[1])
case "red":
fmt.Printf("\x1b[31m%s\x1b[0m\n", flag.Args()[1])
case "green":
fmt.Printf("\x1b[32m%s\x1b[0m\n", flag.Args()[1])
case "yellow":
fmt.Printf("\x1b[33m%s\x1b[0m\n", flag.Args()[1])
case "blue":
fmt.Printf("\x1b[34m%s\x1b[0m\n", flag.Args()[1])
case "magenta":
fmt.Printf("\x1b[35m%s\x1b[0m\n", flag.Args()[1])
case "cyan":
fmt.Printf("\x1b[36m%s\x1b[0m\n", flag.Args()[1])
case "white":
fmt.Printf("\x1b[37m%s\x1b[0m\n", flag.Args()[1])
default:
fmt.Println("selected color\nblack\nred\ngreen\nyellow\nblue\nmagenta\ncyan\nwhite\n")
}
}else{
fmt.Println("Usage:\n")
fmt.Println("cf {color} {text}")
fmt.Println("selected color\nblack\nred\ngreen\nyellow\nblue\nmagenta\ncyan\nwhite\n")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment