shithub: mycel

Download patch

ref: a3d9d2db87066930398d89a3781bb2f3b06a0b83
parent: 1f0d91ec3d2753b90b05ed8d25170d268fb52fbb
author: Philip Silva <philip.silva@protonmail.com>
date: Sat Jul 10 06:35:22 EDT 2021

README: go install

diff: cannot open a/cmd/browse//null: file does not exist: 'a/cmd/browse//null' diff: cannot open b/cmd/opossum//null: file does not exist: 'b/cmd/opossum//null'
--- a/README.md
+++ b/README.md
@@ -32,14 +32,13 @@
 ### Compile from Source
 
 ```
-cd cmd/browse
-go run .
+go install ./cmd/opossum
 ```
 
 There are various command line options, visible with `-h`, most importantly to see errors:
 
 ```
-go run . '-quiet=false'
+opossum '-quiet=false'
 ```
 
 (`-quiet=false` produces a lot of output, consider turning on scroll since processing waits for that...)
@@ -47,7 +46,7 @@
 or all messages:
 
 ```
-go run . '-quiet=false' '-debug=true'
+opossum '-quiet=false' '-debug=true'
 ```
 
 `$font` is used to select the font.
@@ -60,8 +59,7 @@
 - Plan9Port
 
 ```
-cd cmd/browse
-go run .
+go install ./cmd/opossum
 ```
 
 # JS support
@@ -82,9 +80,7 @@
 Build the js engine:
 
 ```
-cd cmd/gojafs
-go build
-cp gojafs /bin/gojafs
+go install ./cmd/gojafs
 ```
 
 On 9legacy also the folder `/mnt/opossum` needs to exist.
@@ -94,13 +90,13 @@
 Then try on Plan 9 with e.g.:
 
 ```
-go run . '-experimentalJsInsecure=true' -startPage https://jqueryui.com/resources/demos/tabs/default.html
+opossum '-experimentalJsInsecure=true' -startPage https://jqueryui.com/resources/demos/tabs/default.html
 ```
 
 or macOS etc.:
 
 ```
-go run . -experimentalJsInsecure=true -startPage https://jqueryui.com/resources/demos/tabs/default.html
+opossum -experimentalJsInsecure=true -startPage https://jqueryui.com/resources/demos/tabs/default.html
 ```
 
 
