From 036e4ef01e4856e4846c48b1066a0f63b72a21e6 Mon Sep 17 00:00:00 2001 From: Shane C Date: Sun, 7 Jul 2024 16:44:49 -0400 Subject: [PATCH] switch list to use color variables --- list/list.go | 37 +++++++++++++++++++++++++++++-------- 1 file changed, 29 insertions(+), 8 deletions(-) diff --git a/list/list.go b/list/list.go index b016bc5..4b332ff 100644 --- a/list/list.go +++ b/list/list.go @@ -3,6 +3,7 @@ package list import ( "bufio" "fmt" + "git.shadowhosting.xyz/Eggactyl/tui" "os" "regexp" "sort" @@ -209,11 +210,15 @@ func (l *ListData) renderList() { 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))) 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))) fmt.Print(listTitle) @@ -231,17 +236,23 @@ func (l *ListData) renderList() { var userInputColor string 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 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 { - 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 { - 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))) @@ -280,7 +291,12 @@ func (l *ListData) inputHandler(items []ListItem) ListItem { 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.renderList() @@ -305,7 +321,12 @@ func (l *ListData) inputHandler(items []ListItem) ListItem { 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.renderList()