Convert Figma logo to code with AI

logrusorgru logoaurora

Golang ultimate ANSI-colors that supports Printf/Sprintf methods

1,416
57
1,416
2

Top Related Projects

1,496

🎨 Terminal color rendering library, support 8/16 colors, 256 colors, RGB color rendering output, support Print/Sprintf methods, compatible with Windows. GO CLI 控制台颜色渲染工具库,支持16色,256色,RGB色彩渲染输出,使用类似于 Print/Sprintf,兼容并支持 Windows 环境的色彩渲染

1,707

Advanced ANSI style & color support for your terminal applications

1,940

💪 Helper Utils(700+): int, byte, string, array/slice, map, struct, dump, convert/format, error, web/http, cli/flag, OS/ENV, filesystem, system, test/assert, time and more. Go 常用的一些工具函数:数字,字符串,数组,Map,结构体,反射,文本,文件,错误,时间日期,特殊处理,格式化,常用信息获取等等

Quick Overview

The logrusorgru/aurora project is a Go library that provides a set of ANSI escape code functions for formatting and coloring text in the terminal. It offers a simple and flexible way to add color and formatting to console output, making it easier to create visually appealing and informative command-line applications.

Pros

  • Cross-platform Compatibility: The library works across different operating systems, including Windows, macOS, and Linux, ensuring consistent behavior and output.
  • Extensive Formatting Options: aurora provides a wide range of formatting options, including colors, styles (bold, italic, underline), and background colors, allowing for highly customizable terminal output.
  • Easy to Use: The library has a straightforward and intuitive API, making it simple to integrate into existing Go projects.
  • Actively Maintained: The project is actively maintained, with regular updates and bug fixes, ensuring its continued reliability and functionality.

Cons

  • Limited to Terminal Output: The library is primarily focused on formatting text for terminal output, and may not be suitable for other types of text-based applications or environments.
  • Potential Performance Impact: Depending on the complexity of the formatting and the frequency of updates, the use of aurora could have a slight performance impact on the application.
  • Dependency on ANSI Escape Codes: The library relies on ANSI escape codes, which may not be supported or rendered correctly in all terminal emulators or environments.
  • Lack of Advanced Features: While aurora provides a solid set of formatting options, it may not offer the same level of advanced features or customization as some other terminal formatting libraries.

Code Examples

Here are a few examples of how to use the aurora library in Go:

// Coloring text
fmt.Println(aurora.Green("This text is green"))
fmt.Println(aurora.Red("This text is red"))
fmt.Println(aurora.Blue("This text is blue"))

// Applying multiple formatting options
fmt.Println(aurora.Bold(aurora.Red("This text is bold and red")))
fmt.Println(aurora.Italic(aurora.Green("This text is italic and green")))
fmt.Println(aurora.Underline(aurora.Blue("This text is underlined and blue")))

// Combining formatting options
fmt.Println(aurora.Bold(aurora.Red(aurora.Underline("This text is bold, red, and underlined"))))

Getting Started

To get started with the aurora library, follow these steps:

  1. Install the library using Go's package manager:

    go get -u github.com/logrusorgru/aurora
    
  2. Import the library in your Go file:

    import "github.com/logrusorgru/aurora"
    
  3. Use the library's functions to format your terminal output:

    fmt.Println(aurora.Green("This text is green"))
    fmt.Println(aurora.Bold(aurora.Red("This text is bold and red")))
    
  4. Explore the library's documentation to learn about the available formatting options and how to customize the output to suit your needs.

Competitor Comparisons

1,496

🎨 Terminal color rendering library, support 8/16 colors, 256 colors, RGB color rendering output, support Print/Sprintf methods, compatible with Windows. GO CLI 控制台颜色渲染工具库,支持16色,256色,RGB色彩渲染输出,使用类似于 Print/Sprintf,兼容并支持 Windows 环境的色彩渲染

Pros of Color

  • More comprehensive color support, including 256 and RGB colors
  • Offers additional features like color mixing and gradient generation
  • Provides a wider range of styling options, including background colors and text attributes

Cons of Color

  • Slightly more complex API compared to Aurora's simpler interface
  • May have a larger footprint due to its extensive feature set

Code Comparison

Aurora:

aurora.Red("This is red").Bold()

Color:

color.Red.Println("This is red")
color.Style{color.FgRed, color.OpBold}.Println("This is red and bold")

Summary

Both Aurora and Color are Go libraries for adding color and style to terminal output. Aurora focuses on simplicity and a fluent interface, while Color offers a more comprehensive set of features and color options. Aurora's API is generally more concise, but Color provides greater flexibility for complex styling needs. The choice between the two depends on the specific requirements of your project and personal preference for API design.

1,707

Advanced ANSI style & color support for your terminal applications

Pros of termenv

  • More comprehensive color support, including true color and 256-color modes
  • Provides additional terminal capabilities beyond just coloring (e.g., cursor movement, screen clearing)
  • Actively maintained with regular updates and improvements

Cons of termenv

  • Slightly more complex API, which may require a steeper learning curve
  • Larger codebase and dependency footprint compared to Aurora
  • May be overkill for projects that only need basic color functionality

Code Comparison

Aurora:

aurora.Red("This is red").Bold()

termenv:

p := termenv.ColorProfile()
s := termenv.String("This is red").Foreground(p.Color("red")).Bold()

Summary

termenv offers a more feature-rich and actively maintained solution for terminal styling and manipulation, while Aurora provides a simpler and more lightweight approach focused primarily on text coloring. The choice between the two depends on the specific needs of your project, with termenv being better suited for more complex terminal interactions and Aurora for basic color formatting.

1,940

💪 Helper Utils(700+): int, byte, string, array/slice, map, struct, dump, convert/format, error, web/http, cli/flag, OS/ENV, filesystem, system, test/assert, time and more. Go 常用的一些工具函数:数字,字符串,数组,Map,结构体,反射,文本,文件,错误,时间日期,特殊处理,格式化,常用信息获取等等

Pros of goutil

  • More comprehensive utility package with a wider range of functionalities
  • Actively maintained with frequent updates and contributions
  • Includes CLI-related utilities and color support for terminal output

Cons of goutil

  • Larger codebase and dependency footprint
  • Less focused on specific color manipulation compared to aurora
  • May require more time to learn and integrate due to its broader scope

Code Comparison

aurora:

aurora.Blue("Hello").Bold().Underline()

goutil:

color.Blue.Println("Hello")
color.Style{color.FgBlue, color.OpBold, color.OpUnderscore}.Println("Hello")

Summary

Aurora is a focused color manipulation library for Go, providing a simple and intuitive API for adding colors and styles to terminal output. It offers a chainable syntax for applying multiple styles.

Goutil, on the other hand, is a more extensive utility package that includes color support among many other features. It provides a broader set of tools for Go developers but may be overkill if you only need color manipulation.

Choose Aurora for a lightweight, color-focused solution, or opt for goutil if you need a more comprehensive utility package with additional features beyond just color manipulation.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

Aurora

go.dev reference Unlicense Build Status Coverage Status GoReportCard

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

The latest version
go get -u github.com/logrusorgru/aurora/v4

With hyperlinks.

Test

go test -cover -race github.com/logrusorgru/aurora/v4

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

Usage

Simple

package main

import (
	"fmt"

	"github.com/logrusorgru/aurora/v4"
)

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

simple png

Printf

package main

import (
	"fmt"

	"github.com/logrusorgru/aurora/v4"
)

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

printf png

aurora.Sprintf

package main

import (
	"fmt"

	"github.com/logrusorgru/aurora/v4"
)

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

sprintf png

Enable/Disable colors

package main

import (
	"fmt"
	"flag"

	"github.com/logrusorgru/aurora/v4"
)

// colorizer
var au *aurora.Aurora

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

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

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

Without flags: disable png

With -colors flag: enable png

Hyperlinks, default colorizer, and configurations

Hyperlinks feature description.

Add a red hyperlinks with text "Example" that is referencing to http://example.com.

package main

import (
	"flag"
	"fmt"

	"github.com/logrusorgru/aurora/v4"
)

func main() {
	var conf = aurora.NewConfig()
	conf.AddFlags(flag.CommandLine, "prefix.")
	flag.Parse()

	aurora.DefaultColorizer = aurora.New(conf.Options()...) // set global

	fmt.Println(aurora.Red("Example").Hyperlink("http://example.com/"))
}

Depending flags: depending flags png depending flags gif

Chains

The following samples are equal

x := aurora.BgMagenta(aurora.Bold(aurora.Red("x")))
x := aurora.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(aurora.Colorize("Greeting", getColors()))
}

Less complicated example

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

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

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

Grayscale

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

grayscale png

8-bit colors

Methods Index and BgIndex implements 8-bit colors.

Index/BgIndexMeaningForegroundBackground
0- 7standard colors30- 3740- 47
8- 15bright colors90- 97100-107
16-231216 colors38;5;n48;5;n
232-25524 grayscale38;5;n48;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() {
	var (
		r = aurora.Red("red")
		i int
	)
	fmt.Printf("%T %p\n", r, aurora.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-2022 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.