--- a/cmd/browse/main.go
+++ /dev/null
@@ -1,202 +1,0 @@
-package main
-
-import (
-	"9fans.net/go/draw"
-	"flag"
-	"fmt"
-	"image"
-	"os"
-	"github.com/knusbaum/go9p"
-	"github.com/psilva261/opossum"
-	"github.com/psilva261/opossum/browser"
-	"github.com/psilva261/opossum/browser/fs"
-	"github.com/psilva261/opossum/img"
-	"github.com/psilva261/opossum/js"
-	"github.com/psilva261/opossum/logger"
-	"github.com/psilva261/opossum/style"
-	"github.com/psilva261/opossum/nodes"
-	"os/signal"
-	"runtime/pprof"
-	"time"
-	"github.com/mjl-/duit"
-)
-
-const debugPrintHtml = false
-
-var dui *duit.DUI
-var log *logger.Logger
-
-var cpuprofile = flag.String("cpuprofile", "", "write cpu profile to file")
-var startPage = flag.String("startPage", "http://9p.io", "")
-var dbg = flag.Bool("debug", false, "show debug logs")
-
-func init() {
-	browser.DebugDumpCSS = flag.Bool("debugDumpCSS", false, "write css to info.css")
-	js.DebugDumpJS = flag.Bool("debugDumpJS", false, "write js to main.js")
-	browser.ExperimentalJsInsecure = flag.Bool("experimentalJsInsecure", false, "DO NOT ACTIVATE UNLESS INSTRUCTED OTHERWISE")
-	browser.EnableNoScriptTag = flag.Bool("enableNoScriptTag", false, "enable noscript tag")
-	logger.Quiet = flag.Bool("quiet", defaultQuietActive, "don't print info messages and non-fatal errors")
-}
-
-func mainView(b *browser.Browser) []*duit.Kid {
-	return duit.NewKids(
-		&duit.Grid{
-			Columns: 2,
-			Padding: duit.NSpace(2, duit.SpaceXY(5, 3)),
-			Halign:  []duit.Halign{duit.HalignLeft, duit.HalignRight},
-			Valign:  []duit.Valign{duit.ValignMiddle, duit.ValignMiddle},
-			Kids: duit.NewKids(
-				&duit.Button{
-					Text:  "Back",
-					Font:  browser.Style.Font(),
-					Click: b.Back,
-				},
-				&duit.Box{
-					Kids: duit.NewKids(
-						b.LocationField,
-					),
-				},
-			),
-		},
-		b.StatusBar,
-		b.Website,
-	)
-}
-
-func render(b *browser.Browser, kids []*duit.Kid) {
-	white, err := dui.Display.AllocImage(image.Rect(0, 0, 10, 10), draw.ARGB32, true, 0xffffffff)
-	if err != nil {
-		log.Errorf("%v", err)
-	}
-	dui.Top.UI = &duit.Box{
-		Kids: kids,
-		Background: white,
-	}
-	browser.PrintTree(b.Website.UI)
-	log.Printf("Render.....")
-	dui.MarkLayout(dui.Top.UI)
-	dui.MarkDraw(dui.Top.UI)
-	dui.Render()
-	log.Printf("Rendering done")
-}
-
-func confirm(b *browser.Browser, text, value string) chan string {
-	res := make(chan string)
-
-	dui.Call <- func() {
-		f := &duit.Field{
-			Text: value,
-		}
-
-		kids := duit.NewKids(
-			&duit.Grid{
-				Columns: 3,
-				Padding: duit.NSpace(3, duit.SpaceXY(5, 3)),
-				Halign:  []duit.Halign{duit.HalignLeft, duit.HalignLeft, duit.HalignRight},
-				Valign:  []duit.Valign{duit.ValignMiddle, duit.ValignMiddle, duit.ValignMiddle},
-				Kids: duit.NewKids(
-					&duit.Button{
-						Text:  "Ok",
-						Font:  browser.Style.Font(),
-						Click: func() (e duit.Event) {
-							res <- f.Text
-							e.Consumed = true
-							return
-						},
-					},
-					&duit.Button{
-						Text:  "Abort",
-						Font:  browser.Style.Font(),
-						Click: func() (e duit.Event) {
-							res <- ""
-							e.Consumed = true
-							return
-						},
-					},
-					f,
-				),
-			},
-			&duit.Label{
-				Text: text,
-			},
-		)
-
-		render(b, kids)
-	}
-
-	return res
-}
-
-func Main() (err error) {
-	dui, err = duit.NewDUI("opossum", nil) // TODO: rm global var
-	if err != nil {
-		return fmt.Errorf("new dui: %w", err)
-	}
-
-	style.Init(dui, log)
-	browser.SetLogger(log)
-	fs.SetLogger(log)
-	img.SetLogger(log)
-	js.SetLogger(log)
-	opossum.SetLogger(log)
-	nodes.SetLogger(log)
-
-	b := browser.NewBrowser(dui, *startPage)
-	b.Download = func(done chan int) chan string {
-		go func() {
-			<-done
-			dui.Call <- func() {
-				render(b, mainView(b))
-			}
-		}()
-		return confirm(b, fmt.Sprintf("Download %v", b.URL()), "/download.file")
-	}
-	render(b, mainView(b))
-
-	for {
-		select {
-		case e := <-dui.Inputs:
-			dui.Input(e)
-
-		case err, ok := <-dui.Error:
-			if !ok {
-				return nil
-			}
-			log.Printf("main: duit: %s\n", err)
-		}
-	}
-}
-
-func main() {
-	flag.Parse()
-	logger.Init()
-
-	if *cpuprofile != "" {
-		f, err := os.Create(*cpuprofile)
-		if err != nil {
-			log.Fatal(err)
-		}
-		pprof.StartCPUProfile(f)
-		go func() {
-			<-time.After(time.Minute)
-			pprof.StopCPUProfile()
-			os.Exit(2)
-		}()
-	}
-
-	log = logger.Log
-	log.Debug = *dbg
-	go9p.Verbose = log.Debug
-
-	done := make(chan os.Signal, 1)
-	signal.Notify(done, os.Interrupt, os.Kill)
-
-	go func() {
-		<-done
-		js.Stop()
-	}()
-
-	if err := Main(); err != nil {
-		log.Fatalf("Main: %v", err)
-	}
-}
--- a/cmd/browse/main_plan9.go
+++ /dev/null
@@ -1,3 +1,0 @@
-package main
-
-const defaultQuietActive = true
--- a/cmd/browse/main_test.go
+++ /dev/null
@@ -1,1 +1,0 @@
-package main
--- a/cmd/browse/main_unix.go
+++ /dev/null
@@ -1,5 +1,0 @@
-// +build !plan9
-
-package main
-
-const defaultQuietActive = false
--- a/cmd/gojafs/main_unix.go
+++ b/cmd/gojafs/main_unix.go
@@ -6,7 +6,6 @@
 	"9fans.net/go/plan9"
 	"9fans.net/go/plan9/client"
 	"fmt"
