switch confirmation to use color variables
This commit is contained in:
parent
bae1313e9b
commit
61364764ad
2 changed files with 82 additions and 26 deletions
31
ansi.go
31
ansi.go
|
@ -1,8 +1,13 @@
|
||||||
package tui
|
package tui
|
||||||
|
|
||||||
|
import "strings"
|
||||||
|
|
||||||
|
type Colors = string
|
||||||
|
type Fmt = string
|
||||||
|
|
||||||
// Formatting
|
// Formatting
|
||||||
const (
|
const (
|
||||||
FmtReset = "\033[0m"
|
FmtReset Colors = "\033[0m"
|
||||||
FmtBold = "\033[1m"
|
FmtBold = "\033[1m"
|
||||||
FmtBoldReset = "\033[22m"
|
FmtBoldReset = "\033[22m"
|
||||||
FmtDim = "\033[2m"
|
FmtDim = "\033[2m"
|
||||||
|
@ -23,8 +28,30 @@ const (
|
||||||
|
|
||||||
// Foreground Colors
|
// Foreground Colors
|
||||||
const (
|
const (
|
||||||
FgColorGrey = "\033[38;5;247m"
|
FgColorGrey Fmt = "\033[38;5;247m"
|
||||||
FgColorGold = "\033[28;5;214m"
|
FgColorGold = "\033[28;5;214m"
|
||||||
FgColorGreen = "\033[38;5;34m"
|
FgColorGreen = "\033[38;5;34m"
|
||||||
FgColorRed = "\033[38;5;167m"
|
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()
|
||||||
|
}
|
||||||
|
|
|
@ -2,6 +2,7 @@ package confirmation
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"git.shadowhosting.xyz/Eggactyl/tui"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"golang.org/x/term"
|
"golang.org/x/term"
|
||||||
|
@ -15,11 +16,23 @@ type InputData struct {
|
||||||
func New(data InputData) (*bool, error) {
|
func New(data InputData) (*bool, error) {
|
||||||
|
|
||||||
if data.Notice != "" {
|
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 != "" {
|
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
|
var input string
|
||||||
|
@ -63,14 +76,30 @@ inputLoop:
|
||||||
for i := 0; i < lineNum; i++ {
|
for i := 0; i < lineNum; i++ {
|
||||||
fmt.Printf("\033[A\033[K\033[0G")
|
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 != "" {
|
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 != "" {
|
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
|
continue inputLoop
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue