logsymbols

package module
v0.3.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 8, 2020 License: MIT Imports: 4 Imported by: 8

README

Tests Go Report Card Go Reference License Coverage

log symbols

Colored symbols for various log levels Includes fallbacks for Windows CMD which only supports a limited character set.

Linux/Mac

logsymbols on Linux

Windows

logsymbols on Windows

Install

$ go get github.com/guumaster/logsymbols

Usage

Basic example

package main

import (
  "fmt"
  "github.com/guumaster/logsymbols"
)

func main() {
    fmt.Println(logsymbols.Success, "Finished successfully!")
    fmt.Println(logsymbols.Error, "Something broke")

    // On good OSes:  ✔ Finished successfully!
    //                ✖ Something broke

    // On Windows:    √ Finished successfully!
    //                × Something broke
}

Forcing colors

logsymbols will autodetect if its not in TTY mode and remove all colors. You can force color output with this example:


  	logsymbols.ForceColors()
    fmt.Println(logsymbols.Success, "Finished successfully!")

    // Terminal Output:  ✔ Finished successfully!
    // Redirected Output:       ^[[1;32m✔^[[0m Finished successfully!
}

Fallback Symbols

logsymbols will autodetect which OS is running and will change to the proper icons on Windows.

You also can get the fallback symbols with this example:


    fallback := logsymbols.FallbackSymbols()
    fmt.Println(fallback.Success, "Finished successfully!")

    // Output:  √ Finished successfully!
}

More examples

See example folder

Ported from npm version

Author(s)

If you like this tool and think is worth it, you can invite me a coffee:

paypal.me/guumaster ko-fi.com/guumaster

LICENSE

MIT license

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func AutodetectTTY

func AutodetectTTY(f *os.File)

AutodetectTTY detects if it's on a TTY output

func ForceColors

func ForceColors()

ForceColors force adding color to all symbols

func ForceNoColors

func ForceNoColors()

ForceNoColors force removing color to all symbols

Example
ForceNoColors()
fmt.Println("\nno color")
fmt.Printf("%s info\n", Info)
fmt.Printf("%s success\n", Success)
fmt.Printf("%s warning\n", Warn)
fmt.Printf("%s error\n", Error)
Output:

no color
ℹ info
✔ success
⚠ warning
✖ error

Types

type Symbol added in v0.2.0

type Symbol string
var (
	// Info represents the information symbol
	Info Symbol
	// Success represents the success symbol
	Success Symbol
	// Ok alias of Success
	Ok Symbol
	// Warning represents the warning symbol
	Warning Symbol
	// Warn alias of Warning
	Warn Symbol
	// Error represents the error symbol
	Error Symbol
)

type Symbols

type Symbols struct {
	Info    Symbol
	Success Symbol
	Ok      Symbol
	Warning Symbol
	Warn    Symbol
	Error   Symbol
}

Symbols struct contains all symbols

func BaseSymbols added in v0.3.0

func BaseSymbols() Symbols

BaseSymbols returns a set with the current OS symbols

func Colorize

func Colorize(s Symbols) Symbols

Colorize adds colors to all symbols

func CurrentSymbols added in v0.2.0

func CurrentSymbols() Symbols

CurrentSymbols returns a set with the current OS symbols (colored if color enabled)

func FallbackSymbols

func FallbackSymbols() Symbols

FallbackSymbols returns a set with the fallback symbols

Example
f := FallbackSymbols()

fmt.Println("\nfallback")
fmt.Printf("%s info\n", f.Info)
fmt.Printf("%s success\n", f.Success)
fmt.Printf("%s warning\n", f.Warning)
fmt.Printf("%s error\n", f.Error)
Output:

fallback
i info
√ success
‼ warning
× error

func NormalSymbols

func NormalSymbols() Symbols

NormalSymbols returns a set with the normal symbols

func (Symbols) String

func (s Symbols) String() string

String returns a printable representation of Symbols struct

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL