Golang a gadget that displays font color and flashing, underline effects at the terminal

Source: Internet
Author: User
This is a creation in Article, where the information may have evolved or changed. In the terminal print different colors of the font, specific instructions see: http://blog.csdn.net/gxut555/article/details/7913591 himself with the Golang implementation of a, in addition to the Mac show no effect, the other side is still normal , the effect is as follows: The code looks like this (see: https://github.com/liuyongshuai/goutils/.) : "*/* * @author Liu yongshuai<liuyongshuai@hotmail.com> * @package gocolorterm * @date 2018-01-25 19:19 */package g Ocolortermimport ("FMT" "Strings" "reflect")//green font, modifier, first control flashing, second control underline func Green (str string, modifier ... interface{}) string {return Clicolorrender (str, 0, modifier ...)} Light green func lightgreen (str string, modifier ... interface{}) string {return Clicolorrender (str, 1, modifier ...)} Cyan/blue-green func Cyan (str string, modifier ... interface{}) string {return Clicolorrender (str, 0, modifier ...)} Light cyan func Lightcyan (str string, modifier ... interface{}) string {return Clicolorrender (str, 1, modifier ...)} Red font func red (str string, modifier ... interface{}) string {return Clicolorrender (str, 0, modifier ...)} Light red func lightred (str string, modifier ... interface{}) string {RetuRN Clicolorrender (str, 1, modifier ...)} Yellow font func Yellow (str string, modifier ... interface{}) string {return Clicolorrender (str, 0, modifier ...)} Black func Black (str string, modifier ... interface{}) string {return Clicolorrender (str, 0, modifier ...)} Dark grey func Darkgray (str string, modifier ... interface{}) string {return Clicolorrender (str, 1, modifier ...)} Light grey func lightgray (str string, modifier ... interface{}) string {return Clicolorrender (str, Notoginseng, 0, modifier ...)} White func (str string, modifier ... interface{}) string {return Clicolorrender (str, PNS, 1, modifier ...)} Blue func Blue (str string, modifier ... interface{}) string {return Clicolorrender (str, 0, modifier ...)} Blue func lightblue (str string, modifier ... interface{}) string {return Clicolorrender (str, 1, modifier ...)} Purple func Purple (str string, modifier ... interface{}) string {return Clicolorrender (str, 0, modifier ...)} Lilac func lightpurple (str string, modifier ... interface{}) string {return ClicolorrenDer (str, 1, modifier ...)} Brown func Brown (str string, modifier ... interface{}) string {return Clicolorrender (str, 0, modifier ...)} Func Clicolorrender (str string, color int, weight int, Extraargs ... interface{}) string {//Flicker effect var isblink int64 = 0if len (Extraargs) > 0 {isblink = reflect. ValueOf (Extraargs[0]). Int ()}//underline effect var isunderline int64 = 0if len (extraargs) > 1 {isunderline = reflect. ValueOf (Extraargs[1]). Int ()}var mo []stringif isblink > 0 {mo = append (Mo, "")}if isunderline > 0 {mo = append (Mo, "" ")}if weight > 0 {mo = append (Mo, FMT. Sprintf ("%d", weight))}if len (MO) <= 0 {mo = append (Mo, "0")}return FMT. Sprintf ("\033[%S;%DM" +str+ "\033[0m", strings. Join (Mo, ";"), color)} ' test code: ' ' Package gocolortermimport ("Testing" "FMT") func Testclicolor (t *testing. T) {//default non-effect fonts display FMT. Println (Green ("Font: Green")) FMT. Println (LightGreen ("Font: LightGreen")) fmt. Println (Cyan ("Font: Cyan")) fmt. Println (Lightcyan ("Font: Lightcyan")) fmt. Println (Red ("Font: Red")) FMT. Println (lightred ("Word(Body: lightred ")) fmt. Println (Yellow ("Font: Yellow")) fmt. Println (Black ("Font: Black")) fmt. Println (Darkgray ("Font: Darkgray")) fmt. Println (Lightgray ("Font: Lightgray")) fmt. Println (White ("Font: White")) fmt. Println (Blue ("Font: Blue")) FMT. Println (LightBlue ("Font: LightBlue")) fmt. Println (Purple ("Font: Purple")) fmt. Println (Lightpurple ("Font: Lightpurple")) fmt. Println (Brown ("Font: Brown")) FMT. Println (Blue ("Font: Blue", 1, 1)//The FMT is displayed in a color font with a blinking effect. Println (Green ("Blinking font: Green", 1, 1)) fmt. Println (LightGreen ("Blinking font: LightGreen", 1)) fmt. Println (Cyan ("Blinking font: Cyan", 1)) fmt. Println (Lightcyan ("Blinking font: Lightcyan", 1)) fmt. Println (Red ("Blinking font: Red", 1)) fmt. Println (lightred ("Blinking font: lightred", 1)) fmt. Println (Yellow ("Blinking font: Yellow", 1)) fmt. Println (Black ("Blinking font: Black", 1)) fmt. Println (Darkgray ("Blinking font: Darkgray", 1)) fmt. Println (Lightgray ("Blinking font: Lightgray", 1)) fmt. Println (White ("Blinking font: White", 1)) fmt. Println (Blue ("Blinking font: Blue", 1)) fmt. Println (LightBlue ("Blinking font: LightBlue", 1)) fmt. Println (Purple ("Blinking font: Purple", 1)) fmt. Println (lightpurple ("Blinking font: Lightpurple", 1)) fmt. Println (Brown ("flashingFont: Brown ", 1))//The underlined effect of the font display FMT. Println ("Flashing and underlined font: Green", 1, 1, 1)) fmt. Println (LightGreen ("flashing and underlined font: LightGreen", 1, 1)) fmt. Println (Cyan ("flashing and underlined font: Cyan", 1, 1)) fmt. Println (Lightcyan ("flashing and underlined font: Lightcyan", 1, 1)) fmt. Println (Red ("flashing and underlined font: Red", 1, 1)) fmt. Println (lightred ("flashing and underlined font: lightred", 1, 1)) fmt. Println (Yellow ("flashing and underlined font: Yellow", 1, 1)) fmt. Println (Black ("flashing and underlined font: Black", 1, 1)) fmt. Println (Darkgray ("flashing and underlined font: Darkgray", 1, 1)) fmt. Println (Lightgray ("flashing and underlined font: Lightgray", 1, 1)) fmt. Println (White ("flashing and underlined font: white", 1, 1)) fmt. Println (Blue ("flashing and underlined font: Blue", 1, 1)) fmt. Println (LightBlue ("flashing and underlined font: LightBlue", 1, 1)) fmt. Println (Purple ("flashing and underlined font: Purple", 1, 1)) fmt. Println (Lightpurple ("flashing and underlined font: Lightpurple", 1, 1)) fmt. Println ("Blinking and underlined font: Brown", 1, 1)} "453 reads  

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.