switch confirmation to use color variables

This commit is contained in:
Shane C 2024-07-07 15:39:09 -04:00
parent bae1313e9b
commit 61364764ad
Signed by: shane
GPG key ID: E46B5FEA35B22FF9
2 changed files with 82 additions and 26 deletions

69
ansi.go
View file

@ -1,30 +1,57 @@
package tui
import "strings"
type Colors = string
type Fmt = string
// Formatting
const (
FmtReset = "\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"
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 = "\033[38;5;247m"
FgColorGold = "\033[28;5;214m"
FgColorGreen = "\033[38;5;34m"
FgColorRed = "\033[38;5;167m"
FgColorGrey Fmt = "\033[38;5;247m"
FgColorGold = "\033[28;5;214m"
FgColorGreen = "\033[38;5;34m"
FgColorRed = "\033[38;5;167m"
)
func Format(codes ...string) string {
var str strings.Builder
for _, code := range codes {
str.WriteString(string(code))
}
return str.String()
}
func Color(colors ...Colors) string {
var str strings.Builder
for _, color := range colors {
str.WriteString(color)
}
return str.String()
}

View file

@ -2,6 +2,7 @@ package confirmation
import (
"fmt"
"git.shadowhosting.xyz/Eggactyl/tui"
"strings"
"golang.org/x/term"
@ -15,11 +16,23 @@ type InputData struct {
func New(data InputData) (*bool, error) {
if data.Notice != "" {
fmt.Printf("\033[1m\033[38;5;247m[\033[38;5;214m!\033[38;5;247m]\033[22m \033[3m%s\033[0m\n", data.Notice)
fmt.Printf(
tui.Format(tui.FmtBold, tui.FgColorGrey) +
"[" + tui.FgColorGold + "!" + tui.FgColorGrey + "]" + tui.FmtBoldReset + " " +
tui.FmtItalic + data.Notice + tui.FmtReset + "\n",
)
//fmt.Printf("\033[1m\033[38;5;247m[\033[38;5;214m!\033[38;5;247m]\033[22m \033[3m%s\033[0m\n", data.Notice)
}
if data.Question != "" {
fmt.Printf("\033[1m\033[38;5;247m[\033[38;5;214m?\033[38;5;247m]\033[0m %s (\033[38;5;34my\033[0m/\033[38;5;167mn\033[0m) \033[38;5;247m>>\033[3m\033[38;5;214m\n", data.Question)
fmt.Printf(
tui.Format(tui.FmtBold, tui.FgColorGrey) +
"[" + tui.FgColorGold + "!" + tui.FgColorGrey + "]" + tui.FmtReset + " " +
data.Question +
"(" + tui.FgColorGreen + "y" + tui.FmtReset + "/" + tui.FgColorRed + "n" + tui.FmtReset + "\n " +
tui.FgColorGrey + ">>" + tui.Format(tui.FmtItalic, tui.FgColorGold) + "\n",
)
//fmt.Printf("\033[1m\033[38;5;247m[\033[38;5;214m?\033[38;5;247m]\033[0m %s (\033[38;5;34my\033[0m/\033[38;5;167mn\033[0m) \033[38;5;247m>>\033[3m\033[38;5;214m\n", data.Question)
}
var input string
@ -63,14 +76,30 @@ inputLoop:
for i := 0; i < lineNum; i++ {
fmt.Printf("\033[A\033[K\033[0G")
}
fmt.Printf("\033[1m\033[38;5;247m[\033[38;5;167m!\033[38;5;247m]\033[0m Invalid input, please try again!\n")
fmt.Printf(
tui.Format(tui.FmtBold, tui.FgColorGrey) +
"[" + tui.FgColorGold + "!" + tui.FgColorGrey + "]" + tui.FmtReset + " " +
"Invalid input, please try again!\n",
)
//fmt.Printf("\033[1m\033[38;5;247m[\033[38;5;167m!\033[38;5;247m]\033[0m Invalid input, please try again!\n")
if data.Notice != "" {
fmt.Printf("\033[1m\033[38;5;247m[\033[38;5;214m!\033[38;5;247m]\033[22m \033[3m%s\033[0m\n", data.Notice)
fmt.Printf(
tui.Format(tui.FmtBold, tui.FgColorGrey) +
"[" + tui.FgColorGold + "!" + tui.FgColorGrey + "]" + tui.FmtBoldReset + " " +
tui.FmtItalic + data.Notice + tui.FmtReset + "\n",
)
//fmt.Printf("\033[1m\033[38;5;247m[\033[38;5;214m!\033[38;5;247m]\033[22m \033[3m%s\033[0m\n", data.Notice)
}
if data.Question != "" {
fmt.Printf("\033[1m\033[38;5;247m[\033[38;5;214m?\033[38;5;247m]\033[0m %s (\033[38;5;34my\033[0m/\033[38;5;167mn\033[0m) \033[38;5;247m>>\033[3m\033[38;5;214m\n", data.Question)
fmt.Printf(
tui.Format(tui.FmtBold, tui.FgColorGrey) +
"[" + tui.FgColorGold + "?" + tui.FgColorGrey + "]" + tui.FmtReset + " " + data.Notice +
"(" + tui.FgColorGreen + "y" + tui.FmtReset + "/" + tui.FgColorRed + "n" + tui.FmtReset + ")" +
tui.FgColorGrey + ">>" + tui.Format(tui.FmtItalic, tui.FgColorGold) + "\n",
)
//fmt.Printf("\033[1m\033[38;5;247m[\033[38;5;214m?\033[38;5;247m]\033[0m %s (\033[38;5;34my\033[0m/\033[38;5;167mn\033[0m) \033[38;5;247m>>\033[3m\033[38;5;214m\n", data.Question)
}
continue inputLoop
}