switch list to use color variables

This commit is contained in:
Shane C 2024-07-07 16:44:49 -04:00
parent 61364764ad
commit 036e4ef01e
Signed by: shane
GPG key ID: E46B5FEA35B22FF9

View file

@ -3,6 +3,7 @@ package list
import ( import (
"bufio" "bufio"
"fmt" "fmt"
"git.shadowhosting.xyz/Eggactyl/tui"
"os" "os"
"regexp" "regexp"
"sort" "sort"
@ -209,11 +210,15 @@ func (l *ListData) renderList() {
currentPage := l.pages[l.currentPage] currentPage := l.pages[l.currentPage]
listNotice := fmt.Sprintf("\033[1m\033[38;5;247m[\033[38;5;214m!\033[38;5;247m]\033[22m \033[3mPlease choose an option from 1 - %d\033[0m\n", len(currentPage.Cache)) listNotice := tui.Format(tui.FmtBold, tui.FgColorGrey) +
"[" + tui.FgColorGold + "!" + tui.FgColorGrey + "]" + tui.FmtBoldReset + " " +
tui.FmtItalic + fmt.Sprintf("Please choose an option from 1 - %d", len(currentPage.Cache)) + "\n"
//listNotice := fmt.Sprintf("\033[1m\033[38;5;247m[\033[38;5;214m!\033[38;5;247m]\033[22m \033[3mPlease choose an option from 1 - %d\033[0m\n", len(currentPage.Cache))
l.strLengths = append(l.strLengths, len(removeANSIEscapeCodes(listNotice))) l.strLengths = append(l.strLengths, len(removeANSIEscapeCodes(listNotice)))
fmt.Print(listNotice) fmt.Print(listNotice)
listTitle := fmt.Sprintf("\033[1m\033[38;5;247m\033[4m%s:\033[0m\n", currentPage.Title) listTitle := tui.Format(tui.FmtBold, tui.FgColorGrey, tui.FmtUnderline) + currentPage.Title + ":" + tui.FmtReset + "\n"
l.strLengths = append(l.strLengths, len(removeANSIEscapeCodes(listTitle))) l.strLengths = append(l.strLengths, len(removeANSIEscapeCodes(listTitle)))
fmt.Print(listTitle) fmt.Print(listTitle)
@ -231,17 +236,23 @@ func (l *ListData) renderList() {
var userInputColor string var userInputColor string
if index == len(currentPage.Cache)-1 { if index == len(currentPage.Cache)-1 {
userInputColor = "\033[3m\033[38;5;214m" userInputColor = tui.Format(tui.FmtItalic, tui.FgColorGrey)
} }
if _, ok := item.Value.(string); ok { if _, ok := item.Value.(string); ok {
if item.Value == "action_back" { if item.Value == "action_back" {
listItem = fmt.Sprintf(" \033[38;5;247m[\033[1m\033[38;5;167m%d\033[22m\033[38;5;247m]\033[0m %-*s \033[3m\033[38;5;247m%s\033[0m%s\n", index+1, longestStrLength, item.Label, item.Notice, userInputColor) listItem = " " + tui.FgColorGrey + "[" + tui.Format(tui.FmtBold, tui.FgColorRed) + string(rune(index+1)) + tui.Format(tui.FmtBoldReset, tui.FgColorGrey) + "]" + tui.FmtReset +
fmt.Sprintf(" %-*s ", longestStrLength, item.Label) + tui.Format(tui.FmtItalic, tui.FgColorGrey) + item.Notice + tui.FmtReset + userInputColor + "\n"
//listItem = fmt.Sprintf(" \033[38;5;247m[\033[1m\033[38;5;167m%d\033[22m\033[38;5;247m]\033[0m %-*s \033[3m\033[38;5;247m%s\033[0m%s\n", index+1, longestStrLength, item.Label, item.Notice, userInputColor)
} else { } else {
listItem = fmt.Sprintf(" \033[38;5;247m[\033[1m\033[38;5;214m%d\033[22m\033[38;5;247m]\033[0m %-*s \033[3m\033[38;5;247m%s\033[0m%s\n", index+1, longestStrLength, item.Label, item.Notice, userInputColor) listItem = " " + tui.FgColorGrey + "[" + tui.Format(tui.FmtBold, tui.FgColorGold) + string(rune(index+1)) + tui.Format(tui.FmtBoldReset, tui.FgColorGrey) + "]" + tui.FmtReset +
fmt.Sprintf(" %-*s ", longestStrLength, item.Label) + tui.Format(tui.FmtItalic, tui.FgColorGrey) + item.Notice + tui.FmtReset + userInputColor + "\n"
//listItem = fmt.Sprintf(" \033[38;5;247m[\033[1m\033[38;5;214m%d\033[22m\033[38;5;247m]\033[0m %-*s \033[3m\033[38;5;247m%s\033[0m%s\n", index+1, longestStrLength, item.Label, item.Notice, userInputColor)
} }
} else { } else {
listItem = fmt.Sprintf(" \033[38;5;247m[\033[1m\033[38;5;214m%d\033[22m\033[38;5;247m]\033[0m %-*s \033[3m\033[38;5;247m%s\033[0m%s\n", index+1, longestStrLength, item.Label, item.Notice, userInputColor) listItem = " " + tui.FgColorGrey + "[" + tui.Format(tui.FmtBold, tui.FgColorGold) + string(rune(index+1)) + tui.Format(tui.FmtBoldReset, tui.FgColorGrey) + "]" + tui.FmtReset +
fmt.Sprintf(" %-*s ", longestStrLength, item.Label) + tui.Format(tui.FmtItalic, tui.FgColorGrey) + item.Notice + tui.FmtReset + userInputColor + "\n"
//listItem = fmt.Sprintf(" \033[38;5;247m[\033[1m\033[38;5;214m%d\033[22m\033[38;5;247m]\033[0m %-*s \033[3m\033[38;5;247m%s\033[0m%s\n", index+1, longestStrLength, item.Label, item.Notice, userInputColor)
} }
l.strLengths = append(l.strLengths, len(removeANSIEscapeCodes(listItem))) l.strLengths = append(l.strLengths, len(removeANSIEscapeCodes(listItem)))
@ -280,7 +291,12 @@ func (l *ListData) inputHandler(items []ListItem) ListItem {
fmt.Printf("\033[0m\033[A\033[K\033[0G") fmt.Printf("\033[0m\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.FgColorRed + "!" + tui.FgColorGrey + "]" + tui.FmtBoldReset + " " +
" 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")
l.strLengths = []int{} l.strLengths = []int{}
l.renderList() l.renderList()
@ -305,7 +321,12 @@ func (l *ListData) inputHandler(items []ListItem) ListItem {
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.FgColorRed + "!" + tui.FgColorGrey + "]" + tui.FmtBoldReset + " " +
" 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")
l.strLengths = []int{} l.strLengths = []int{}
l.renderList() l.renderList()