mirror of
https://github.com/taigrr/gico.git
synced 2026-04-02 03:09:07 -07:00
gitgraph term and svg generation complete
This commit is contained in:
2
.gitignore
vendored
2
.gitignore
vendored
@@ -1,2 +1,4 @@
|
||||
*.svg
|
||||
gitgraph
|
||||
bin/cli/cli
|
||||
bin/server/svg-server
|
||||
|
||||
30
bin/cli/cli.go
Normal file
30
bin/cli/cli.go
Normal file
@@ -0,0 +1,30 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"math/rand"
|
||||
"time"
|
||||
|
||||
"github.com/taigrr/gitgraph/term"
|
||||
)
|
||||
|
||||
func init() {
|
||||
rand.Seed(time.Now().UnixMilli())
|
||||
}
|
||||
func main() {
|
||||
freq := []int{}
|
||||
for i := 0; i < 7; i++ {
|
||||
freq = append(freq, rand.Int())
|
||||
}
|
||||
fmt.Println("week:")
|
||||
term.GetWeekUnicode(freq)
|
||||
fmt.Println()
|
||||
fmt.Println()
|
||||
fmt.Println()
|
||||
freq = []int{}
|
||||
for i := 0; i < 365; i++ {
|
||||
freq = append(freq, rand.Int())
|
||||
}
|
||||
fmt.Println("year:")
|
||||
term.GetYearUnicode(freq)
|
||||
}
|
||||
8
go.mod
8
go.mod
@@ -4,16 +4,24 @@ go 1.18
|
||||
|
||||
replace github.com/taigrr/go-colorpallettes => ../go-colorpallettes
|
||||
|
||||
replace github.com/muesli/termenv => github.com/taigrr/termenv v0.11.2
|
||||
|
||||
require (
|
||||
github.com/ajstarks/svgo v0.0.0-20211024235047-1546f124cd8b
|
||||
github.com/gorilla/mux v1.8.0
|
||||
github.com/muesli/termenv v0.11.1
|
||||
github.com/srwiley/oksvg v0.0.0-20220128195007-1f435e4c2b44
|
||||
github.com/srwiley/rasterx v0.0.0-20220615024203-67b7089efd25
|
||||
github.com/taigrr/go-colorpallettes v0.0.0-00010101000000-000000000000
|
||||
)
|
||||
|
||||
require (
|
||||
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
|
||||
github.com/mattn/go-isatty v0.0.14 // indirect
|
||||
github.com/mattn/go-runewidth v0.0.13 // indirect
|
||||
github.com/rivo/uniseg v0.2.0 // indirect
|
||||
golang.org/x/image v0.0.0-20211028202545-6944b10bf410 // indirect
|
||||
golang.org/x/net v0.0.0-20211118161319-6a13c67c3ce4 // indirect
|
||||
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a // indirect
|
||||
golang.org/x/text v0.3.6 // indirect
|
||||
)
|
||||
|
||||
17
go.sum
17
go.sum
@@ -6,10 +6,22 @@ github.com/ajstarks/svgo v0.0.0-20211024235047-1546f124cd8b/go.mod h1:1KcenG0jGW
|
||||
github.com/gorilla/mux v1.8.0 h1:i40aqfkR1h2SlN9hojwV5ZA91wcXFOvkdNIeFDP5koI=
|
||||
github.com/gorilla/mux v1.8.0/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB71So=
|
||||
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
|
||||
github.com/lucasb-eyer/go-colorful v1.2.0 h1:1nnpGOrhyZZuNyfu1QjKiUICQ74+3FNCN69Aj6K7nkY=
|
||||
github.com/lucasb-eyer/go-colorful v1.2.0/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0=
|
||||
github.com/mattn/go-isatty v0.0.14 h1:yVuAays6BHfxijgZPzw+3Zlu5yQgKGP2/hcQbHb7S9Y=
|
||||
github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94=
|
||||
github.com/mattn/go-runewidth v0.0.13 h1:lTGmDsbAYt5DmK6OnoV7EuIF1wEIFAcxld6ypU4OSgU=
|
||||
github.com/mattn/go-runewidth v0.0.13/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
|
||||
github.com/rivo/uniseg v0.2.0 h1:S1pD9weZBuJdFmowNwbpi7BJ8TNftyUImj/0WQi72jY=
|
||||
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
|
||||
github.com/srwiley/oksvg v0.0.0-20220128195007-1f435e4c2b44 h1:XPYXKIuH/n5zpUoEWk2jWV/SjEMNYmqDYmTgbjmhtaI=
|
||||
github.com/srwiley/oksvg v0.0.0-20220128195007-1f435e4c2b44/go.mod h1:cNQ3dwVJtS5Hmnjxy6AgTPd0Inb3pW05ftPSX7NZO7Q=
|
||||
github.com/srwiley/rasterx v0.0.0-20220615024203-67b7089efd25 h1:uyi1c8AxAw2b9MTr639iqz45FMFb4dDR7rB++NaVooo=
|
||||
github.com/srwiley/rasterx v0.0.0-20220615024203-67b7089efd25/go.mod h1:nXTWP6+gD5+LUJ8krVhhoeHjvHTutPxMYl5SvkcnJNE=
|
||||
github.com/taigrr/termenv v0.11.2 h1:oqZR08HjGIzFWml4ROmoFvWi3KRG4UZYTPRrI9/lrPA=
|
||||
github.com/taigrr/termenv v0.11.2 h1:oqZR08HjGIzFWml4ROmoFvWi3KRG4UZYTPRrI9/lrPA=
|
||||
github.com/taigrr/termenv v0.11.2/go.mod h1:Bd5NYQ7pd+SrtBSrSNoBBmXlcY8+Xj4BMJgh8qcZrvs=
|
||||
github.com/taigrr/termenv v0.11.2/go.mod h1:Bd5NYQ7pd+SrtBSrSNoBBmXlcY8+Xj4BMJgh8qcZrvs=
|
||||
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
|
||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
||||
@@ -28,11 +40,16 @@ golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5h
|
||||
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20210119212857-b64e53b001e4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a h1:dGzPydgVsqGcTRVwiLJ1jVbufYwmzD3LfVPLKsKg+0k=
|
||||
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||
golang.org/x/text v0.3.6 h1:aRYxNxv6iGQlyVaZmk6ZgYEDa+Jg18DxebPSrd6bg1M=
|
||||
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
||||
golang.org/x/tools v0.1.0/go.mod h1:xkSsbof2nBLbhDlRMhhhyNLN/zl3eTqcnHD5viDpcZ0=
|
||||
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
|
||||
69
term/term.go
Normal file
69
term/term.go
Normal file
@@ -0,0 +1,69 @@
|
||||
package term
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"sync"
|
||||
|
||||
"github.com/muesli/termenv"
|
||||
"github.com/taigrr/gitgraph/common"
|
||||
sc "github.com/taigrr/go-colorpallettes/simplecolor"
|
||||
)
|
||||
|
||||
var colorsLoaded sync.Once
|
||||
var colorScheme []sc.SimpleColor
|
||||
|
||||
func GetWeekUnicode(frequencies []int) {
|
||||
squareColors := []sc.SimpleColor{}
|
||||
min, max := common.MinMax(frequencies)
|
||||
for _, f := range frequencies {
|
||||
squareColors = append(squareColors, common.ColorForFrequency(f, min, max))
|
||||
}
|
||||
drawWeekUnicode(squareColors)
|
||||
}
|
||||
func drawWeekUnicode(c []sc.SimpleColor) {
|
||||
//o := termenv.NewOutput(os.Stdout)
|
||||
o := termenv.NewOutputWithProfile(os.Stdout, termenv.TrueColor)
|
||||
for w, color := range c {
|
||||
style := o.String(block).Foreground(termenv.TrueColor.Color(color.HexString()))
|
||||
fmt.Print(style.String())
|
||||
// termenv.SetForegroundColor(termenv.ForegroundColor())
|
||||
if w == len(c)-1 {
|
||||
fmt.Println()
|
||||
} else {
|
||||
fmt.Print(" ")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func GetYearUnicode(frequencies []int) {
|
||||
squareColors := []sc.SimpleColor{}
|
||||
min, max := common.MinMax(frequencies)
|
||||
for _, f := range frequencies {
|
||||
squareColors = append(squareColors, common.ColorForFrequency(f, min, max))
|
||||
}
|
||||
drawYearUnicode(squareColors)
|
||||
}
|
||||
func drawYearUnicode(c []sc.SimpleColor) {
|
||||
//o := termenv.NewOutput(os.Stdout)
|
||||
o := termenv.NewOutputWithProfile(os.Stdout, termenv.TrueColor)
|
||||
weeks := [7][]sc.SimpleColor{{}}
|
||||
for i := 0; i < 7; i++ {
|
||||
weeks[i] = []sc.SimpleColor{}
|
||||
}
|
||||
for i := range c {
|
||||
weeks[i%7] = append(weeks[i%7], c[i])
|
||||
}
|
||||
for _, row := range weeks {
|
||||
for w, d := range row {
|
||||
style := o.String(block).Foreground(termenv.TrueColor.Color(d.HexString()))
|
||||
fmt.Print(style.String())
|
||||
if w == len(row)-1 {
|
||||
fmt.Println()
|
||||
} else {
|
||||
fmt.Print(" ")
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,3 @@
|
||||
package main
|
||||
package term
|
||||
|
||||
const block = "▅"
|
||||
|
||||
Reference in New Issue
Block a user