Coder Social home page Coder Social logo

areski / go.sgr Goto Github PK

View Code? Open in Web Editor NEW

This project forked from foize/go.sgr

0.0 3.0 0.0 873 KB

Terminal/console colors and text decoration (bold,underlined,etc). Uses ANSI SGR: Select Graphic Rendition

Home Page: godoc.org/github.com/foize/go.sgr

License: Other

go.sgr's Introduction

SGR (Select Graphic Rendition) for Go

The package sgr provides methods to use colors and text-decoration in ANSI-escape-sequence compatible terminals. It has support for 256-colors and makes available text-decorations such as bold, underline, negative and blink.

Installation

Please use go-get to install this package.

go get github.com/foize/go.sgr

Usage

Typical usage is to use Parseln() or MustParseln(), and use the resulting string in succeeding fmt or log calls.

package main

import (
	"fmt"
	"github.com/foize/go.sgr"
)

func main() {
	exampleString := sgr.MustParseln("This is an example: [fg-red bold] important text [reset] normal text again.")
	fmt.Print(exampleString)

	secretNumberFormat := sgr.MustParseln("The secret number is [bg-17 blink]%d")
	fmt.Printf(secretNumberFormat, 42)

	fmt.Println("This text is normal again, MustParseln puts a reset at the end of the line.")
}

Examples

For more examples, see the example/example.go file. You can also run the example.

Escaping

If you want to use an opening square bracket you should escape it like this:

sgr.MustParseln("foo [[ bar")

This will print "foo [ bar".

TODO

Features like the stdlib log package (date time) might be added in a subpackage.

License

This package is licensed under a modified BSD 3-clause license.

Godoc

For more information visit godoc.org/github.com/foize/go.sgr

xterm color codes

ansi sgr color codes

go.sgr's People

Watchers

 avatar  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.