2024-01-20 16:09:15 -06:00
|
|
|
// This is a simple example
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"io/ioutil"
|
|
|
|
"net/http"
|
2024-01-25 13:09:33 -06:00
|
|
|
"os"
|
2024-01-20 16:09:15 -06:00
|
|
|
"strings"
|
|
|
|
|
|
|
|
"go.wit.com/gui"
|
|
|
|
"go.wit.com/log"
|
|
|
|
|
|
|
|
"go.wit.com/lib/gadgets"
|
|
|
|
)
|
|
|
|
|
|
|
|
var lw *gadgets.BasicWindow
|
|
|
|
var allsections []*section
|
|
|
|
|
2024-01-25 13:09:33 -06:00
|
|
|
type witRepo struct {
|
|
|
|
sec *section
|
|
|
|
path *gui.Node
|
|
|
|
downloadB *gui.Node
|
|
|
|
}
|
|
|
|
|
2024-01-20 16:09:15 -06:00
|
|
|
type section struct {
|
|
|
|
name string
|
|
|
|
parent *gui.Node
|
|
|
|
box *gui.Node
|
|
|
|
group *gui.Node
|
2024-01-25 13:09:33 -06:00
|
|
|
grid *gui.Node // where the repos are listed
|
|
|
|
hideCB *gui.Node
|
|
|
|
witRepos []*witRepo
|
2024-01-20 16:09:15 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
func listWindow() {
|
|
|
|
if lw != nil {
|
|
|
|
lw.Toggle()
|
|
|
|
return
|
|
|
|
}
|
|
|
|
lw = gadgets.NewBasicWindow(me.myGui, "go.wit.com repositories")
|
|
|
|
lw.Custom = func() {
|
|
|
|
log.Warn("got to close")
|
|
|
|
}
|
|
|
|
|
|
|
|
lw.Make()
|
|
|
|
lw.StandardClose()
|
|
|
|
lw.Draw()
|
|
|
|
box := lw.Box()
|
|
|
|
group := box.NewGroup("list")
|
|
|
|
group.NewButton("blah", func() {})
|
|
|
|
|
|
|
|
var lines []string
|
|
|
|
var curs *section
|
|
|
|
|
|
|
|
lines = dumpURL("https://go.wit.com/list")
|
|
|
|
for i, line := range lines {
|
|
|
|
if line == "" {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
if line[0] == '#' {
|
|
|
|
curs = NewSection(group, line)
|
|
|
|
log.Warn("new group:", line)
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
log.Warn(i, line)
|
|
|
|
parts := strings.Split(line, " ")
|
|
|
|
if curs != nil {
|
|
|
|
curs.add(parts[0])
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *section) add(path string) {
|
|
|
|
if s == nil {
|
|
|
|
return
|
|
|
|
}
|
2024-01-25 13:09:33 -06:00
|
|
|
tmp := new(witRepo)
|
|
|
|
tmp.sec = s
|
|
|
|
tmp.path = s.grid.NewLabel(path)
|
|
|
|
tmp.downloadB = s.grid.NewButton("download", func() {
|
|
|
|
lw.Disable()
|
|
|
|
log.Info("downloading", tmp.path.String(), "here")
|
|
|
|
os.Setenv("GO111MODULE", "off")
|
|
|
|
fullpath := "/home/jcarr/go/src/go.wit.com/"
|
|
|
|
quickCmd(fullpath, []string{"go", "get", "-v", tmp.path.String()})
|
|
|
|
lw.Enable()
|
|
|
|
})
|
|
|
|
|
|
|
|
s.witRepos = append(s.witRepos, tmp)
|
2024-01-20 16:09:15 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
func NewSection(parent *gui.Node, path string) *section {
|
|
|
|
news := new(section)
|
|
|
|
news.parent = parent
|
|
|
|
news.box = news.parent.NewBox("bw vbox", true)
|
|
|
|
news.group = news.box.NewGroup(path)
|
2024-01-25 13:09:33 -06:00
|
|
|
news.hideCB = news.box.NewCheckbox("hide")
|
|
|
|
news.hideCB.Custom = func() {
|
2024-01-20 16:09:15 -06:00
|
|
|
news.toggle()
|
|
|
|
}
|
2024-01-25 13:09:33 -06:00
|
|
|
news.grid = news.parent.NewGrid("sections", 2, 1)
|
2024-01-20 16:09:15 -06:00
|
|
|
allsections = append(allsections, news)
|
|
|
|
return news
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *section) toggle() {
|
|
|
|
log.Warn(s.name)
|
2024-01-25 13:09:33 -06:00
|
|
|
for i, wrepo := range s.witRepos {
|
|
|
|
log.Warn(i, wrepo.path.String())
|
|
|
|
wrepo.path.Hide()
|
|
|
|
wrepo.downloadB.Hide()
|
2024-01-20 16:09:15 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
func dumpURL(url string) string {
|
|
|
|
resp, err := http.Get(url)
|
|
|
|
if err != nil {
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
defer resp.Body.Close()
|
|
|
|
|
|
|
|
return resp.Body.String()
|
|
|
|
|
|
|
|
_, err = io.Copy(os.Stdout, resp.Body)
|
|
|
|
if err != nil {
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
|
|
|
|
func dumpURL(url string) []string {
|
|
|
|
resp, err := http.Get(url)
|
|
|
|
if err != nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
defer resp.Body.Close()
|
|
|
|
|
|
|
|
bodyBytes, err := ioutil.ReadAll(resp.Body)
|
|
|
|
if err != nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
return strings.Split(string(bodyBytes), "\n")
|
|
|
|
}
|