Git Product home page Git Product logo

colors's Introduction

Colors Build Status GoDoc

About this

This package offers a simple way to colorize strings that will be printed into the standard output. Note that Windows is not supported. The available colors are:

Black
Red
Green
Yellow
Blue
Magenta
Cyan
White
Saved

The Saved color asks to preserve the color being used in the console. Moreover, this packages acknowledges different modes:

Regular
Bold
Underlined
Reversed

In order to use all this, we'll have to create a new Color object. You usually want to do this with the Default function. This function will build a new Color object with the default values. With a Color object we can call the following methods:

// Change the color. The bg parameter asks whether this color has to be
// applied to the background or not.
func (c *Color) Change(color Colors, bg bool)

// Changes the mode for the given one.
func (c *Color) SetMode(m Mode)

// Returns the given string but with the color & mode applied.
func (c *Color) Get(s string) string

For more information check out the documentation.

tl;dr

package main

import (
    "fmt"

    "github.com/mssola/colors"
)

func main() {
    // By default it respects the current terminal schema.
    c := colors.Default()
    fmt.Printf(c.Get("Nothing\n"))

    // c := colors.Default() is equivalent to:
    //
    // c := &colors.Color{
    //    Foreground: colors.Saved,
    //    Background: colors.Saved,
    //    Mode: colors.Regular,
    // }
    //
    // You might want to initialize the struct directly if you just want to
    // print a colorful message and get out.

    // Let's print a red bold message.
    c.Change(colors.Red, false)
    c.SetMode(colors.Bold)
    fmt.Printf(c.Get("Red\n"))

    // It will print the same as before but reversed: the background is now red
    // and the foreground white.
    c.SetMode(colors.Reversed)
    fmt.Printf(c.Get("Reversed Red\n"))
}

License

Copyright © 2014-2016 Miquel Sabaté Solà, released under the MIT License.

colors's People

Contributors

mssola avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.