Documentation
¶
Overview ¶
Package clistyle is the single place for terminal color, semantic styles and the ASCII logo. It only writes to the io.Writer it is given.
Index ¶
- Constants
- func BannerString(mode Mode, light, unicode bool, info []string) string
- func LogoString(size LogoSize, mode Mode, light, unicode bool) string
- func RenderLogo(w io.Writer, size LogoSize, mode Mode, light, unicode bool) error
- func RoleName(r Role) string
- func ThemeNames() []string
- func UnicodeOK(lookup Lookup) bool
- type LogoContext
- type LogoSize
- type LogoState
- type Lookup
- type Mode
- type Options
- type Role
- type RoleStyle
- type Styler
- func (s Styler) Accent(t string) string
- func (s Styler) Brand(t string) string
- func (s Styler) Fail(t string) string
- func (s Styler) Hint(t string) string
- func (s Styler) Mode() Mode
- func (s Styler) Muted(t string) string
- func (s Styler) OK(t string) string
- func (s Styler) ThemeName() string
- func (s Styler) Warn(t string) string
- func (s Styler) WithTheme(t Theme) Styler
- type Theme
- type ThemeChoice
Constants ¶
const DefaultThemeName = "default"
DefaultThemeName is the palette used when nothing else is chosen.
const EnvTheme = "LEVELRAIL_THEME"
EnvTheme is the environment variable that picks a theme.
Variables ¶
This section is empty.
Functions ¶
func BannerString ¶
BannerString draws the medium mark with up to six text lines beside it, vertically centered on the mark: line 0 is the product name in the brand color, the rest are muted. The mark is skipped without unicode, so the text stands alone. Escape-free when mode is ModeNone.
func LogoString ¶
LogoString renders the logo. Without unicode every size is the ASCII wordmark.
func RenderLogo ¶
RenderLogo writes the logo to w.
Types ¶
type LogoContext ¶
type LogoContext int
LogoContext is where the caller is about to print.
const ( CtxOther LogoContext = iota // any other command, never shows CtxFirstRun // setup or the first command ever run CtxVersion // the version verb CtxVersionFlg // --version, never shows CtxUpdateDone // after a successful update )
Print contexts the caller can report.
type LogoState ¶
type LogoState struct {
Context LogoContext
JSON bool
CI bool
IsTTY bool
NoBanner bool // --no-banner or LEVELRAIL_NO_BANNER
FirstRunDone bool // a banner or setup already ran on this machine
LastLogoShown string // version the post update logo was last shown for
CurrentVersion string
}
LogoState is everything the decision needs. The caller reads files and env.
type Mode ¶
type Mode int
Mode is the color depth a stream can show.
func DetectMode ¶
DetectMode decides the color depth for w. Only a *os.File can be a terminal.
func DetectModeTTY ¶
DetectModeTTY is the pure core of DetectMode.
type Options ¶
type Options struct {
NoColor bool // --no-color
JSON bool // --json always means no color
CI bool // resolved CI mode
// GOOS is runtime.GOOS when empty. Tests set it.
GOOS string
}
Options are the caller side switches (flags and resolved CI mode).
type Role ¶
type Role int
Role is a semantic style. Callers always pair it with a word or symbol.
Semantic roles.
type RoleStyle ¶
type RoleStyle struct {
RGB string // optional "rrggbb" for truecolor, else the 256 index is used
C256 int
ANSI16 int // full SGR parameter, for example 32 or 90
Bold bool
Dim bool
}
RoleStyle is one role in a theme. A zero C256 or ANSI16 means "no foreground color at that depth", so a role can be only bold or only dim.
type Styler ¶
type Styler struct {
// contains filtered or unexported fields
}
Styler paints text for one stream. The zero value paints nothing.
func New ¶
New returns a Styler. light picks the light background brand shade, the default (dark) is used when the background is unknown.
type Theme ¶
type Theme struct {
Name string
Description string
Roles map[Role]RoleStyle
// BrandLight replaces the brand role on a light background.
BrandLight RoleStyle
}
Theme is a named palette over the semantic roles.
func LookupTheme ¶
LookupTheme finds a theme by case-insensitive name.
type ThemeChoice ¶
type ThemeChoice struct {
Theme Theme
Source string // flag, env, account, saved or default
// Unknown is the rejected name when a source named a theme that does not exist.
Unknown string
}
ThemeChoice is a resolved theme and where it came from.
func ResolveTheme ¶
func ResolveTheme(flag string, lookup Lookup, account, saved string) ThemeChoice
ResolveTheme picks the first non-empty of flag, LEVELRAIL_THEME, the cached account theme and the locally saved theme. An unknown name falls back to default and is reported in Unknown. Theme choice never changes the color mode, see Styler.