2024-04-28 21:35:37 +02:00
|
|
|
package components
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"himitsu/config"
|
|
|
|
"himitsu/totp"
|
|
|
|
"himitsu/ui/styling"
|
|
|
|
"math"
|
|
|
|
"strings"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/muesli/termenv"
|
|
|
|
)
|
|
|
|
|
|
|
|
func VersionNumber() string {
|
2024-05-01 14:21:48 +02:00
|
|
|
return "himitsu " + styling.ColorFg(config.Version, styling.HighlightedColor)
|
2024-04-28 21:35:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func Checkbox(label string, checked bool, selected bool) string {
|
|
|
|
s := fmt.Sprintf("[ ] %s", label)
|
|
|
|
if checked {
|
|
|
|
s = "[x] " + label
|
|
|
|
}
|
|
|
|
if selected {
|
|
|
|
return styling.ColorFg(s, styling.HighlightedColor)
|
|
|
|
}
|
|
|
|
return s
|
|
|
|
}
|
|
|
|
|
|
|
|
func Progressbar(width int, percent float64) string {
|
|
|
|
w := float64(width)
|
|
|
|
|
|
|
|
fullSize := int(math.Round(w * percent))
|
|
|
|
var fullCells string
|
|
|
|
for i := 0; i < fullSize; i++ {
|
|
|
|
fullCells += termenv.String(styling.ProgressFullChar).Foreground(styling.Term.Color(styling.Ramp[i])).String()
|
|
|
|
}
|
|
|
|
|
|
|
|
emptySize := int(w) - fullSize
|
|
|
|
emptyCells := strings.Repeat(styling.ProgressEmpty, emptySize)
|
|
|
|
|
|
|
|
return fmt.Sprintf("%s%s %02ds", fullCells, emptyCells, 30-int(math.Round(percent*30)))
|
|
|
|
}
|
|
|
|
|
|
|
|
func TOTP(currTotp totp.TOTP) string {
|
2024-04-29 12:34:04 +02:00
|
|
|
code := totp.GetCode(currTotp.Secret)
|
2024-05-01 14:21:48 +02:00
|
|
|
s := fmt.Sprintf(" ╔═════════════════════════════════════════════════════════════════════╗\n ║ %s %-25.25s %s %s %s ║\n ╚═════════════════════════════════════════════════════════════════════╝\n", styling.ColorFg(fmt.Sprintf("%-15.15s", currTotp.Label), styling.HighlightedColor), currTotp.Account, code[0:3], code[3:6], Progressbar(10, float64(time.Now().UnixMilli()%30000)/30000.))
|
2024-04-28 21:35:37 +02:00
|
|
|
return s
|
|
|
|
}
|
|
|
|
|
|
|
|
func KeybindsHints(keybinds []string) string {
|
2024-05-01 14:21:48 +02:00
|
|
|
s := ""
|
2024-04-28 21:35:37 +02:00
|
|
|
for index, keybind := range keybinds {
|
|
|
|
if index != 0 {
|
|
|
|
s += styling.Dot
|
|
|
|
}
|
|
|
|
s += styling.Subtle(keybind)
|
|
|
|
}
|
|
|
|
return s
|
|
|
|
}
|