skipper/backup

72 lines
1.4 KiB
Plaintext
Raw Normal View History

2022-11-26 09:44:07 -07:00
package main
import "io"
import "os"
import "fmt"
import "image"
import _ "image/png"
import "git.sr.ht/~yotam/go-gemini"
import "git.tebibyte.media/sashakoshka/stone"
import _ "git.tebibyte.media/sashakoshka/stone/backends/x"
var application = &stone.Application { }
var client = gemini.Client { InsecureSkipVerify: true }
var document string
func loadImage (name string) (output image.Image) {
file, err := os.Open(name)
defer file.Close()
if err != nil { panic(err) }
output, _, err = image.Decode(file)
if err != nil { panic(err) }
return
}
func main () {
application.SetTitle("hellorld")
application.SetSize(12, 7)
application.SetIcon ([]image.Image {
loadImage("icon/icon16.png"),
loadImage("icon/icon24.png"),
loadImage("icon/icon32.png"),
loadImage("icon/icon48.png"),
})
channel, err := application.Run()
if err != nil { panic(err) }
response, err := client.Fetch("gemini://gemini.circumlunar.space:1965")
if err != nil {
panic(err.Error())
}
responseBytes, err := io.ReadAll(response.Body)
if err != nil {
panic(err.Error())
}
response.Body.Close()
println("read")
document = string(responseBytes)
println(document)
redraw()
for {
event := <- channel
switch event.(type) {
case stone.EventQuit:
os.Exit(0)
case stone.EventResize:
redraw()
}
}
}
func redraw () {
// width, height := application.Size()
application.ResetDot()
fmt.Fprint(application, document)
application.Draw()
}