lscolors

package
v12.120.0 Latest Latest
Warning

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

Go to latest
Published: Apr 29, 2024 License: Apache-2.0 Imports: 3 Imported by: 2

Documentation

Overview

Package lscolors provides methods for colorizing file names based on colors from dircolors

Index

Examples

Constants

View Source
const (
	RESET  = "rs" // Reset
	DIR    = "di" // Directory
	LINK   = "ln" // Symbolic link
	FIFO   = "pi" // Pipe
	SOCK   = "so" // Socket
	BLK    = "bd" // Block device driver
	CHR    = "cd" // Character device driver
	STICKY = "st" // Dir with the sticky bit set (+t) and not other-writable
	EXEC   = "ex" // Executable files
)

Variables

View Source
var DisableColors = os.Getenv("NO_COLOR") != ""

DisableColors disables all colors in output

Functions

func Colorize

func Colorize(file string) string

Colorize return file name with ANSI control sequences

Example
file := "myfile.txt"
fmt.Println(Colorize(file))
Output:

func ColorizePath

func ColorizePath(fullPath string) string

Colorize return path with ANSI control sequences

Example
path := "/home/john/myfile.txt"
fmt.Println(ColorizePath(path))
Output:

func GetColor

func GetColor(file string) string

GetColor returns ANSI control sequence with color for given file

Example
file := "myfile.txt"
dir := "/home/john"

colorSeq := GetColor(file)

fmt.Printf(
	"%s/"+colorSeq+"%s"+GetColor(RESET)+"\n",
	dir, file,
)
Output:

Types

This section is empty.

Jump to

Keyboard shortcuts

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