img: in questions and clues supported woo
parent
1ba823c13a
commit
bf9af0dd64
|
|
@ -1,2 +1,4 @@
|
|||
**/*.bak
|
||||
**/*.sw*
|
||||
/anki
|
||||
/anki.d
|
||||
|
|
|
|||
2
go.mod
2
go.mod
|
|
@ -1,4 +1,4 @@
|
|||
module gogs.inhome.blapointe.com/anki.d
|
||||
module gogs.inhome.blapointe.com/bel/anki
|
||||
|
||||
go 1.19
|
||||
|
||||
|
|
|
|||
12
image.go
12
image.go
|
|
@ -5,6 +5,7 @@ import (
|
|||
"image"
|
||||
"image/jpeg"
|
||||
"image/png"
|
||||
"io"
|
||||
"os"
|
||||
"path"
|
||||
|
||||
|
|
@ -12,7 +13,7 @@ import (
|
|||
"github.com/nfnt/resize"
|
||||
)
|
||||
|
||||
func View(p string) {
|
||||
func View(w io.Writer, p string) {
|
||||
in, err := os.Open(p)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
|
|
@ -31,10 +32,10 @@ func View(p string) {
|
|||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
printImage(40, src)
|
||||
printImage(w, 40, src)
|
||||
}
|
||||
|
||||
func printImage(limit int, image image.Image) {
|
||||
func printImage(w io.Writer, limit int, image image.Image) {
|
||||
if image.Bounds().Max.X > image.Bounds().Max.Y {
|
||||
xmax := image.Bounds().Max.X
|
||||
ratio := float64(limit) / float64(xmax)
|
||||
|
|
@ -46,14 +47,15 @@ func printImage(limit int, image image.Image) {
|
|||
height := uint(float64(ymax) * ratio)
|
||||
image = resize.Resize(0, height, image, resize.Bicubic)
|
||||
}
|
||||
escape := "\x1b"
|
||||
for i := 0; i < image.Bounds().Max.Y; i++ {
|
||||
for j := 0; j < image.Bounds().Max.X; j++ {
|
||||
r, g, b, _ := image.At(j, i).RGBA()
|
||||
r = ansi.To256(r)
|
||||
g = ansi.To256(g)
|
||||
b = ansi.To256(b)
|
||||
ansi.Print(r, g, b)
|
||||
fmt.Fprintf(w, "%s[7m%s[38;2;%d;%d;%dm ", escape, escape, r, g, b)
|
||||
}
|
||||
fmt.Printf("\n")
|
||||
fmt.Fprintf(w, "\n")
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,8 +9,8 @@ func TestView(t *testing.T) {
|
|||
if os.Getenv("INTEGRATION") == "" {
|
||||
t.SkipNow()
|
||||
}
|
||||
View("./testdata/tofugu.d/a-hiragana-0.png")
|
||||
View("./testdata/tofugu.d/a-hiragana-0.sm.png")
|
||||
View("./testdata/tofugu.d/a-hiragana-1.png")
|
||||
View("./testdata/tofugu.d/a-hiragana-2.png")
|
||||
View(os.Stderr, "./testdata/tofugu.d/a-hiragana-0.png")
|
||||
View(os.Stderr, "./testdata/tofugu.d/a-hiragana-0.sm.png")
|
||||
View(os.Stderr, "./testdata/tofugu.d/a-hiragana-1.png")
|
||||
View(os.Stderr, "./testdata/tofugu.d/a-hiragana-2.png")
|
||||
}
|
||||
|
|
|
|||
17
main.go
17
main.go
|
|
@ -2,6 +2,7 @@ package main
|
|||
|
||||
import (
|
||||
"bufio"
|
||||
"bytes"
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
|
|
@ -62,11 +63,7 @@ func Main() error {
|
|||
continue
|
||||
}
|
||||
question := db.Question(q)
|
||||
fmt.Printf("> Q: ")
|
||||
if strings.HasPrefix(string(question.Q), "img:") {
|
||||
} else {
|
||||
fmt.Printf("%s", question.Q)
|
||||
}
|
||||
fmt.Printf("> Q: %s\n", question.Q)
|
||||
fmt.Printf("\n")
|
||||
fmt.Printf("> %+v\n", question.Tags)
|
||||
var response string
|
||||
|
|
@ -130,3 +127,13 @@ func (q Question) Tagged(tag IDT) bool {
|
|||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (renderable Renderable) String() string {
|
||||
s := string(renderable)
|
||||
if !strings.HasPrefix(s, "img:") {
|
||||
return s
|
||||
}
|
||||
buff := bytes.NewBuffer(nil)
|
||||
View(buff, s[4:])
|
||||
return string(buff.Bytes())
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,10 +1,9 @@
|
|||
knowledge:
|
||||
questions:
|
||||
a-hiragana:
|
||||
q: img:testdata/tofugu.d/a-hiragana-0.jpg
|
||||
q: img:testdata/tofugu.d/a-hiragana-0.png
|
||||
clues:
|
||||
- img:testdata/tofugu.d/a-hiragana-1.jpg
|
||||
- img:testdata/tofugu.d/a-hiragana-2.jpg
|
||||
- img:testdata/tofugu.d/a-hiragana-1.png
|
||||
tags: [hiragana, vowel]
|
||||
users:
|
||||
breel:
|
||||
|
|
|
|||
Loading…
Reference in New Issue