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 ¶
- Variables
- func ColorModeBeforeRun() error
- func ColorModeSetupCLI(rootCmd *cobra.Command)
- func PrepareForTest()
- func ProcModeSetupCLI(rootCmd *cobra.Command)
- func ProcessName(proc *model.Process) string
- func ThemeBeforeRun() error
- func ThemeSetupCLI(rootCmd *cobra.Command)
- func TreeStyleBeforeRun() error
- func TreeStyleSetupCLI(rootCmd *cobra.Command)
- type ColorMode
- type ProcNameMode
- type Style
- type StyledValue
- type Theme
- type TreeStyle
Constants ¶
This section is empty.
Variables ¶
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.
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, "controlgroup": &ControlGroupStyle, "unknown": &UnknownStyle, }
Styles maps style configuration top-level element names to their corresponding Style objects for storing and using specific style information.
Functions ¶
func ColorModeBeforeRun ¶
func ColorModeBeforeRun() error
ColorModeBeforeRun 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 ¶
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 ¶
ProcModeSetupCLI is a plugin function that registers the CLI "--proc" flag.
func ProcessName ¶
ProcessName returns the "name" of a process for display, based on the display mode in procNameMode.
func ThemeBeforeRun ¶
func ThemeBeforeRun() error
ThemeBeforeRun 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 ¶
ThemeSetupCLI is a plugin function that registers the CLI flags related to theming.
func TreeStyleBeforeRun ¶
func TreeStyleBeforeRun() error
TreeStyleBeforeRun 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 ¶
TreeStyleSetupCLI is a plugin function that registers the CLI "treestyle" flag.
Types ¶
type ProcNameMode ¶
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 ControlGroupStyle Style // control group names/references 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 ¶
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.