mirror of
https://github.com/taigrr/gico.git
synced 2026-04-02 03:09:07 -07:00
- Update Go version from 1.19 to 1.26 - Update all dependencies to latest versions - Fix staticcheck warnings (unused vars, types, functions) - Remove unused svgToPng function - Add GitHub Actions CI workflow
112 lines
3.0 KiB
Go
112 lines
3.0 KiB
Go
package term
|
|
|
|
import (
|
|
"os"
|
|
"strings"
|
|
|
|
"github.com/muesli/termenv"
|
|
sc "github.com/taigrr/simplecolorpalettes/simplecolor"
|
|
|
|
"github.com/taigrr/gico/graph/common"
|
|
)
|
|
|
|
func GetWeekUnicode(frequencies []int) string {
|
|
squareColors := []sc.SimpleColor{}
|
|
min, max := common.MinMax(frequencies)
|
|
for _, f := range frequencies {
|
|
squareColors = append(squareColors, common.ColorForFrequency(f, min, max))
|
|
}
|
|
return drawWeekUnicode(squareColors)
|
|
}
|
|
|
|
func drawWeekUnicode(c []sc.SimpleColor) string {
|
|
// o := termenv.NewOutput(os.Stdout)
|
|
s := strings.Builder{}
|
|
o := termenv.NewOutput(os.Stdout, termenv.WithProfile(termenv.TrueColor))
|
|
for w, color := range c {
|
|
style := o.String(block).Foreground(termenv.TrueColor.Color(color.ToHex()))
|
|
s.WriteString(style.String())
|
|
// termenv.SetForegroundColor(termenv.ForegroundColor())
|
|
if w == len(c)-1 {
|
|
s.WriteString("\n")
|
|
} else {
|
|
s.WriteString(" ")
|
|
}
|
|
}
|
|
return s.String()
|
|
}
|
|
|
|
func GetYearUnicodeSelected(frequencies []int, selected int) string {
|
|
squareColors := []sc.SimpleColor{}
|
|
min, max := common.MinMax(frequencies)
|
|
for _, f := range frequencies {
|
|
squareColors = append(squareColors, common.ColorForFrequency(f, min, max))
|
|
}
|
|
return drawYearUnicodeSelected(squareColors, selected)
|
|
}
|
|
|
|
func GetYearUnicode(frequencies []int) string {
|
|
squareColors := []sc.SimpleColor{}
|
|
min, max := common.MinMax(frequencies)
|
|
for _, f := range frequencies {
|
|
squareColors = append(squareColors, common.ColorForFrequency(f, min, max))
|
|
}
|
|
return drawYearUnicode(squareColors)
|
|
}
|
|
|
|
func drawYearUnicodeSelected(c []sc.SimpleColor, selected int) string {
|
|
// o := termenv.NewOutput(os.Stdout)
|
|
var s strings.Builder
|
|
o := termenv.NewOutput(os.Stdout, termenv.WithProfile(termenv.TrueColor))
|
|
weekRows := [7][]sc.SimpleColor{{}}
|
|
for i := 0; i < 7; i++ {
|
|
weekRows[i] = []sc.SimpleColor{}
|
|
}
|
|
for i := 0; i < len(c); i++ {
|
|
weekRows[i%7] = append(weekRows[i%7], c[i])
|
|
}
|
|
for i, row := range weekRows {
|
|
for w, d := range row {
|
|
style := o.String(block).Foreground(termenv.TrueColor.Color(d.ToHex()))
|
|
if w*7+i == selected {
|
|
style = o.String(block).Foreground(termenv.TrueColor.Color("#FFFFFF"))
|
|
// style = style.Background(termenv.TrueColor.Color("#FF0000"))
|
|
}
|
|
s.WriteString(style.String())
|
|
if w == len(row)-1 {
|
|
s.WriteString("\n")
|
|
} else {
|
|
s.WriteString(" ")
|
|
}
|
|
|
|
}
|
|
}
|
|
return s.String()
|
|
}
|
|
|
|
func drawYearUnicode(c []sc.SimpleColor) string {
|
|
// o := termenv.NewOutput(os.Stdout)
|
|
var s strings.Builder
|
|
o := termenv.NewOutput(os.Stdout, termenv.WithProfile(termenv.TrueColor))
|
|
weekRows := [7][]sc.SimpleColor{{}}
|
|
for i := 0; i < 7; i++ {
|
|
weekRows[i] = []sc.SimpleColor{}
|
|
}
|
|
for i := 0; i < len(c); i++ {
|
|
weekRows[i%7] = append(weekRows[i%7], c[i])
|
|
}
|
|
for _, row := range weekRows {
|
|
for w, d := range row {
|
|
style := o.String(block).Foreground(termenv.TrueColor.Color(d.ToHex()))
|
|
s.WriteString(style.String())
|
|
if w == len(row)-1 {
|
|
s.WriteString("\n")
|
|
} else {
|
|
s.WriteString(" ")
|
|
}
|
|
|
|
}
|
|
}
|
|
return s.String()
|
|
}
|