Compare commits
21 commits
Author | SHA1 | Date | |
---|---|---|---|
4c617ba4b5 | |||
2b4361d641 | |||
628eb8343d | |||
538949679f | |||
42c4dbb3da | |||
80d705644f | |||
23540cb43f | |||
d6c77ae8e0 | |||
6f111d7028 | |||
e662ed7a9f | |||
8d13e466bb | |||
f2ff008b6a | |||
cd140e6e1f | |||
530a37e631 | |||
689d9d1333 | |||
c483788ca5 | |||
036e4ef01e | |||
61364764ad | |||
bae1313e9b | |||
897ced93e2 | |||
f1f2f5601c |
7 changed files with 350 additions and 25 deletions
64
ansi.go
Normal file
64
ansi.go
Normal file
|
@ -0,0 +1,64 @@
|
|||
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"
|
||||
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 {
|
||||
str.WriteString(code)
|
||||
}
|
||||
|
||||
return str.String()
|
||||
}
|
|
@ -2,6 +2,7 @@ package confirmation
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"git.eggactyl.cloud/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 + ") " +
|
||||
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,31 @@ 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.Question + " " +
|
||||
"(" + 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
|
||||
}
|
||||
|
|
31
displaylist/displaylist.go
Normal file
31
displaylist/displaylist.go
Normal file
|
@ -0,0 +1,31 @@
|
|||
package displaylist
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"git.eggactyl.cloud/Eggactyl/tui"
|
||||
)
|
||||
|
||||
type ListOptions struct {
|
||||
Title string
|
||||
Items []Item
|
||||
}
|
||||
|
||||
type Item struct {
|
||||
Key string
|
||||
Value string
|
||||
}
|
||||
|
||||
func New(opts ListOptions) {
|
||||
|
||||
fmt.Println(tui.FgColorGrey + "[ " + tui.Format(tui.FgColorGold, tui.FmtUnderline) + opts.Title + tui.Format(tui.FmtUnderlineReset, tui.FgColorGrey) + " ]" + tui.FmtReset)
|
||||
|
||||
for _, item := range opts.Items {
|
||||
fmt.Println(itemString(item.Key, item.Value))
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func itemString(key string, value string) string {
|
||||
return tui.FgColorGrey + "[ " + tui.FgColorGold + key + " " + tui.FgColorGrey + value + tui.FgColorGrey + " ]" + tui.FmtReset
|
||||
}
|
4
go.mod
4
go.mod
|
@ -1,6 +1,6 @@
|
|||
module git.shadowhosting.xyz/Eggactyl/tui
|
||||
module git.eggactyl.cloud/Eggactyl/tui
|
||||
|
||||
go 1.22.4
|
||||
go 1.22.5
|
||||
|
||||
require (
|
||||
github.com/nicksnyder/go-i18n/v2 v2.4.0
|
||||
|
|
41
list/list.go
41
list/list.go
|
@ -3,6 +3,7 @@ package list
|
|||
import (
|
||||
"bufio"
|
||||
"fmt"
|
||||
"git.eggactyl.cloud/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.FgColorGrey + "[ " + tui.Format(tui.FgColorGold, tui.FmtUnderline) + currentPage.Title + ":" + tui.Format(tui.FmtUnderlineReset, tui.FgColorGrey) + " ]" + 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) + strconv.Itoa(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) + strconv.Itoa(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) + strconv.Itoa(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)))
|
||||
|
@ -271,7 +282,7 @@ func (l *ListData) inputHandler(items []ListItem) ListItem {
|
|||
totalLineNum = len(l.strLengths)
|
||||
} else {
|
||||
for _, strLength := range l.strLengths {
|
||||
totalLineNum += ((strLength) / width)
|
||||
totalLineNum += (strLength) / width
|
||||
}
|
||||
}
|
||||
totalLineNum++ //User input line
|
||||
|
@ -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()
|
||||
|
@ -296,7 +312,7 @@ func (l *ListData) inputHandler(items []ListItem) ListItem {
|
|||
totalLineNum = len(l.strLengths)
|
||||
} else {
|
||||
for _, strLength := range l.strLengths {
|
||||
totalLineNum += ((strLength) / width)
|
||||
totalLineNum += (strLength) / width
|
||||
}
|
||||
}
|
||||
totalLineNum++ //User input line
|
||||
|
@ -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()
|
||||
|
|
|
@ -2,6 +2,7 @@ package progress
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"git.eggactyl.cloud/Eggactyl/tui"
|
||||
"math"
|
||||
"regexp"
|
||||
"strconv"
|
||||
|
@ -59,9 +60,9 @@ func (p *ProgressBar) render(final bool) {
|
|||
var blockColor string
|
||||
|
||||
if final {
|
||||
blockColor = "34"
|
||||
blockColor = tui.FgColorGreen
|
||||
} else {
|
||||
blockColor = "214"
|
||||
blockColor = tui.FgColorGold
|
||||
}
|
||||
|
||||
sb.WriteString(p.desc)
|
||||
|
@ -76,11 +77,13 @@ func (p *ProgressBar) render(final bool) {
|
|||
|
||||
sb.WriteString(percentString)
|
||||
|
||||
sb.WriteString("\033[1m\033[38;5;247m [\033[0m")
|
||||
sb.WriteString(tui.Format(tui.FmtBold, tui.FgColorGrey) + " [" + tui.FmtReset)
|
||||
//sb.WriteString("\033[1m\033[38;5;247m [\033[0m")
|
||||
|
||||
for i := 0; i < int(numFilled); i++ {
|
||||
|
||||
sb.WriteString(fmt.Sprintf("\033[38;5;%sm█\033[0m", blockColor))
|
||||
sb.WriteString(blockColor + "█" + tui.FmtReset)
|
||||
//sb.WriteString(fmt.Sprintf("%sm█\033[0m", blockColor))
|
||||
|
||||
}
|
||||
|
||||
|
@ -88,21 +91,25 @@ func (p *ProgressBar) render(final bool) {
|
|||
|
||||
numBlank = numBlank - 1
|
||||
|
||||
sb.WriteString("\033[38;5;214m▒\033[0m")
|
||||
sb.WriteString(tui.FgColorGold + "▒" + tui.FmtReset)
|
||||
//sb.WriteString("\033[38;5;214m▒\033[0m")
|
||||
|
||||
for i := 0; i < int(numBlank); i++ {
|
||||
sb.WriteString("\033[38;5;247m░\033[0m")
|
||||
sb.WriteString(tui.FgColorGrey + "░" + tui.FmtReset)
|
||||
//sb.WriteString("\033[38;5;247m░\033[0m")
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
for i := 0; i < int(numBlank); i++ {
|
||||
sb.WriteString("\033[38;5;247m░\033[0m")
|
||||
sb.WriteString(tui.FgColorGrey + "░" + tui.FmtReset)
|
||||
//sb.WriteString("\033[38;5;247m░\033[0m")
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
sb.WriteString("\033[1m\033[38;5;247m]\033[0m")
|
||||
sb.WriteString(tui.Format(tui.FmtBold, tui.FgColorGrey) + "]" + tui.FmtReset)
|
||||
//sb.WriteString("\033[1m\033[38;5;247m]\033[0m")
|
||||
|
||||
width, _, err := term.GetSize(0)
|
||||
if err != nil {
|
||||
|
|
172
textinput/text.go
Normal file
172
textinput/text.go
Normal file
|
@ -0,0 +1,172 @@
|
|||
package textinput
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"git.eggactyl.cloud/Eggactyl/tui"
|
||||
"git.eggactyl.cloud/Eggactyl/tui/validators"
|
||||
|
||||
"golang.org/x/term"
|
||||
)
|
||||
|
||||
type InputData struct {
|
||||
Notice string
|
||||
Question string
|
||||
Validator validators.TextInputValidator
|
||||
ValidationFunc func(input string) bool
|
||||
}
|
||||
|
||||
func New(data InputData) (*string, error) {
|
||||
|
||||
if data.Notice != "" {
|
||||
fmt.Printf(
|
||||
tui.Format(tui.FmtBold, tui.FgColorGrey) +
|
||||
"[" + tui.FgColorGold + "!" + tui.FgColorGrey + "]" + tui.FmtBoldReset + " " +
|
||||
tui.FmtItalic + data.Notice + tui.FmtReset + "\n",
|
||||
)
|
||||
} else if data.Validator != nil && data.Validator.Notice() != "" {
|
||||
fmt.Printf(
|
||||
tui.Format(tui.FmtBold, tui.FgColorGrey) +
|
||||
"[" + tui.FgColorGold + "!" + tui.FgColorGrey + "]" + tui.FmtBoldReset + " " +
|
||||
tui.FmtItalic + data.Validator.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.Validator.Notice())
|
||||
}
|
||||
|
||||
if data.Question != "" {
|
||||
fmt.Printf(
|
||||
tui.Format(tui.FmtBold, tui.FgColorGrey) +
|
||||
"[" + tui.FgColorGold + "?" + tui.FgColorGrey + "]" + tui.FmtReset + " " +
|
||||
data.Question + " " + tui.FgColorGrey + ">>" + tui.Format(tui.FmtItalic, tui.FgColorGold) + "\n",
|
||||
)
|
||||
}
|
||||
|
||||
var input string
|
||||
|
||||
for {
|
||||
|
||||
if _, err := fmt.Scanln(&input); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
width, _, err := term.GetSize(0)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if data.ValidationFunc != nil {
|
||||
if !data.ValidationFunc(input) {
|
||||
var lineNum int
|
||||
|
||||
if width == 0 {
|
||||
if data.Notice != "" {
|
||||
lineNum++
|
||||
}
|
||||
lineNum += 2
|
||||
} else {
|
||||
if data.Notice == "" {
|
||||
lineNum = ((len(data.Question) + 5 + width - 1) / width) + 1
|
||||
} else {
|
||||
lineNum = ((len(data.Notice) + 5 + width) / width) + ((len(data.Question) + 5 + width - 1) / width) + 1
|
||||
}
|
||||
}
|
||||
|
||||
for i := 0; i < lineNum; i++ {
|
||||
fmt.Printf("\033[A\033[K\033[0G")
|
||||
}
|
||||
|
||||
fmt.Printf(
|
||||
tui.Format(tui.FmtBold, tui.FgColorGrey) +
|
||||
"[" + tui.FgColorRed + "!" + tui.FgColorGrey + "]" + tui.FmtBoldReset + " " +
|
||||
" Invalid input, please try again!\n",
|
||||
)
|
||||
|
||||
if data.Notice != "" {
|
||||
fmt.Printf(
|
||||
tui.Format(tui.FmtBold, tui.FgColorGrey) +
|
||||
"[" + tui.FgColorGold + "!" + tui.FgColorGrey + "]" + tui.FmtBoldReset + " " +
|
||||
tui.FmtItalic + data.Notice + tui.FmtReset + "\n",
|
||||
)
|
||||
} else if data.Validator != nil {
|
||||
fmt.Printf(
|
||||
tui.Format(tui.FmtBold, tui.FgColorGrey) +
|
||||
"[" + tui.FgColorGold + "!" + tui.FgColorGrey + "]" + tui.FmtBoldReset + " " +
|
||||
tui.FmtItalic + data.Validator.Notice() + tui.FmtReset + "\n",
|
||||
)
|
||||
}
|
||||
|
||||
if data.Question != "" {
|
||||
fmt.Printf(
|
||||
tui.Format(tui.FmtBold, tui.FgColorGrey) +
|
||||
"[" + tui.FgColorGold + "?" + tui.FgColorGrey + "]" + tui.FmtReset + " " +
|
||||
data.Question + " " + tui.FgColorGrey + ">>" + tui.Format(tui.FmtItalic, tui.FgColorGold) + "\n",
|
||||
)
|
||||
}
|
||||
continue
|
||||
}
|
||||
} else if data.Validator != nil {
|
||||
if !data.Validator.ValidationFunc(input) {
|
||||
var lineNum int
|
||||
|
||||
if width == 0 {
|
||||
if data.Notice != "" || data.Validator.Notice() != "" {
|
||||
lineNum++
|
||||
}
|
||||
lineNum += 2
|
||||
} else {
|
||||
if data.Notice == "" && data.Validator.Notice() == "" {
|
||||
lineNum = ((len(data.Question) + 5 + width - 1) / width) + 1
|
||||
} else {
|
||||
if data.Notice != "" {
|
||||
lineNum = ((len(data.Notice) + 5 + width) / width) + ((len(data.Question) + 5 + width - 1) / width) + 1
|
||||
} else if data.Validator.Notice() != "" {
|
||||
lineNum = ((len(data.Validator.Notice()) + 5 + width - 1) / width) + ((len(data.Question) + 5 + width - 1) / width) + 1
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for i := 0; i < lineNum; i++ {
|
||||
fmt.Printf("\033[A\033[K\033[0G")
|
||||
}
|
||||
|
||||
fmt.Printf(
|
||||
tui.Format(tui.FmtBold, tui.FgColorGrey) +
|
||||
"[" + tui.FgColorRed + "!" + tui.FgColorGrey + "]" + tui.FmtBoldReset + " " +
|
||||
" Invalid input, please try again!\n",
|
||||
)
|
||||
|
||||
if 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)
|
||||
} else if data.Validator.Notice() != "" {
|
||||
fmt.Printf(
|
||||
tui.Format(tui.FmtBold, tui.FgColorGrey) +
|
||||
"[" + tui.FgColorGold + "!" + tui.FgColorGrey + "]" + tui.FmtBoldReset + " " +
|
||||
tui.FmtItalic + data.Validator.Notice() + tui.FmtReset + "\n",
|
||||
)
|
||||
}
|
||||
|
||||
if data.Question != "" {
|
||||
fmt.Printf(
|
||||
tui.Format(tui.FmtBold, tui.FgColorGrey) +
|
||||
"[" + tui.FgColorGold + "?" + tui.FgColorGrey + "]" + tui.FmtReset + " " +
|
||||
data.Question + " " + 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;247m>>\033[3m\033[38;5;214m\n", data.Question)
|
||||
}
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
break
|
||||
|
||||
}
|
||||
|
||||
fmt.Println("\033[0m")
|
||||
|
||||
return &input, nil
|
||||
|
||||
}
|
Loading…
Reference in a new issue