status

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jan 6, 2019 License: GPL-3.0 Imports: 5 Imported by: 0

README

status GoDoc Go Report Card

Print status lines debian init-style.

Usage

In any package where status output should be printed to the command line, simply import "github.com/els0r/status" and access the familiar functions with

status.Line("Updating database")
// do something awesomely magical
// ...
status.Okf("%d/10 entries updated", 10)

The two functions Custom and AnyStatus allow you to customize what is written into the enclosed status. Say you want to print DONE instead of OK, then use Custom:

status.Line("Waiting for database update")
status.Custom(status.Blue, "DONE", "10/10 entries updated")

By default Custom truncates whatever you supply as the status argument to four characters such that the width is not altered with regard to the standard status types.

If you don't care and want it to be of arbitrary width, use AnyStatus:

status.Line("Status of database")
status.AnyStatus(status.Green, "UPDATED", "10/10 entries updated")

If you want to control where the output is sent, you can explicitly set an io.Writer object with SetOutput. The default writer will be os.Stdout. Example:

type myWriter struct{} // implements Write method of io.Writer

mw := myWriter{}
status.SetOutput(mw) // statusline output now handled by your own Write() implementation

Documentation

Overview

Package status is a go implementation of a debian-like statusline.

The idea of the package is that no prior configuration needs to be applied before using it so that functions can be called "off-the-shelf"

Example:

package main
import (
    "os"
    "time"

    "github.com/els0r/status"
)

func main() {
    // print a status line
    status.Linef("Waiting %d seconds", 5)
    time.Sleep(5*time.Second)
    status.Ok("")

    // now write to stderr
    status.SetOutput(os.Stderr)

    // print another status line
    status.Linef("Alerting you in %d seconds", 5)
    time.Sleep(5*time.Second)
    status.Warn("this went to stderr")
}

Index

Constants

View Source
const StatusLineIndent = 54

StatusLineIndent is exported in case people want to adapt other formatting to the status line width

Variables

This section is empty.

Functions

func AnyStatus

func AnyStatus(color Color, status, msg string)

AnyStatus is the same as AnyStatusf with a fixed message string

func AnyStatusf

func AnyStatusf(color Color, status, fmtStr string, args ...interface{})

AnyStatusf is the same as Customf without the status length constraint

func Attn

func Attn(msg string)

Attn is an alias for Warn

func Attnf

func Attnf(fmtStr string, args ...interface{})

Attnf is an alias for Warnf

func Custom

func Custom(color Color, status, msg string)

Custom is Customf with with fixed message string

func Customf

func Customf(color Color, status, fmtStr string, args ...interface{})

Customf is a function allowing the user to set the status to something other than OK, ATTN, or FAIL.

Arguments:

  • color: any available color from the enumerated constants (e.g. Blue)
  • status: the enclosed status. Will be trimmed to 4 characters to fit the
  • fmtStr: the format string (message)
  • args: arguments to the message

func Fail

func Fail(msg string)

Fail prints a FAIL event enclosed by brackets

func Failf

func Failf(fmtStr string, args ...interface{})

Failf prints a FAIL event enclosed by brackets with formatted status explanation

func Line

func Line(msg string)

Line prints msg on a new line.

func Linef

func Linef(fmtStr string, args ...interface{})

Linef prints the status on a new line allowing for the status text to be formatted

func Ok

func Ok(msg string)

Ok prints an OK status event enclosed by brackets and appends msg as the status explanation

func Okf

func Okf(fmtStr string, args ...interface{})

Okf prints an OK status event enclosed by brackets with formatted status explanation

func SetOutput

func SetOutput(w io.Writer)

SetOutput allows the user to control where the status should be written to

func Warn

func Warn(msg string)

Warn prints an ATTN status enclosed by brackets and appends msg as the status explanation

func Warnf

func Warnf(fmtStr string, args ...interface{})

Warnf prints an ATTN status enclosed by brackets with formatted status explanation

Types

type Color

type Color int

Color provides access to colors used by the status printer

const (
	None Color = iota
	Red
	Yellow
	Green
	Blue
	Magenta
	Cyan
	White
	Black
)

Supported colors (bold by default)

Jump to

Keyboard shortcuts

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