colorgful

package module
v0.0.0-...-3b7d32b Latest Latest
Warning

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

Go to latest
Published: Sep 14, 2021 License: MIT Imports: 10 Imported by: 3

README

colorgful report

Colorizer extension for lorg.

Basically, turns lorg output into this:

dark

Or this:

light

colorgful comes with two embedded themes: light and dark.

Example

package main

import (
	"github.com/kovetskiy/lorg"
	"github.com/reconquest/colorgful"
)

func main() {
	log := lorg.NewLog()

	log.SetFormat(colorgful.MustApplyDefaultTheme(
		`* ${time} ${level} %s`,
		colorgful.Light,
	))

	log.SetLevel(lorg.LevelTrace)

	log.Trace("tracing dead status")

	log.Debug("debuggin dead status")

	log.Info("soon you will be dead")

	log.Warning("you are not prepared to be dead")

	log.Error("you're dead!")

	log.Fatal("stopping")
}

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// Dark are the default styles, suitable for the dark shell
	// backgrounds.
	Dark = DefaultThemeStyles{
		Trace:   DefaultThemeLevel{First: `{fg 243}`},
		Debug:   DefaultThemeLevel{First: `{fg 250}`},
		Info:    DefaultThemeLevel{First: `{fg 110}`},
		Warning: DefaultThemeLevel{First: `{fg 178}`},
		Error: DefaultThemeLevel{
			Level: `{bold}{bg 52}`,
		},
		Fatal: DefaultThemeLevel{First: `{bold}{fg 197}{bg 17}`},
	}

	// Light are the default styles, suitable for the light shell
	// backgrounds.
	Light = DefaultThemeStyles{
		Trace:   DefaultThemeLevel{First: `{fg 250}`},
		Debug:   DefaultThemeLevel{First: `{fg 243}`},
		Info:    DefaultThemeLevel{First: `{fg 26}`},
		Warning: DefaultThemeLevel{First: `{fg 167}{bg 230}`},
		Error: DefaultThemeLevel{
			Level: `{reverse}{bold}{bg 231}`,
		},
		Fatal: DefaultThemeLevel{First: `{bold}{fg 231}{bg 124}`},
	}

	// Default are the default styles, suitable for the both
	// light and dark shell backgrounds.
	Default = DefaultThemeStyles{
		Trace: DefaultThemeLevel{First: `{nofg}`},
		Debug: DefaultThemeLevel{First: `{fg 31}`},
		Info:  DefaultThemeLevel{First: `{fg 33}`},
		Warning: DefaultThemeLevel{
			Level: `{bold}{fg 231}{bg 178}`,
		},
		Error: DefaultThemeLevel{
			Level: `{bold}{fg 231}{bg 202}`,
		},
		Fatal: DefaultThemeLevel{
			Level: `{bold}{fg 231}{bg 196}`,
		},
	}
)

Functions

func Format

func Format(formatting string) (lorg.Formatter, error)

Format parses specified formatting (loreley based) and return lorg.Formatter.

Following functions are available:

  • {bg <color>}, {fg <color>}, {nobg}, {nofg}, {bold}, {nobold}, {reverse}, {noreverse}, {reset}, {from <text> <bg>}, {to <bg> <text>}.
  • {onlevel <level> <style>} - match given level and insert given style.
  • {ontrace <style>} - alias for {onlevel "trace" <style>}.
  • {ondebug <style>} - alias for {onlevel "debug" <style>}.
  • {oninfo <style>} - alias for {onlevel "info" <style>}.
  • {onwarning <style>} - alias for {onlevel "warning" <style>}.
  • {onerror <style>} - alias for {onlevel "error" <style>}.
  • {onfatal <style>} - alias for {onlevel "fatal" <style>}.
  • {store} - store all previous style
  • {restore} - restore previous style, saved by {store}.

func FormatWithReset

func FormatWithReset(formatting string) (lorg.Formatter, error)

FormatWithReset is same as Format, but appends {reset} to the end.

Types

type DefaultOutput

type DefaultOutput struct {
	io.Writer

	Trailer lorg.Formatter
}

func (*DefaultOutput) WriteWithLevel

func (output *DefaultOutput) WriteWithLevel(
	data []byte,
	level lorg.Level,
) (int, error)

type DefaultThemeLevel

type DefaultThemeLevel struct {
	// First describes style for first line.
	First string

	// Trail describes style for all other lines.
	Trail string

	// Level describes style for level substring.
	Level string
}

DefaultThemeLevel describes how to highlight given level.

type DefaultThemeStyles

type DefaultThemeStyles struct {
	// Trace specifies overall style for trace logs level
	Trace DefaultThemeLevel

	// Debug specifies overall style for debug logs level
	Debug DefaultThemeLevel

	// Info specifies overall style for info logs level
	Info DefaultThemeLevel

	// Warning specifies overall style for warning log level
	Warning DefaultThemeLevel

	// Error specifies overall style for error log level
	Error DefaultThemeLevel

	// Fatal specifies overall style for fatal log level
	Fatal DefaultThemeLevel
}

DefaultThemeStyles represents template values for default Light and Dark themes.

type Theme

type Theme struct {
	lorg.Formatter
	lorg.SmartOutput
}

func ApplyDefaultTheme

func ApplyDefaultTheme(
	formatting string,
	styles DefaultThemeStyles,
) (*Theme, error)

ApplyDefaultTheme applies default theme to the given lorg formatting string.

`styles` can be used to specify color scheme for the default theme.

func MustApplyDefaultTheme

func MustApplyDefaultTheme(
	formatting string,
	styles DefaultThemeStyles,
) *Theme

MustApplyDefaultTheme is the same, as ApplyDefaultTheme, but panics on error.

Jump to

Keyboard shortcuts

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