// +build darwin linux package main import ( "fmt" "runtime" "strconv" "gitlab.wow.st/gmp/rand" //"gitlab.wow.st/gmp/nuklear/nk" ) func main() { runtime.LockOSThread() length = 5 buf = make([]byte,16) copy(buf,[]byte(fmt.Sprintf("%d\000",length))) fmt.Println(buf) fun = rand.Char generate() log(Info,"Staring event loop") uiInit() eventloop() log(Info,"Event loop returned") } const ( maxlen int = 40 ) var ( fun func() (byte,error) length int out []byte buf []byte ) func generate() { if length <= 0 { return } buf, err := rand.Slice(fun,length) if err != nil { out = []byte("Error") } out = buf } func gfxMain() { if ctx == nil { log(Error,"gfxMain(): ctx is nil") return } if uiBegin() { row(4) if button("Char") { fun = rand.Char generate() } if button("Letter") { fun = rand.Letter generate() } if button("Digit") { fun = rand.Digit generate() } if button("Symbol") { fun = rand.Symbol generate() } row(3) if button("<") { length -= 1; if length == 0 { length = 1 } copy(buf,[]byte(fmt.Sprintf("%d\000",length))) generate() } //label(fmt.Sprintf("%d",length),nk.TextAlignCentered | nk.TextAlignMiddle) editstring(buf) lastlen := length nb := make([]byte,0) for i := 0; i < len(buf); i++ { if buf[i] == 0 || buf[i] == '\n' { break } nb = append(nb,buf[i]) } num,err := strconv.Atoi(string(nb)) if err == nil { length = num } if length != lastlen { if length > maxlen { length = maxlen } copy(buf,[]byte(fmt.Sprintf("%d\000",length))) generate() } if button(">") { length += 1; if length > maxlen { length = maxlen } copy(buf,[]byte(fmt.Sprintf("%d\000",length))) generate() } row(1) if button(string(out)) { Clip(string(out)) } } uiEnd() }