All Projects → logrusorgru → Aurora

logrusorgru / Aurora

Licence: unlicense
Golang ultimate ANSI-colors that supports Printf/Sprintf methods

Programming Languages

go
31211 projects - #10 most used programming language
golang
3204 projects

Projects that are alternatives of or similar to Aurora

image-to-ansi
Convert an image to ANSI colour codes using JavaScript.
Stars: ✭ 15 (-98.59%)
Mutual labels:  ansi-colors
Python Coloredlogs
Colored terminal output for Python's logging module
Stars: ✭ 408 (-61.55%)
Mutual labels:  ansi-colors
Rich
Rich is a Python library for rich text and beautiful formatting in the terminal.
Stars: ✭ 31,664 (+2884.35%)
Mutual labels:  ansi-colors
Taoup
The Tao of Unix Programming (Ruby-powered ANSI colored fortunes)
Stars: ✭ 265 (-75.02%)
Mutual labels:  ansi-colors
Ansi
Small, fast library to create ANSI colored strings and codes. [go, golang]
Stars: ✭ 323 (-69.56%)
Mutual labels:  ansi-colors
Pterm
✨ #PTerm is a modern go module to beautify console output. Featuring charts, progressbars, tables, trees, and many more 🚀 It's completely configurable and 100% cross-platform compatible.
Stars: ✭ 449 (-57.68%)
Mutual labels:  ansi-colors
rich
Rich is a Python library for rich text and beautiful formatting in the terminal.
Stars: ✭ 36,988 (+3386.15%)
Mutual labels:  ansi-colors
Video To Ascii
It is a simple python package to play videos in the terminal using characters as pixels
Stars: ✭ 960 (-9.52%)
Mutual labels:  ansi-colors
Mordant
Full-featured text styling for Kotlin command-line applications
Stars: ✭ 382 (-64%)
Mutual labels:  ansi-colors
Pretty
Library for helping print things prettily, in Clojure - ANSI fonts, formatted exceptions
Stars: ✭ 474 (-55.33%)
Mutual labels:  ansi-colors
Picocli
Picocli is a modern framework for building powerful, user-friendly, GraalVM-enabled command line apps with ease. It supports colors, autocompletion, subcommands, and more. In 1 source file so apps can include as source & avoid adding a dependency. Written in Java, usable from Groovy, Kotlin, Scala, etc.
Stars: ✭ 3,286 (+209.71%)
Mutual labels:  ansi-colors
Paint
Ruby gem for ANSI terminal colors 🎨︎ VERY FAST
Stars: ✭ 317 (-70.12%)
Mutual labels:  ansi-colors
2048.c
Console version of the game "2048" for GNU/Linux
Stars: ✭ 453 (-57.3%)
Mutual labels:  ansi-colors
Jcolor
An easy syntax to format your strings with colored fonts and backgrounds.
Stars: ✭ 255 (-75.97%)
Mutual labels:  ansi-colors
Terminalimageviewer
Small C++ program to display images in a (modern) terminal using RGB ANSI codes and unicode block graphics characters
Stars: ✭ 917 (-13.57%)
Mutual labels:  ansi-colors
gitlab-job-log-viewer
Browser extension for code highlighting raw logs in Gitlab CI
Stars: ✭ 21 (-98.02%)
Mutual labels:  ansi-colors
Shml
SHell Markup Language | Style Framework for The Terminal
Stars: ✭ 411 (-61.26%)
Mutual labels:  ansi-colors
Ansi Escape Sequences
A simple, isomorphic library containing all known terminal ansi escape codes and sequences.
Stars: ✭ 44 (-95.85%)
Mutual labels:  ansi-colors
Cl Ansi Text
Enables ANSI colors for printing.
Stars: ✭ 30 (-97.17%)
Mutual labels:  ansi-colors
Gradle Test Logger Plugin
A Gradle plugin for printing beautiful logs on the console while running tests
Stars: ✭ 460 (-56.64%)
Mutual labels:  ansi-colors

Aurora

go.dev reference Unlicense Build Status Coverage Status GoReportCard Gitter

Ultimate ANSI colors for Golang. The package supports Printf/Sprintf etc.

aurora logo

TOC

Installation

Version 1.x

Using gopkg.in.

go get -u gopkg.in/logrusorgru/aurora.v1

Version 2.x

go get -u github.com/logrusorgru/aurora

Go modules support, version v3+

Get

go get -u github.com/logrusorgru/aurora/v3

