tui/ansi.go

65 lines
1.3 KiB
Go
Raw Permalink Normal View History

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"
2024-08-07 17:38:48 +01:00
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 {
2024-07-25 18:36:42 +01:00
str.WriteString(code)
}
return str.String()
}