style

package
v0.31.0 Latest Latest
Warning

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

Go to latest
Published: Jan 9, 2024 License: Apache-2.0 Imports: 14 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,
	"time":   &TimeStyle,

	"user-nocaps":   &UserNoCapsStyle,
	"user-effcaps":  &UserEffCapsStyle,
	"user-fullcaps": &UserFullCapsStyle,

	"owner":        &OwnerStyle,
	"process":      &ProcessStyle,
	"task":         &TaskStyle,
	"controlgroup": &ControlGroupStyle,
	"unknown":      &UnknownStyle,

	"container": &ContainerStyle,
	"path":      &PathStyle,
}

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

Functions

func ColorModeBeforeCommand added in v0.23.0

func ColorModeBeforeCommand(*cobra.Command) error

ColorModeBeforeCommand is a plugin function that delays color profile selection based on our CLI flag and terminal profile detection until the last minute, just before the selected command runs.

func ColorModeSetupCLI

func ColorModeSetupCLI(rootCmd *cobra.Command)

ColorModeSetupCLI is a plugin function that registers the CLI "color" flag.

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 ProcModeSetupCLI

func ProcModeSetupCLI(rootCmd *cobra.Command)

ProcModeSetupCLI is a plugin function that registers the CLI "--proc" flag.

func ProcessName

func ProcessName(proc *model.Process) string

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

func ThemeBeforeCommand added in v0.23.0

func ThemeBeforeCommand(*cobra.Command) error

ThemeBeforeCommand is a plugin function that handles selection, reading, or dumping of styling profiles, just before the selected command runs. In case of dumping, it also exits this process, so the itself command won't ever start.

func ThemeSetupCLI

func ThemeSetupCLI(rootCmd *cobra.Command)

ThemeSetupCLI is a plugin function that registers the CLI flags related to theming.

func TreeStyleBeforeCommand added in v0.23.0

func TreeStyleBeforeCommand(*cobra.Command) error

TreeStyleBeforeCommand is a plugin function that handles selection, reading, or dumping of styling profiles, just before the selected command runs. In case of dumping, it also exits this process, so the itself command won't ever start.

func TreeStyleSetupCLI

func TreeStyleSetupCLI(rootCmd *cobra.Command)

TreeStyleSetupCLI is a plugin function that registers the CLI "treestyle" flag.

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 user: namespaces
	PIDStyle    Style // styles pid: namespaces
	NetStyle    Style // styles net: namespaces
	TimeStyle   Style // styles time: namespaces

	UserNoCapsStyle   Style // user: namespaces without capabilities
	UserEffCapsStyle  Style // user: namespaces with effective capabilities
	UserFullCapsStyle Style // user: namespaces with full capabilities

	OwnerStyle        Style // styles owner username and UID
	ProcessStyle      Style // styles process names
	TaskStyle         Style // styles task names
	ControlGroupStyle Style // control group names/references
	UnknownStyle      Style // styles undetermined elements, such as unknown PIDs.

	ContainerStyle Style // styles container names/IDs
	PathStyle      Style // styles bindmounted/procfs path references.
)

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