feat: init
This commit is contained in:
commit
0b79635505
|
@ -0,0 +1 @@
|
|||
mppppcg
|
|
@ -0,0 +1,14 @@
|
|||
pppcg: A PrePostPrint inspired political compass generator with SVG output.
|
||||
Copyright (C) 2023 decentral1se
|
||||
|
||||
This program is free software: you can redistribute it and/or modify it under
|
||||
the terms of the GNU General Public License as published by the Free Software
|
||||
Foundation, either version 3 of the License, or (at your option) any later
|
||||
version.
|
||||
|
||||
This program is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License along with
|
||||
this program. If not, see <http://www.gnu.org/licenses/>.
|
|
@ -0,0 +1,68 @@
|
|||
# PrePostPrint political compass generator (`ppppcg`)
|
||||
|
||||
A [PrePostPrint](https://prepostprint.org) inspired political compass generator with SVG output.
|
||||
|
||||
## Install
|
||||
|
||||
> TODO
|
||||
|
||||
## Usage
|
||||
|
||||
```
|
||||
pcg
|
||||
```
|
||||
|
||||
A SVG will be outputted. This can be piped to a graphical program such as `display`:
|
||||
|
||||
```
|
||||
pcg | display
|
||||
```
|
||||
|
||||
You can also save them to file and embed them in HTML pages:
|
||||
|
||||
```
|
||||
pcg > pcg.svg
|
||||
```
|
||||
|
||||
A default `pcg.yml` configuration file is automatically generated in the current working directory.
|
||||
|
||||
```yaml
|
||||
width: 500
|
||||
height: 500
|
||||
|
||||
axis:
|
||||
top: W3C
|
||||
right: Industry
|
||||
bottom: Custom hacks
|
||||
left: Punk
|
||||
|
||||
comments:
|
||||
left: Aesthetics
|
||||
bottom: Approach
|
||||
|
||||
points:
|
||||
- name: OSPKit
|
||||
x: 20
|
||||
y: 20
|
||||
```
|
||||
|
||||
Add a new point:
|
||||
|
||||
```yaml
|
||||
points:
|
||||
// ...
|
||||
- name: PagedJS
|
||||
x: 700
|
||||
y: 700
|
||||
```
|
||||
|
||||
## License
|
||||
|
||||
<a href="https://git.coopcloud.tech/decentral1se/rss-butt-plug/src/branch/main/LICENSE">
|
||||
<img src="https://www.gnu.org/graphics/gplv3-with-text-136x68.png" />
|
||||
</a>
|
||||
|
||||
## ACK
|
||||
|
||||
* [PrePostPrint](https://prepostprint.org)
|
||||
* [`svgo`](https://github.com/ajstarks/svgo)
|
|
@ -0,0 +1,8 @@
|
|||
module d1/ppppcg
|
||||
|
||||
go 1.21.1
|
||||
|
||||
require (
|
||||
github.com/ajstarks/svgo v0.0.0-20211024235047-1546f124cd8b
|
||||
gopkg.in/yaml.v2 v2.4.0
|
||||
)
|
|
@ -0,0 +1,33 @@
|
|||
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
|
||||
github.com/ajstarks/deck v0.0.0-20200831202436-30c9fc6549a9/go.mod h1:JynElWSGnm/4RlzPXRlREEwqTHAN3T56Bv2ITsFT3gY=
|
||||
github.com/ajstarks/deck/generate v0.0.0-20210309230005-c3f852c02e19/go.mod h1:T13YZdzov6OU0A1+RfKZiZN9ca6VeKdBdyDV+BY97Tk=
|
||||
github.com/ajstarks/svgo v0.0.0-20211024235047-1546f124cd8b h1:slYM766cy2nI3BwyRiyQj/Ud48djTMtMebDqepE95rw=
|
||||
github.com/ajstarks/svgo v0.0.0-20211024235047-1546f124cd8b/go.mod h1:1KcenG0jGWcpt8ov532z81sp/kMMUG485J2InIOyADM=
|
||||
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
|
||||
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
|
||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
||||
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
||||
golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
|
||||
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
||||
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||
golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
|
||||
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20210119212857-b64e53b001e4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
||||
golang.org/x/tools v0.1.0/go.mod h1:xkSsbof2nBLbhDlRMhhhyNLN/zl3eTqcnHD5viDpcZ0=
|
||||
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
|
||||
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
|
||||
honnef.co/go/tools v0.1.3/go.mod h1:NgwopIslSNH47DimFoV78dnkksY2EFtX0ajyb3K/las=
|
|
@ -0,0 +1,4 @@
|
|||
PROG := ./ppppcg
|
||||
|
||||
default:
|
||||
@go build .; ./$(PROG) | display
|
|
@ -0,0 +1,109 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
svg "github.com/ajstarks/svgo"
|
||||
"gopkg.in/yaml.v2"
|
||||
)
|
||||
|
||||
const help = `mppppcg [options]
|
||||
|
||||
My PrePostPrint Political Compass Generator.
|
||||
|
||||
Options:
|
||||
-h output help
|
||||
`
|
||||
|
||||
type config struct {
|
||||
Width int
|
||||
Height int
|
||||
|
||||
Axis struct {
|
||||
Top string
|
||||
Right string
|
||||
Bottom string
|
||||
Left string
|
||||
}
|
||||
|
||||
Comments struct {
|
||||
Top string
|
||||
Right string
|
||||
Bottom string
|
||||
Left string
|
||||
}
|
||||
|
||||
Points []struct {
|
||||
Name string
|
||||
X int
|
||||
Y int
|
||||
}
|
||||
}
|
||||
|
||||
var helpFlag bool
|
||||
var debugFlag bool
|
||||
var configFlag string
|
||||
|
||||
// handleCliFlags parses CLI flags.
|
||||
func handleCliFlags() error {
|
||||
flag.BoolVar(&helpFlag, "h", false, "output help")
|
||||
flag.StringVar(&configFlag, "c", "mppppcg.yml", "config file")
|
||||
flag.Parse()
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// loadYAMLConfig loads a mppppcg YAML user config.
|
||||
func loadYAMLConfig() (config, error) {
|
||||
var cfg config
|
||||
|
||||
configPath, err := filepath.Abs(configFlag)
|
||||
if err != nil {
|
||||
return config{}, fmt.Errorf("loadYAMLConfig: unable to convert %s to an absolute path: %w", configFlag, err)
|
||||
}
|
||||
|
||||
conf, err := os.ReadFile(configPath)
|
||||
if err != nil {
|
||||
return config{}, fmt.Errorf("loadYAMLConfig: unable to read %s: %w", configFlag, err)
|
||||
}
|
||||
|
||||
err = yaml.UnmarshalStrict(conf, &cfg)
|
||||
if err != nil {
|
||||
return config{}, fmt.Errorf("loadYAMLConfig: unable to unmarshal %s: %w", string(conf), err)
|
||||
}
|
||||
|
||||
return cfg, nil
|
||||
}
|
||||
|
||||
var fillNoneStrokeBlack = "fill:none;stroke:black"
|
||||
|
||||
func main() {
|
||||
handleCliFlags()
|
||||
|
||||
if helpFlag {
|
||||
fmt.Printf(help)
|
||||
os.Exit(0)
|
||||
}
|
||||
|
||||
cfg, err := loadYAMLConfig()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
canvas := svg.New(os.Stdout)
|
||||
canvas.Start(cfg.Width, cfg.Height)
|
||||
|
||||
rectMargins := cfg.Width - 50
|
||||
canvas.CenterRect(cfg.Width/2, cfg.Height/2, rectMargins, rectMargins, fillNoneStrokeBlack)
|
||||
|
||||
canvas.Line(cfg.Width/2, 0, cfg.Width/2, cfg.Width, fillNoneStrokeBlack)
|
||||
canvas.Line(0, cfg.Width/2, cfg.Width, cfg.Width/2, fillNoneStrokeBlack)
|
||||
|
||||
canvas.Text(cfg.Width/2+10, 15, cfg.Axis.Top)
|
||||
|
||||
canvas.End()
|
||||
}
|
|
@ -0,0 +1,17 @@
|
|||
width: 500
|
||||
height: 500
|
||||
|
||||
axis:
|
||||
top: W3C
|
||||
right: Industry
|
||||
bottom: Custom hacks
|
||||
left: Punk
|
||||
|
||||
comments:
|
||||
left: Aesthetics
|
||||
bottom: Approach
|
||||
|
||||
points:
|
||||
- name: OSPKit
|
||||
x: 20
|
||||
y: 20
|
Reference in New Issue