tui/ansi.go

65 lines
1.3 KiB
Go
Raw Permalink Normal View History

2024-11-01 21:04:01 +01:00
package tui
import (
"fmt"
"golang.org/x/term"
"os"
"strings"
)
type Colors = string
type Fmt = string
// Formatting
const (
FmtReset Colors = "\033[0m"
FmtBold = "\033[1m"
FmtBoldReset = "\033[22m"
FmtDim = "\033[2m"
FmtDimReset = FmtBoldReset
FmtItalic = "\033[3m"
FmtItalicReset = "\033[23m"
FmtUnderline = "\033[4m"
FmtUnderlineReset = "\033[24m"
FmtBlink = "\033[5m"
FmtBlinkReset = "\033[25m"
FmtReverse = "\033[7m"
FmtReverseReset = "\033[27m"
FmtHidden = "\033[8m"
FmtHiddenReset = "\033[28m"
FmtStrikethrough = "\033[9m"
FmtStrikethroughReset = "\033[29m"
)
// Foreground Colors
const (
FgColorGrey Fmt = "\033[38;5;247m"
FgColorGold = "\033[38;5;214m"
FgColorGreen = "\033[38;5;34m"
FgColorRed = "\033[38;5;167m"
)
func BlankLine() {
width, _, _ := term.GetSize(int(os.Stdin.Fd()))
// Assume ptero terminal if no width.
if width == 0 {
fmt.Print("\033[1B")
} else {
fmt.Println("")
}
}
func Format(codes ...string) string {
var str strings.Builder
for _, code := range codes {
str.WriteString(code)
}
return str.String()
}