messages

package module
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Jan 20, 2024 License: MIT Imports: 9 Imported by: 3

README

Messages

Messages is a toolbox for CLI output with no pretension.

  • It will setup aurora is tty is detected (you can force it)
  • You can easily switch output to stdout or stderr
  • Write message with a level (info, warn, error, fatal as prefix)
  • Set context value for getting/set state in your CLI (like verbose mode, debug mode, etc...)
  • Add a spinner to your cli from yacspin and null one if you want to not take care when you should show spinner or you should avoid it.

Usage

Get the package:

go get github.com/ArthurHlt/messages

Import it, example:

package main

import (
	msg "github.com/ArthurHlt/messages"
	"time"
)

func main() {
	msg.Success("success")
	msg.Debug("debug")
	msg.Info("info")
	msg.Warning("warning")
	msg.Error("error")
	// next command will exit with code 1
	// messages.Fatal("fatal")
	msg.Tips("tips")

	msg.Printf("%s %s\n", msg.Bold("bold"), msg.Italic("italic"))

	msg.Infof("Is verbose ? %t", msg.Red(msg.IsContextValue("verbose")))
	msg.SetContextValue("verbose", true)
	msg.Infof("Is verbose ? %t", msg.Green(msg.IsContextValue("verbose")))

	imInTerminal := true
	exampleSpin(imInTerminal) // will show a spinner in terminal
	imInTerminal = false
	exampleSpin(imInTerminal) // will not display anything but keep the same code for both

}

func exampleSpin(imInTerminal bool) {
	spin := msg.GetSpinner(!imInTerminal)
	spin.Message("running")
	spin.Start()
	time.Sleep(2 * time.Second)
	spin.Stop()
}

This will output:

example

Documentation

Overview

Package messages - You should use messages for user communication as it's write on stderr For exporting command or others (for machine and scripting), use fmt and O color variable to ensure to set color or not

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BgBlack

func BgBlack(arg interface{}) aurora.Value

func BgBlue

func BgBlue(arg interface{}) aurora.Value

func BgBrightBlack

func BgBrightBlack(arg interface{}) aurora.Value

func BgBrightBlue

func BgBrightBlue(arg interface{}) aurora.Value

func BgBrightCyan

func BgBrightCyan(arg interface{}) aurora.Value

func BgBrightGreen

func BgBrightGreen(arg interface{}) aurora.Value

func BgBrightMagenta

func BgBrightMagenta(arg interface{}) aurora.Value

func BgBrightRed

func BgBrightRed(arg interface{}) aurora.Value

func BgBrightWhite

func BgBrightWhite(arg interface{}) aurora.Value

func BgBrightYellow

func BgBrightYellow(arg interface{}) aurora.Value

func BgCyan

func BgCyan(arg interface{}) aurora.Value

func BgGray

func BgGray(n aurora.GrayIndex, arg interface{}) aurora.Value

func BgGreen

func BgGreen(arg interface{}) aurora.Value

func BgIndex

func BgIndex(n aurora.ColorIndex, arg interface{}) aurora.Value

func BgMagenta

func BgMagenta(arg interface{}) aurora.Value

func BgRed

func BgRed(arg interface{}) aurora.Value

func BgWhite

func BgWhite(arg interface{}) aurora.Value

func BgYellow

func BgYellow(arg interface{}) aurora.Value

func Black

func Black(arg interface{}) aurora.Value
func Blink(arg interface{}) aurora.Value

func Blue

func Blue(arg interface{}) aurora.Value

func Bold

func Bold(arg interface{}) aurora.Value

func BrightBlack

func BrightBlack(arg interface{}) aurora.Value

func BrightBlue

func BrightBlue(arg interface{}) aurora.Value

func BrightCyan

func BrightCyan(arg interface{}) aurora.Value

func BrightGreen

func BrightGreen(arg interface{}) aurora.Value

func BrightMagenta

func BrightMagenta(arg interface{}) aurora.Value

func BrightRed

func BrightRed(arg interface{}) aurora.Value

func BrightWhite

func BrightWhite(arg interface{}) aurora.Value

func BrightYellow

func BrightYellow(arg interface{}) aurora.Value

func Clear

func Clear(arg interface{}) aurora.Value

func Colorize

func Colorize(arg interface{}, color aurora.Color) aurora.Value

func Conceal

func Conceal(arg interface{}) aurora.Value

func CrossedOut

