Documentation ¶
Index ¶
- Constants
- Variables
- func AutoSetColorState()
- func Color(s, style string) string
- func ColorCode(style string) string
- func ColorIndexBg(index int) string
- func ColorIndexFg(index int) string
- func CursorDown(lines int)
- func CursorDownVar(lines int) string
- func CursorRight(columns int)
- func CursorRightVar(columns int) string
- func CursorUp(lines int)
- func CursorUpVar(lines int) string
- func DisableLineWrap()
- func DisableResetStyle(disabled bool)
- func EnableLineWrap()
- func ExtensionIsOneOf(ext string, extensions []string) bool
- func GetExtOnly(filename string) string
- func GetFileColor(filename string, mode ...os.FileMode) string
- func GetFileColorStat(stat os.FileInfo) string
- func GetFileModeColor(mode os.FileMode) string
- func GetFileTypeColor(filename string) string
- func HideCursor()
- func HighlightFile(filename string, mode ...os.FileMode) string
- func HighlightFileMode(mode os.FileMode) string
- func HighlightFileStat(filename string, stat ...os.FileInfo) string
- func HighlightPath(path string, mode ...os.FileMode) string
- func HighlightPathStat(path string, stat ...os.FileInfo) string
- func IsColorTerm() bool
- func IsCompiled(ext string) bool
- func IsCompressed(ext string) bool
- func IsCrypto(ext string) bool
- func IsDocument(ext string) bool
- func IsImage(ext string) bool
- func IsImmediate(filename string) bool
- func IsLossless(ext string) bool
- func IsMusic(ext string) bool
- func IsTemp(filename string) bool
- func IsTerminal() bool
- func IsVideo(ext string) bool
- func Print(a ...interface{}) (n int)
- func Printf(format string, a ...interface{}) (n int)
- func Println(a ...interface{}) (n int)
- func SetColorState(enabled bool)
- func ShowCursor()
- type ColorPrinter
- type ColorState
- type Colorizer
- type FileColorsT
Constants ¶
const ( ShowCursorSeq = "\x1b[?25h" HideCursorSeq = "\x1b[?25l" EnableLineWrapSeq = "\x1b[?7h" DisableLineWrapSeq = "\x1b[?7l" CursorUpSeq = "\x1b[%dA" CursorRightSeq = "\x1b[%dG" CursorDownSeq = "\x1b[%dB" )
Variables ¶
var ( // Black FG Black = start + "30m" // Red FG Red = start + "31m" // Green FG Green = start + "32m" // Yellow FG Yellow = start + "33m" // Blue FG Blue = start + "34m" // Magenta FG Magenta = start + "35m" // Cyan FG Cyan = start + "36m" // White FG White = start + "37m" // LightBlack FG LightBlack = start + "90m" // LightRed FG LightRed = start + "91m" // LightGreen FG LightGreen = start + "92m" // LightYellow FG LightYellow = start + "93m" // LightBlue FG LightBlue = start + "94m" // LightMagenta FG LightMagenta = start + "95m" // LightCyan FG LightCyan = start + "96m" // LightWhite FG LightWhite = start + "97m" // Reset is the ANSI reset escape sequence Reset = "\033[0m" // DefaultBG is the default background DefaultBG = "\033[49m" // DefaultFG is the default foreground DefaultFG = "\033[39m" // Bold FG Bold = start + "1m" )
var ( ImmediateNames = []string{ "Makefile", "Cargo.toml", "SConstruct", "CMakeLists.txt", "build.gradle", "pom.xml", "Rakefile", "package.json", "Gruntfile.js", "Gruntfile.coffee", "BUILD", "BUILD.bazel", "WORKSPACE", "build.xml", "Podfile", "webpack.config.js", "meson.build", "composer.json", "RoboFile.php", "PKGBUILD", "Justfile", "Procfile", "Dockerfile", "Containerfile", "Vagrantfile", "Brewfile", "Gemfile", "Pipfile", "build.sbt", "mix.exs", "bsconfig.json", "tsconfig.json", } ImageExt = []string{ "png", "jfi", "jfif", "jif", "jpe", "jpeg", "jpg", "gif", "bmp", "tiff", "tif", "ppm", "pgm", "pbm", "pnm", "webp", "raw", "arw", "svg", "stl", "eps", "dvi", "ps", "cbr", "jpf", "cbz", "xpm", "ico", "cr2", "orf", "nef", "heif", } VideoExt = []string{ "avi", "flv", "m2v", "m4v", "mkv", "mov", "mp4", "mpeg", "mpg", "ogm", "ogv", "vob", "wmv", "webm", "m2ts", "heic", } MusicExt = []string{ "aac", "m4a", "mp3", "ogg", "wma", "mka", "opus", } LosslessExt = []string{ "alac", "ape", "flac", "wav", } CryptoExt = []string{ "asc", "enc", "gpg", "pgp", "sig", "signature", "pfx", "p12", } DocumentExt = []string{ "djvu", "doc", "docx", "dvi", "eml", "eps", "fotd", "key", "keynote", "numbers", "odp", "odt", "pages", "pdf", "ppt", "pptx", "rtf", "xls", "xlsx", } CompressedExt = []string{ "zip", "tar", "Z", "z", "gz", "bz2", "a", "ar", "7z", "iso", "dmg", "tc", "rar", "par", "tgz", "xz", "txz", "lz", "tlz", "lzma", "deb", "rpm", "zst", } TempExt = []string{ "tmp", "swp", "swo", "swn", "bak", "bkp", "bk", } CompiledExt = []string{ "class", "elc", "hi", "o", "pyc", "zwc", "ko", } )
var ( Stdout io.Writer Stderr io.Writer )
var ColorEnabled bool
var ( // Colors maps common color names to their ANSI color code. Colors = map[string]int{ "black": black, "red": red, "green": green, "yellow": yellow, "blue": blue, "magenta": magenta, "cyan": cyan, "white": white, "default": defaultt, } )
var FileColors = FileColorsT{ Base: Cyan, NonExistent: ColorCode("red+u"), Temp: ColorIndexFg(244), Immediate: ColorCode("yellow+bu"), Image: ColorIndexFg(133), Video: ColorIndexFg(135), Music: ColorIndexFg(92), Lossless: ColorIndexFg(93), Crypto: ColorIndexFg(109), Document: ColorIndexFg(105), Compressed: Red, Compiled: ColorIndexFg(137), Directory: ColorCode("blue+b"), Symlink: ColorCode("cyan+b"), Pipe: Yellow, Device: ColorCode("yellow+b"), Socket: ColorCode("red+b"), Irregular: Yellow, Executable: ColorCode("green+b"), File: White, }
Functions ¶
func AutoSetColorState ¶
func AutoSetColorState()
AutoSetColorState automatically SetColorState based on the whether we are outputting to a terminal or the environment variables
func ColorIndexBg ¶
ColorIndexBg convert 256 color code to ANSI background color
func ColorIndexFg ¶
ColorIndexFg convert 256 color code to ANSI foreground color
func CursorDown ¶
func CursorDown(lines int)
func CursorDownVar ¶
func CursorRight ¶
func CursorRight(columns int)
func CursorRightVar ¶
func CursorUpVar ¶
func DisableLineWrap ¶
func DisableLineWrap()
func DisableResetStyle ¶ added in v0.3.3
func DisableResetStyle(disabled bool)
func EnableLineWrap ¶
func EnableLineWrap()
func ExtensionIsOneOf ¶ added in v0.3.0
func GetExtOnly ¶ added in v0.3.0
func GetFileColorStat ¶ added in v0.3.0
func GetFileModeColor ¶ added in v0.3.0
func GetFileTypeColor ¶ added in v0.3.0
func HideCursor ¶
func HideCursor()
func HighlightFile ¶ added in v0.3.0
func HighlightFileMode ¶ added in v0.3.0
func HighlightFileStat ¶ added in v0.3.0
func HighlightPathStat ¶ added in v0.3.0
func IsCompiled ¶ added in v0.3.0
func IsCompressed ¶ added in v0.3.0
func IsDocument ¶ added in v0.3.0
func IsImmediate ¶ added in v0.3.0
func IsLossless ¶ added in v0.3.0
func IsTerminal ¶
func IsTerminal() bool
IsTerminal returns true if stdout is attached to a terminal
func SetColorState ¶
func SetColorState(enabled bool)
SetColorState enables or disables ANSI support in the library using this function is preferred to directly setting `ColorEnabled` as it allows us to perform other actions.
func ShowCursor ¶
func ShowCursor()
Types ¶
type ColorPrinter ¶
type ColorPrinter struct {
ANSI string
}
func ColorInterface ¶
func ColorInterface(style string) ColorPrinter
func (ColorPrinter) Print ¶
func (c ColorPrinter) Print(a ...interface{})
func (ColorPrinter) Printf ¶
func (c ColorPrinter) Printf(format string, a ...interface{})
func (ColorPrinter) Println ¶
func (c ColorPrinter) Println(a ...interface{})
type ColorState ¶
type ColorState int
const ( ColorDisabled ColorState = iota ColorForced ColorUnset )
func ColorPreference ¶
func ColorPreference() ColorState
ColorPreference returns the color preference based on the environment variables
type Colorizer ¶ added in v0.2.0
Colorizer takes an input string and colorizes it based on the style it was created with.
func ColorFuncVar ¶
ColorFuncVar creates a closure to avoid computation ANSI color code and returns ANSI sequence.
type FileColorsT ¶ added in v0.3.0
type FileColorsT struct { Base string NonExistent string Temp string Immediate string Image string Video string Music string Lossless string Crypto string Document string Compressed string Compiled string Directory string Symlink string Pipe string Device string Socket string Irregular string Executable string File string }