The v3 was introduced to support go.mod and leave previous import paths as is. Currently, there is no changes between them (excluding the importpath's /v3 tail).

Test

go test -cover github.com/logrusorgru/aurora/v3

Replace the import path with your, if it's different.

Usage

Simple

package main

import (
	"fmt"

	. "github.com/logrusorgru/aurora"
)

func main() {
	fmt.Println("Hello,", Magenta("Aurora"))
	fmt.Println(Bold(Cyan("Cya!")))
}

simple png

Printf

package main

import (
	"fmt"

	. "github.com/logrusorgru/aurora"
)

func main() {
	fmt.Printf("Got it %d times\n", Green(1240))
	fmt.Printf("PI is %+1.2e\n", Cyan(3.14))
}

printf png

aurora.Sprintf

package main

import (
	"fmt"

	. "github.com/logrusorgru/aurora"
)

func main() {
	fmt.Println(Sprintf(Magenta("Got it %d times"), Green(1240)))
}

sprintf png

Enable/Disable colors

package main

import (
	"fmt"
	"flag"

	"github.com/logrusorgru/aurora"
)

// colorizer
var au aurora.Aurora

var colors = flag.Bool("colors", false, "enable or disable colors")

func init() {
	flag.Parse()
	au = aurora.NewAurora(*colors)
}

func main() {
	// use colorizer
	fmt.Println(au.Green("Hello"))
}

Without flags: disable png

With -colors flag: enable png

Chains

The following samples are equal

x := BgMagenta(Bold(Red("x")))
x := Red("x").Bold().BgMagenta()

The second is more readable

Colorize

There is Colorize function that allows to choose some colors and format from a side


func getColors() Color {
	// some stuff that returns appropriate colors and format
}

// [...]

func main() {
	fmt.Println(Colorize("Greeting", getColors()))
}

Less complicated example

x := Colorize("Greeting", GreenFg|GrayBg|BoldFm)

Unlike other color functions and methods (such as Red/BgBlue etc) a Colorize clears previous colors

x := Red("x").Colorize(BgGreen) // will be with green background only

Grayscale

fmt.Println("  ",
	Gray(1-1, " 00-23 ").BgGray(24-1),
	Gray(4-1, " 03-19 ").BgGray(20-1),
	Gray(8-1, " 07-15 ").BgGray(16-1),
	Gray(12-1, " 11-11 ").BgGray(12-1),
	Gray(16-1, " 15-07 ").BgGray(8-1),
	Gray(20-1, " 19-03 ").BgGray(4-1),
	Gray(24-1, " 23-00 ").BgGray(1-1),
)

grayscale png

8-bit colors

Methods Index and BgIndex implements 8-bit colors.

Index/BgIndex Meaning Foreground Background
0- 7 standard colors 30- 37 40- 47
8- 15 bright colors 90- 97 100-107
16-231 216 colors 38;5;n 48;5;n
232-255 24 grayscale 38;5;n 48;5;n

Example

package main

import (
	"fmt"
	"github.com/logrusorgru/aurora"
)

func main() {
	for i := uint8(16); i <= 231; i++ {
		fmt.Println(i, aurora.Index(i, "pew-pew"), aurora.BgIndex(i, "pew-pew"))
	}
}

Supported colors & formats

  • formats
    • bold (1)
    • faint (2)
    • doubly-underline (21)
    • fraktur (20)
    • italic (3)
    • underline (4)
    • slow blink (5)
    • rapid blink (6)
    • reverse video (7)
    • conceal (8)
    • crossed out (9)
    • framed (51)
    • encircled (52)
    • overlined (53)
  • background and foreground colors, including bright
    • black
    • red
    • green
    • yellow (brown)
    • blue
    • magenta
    • cyan
    • white
    • 24 grayscale colors
    • 216 8-bit colors

All colors

linux png
white png

Standard and bright colors

linux black standard png linux white standard png

Formats are likely supported

formats supported gif

Formats are likely unsupported

formats rarely supported png

Limitations

There is no way to represent %T and %p with colors using a standard approach

package main

import (
	"fmt"

	. "github.com/logrusorgru/aurora"
)

func main() {
	r := Red("red")
	var i int
	fmt.Printf("%T %p\n", r, Green(&i))
}

Output will be without colors

aurora.value %!p(aurora.value={0xc42000a310 768 0})

The obvious workaround is Red(fmt.Sprintf("%T", some))

Windows

The Aurora provides ANSI colors only, so there is no support for Windows. That said, there are workarounds available. Check out these comments to learn more:

TTY

The Aurora has no internal TTY detectors by design. Take a look this comment if you want turn on colors for a terminal only, and turn them off for a file.

Licensing

Copyright © 2016-2020 The Aurora Authors. This work is free. It comes without any warranty, to the extent permitted by applicable law. You can redistribute it and/or modify it under the terms of the the Unlicense. See the LICENSE file for more details.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].