logSymbols

package module
v0.0.0-...-7bd5881 Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2020 License: MIT Imports: 4 Imported by: 0

README

Tests Go Report Card Go Reference License Coverage

logSymbols

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!
}

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

View Source
var (
	Info    symbol
	Success symbol
	Ok      symbol
	Warning symbol
	Warn    symbol
	Error   symbol
)

Functions

func AutodetectTTY

func AutodetectTTY(f *os.File)

func ForceColors

func ForceColors()

func ForceNoColors

func ForceNoColors()
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 Symbols

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

func Colorize

func Colorize(s Symbols) Symbols

func FallbackSymbols

func FallbackSymbols() 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

func (Symbols) String

func (s Symbols) String() string

Jump to

Keyboard shortcuts

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