ProductPromotion
Logo

Go.Lang

made by https://0x3d.site

GitHub - abusomani/go-palette: Decorate your terminals using Palette 🎨
Decorate your terminals using Palette 🎨. Contribute to abusomani/go-palette development by creating an account on GitHub.
Visit Site

GitHub - abusomani/go-palette: Decorate your terminals using Palette 🎨

GitHub - abusomani/go-palette: Decorate your terminals using Palette 🎨

Build Status Github top language Github language count License Go Report Card Go Reference Coverage Status Mentioned in Awesome Go

Elegant and convenient style definitions using ANSI colors. Fully compatible and wraps the fmt library for nice terminal layouts.

Supported Colors & Formats

Standard colors

standard colors

The following colors are supported to be used by their names for both foreground and background as shown in Example using color names

Color Name Color Code
Black 0
Red 1
Green 2
Yellow 3
Blue 4
Magenta 5
Cyan 6
White 7
BrightBlack 8
BrightRed 9
BrightGreen 10
BrightYellow 11
BrightBlue 12
BrightMagenta 13
BrightCyan 14
BrightWhite 15

Standard colors used as foreground as well as background

standard colors used as foreground as well as background

Supported Foreground Palette

The following palette is supported as foreground/text colors. The numbers represent the color-codes which can be used as shown in Example using color codes.

complete supported foreground palette

Supported Background Palette

The following palette is supported as background colors. The numbers represent the color-codes which can be used as shown in Example using color codes.

complete supported background palette

Supported Text Formats

The following text formats are supported.

  • Reset
  • Bold
  • Dim
  • Italic
  • Underline
  • SlowBlink
  • Hidden
  • Strikethrough

supported text formats

Prerequisites

A go module where you want to integrate go-palette. To create one, follow this guide.

Installation

go get github.com/abusomani/go-palette

Usage

After installing the go-palette package, we start using it the following way.

Import

A very useful feature of Go’s import statement are aliases. A common use case for import aliases is to provide a shorter alternative to a library’s package name.

In this example, we save ourselves having to type palette everytime we want to call one of the library’s functions, we just use pal instead.

import (
    pal "github.com/abusomani/go-palette/palette"
)

Example using Color names

package main

import (
	pal "github.com/abusomani/go-palette/palette"
)

func main() {
	p := pal.New()
	p.Println("This text is going to be in default color.")
	p.SetOptions(pal.WithBackground(pal.Color(pal.BrightYellow)), pal.WithForeground(pal.Black))
	p.Println("This text is going to be in black color with a yellow background.")
}

Output

Code output

Example using Color codes

package main

import (
	pal "github.com/abusomani/go-palette/palette"
)

func main() {
	p := pal.New()
	p.Println("This text is going to be in default color.")
	// We can use color codes from the palette to set as foreground and background colors
	p.SetOptions(pal.WithBackground(pal.Color(11)), pal.WithForeground(0))
	p.Println("This text is going to be in black color with a yellow background.")
}

Output

Code output

Example using Special effects

package main

import (
	pal "github.com/abusomani/go-palette/palette"
)

func main() {
	p := pal.New(pal.WithSpecialEffects([]pal.Special{pal.Bold}))
	p.Println("Bold")
	p.SetOptions(pal.WithSpecialEffects([]pal.Special{pal.Dim}))
	p.Println("Dim")
	p.SetOptions(pal.WithSpecialEffects([]pal.Special{pal.Italic}))
	p.Println("Italic")
	p.SetOptions(pal.WithSpecialEffects([]pal.Special{pal.Underline}))
	p.Println("Underline")
	p.SetOptions(pal.WithSpecialEffects([]pal.Special{pal.SlowBlink}))
	p.Println("SlowBlink")
	p.SetOptions(pal.WithSpecialEffects([]pal.Special{pal.Hidden}))
	p.Print("Hidden")
	p.SetOptions(pal.WithDefaults())
	p.Println("<-Hidden")
	p.SetOptions(pal.WithSpecialEffects([]pal.Special{pal.Strikethrough}))
	p.Println("Strikethrough")
}

Flush

Flush resets the Palette options with default values and disables the Palette.

package main

import (
	pal "github.com/abusomani/go-palette/palette"
)

func main() {
	p := pal.New()
	p.Println("This text is going to be in default color.")
	// We can use color codes from the palette to set as foreground and background colors
	p.SetOptions(pal.WithBackground(pal.BrightMagenta), pal.WithForeground(pal.Black))
	p.Println("This text is going to be in black color with a bright magenta background.")
	p.Flush()
	p.Println("This text is going to be in default color.")
}

Output

Flush output

Limitations

Windows

Go-Palette provides ANSI colors only. Windows does not support ANSI out of the box. To toggle the ANSI color support follow the steps listed in this superuser thread.

Different behaviours in special effects

Go-Palette provides styled support using ANSI Color codes through escape sequences. This varies between different Terminals based on its setting. Refer ANSI Escape Codes for more details.

License

Licensed under MIT

Articles
to learn more about the golang concepts.

Resources
which are currently available to browse on.

mail [email protected] to add your project or resources here 🔥.

FAQ's
to know more about the topic.

mail [email protected] to add your project or resources here 🔥.

Queries
or most google FAQ's about GoLang.

mail [email protected] to add more queries here 🔍.

More Sites
to check out once you're finished browsing here.

0x3d
https://www.0x3d.site/
0x3d is designed for aggregating information.
NodeJS
https://nodejs.0x3d.site/
NodeJS Online Directory
Cross Platform
https://cross-platform.0x3d.site/
Cross Platform Online Directory
Open Source
https://open-source.0x3d.site/
Open Source Online Directory
Analytics
https://analytics.0x3d.site/
Analytics Online Directory
JavaScript
https://javascript.0x3d.site/
JavaScript Online Directory
GoLang
https://golang.0x3d.site/
GoLang Online Directory
Python
https://python.0x3d.site/
Python Online Directory
Swift
https://swift.0x3d.site/
Swift Online Directory
Rust
https://rust.0x3d.site/
Rust Online Directory
Scala
https://scala.0x3d.site/
Scala Online Directory
Ruby
https://ruby.0x3d.site/
Ruby Online Directory
Clojure
https://clojure.0x3d.site/
Clojure Online Directory
Elixir
https://elixir.0x3d.site/
Elixir Online Directory
Elm
https://elm.0x3d.site/
Elm Online Directory
Lua
https://lua.0x3d.site/
Lua Online Directory
C Programming
https://c-programming.0x3d.site/
C Programming Online Directory
C++ Programming
https://cpp-programming.0x3d.site/
C++ Programming Online Directory
R Programming
https://r-programming.0x3d.site/
R Programming Online Directory
Perl
https://perl.0x3d.site/
Perl Online Directory
Java
https://java.0x3d.site/
Java Online Directory
Kotlin
https://kotlin.0x3d.site/
Kotlin Online Directory
PHP
https://php.0x3d.site/
PHP Online Directory
React JS
https://react.0x3d.site/
React JS Online Directory
Angular
https://angular.0x3d.site/
Angular JS Online Directory