diff --git a/ansi.go b/ansi.go index 2861e62..84e41fe 100644 --- a/ansi.go +++ b/ansi.go @@ -1,6 +1,11 @@ package tui -import "strings" +import ( + "fmt" + "golang.org/x/term" + "os" + "strings" +) type Colors = string type Fmt = string @@ -34,6 +39,19 @@ const ( 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 diff --git a/list/list.go b/list/list.go index 6e9fefe..a31680b 100644 --- a/list/list.go +++ b/list/list.go @@ -241,16 +241,16 @@ func (l *ListData) renderList() { if _, ok := item.Value.(string); ok { if item.Value == "action_back" { - listItem = " " + tui.FgColorGrey + "[" + tui.Format(tui.FmtBold, tui.FgColorRed) + string(rune(index+1)) + tui.Format(tui.FmtBoldReset, tui.FgColorGrey) + "]" + tui.FmtReset + + 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 = " " + tui.FgColorGrey + "[" + tui.Format(tui.FmtBold, tui.FgColorGold) + string(rune(index+1)) + tui.Format(tui.FmtBoldReset, tui.FgColorGrey) + "]" + tui.FmtReset + + 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 = " " + tui.FgColorGrey + "[" + tui.Format(tui.FmtBold, tui.FgColorGold) + string(rune(index+1)) + tui.Format(tui.FmtBoldReset, tui.FgColorGrey) + "]" + tui.FmtReset + + 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) } @@ -282,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 @@ -312,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