-	"github.com/knusbaum/go9p"
 	"io"
 	"os/user"
 )
--- /dev/null
+++ b/cmd/opossum/main.go
@@ -1,0 +1,202 @@
+package main
+
+import (
+	"9fans.net/go/draw"
+	"flag"
+	"fmt"
+	"image"
+	"os"
+	"github.com/knusbaum/go9p"
+	"github.com/psilva261/opossum"
+	"github.com/psilva261/opossum/browser"
+	"github.com/psilva261/opossum/browser/fs"
+	"github.com/psilva261/opossum/img"
+	"github.com/psilva261/opossum/js"
+	"github.com/psilva261/opossum/logger"
+	"github.com/psilva261/opossum/style"
+	"github.com/psilva261/opossum/nodes"
+	"os/signal"
+	"runtime/pprof"
+	"time"
+	"github.com/mjl-/duit"
+)
+
+const debugPrintHtml = false
+
+var dui *duit.DUI
+var log *logger.Logger
+
+var cpuprofile = flag.String("cpuprofile", "", "write cpu profile to file")
+var startPage = flag.String("startPage", "http://9p.io", "")
+var dbg = flag.Bool("debug", false, "show debug logs")
+
+func init() {
+	browser.DebugDumpCSS = flag.Bool("debugDumpCSS", false, "write css to info.css")
+	js.DebugDumpJS = flag.Bool("debugDumpJS", false, "write js to main.js")
+	browser.ExperimentalJsInsecure = flag.Bool("experimentalJsInsecure", false, "DO NOT ACTIVATE UNLESS INSTRUCTED OTHERWISE")
+	browser.EnableNoScriptTag = flag.Bool("enableNoScriptTag", false, "enable noscript tag")
+	logger.Quiet = flag.Bool("quiet", defaultQuietActive, "don't print info messages and non-fatal errors")
+}
+
+func mainView(b *browser.Browser) []*duit.Kid {
+	return duit.NewKids(
+		&duit.Grid{
+			Columns: 2,
+			Padding: duit.NSpace(2, duit.SpaceXY(5, 3)),
+			Halign:  []duit.Halign{duit.HalignLeft, duit.HalignRight},
+			Valign:  []duit.Valign{duit.ValignMiddle, duit.ValignMiddle},
+			Kids: duit.NewKids(
+				&duit.Button{
+					Text:  "Back",
+					Font:  browser.Style.Font(),
+					Click: b.Back,
+				},
+				&duit.Box{
+					Kids: duit.NewKids(
+						b.LocationField,
+					),
+				},
+			),
+		},
+		b.StatusBar,
+		b.Website,
+	)
+}
+
+func render(b *browser.Browser, kids []*duit.Kid) {
+	white, err := dui.Display.AllocImage(image.Rect(0, 0, 10, 10), draw.ARGB32, true, 0xffffffff)
+	if err != nil {
+		log.Errorf("%v", err)
+	}
+	dui.Top.UI = &duit.Box{
+		Kids: kids,
+		Background: white,
+	}
+	browser.PrintTree(b.Website.UI)
+	log.Printf("Render.....")
+	dui.MarkLayout(dui.Top.UI)
+	dui.MarkDraw(dui.Top.UI)
+	dui.Render()
+	log.Printf("Rendering done")
+}
+
+func confirm(b *browser.Browser, text, value string) chan string {
+	res := make(chan string)
+
+	dui.Call <- func() {
+		f := &duit.Field{
+			Text: value,
+		}
+
+		kids := duit.NewKids(
+			&duit.Grid{
+				Columns: 3,
+				Padding: duit.NSpace(3, duit.SpaceXY(5, 3)),
+				Halign:  []duit.Halign{duit.HalignLeft, duit.HalignLeft, duit.HalignRight},
+				Valign:  []duit.Valign{duit.ValignMiddle, duit.ValignMiddle, duit.ValignMiddle},
+				Kids: duit.NewKids(
+					&duit.Button{
+						Text:  "Ok",
+						Font:  browser.Style.Font(),
+						Click: func() (e duit.Event) {
+							res <- f.Text
+							e.Consumed = true
+							return
+						},
+					},
+					&duit.Button{
+						Text:  "Abort",
+						Font:  browser.Style.Font(),
+						Click: func() (e duit.Event) {
+							res <- ""
+							e.Consumed = true
+							return
+						},
+					},
+					f,
+				),
+			},
+			&duit.Label{
+				Text: text,
+			},
+		)
+
+		render(b, kids)
+	}
+
+	return res
+}
+
+func Main() (err error) {
+	dui, err = duit.NewDUI("opossum", nil) // TODO: rm global var
+	if err != nil {
+		return fmt.Errorf("new dui: %w", err)
+	}
+
+	style.Init(dui, log)
+	browser.SetLogger(log)
+	fs.SetLogger(log)
+	img.SetLogger(log)
+	js.SetLogger(log)
+	opossum.SetLogger(log)
+	nodes.SetLogger(log)
+
+	b := browser.NewBrowser(dui, *startPage)
+	b.Download = func(done chan int) chan string {
+		go func() {
+			<-done
+			dui.Call <- func() {
+				render(b, mainView(b))
+			}
+		}()
+		return confirm(b, fmt.Sprintf("Download %v", b.URL()), "/download.file")
+	}
+	render(b, mainView(b))
+
+	for {
+		select {
+		case e := <-dui.Inputs:
+			dui.Input(e)
+
+		case err, ok := <-dui.Error:
+			if !ok {
+				return nil
+			}
+			log.Printf("main: duit: %s\n", err)
+		}
+	}
+}
+
+func main() {
+	flag.Parse()
+	logger.Init()
+
+	if *cpuprofile != "" {
+		f, err := os.Create(*cpuprofile)
+		if err != nil {
+			log.Fatal(err)
+		}
+		pprof.StartCPUProfile(f)
+		go func() {
+			<-time.After(time.Minute)
+			pprof.StopCPUProfile()
+			os.Exit(2)
+		}()
+	}
+
+	log = logger.Log
+	log.Debug = *dbg
+	go9p.Verbose = log.Debug
+
+	done := make(chan os.Signal, 1)
+	signal.Notify(done, os.Interrupt, os.Kill)
+
+	go func() {
+		<-done
+		js.Stop()
+	}()
+
+	if err := Main(); err != nil {
+		log.Fatalf("Main: %v", err)
+	}
+}
--- /dev/null
+++ b/cmd/opossum/main_plan9.go
@@ -1,0 +1,3 @@
+package main
+
+const defaultQuietActive = true
--- /dev/null
+++ b/cmd/opossum/main_test.go
@@ -1,0 +1,1 @@
+package main
--- /dev/null
+++ b/cmd/opossum/main_unix.go
@@ -1,0 +1,5 @@
+// +build !plan9
+
+package main
+
+const defaultQuietActive = false
--- a/package.rc
+++ b/package.rc
@@ -14,10 +14,10 @@
 	chmod +t ./$name
 
 	echo Compiling $GOARCH...
-	cd cmd/browse
+	cd cmd/opossum
 	go build -ldflags '-s -w' -o $name.bin
 	cd ../..
-	mv cmd/browse/$name.bin .
+	mv cmd/opossum/$name.bin .
 	mv $name.bin ./$name/
 	cp README.md ./$name/
 	cp opossum.jpg ./$name/