feat: init

This commit is contained in:
decentral1se 2023-11-27 13:04:00 +01:00
commit 2fc9dba781
Signed by: decentral1se
GPG Key ID: 03789458B3D0C410
8 changed files with 301 additions and 0 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
ppppcg

14
LICENSE Normal file
View File

@ -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/>.

75
README.md Normal file
View File

@ -0,0 +1,75 @@
# PrePostPrint political compass generator (`ppppcg`)
A [PrePostPrint](https://prepostprint.org) inspired political compass generator
with SVG output.
## Install
> TODO
## Usage
Create a configuration file in your current working directory. `ppppcg.yml` is
the default, you can use the `-c` flag to customise this. Here's an example
inspired by `@mb`.
```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
```
Then run `ppppcg` in the same directory.
```
ppppcg
```
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
```
You can easily add a new point:
```yaml
points:
// ...
- name: PagedJS
x: 700
y: 700
```
Enjoy ✌️
## 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)

8
go.mod Normal file
View File

@ -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
)

33
go.sum Normal file
View File

@ -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=

4
makefile Normal file
View File

@ -0,0 +1,4 @@
PROG := ./ppppcg
default:
@go build .; ./$(PROG) | display

149
ppppcg.go Normal file
View File

@ -0,0 +1,149 @@
// ppppcg is a PrePostPrint inspired political compass generator with SVG output.
package main
import (
"flag"
"fmt"
"log"
"os"
"path/filepath"
svg "github.com/ajstarks/svgo"
"gopkg.in/yaml.v2"
)
// help is the CLI help text.
const help = `ppppcg [options]
A PrePostPrint inspired political compass generator with SVG output.
Options:
-h output help
`
// config is the user configuration file.
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
configFlag string
// rectMargin is the margin for the compass rectangle.
rectMargin = 300
// fillNoneStrokeBlack is a default calm line style.
fillNoneStrokeBlack = "fill:none;stroke:black"
// lineOverflow is the amount of overflow permitted for each compass line.
lineOverflow = 130
)
// handleCliFlags parses CLI flags.
func handleCliFlags() error {
flag.BoolVar(&helpFlag, "h", false, "output help")
flag.StringVar(&configFlag, "c", "ppppcg.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
}
// main is the CLI entrypoint.
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)
canvas.CenterRect(
cfg.Width/2,
cfg.Height/2,
cfg.Width-rectMargin,
cfg.Width-rectMargin,
fillNoneStrokeBlack,
)
canvas.Line(
cfg.Width/2,
lineOverflow,
cfg.Width/2,
cfg.Width-lineOverflow,
fillNoneStrokeBlack,
)
canvas.Line(
lineOverflow,
cfg.Width/2,
cfg.Width-lineOverflow,
cfg.Width/2,
fillNoneStrokeBlack,
)
canvas.Text(
(cfg.Width/2)-len(cfg.Axis.Top)*2,
20,
cfg.Axis.Top,
)
canvas.Text(
cfg.Width/2,
cfg.Width/2,
cfg.Axis.Right,
)
canvas.End()
}

17
ppppcg.yml Normal file
View File

@ -0,0 +1,17 @@
width: 700
height: 700
axis:
top: W3C
right: Industry
bottom: Custom hacks
left: Punk
comments:
left: Aesthetics
bottom: Approach
points:
- name: OSPKit
x: 20
y: 20