Auto generate full license text and embed

Display the licenses of all dependencies in a context menu suboption
pull/3/head
lawl 4 years ago
parent d87c8153c7
commit 3083a4084f

3
.gitignore vendored

@ -1,3 +1,4 @@
bin/
librnnoise.go
version.go
version.go
licenses.go

@ -652,7 +652,7 @@ Also add information on how to contact you by electronic and paper mail.
If the program does terminal interaction, make it output a short
notice like this when it starts in an interactive mode:
<program> Copyright (C) <year> <name of author>
NoiseTorch Copyright (C) 2020 lawl (github.com/lawl)
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.

@ -17,6 +17,7 @@ import (
//go:generate go run scripts/embedlibrnnoise.go
//go:generate go run scripts/embedversion.go
//go:generate go run scripts/embedlicenses.go
type input struct {
ID string

@ -0,0 +1,44 @@
package main
import (
"io/ioutil"
"os"
"path/filepath"
"strings"
)
func main() {
cwd, err := os.Getwd()
if err != nil {
panic(err)
}
out, _ := os.Create("licenses.go")
out.Write([]byte("package main \n\nvar licenseString=`"))
out.WriteString("LICENSES\n")
out.WriteString("========\n")
defer out.Close()
filepath.Walk(cwd, func(path string, info os.FileInfo, err error) error {
if err != nil {
panic(err)
}
if strings.HasPrefix("LICENSE", info.Name()) {
rel, err := filepath.Rel(cwd, path)
if err != nil {
panic(err)
}
dir := filepath.Dir(rel)
out.WriteString("FILES: " + dir + "\n")
c, err := ioutil.ReadFile(path)
str := string(c)
str = strings.ReplaceAll(str, "`", "`"+" + \"`\" + `") // escape backticks in license text for go src
if err != nil {
panic(err)
}
out.WriteString(str)
out.WriteString("\n\n")
}
return nil
})
out.Write([]byte("`\n"))
}

@ -45,7 +45,7 @@ func updatefn(w *nucular.Window, ui *uistate) {
}
w.MenubarBegin()
w.WindowStyle().Background = color.RGBA{0, 255, 0, 255}
w.Row(10).Dynamic(1)
if w := w.Menu(label.TA("About", "LC"), 120, nil); w != nil {
w.Row(10).Dynamic(1)
@ -203,7 +203,7 @@ func licenseScreen(w *nucular.Window, ui *uistate) {
field := &ui.licenseTextArea
field.Flags |= nucular.EditMultiline
if len(field.Buffer) < 1 {
field.Buffer = []rune("foo\nbar\nfoo\nbar\nfoo\nbar\nfoo\nbar\nfoo\nbar\nfoo\nbar\nfoo\nbar\nfoo\nbar\nfoo\nbar\nfoo\nbar\nfoo\nbar\nfoo\nbar\nfoo\nbar\nfoo\nbar\nfoo\nbar\nfoo\nbar\nfoo\nbar\nfoo\nbar\nfoo\nbar\nfoo\nbar\nfoo\nbar\nfoo\nbar\nfoo\nbar\nfoo\nbar\nfoo\nbar\nfoo\nbar\nfoo\nbar\nfoo\nbar\nfoo\nbar\nfoo\nbar\n")
field.Buffer = []rune(licenseString)
}
field.Edit(w)

Loading…
Cancel
Save