Files
mgsh/colors.go
T

60 lines
1.5 KiB
Go

package main
import (
"fmt"
"strings"
)
// Colors for the prompt, banner and output, using the Catppuccin Mocha palette
// as 24-bit truecolor escapes
// (https://terminalcolors.com/themes/catppuccin/mocha/).
const (
cReset = "\033[0m"
cBold = "\033[1m"
cDim = "\033[2m"
cGreen = "\033[38;2;166;227;161m" // Green #a6e3a1
cYellow = "\033[38;2;249;226;175m" // Yellow #f9e2af
cRed = "\033[38;2;243;139;168m" // Red #f38ba8
cCyan = "\033[38;2;148;226;213m" // Teal #94e2d5
cPurple = "\033[38;2;203;166;247m" // Mauve #cba6f7
cWhite = "\033[38;2;205;214;244m" // Text #cdd6f4
cGray = "\033[38;2;108;112;134m" // Overlay0 #6c7086
)
// col wraps s in color c, but only when color output is enabled.
func col(c, s string) string {
if useColor {
return c + s + cReset
}
return s
}
// errorln prints an error/status message in red (when color is enabled).
func errorln(msg string) {
fmt.Println(col(cRed, msg))
}
// padRight pads an ASCII string with trailing spaces to width n.
func padRight(s string, n int) string {
if len(s) < n {
return s + strings.Repeat(" ", n-len(s))
}
return s
}
// colorRepoLine colors a `list` entry: the leading `ls -ltr` date (3 fields) in
// yellow and the repository name in green.
func colorRepoLine(s string) string {
if !useColor {
return s
}
parts := strings.Fields(s)
if len(parts) >= 4 {
date := strings.Join(parts[:3], " ")
name := strings.Join(parts[3:], " ")
return col(cYellow, date) + " " + col(cGreen, name)
}
return col(cGreen, s)
}