func CrossedOut(arg interface{}) aurora.Value

func Cyan

func Cyan(arg interface{}) aurora.Value

func Debug

func Debug(str string)

func Debugf

func Debugf(format string, a ...interface{})

func DoublyUnderline

func DoublyUnderline(arg interface{}) aurora.Value

func Encircled

func Encircled(arg interface{}) aurora.Value

func Error

func Error(str string)

func Errorf

func Errorf(format string, a ...interface{})

func Faint

func Faint(arg interface{}) aurora.Value

func Fatal

func Fatal(str string)

func Fatalf

func Fatalf(format string, a ...interface{})

func ForceTty

func ForceTty()

func Fraktur

func Fraktur(arg interface{}) aurora.Value

func Framed

func Framed(arg interface{}) aurora.Value

func GetContextValue

func GetContextValue(key any) any

func Gray

func Gray(n aurora.GrayIndex, arg interface{}) aurora.Value

func Green

func Green(arg interface{}) aurora.Value

func Hidden

func Hidden(arg interface{}) aurora.Value
func Hyperlink(arg interface{}, target string, params ...aurora.HyperlinkParam) aurora.Value

func HyperlinkParams

func HyperlinkParams(arg interface{}) (params []aurora.HyperlinkParam)

func HyperlinkTarget

func HyperlinkTarget(arg interface{}) (target string)

func Index

func Index(n aurora.ColorIndex, arg interface{}) aurora.Value

func Info

func Info(str string)

func Infof

func Infof(format string, a ...interface{})

func Inverse

func Inverse(arg interface{}) aurora.Value

func IsContextValue

func IsContextValue(key any) bool

IsContextValue returns true if the key is set in the context and the value is not nil

func Isatty

func Isatty() bool

func Italic

func Italic(arg interface{}) aurora.Value

func Magenta

func Magenta(arg interface{}) aurora.Value

func Output

func Output() io.Writer

func Overlined

func Overlined(arg interface{}) aurora.Value

func Print

func Print(a ...interface{}) (n int, err error)

func Printf

func Printf(format string, a ...interface{}) (n int, err error)

func Printfln

func Printfln(format string, a ...interface{}) (n int, err error)

func Println

func Println(a ...interface{}) (n int, err error)
func RapidBlink(arg interface{}) aurora.Value

func Red

func Red(arg interface{}) aurora.Value

func Reset

func Reset(arg interface{}) aurora.Value

func Reverse

func Reverse(arg interface{}) aurora.Value

func SetColor added in v1.1.0

func SetColor(color bool)

func SetContextValue

func SetContextValue(key, value any)

func SetSpinner

func SetSpinner(s Spinner)
func SlowBlink(arg interface{}) aurora.Value

func Sprintf

func Sprintf(format interface{}, args ...interface{}) string

func StrikeThrough

func StrikeThrough(arg interface{}) aurora.Value

func Success

func Success(str string)

func Successf

func Successf(format string, a ...interface{})

func Tips

func Tips(str string)

func Tipsf

func Tipsf(format string, a ...interface{})

func Underline

func Underline(arg interface{}) aurora.Value

func UseStderr

func UseStderr()

func UseStdout

func UseStdout()

func Warning

func Warning(str string)

func Warningf

func Warningf(format string, a ...interface{})

func White

func White(arg interface{}) aurora.Value

func Yellow

func Yellow(arg interface{}) aurora.Value

Types

type NullSpinner

type NullSpinner struct{}

func (NullSpinner) Colors

func (n NullSpinner) Colors(colors ...string) error

func (NullSpinner) Message

func (n NullSpinner) Message(message string)

func (NullSpinner) Pause

func (n NullSpinner) Pause() error

func (NullSpinner) Start

func (n NullSpinner) Start() error

func (NullSpinner) Stop

func (n NullSpinner) Stop() error

func (NullSpinner) StopColors

func (n NullSpinner) StopColors(colors ...string) error

func (NullSpinner) StopMessage

func (n NullSpinner) StopMessage(message string)

func (NullSpinner) Unpause

func (n NullSpinner) Unpause() error

type Spinner

type Spinner interface {
	Start() error
	Pause() error
	Unpause() error
	Stop() error
	Message(message string)
	Colors(colors ...string) error
	StopMessage(message string)
	StopColors(colors ...string) error
}

func GetSpinner

func GetSpinner(forceNull ...bool) Spinner

Jump to

Keyboard shortcuts

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