This commit is contained in:
Nico 2021-02-11 22:10:03 +00:00
parent 00692961d4
commit 46c54be46b
2 changed files with 29 additions and 29 deletions

View File

@ -68,7 +68,7 @@ func do(req *gemini.Request, via []*gemini.Request) (*gemini.Response, error) {
switch resp.Status.Class() {
case gemini.StatusClassInput: // TODO sensitive input
input, err := GetInput(&face, resp.Meta + ":")
input, err := GetInput(&face, resp.Meta+":")
if err != nil {
break
}
@ -119,7 +119,6 @@ func main() {
var logger *log.Logger = log.New(logFile, "gemini", log.LstdFlags)
defer logFile.Close()
path := "/mnt/onboard/.adds/gemini/known-hosts" // TODO don't hardcode
// Reload or create known hosts file
@ -186,14 +185,14 @@ func main() {
drawErrorBox(err, &face)
logger.Fatal(err)
}
fb.ClearScreen(&fbinkOpts)
fb.ClearScreen(&fbinkOpts)
fb.Println(string(body))
fmt.Println(string(body))
} else {
fb.Println(fmt.Sprintf("%d %s\n", resp.Status, resp.Meta))
}
for {
x,y,_ := t.GetInput()
x, y, _ := t.GetInput()
if x < 100 && y < 100 {
break
}

51
ui.go
View File

@ -4,18 +4,19 @@ import (
"github.com/fogleman/gg"
//"github.com/shermp/go-fbink-v2/gofbink"
//"github.com/shermp/go-kobo-input/koboin"
"golang.org/x/image/font"
"image"
"fmt"
"strings"
"fmt"
"golang.org/x/image/font"
"image"
"strings"
)
var keyboardLowercase [][]string = [][]string{
{"1","2","3","4","5","6","7","8","9","10","BKSP"},
{"q","w","e","r","t","y","u","i","o","p","ENTER"},
{"a","s","d","f","g","h","j","k","l","~","SHIFT"},
{"z","x","c","v","b","n","m",".","/",":","SPACE"},
{"1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "BKSP"},
{"q", "w", "e", "r", "t", "y", "u", "i", "o", "p", "ENTER"},
{"a", "s", "d", "f", "g", "h", "j", "k", "l", "~", "SHIFT"},
{"z", "x", "c", "v", "b", "n", "m", ".", "/", ":", "SPACE"},
}
/*
var keyboardUppercase [][]string = [][]string{
{"!","\"","£","$","%","^","&","*","(",")","BKSP"},
@ -27,9 +28,9 @@ var keyboardUppercase [][]string = [][]string{
// KeyLocation encodes a keyboard key and where it is on the screen, so input can be scanned.
type KeyLocation struct {
X,Y,W,H int
Label string
Keycode string
X, Y, W, H int
Label string
Keycode string
}
func touchingKey(x, y int, k KeyLocation) bool {
@ -47,7 +48,7 @@ func drawDialog(text string, f *font.Face) {
i := image.NewRGBA(image.Rect(0, 0, boxwidth, boxheight))
dc := gg.NewContextForRGBA(i)
if *f != nil {
dc.SetFontFace(*f)
dc.SetFontFace(*f)
}
dc.SetLineWidth(linewidth)
dc.DrawRectangle(0, 0, float64(boxwidth), float64(boxheight))
@ -72,7 +73,7 @@ func GetInput(f *font.Face, prompt string) (string, error) {
if err != nil {
return "", err
}
drawDialog(prompt + "\n ", f)
drawDialog(prompt+"\n ", f)
// Handle input
for {
@ -82,7 +83,7 @@ func GetInput(f *font.Face, prompt string) (string, error) {
continue
}
for _, key := range board {
if touchingKey(x,y, key) {
if touchingKey(x, y, key) {
if key.Keycode == "ENTER" {
return s, nil
} else if key.Keycode == "BKSP" {
@ -94,8 +95,8 @@ func GetInput(f *font.Face, prompt string) (string, error) {
//board, err = drawOSK(fb, opts, f, keyboardUppercase)
s = s + "^"
//if err != nil {
// return "", err
// }
// return "", err
// }
} else if key.Keycode == "SPACE" {
s = s + " "
} else {
@ -107,7 +108,7 @@ func GetInput(f *font.Face, prompt string) (string, error) {
s = s + key.Keycode
}
}
drawDialog(prompt + "\n" + s, f)
drawDialog(prompt+"\n"+s, f)
}
}
}
@ -116,24 +117,24 @@ func GetInput(f *font.Face, prompt string) (string, error) {
// drawOSK draws an on-screen keyboard.
func drawOSK(f *font.Face, keyboard [][]string) ([]KeyLocation, error) {
var board []KeyLocation
var keysw int // Keys wide
var keysw int // Keys wide
keysh := len(keyboard) // Keys high
for _, r := range keyboard {
if len(r) > keysw {
keysw = len(r)
}
}
oskheight := height/3
oskheight := height / 3
i := image.NewRGBA(image.Rect(0, 0, width, oskheight))
dc := gg.NewContextForRGBA(i)
if *f != nil {
dc.SetFontFace(*f)
dc.SetFontFace(*f)
}
dc.SetLineWidth(linewidth)
dc.DrawRectangle(0,0,float64(width),float64(oskheight))
dc.SetRGB(1,1,1)
dc.DrawRectangle(0, 0, float64(width), float64(oskheight))
dc.SetRGB(1, 1, 1)
dc.FillPreserve()
dc.SetRGB(0,0,0)
dc.SetRGB(0, 0, 0)
dc.Stroke()
boardwidth := float64(width) - oskpadding*2
boardheight := float64(height/3) - oskpadding*2
@ -145,12 +146,12 @@ func drawOSK(f *font.Face, keyboard [][]string) ([]KeyLocation, error) {
for _, k := range r {
dc.DrawStringAnchored(k, xpos+keywidth/2, ypos+keyheight/2, 0.5, 0.5)
dc.Fill()
board = append(board, KeyLocation{X: int(xpos), Y: int(ypos)+(height/3)*2, W: int(keywidth), H: int(keyheight), Label: k, Keycode: k})
board = append(board, KeyLocation{X: int(xpos), Y: int(ypos) + (height/3)*2, W: int(keywidth), H: int(keyheight), Label: k, Keycode: k})
xpos += keywidth
}
ypos += keyheight
}
err := fb.PrintRBGA(0, int16(height-oskheight), i, &fbinkOpts)
if err != nil {
return nil, err