style

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Apr 16, 2020 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

Package style styles text output of the CLI commands with foreground and background colors, as well as different text styles (bold, italics, ...).

Text styling is user-configurable and optionally stored in a YAML file in the users' home directories as ~/.lxknsrc.yaml.

Additionally, this package provides CLI flags: "--theme" to control the theme used (dark or light), "--color" for enabling or disabling colorization (including automatic detection), and "--treestyle" for changing the style of the ASCII/Unicode tree rendering.

Index

Constants

This section is empty.

Variables

View Source
var NamespaceStyler *asciitree.TreeStyler

NamespaceStyler styles namespace hierarchies (trees) using the selected tree style. This object can directly be used by other packages consuming our cmd/internal/style package. This styler object is correctly set when the particular (cobra) command runs.

View Source
var Styles = map[string]*Style{
	"mnt":    &MntStyle,
	"cgroup": &CgroupStyle,
	"uts":    &UTSStyle,
	"ipc":    &IPCStyle,
	"user":   &UserStyle,
	"pid":    &PIDStyle,
	"net":    &NetStyle,

	"owner":   &OwnerStyle,
	"process": &ProcessStyle,
	"unknown": &UnknownStyle,
}

Styles maps style configuration top-level element names to their corresponding Style objects for storing and using specific style information.

Functions

func AddFlags added in v0.9.0

func AddFlags(rootCmd *cobra.Command)

AddFlags adds global CLI command flags related to colorization and styling.

func BeforeCommand added in v0.9.0

func BeforeCommand() error

BeforeCommand needs to be called just before the selected command is run, ideally as a "PersistentPreRun" of a Cobra root command. It configures the various output rendering styles based on CLI command flags and/or configuration files.

func PrepareForTest

func PrepareForTest()

PrepareForTest needs to be called during test setup in order to correctly initialize styling to a well-known minimal state suitable for testing.

func ProcessName

func ProcessName(proc *lxkns.Process) string

ProcessName returns the "name" of a process for display, based on the display mode in procNameMode.

Types

type ColorMode

type ColorMode enumflag.Flag

ColorMode is an enumeration for colorizing output always, auto(matic), and never.

const (
	ColorAlways ColorMode = iota // always colorize
	ColorAuto                    // colorize if output goes to a terminal
	ColorNever                   // never colorize
)

Enumeration of allowed ColorMode values.

type ProcNameMode

type ProcNameMode enumflag.Flag

ProcNameMode is an enumeration setting the process name display mode.

const (
	ProcName ProcNameMode = iota
	ProcBasename
	ProcExe
)

Enumeration of allowed ProcNameMode values.

type Style

type Style struct {
	// contains filtered or unexported fields
}

Style represents a set of style settings to apply to text or value when rendering to a terminal supporting ANSI coloring and styling. Style settings are foreground and background colors, bold, italic, underlined, et cetera.

var (
	MntStyle    Style // styles mnt: namespaces
	CgroupStyle Style // styles cgroup: namespaces
	UTSStyle    Style // styles uts: namespaces
	IPCStyle    Style // styles ipc: namespaces
	UserStyle   Style // styles utc: namespaces
	PIDStyle    Style // styles pid: namespaces
	NetStyle    Style // styles net: namespaces

	OwnerStyle   Style // styles owner username and UID
	ProcessStyle Style // styles process names
	UnknownStyle Style // styles undetermined elements, such as unknown PIDs.
)

The set of styles for styling types of Linux-kernel namespaces differently, as well as some more elements, such as process names, user names, et cetera. The styles are meant to be directly referenced (used) by other packages importing our cmd/internal/style package

func (*Style) S

func (st *Style) S(args ...interface{}) (s string)

S returns the specified text s styled according to this Style's configuration. If multiple strings are specified, then the styling is applied to each string anew, thus allowing interleaving differently styled strings with this styling. The individual strings are put immediately adjacent to each without any intermediate spaces.

func (Style) V

func (st Style) V(value interface{}) StyledValue

V returns the value in the given style, so it can later be formatted by common formatters, such as fmt.Printf, et cetera.

type StyledValue

type StyledValue struct {
	// contains filtered or unexported fields
}

StyledValue represents a styled value which can be formatted in different formats, such as decimal, string, quoted string, et cetera.

func (StyledValue) Format

func (sv StyledValue) Format(s fmt.State, c rune)

Format is a custom formatter which formats a styled value. It does not introduce its own % formats, but instead relies on fmt.Sprintf for % format support and then styles the formatted value string. This was inspired by github.com/ogrusorgru/aurora's value custom formatter implementation.

func (StyledValue) String

func (sv StyledValue) String() string

String returns the styled text representation of the styled value.

type Theme

type Theme enumflag.Flag

Theme is an enumeration for selecting either a light or dark theme.

const (
	ThemeDark  Theme = iota // default dark (background) theme
	ThemeLight              // light (background) theme
)

Enumeration of allowed Theme values.

type TreeStyle

type TreeStyle enumflag.Flag

TreeStyle is an enumeration for selecting a specific tree style.

const (
	TreeStyleLine  TreeStyle = iota // default tree line style
	TreeStyleAscii                  // simple ASCII tree style
)

Enumeration of allowed Theme values.

Jump to

Keyboard shortcuts

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