diff --git a/README.md b/README.md index 9d5f1aa..f544e6c 100644 --- a/README.md +++ b/README.md @@ -13,6 +13,23 @@ color and terminal codes instead of CSS properties and hex colors. See [cmd/gold](cmd/gold/). +## Example Output + +![Gold Dark Style](https://github.com/charmbracelet/gold/raw/master/styles/dark.png) + +Check out the [Gold Style Gallery](https://github.com/charmbracelet/gold/blob/master/styles/README.md)! + ## Colors Currently `gold` uses the [Aurora ANSI colors](https://godoc.org/github.com/logrusorgru/aurora#Index). + +## Development + +Style definitions located in `styles/` can be embedded into the binary by +running [statik](https://github.com/rakyll/statik): +``` +statik -f -src styles -include "*.json" +``` + +You can re-generate screenshots of all available styles by running `gallery.sh`. +This requires `termshot` and `pngcrush` installed on your system! diff --git a/gallery.sh b/gallery.sh new file mode 100755 index 0000000..1b84afc --- /dev/null +++ b/gallery.sh @@ -0,0 +1,14 @@ +#!/bin/bash + +for style in ./styles/*.json; do + echo "Generating screenshot for ${style}" + filename="`basename -s .json ${style}`.png" + + light="" + if [[ $style == *"light"* ]]; then + light="-l" + fi + + ./termshot ${light} -o ./styles/ -f "$filename" ./gold -s ${style} + pngcrush -ow "./styles/$filename" +done diff --git a/gold.go b/gold.go index c0d78c1..42f48f9 100644 --- a/gold.go +++ b/gold.go @@ -4,10 +4,8 @@ import ( "encoding/json" "fmt" "io" - "io/ioutil" "log" "net/url" - "os" "github.com/microcosm-cc/bluemonday" bf "gopkg.in/russross/blackfriday.v2" @@ -46,12 +44,11 @@ func NewTermRenderer(stylePath string) (*TermRenderer, error) { if stylePath == "" { return NewTermRendererFromBytes([]byte("{}")) } - f, err := os.Open(stylePath) + + b, err := loadStyle(stylePath) if err != nil { return nil, err } - defer f.Close() - b, _ := ioutil.ReadAll(f) return NewTermRendererFromBytes(b) } diff --git a/statik/statik.go b/statik/statik.go new file mode 100644 index 0000000..279e4b0 --- /dev/null +++ b/statik/statik.go @@ -0,0 +1,12 @@ +// Code generated by statik. DO NOT EDIT. + +package statik + +import ( + "github.com/rakyll/statik/fs" +) + +func init() { + data := "PK\x03\x04\x14\x00\x08\x00\x08\x00\x88\x03\x86O\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00 \x00 \x00dark.jsonUT\x05\x00\x01\xa0\xa0\xe9]\x94\x92[N\xeb0\x10\x86\xdf\xb3\n\xcb\xe7\xe5 \x01j\xdd\x96KE\xd9\x08\xa0\xca\x89\xa7\xa9\x15_\xaa\x89-U\xa0J\xec\x81\x05 \xb1 \xf6\xc3\nX\x02\x8az\xb1CL(\x8f\xfe\xfd\xcf|s{\xca\x08\xa1\xc2\x16^\x83qtJ\x9a7!T\x1a\xb1}\x8fO\xb7B\xce\x8b\xaaD\xeb\x8d\x98\x17VY\xa4SB\xd9hLw\xdf+\x84\x85\\7\xe2\xbd\xd9k\xb5_\x04-#d\xd3\xe8TIS\x05\xce!\xd7\x90\x8d\xf6q\xde\x08@%\x0d\xd0)q\xe8\xa1\x83\xf8\xdf%\x9c\xb4\x01s\x07k\xd7O\xc9\xad\x12;\xc0!Tj^B\x7fX\xa8\xe2\xee\xf3\xf5\xe5\x9dtKy\xa0\xed|?\xd5r\x15|K\xe0B\x9a2\x98R\xe3\xd4\x1cKi\xa2\x95\x84\xf2&\xb4gK\x93\xcb\x084L3f\xb7\x89F\xc8\xcd\xac\xc3f\xdd\xe9\xf5\xa0/\xae#4K\xa3\xff\x91\xe0qH\x88\xd8\x02^\xdd\xdcb\xf3]\x9d\xbc\xa1(\xec [\xd08\xd1\xcf\xc3!\xd2\x9e\x8fI\x7f\x96\xd5\xe3\xb4\x9f\x8b\xe7\xf8Y{i2l\xabt\xd4e\xe2uA\xdc\x0513\xac\xb2`\xd7\x0d\xf4\x7f\xe0\x9c\xeb\xfe.u\xb4\xb0\x14\xef\x01O\xbd\xff\xceW\xe9-u\x86\xfdP\x8a\x8b\xd8\xcd\x89\xc1e\xdd\xde\x07\xb32\xc9oPRnw\x12\xfa\x95S\x95\x8bSK.\xd9\xe2\x18\xa4\x8b\xfcD\xe6Bx\xb0Z;\x92;\xd8\xd2\x8b\xb5\x13\xee\x97\x16>j\x0c\xab3\xd6\xebSr\xa5.\xdf\xe0\xfd\xf5\x0df\xfe&}\x1f\x01\x00\x00\xff\xffPK\x07\x08\xac\xc6\xad\xf0\xdf\x00\x00\x00|\x02\x00\x00PK\x01\x02\x14\x03\x14\x00\x08\x00\x08\x00\x88\x03\x86O\x9e\x12\xa9mU\x01\x00\x00n\x04\x00\x00 \x00 \x00\x00\x00\x00\x00\x00\x00\x00\x00\xa4\x81\x00\x00\x00\x00dark.jsonUT\x05\x00\x01\xa0\xa0\xe9]PK\x01\x02\x14\x03\x14\x00\x08\x00\x08\x00\x13x\x82O\xac\xc6\xad\xf0\xdf\x00\x00\x00|\x02\x00\x00\n\x00 \x00\x00\x00\x00\x00\x00\x00\x00\x00\xa4\x81\x95\x01\x00\x00light.jsonUT\x05\x00\x01\x16'\xe5]PK\x05\x06\x00\x00\x00\x00\x02\x00\x02\x00\x81\x00\x00\x00\xb5\x02\x00\x00\x00\x00" + fs.Register(data) +} diff --git a/style.go b/style.go index e634c46..86b855c 100644 --- a/style.go +++ b/style.go @@ -2,8 +2,14 @@ package gold import ( "fmt" + "io" + "io/ioutil" + "os" "github.com/lucasb-eyer/go-colorful" + "github.com/rakyll/statik/fs" + + _ "github.com/charmbracelet/gold/statik" ) type StyleType int @@ -63,6 +69,27 @@ type ElementStyle struct { Suffix string `json:"suffix"` } +func loadStyle(f string) ([]byte, error) { + var r io.ReadCloser + var err error + + r, err = os.Open(f) + if err != nil { + statikFS, err := fs.New() + if err != nil { + return nil, err + } + + r, err = statikFS.Open("/" + f + ".json") + if err != nil { + return nil, err + } + } + + defer r.Close() + return ioutil.ReadAll(r) +} + func cascadeStyles(onlyColors bool, s ...ElementStyle) ElementStyle { var r ElementStyle diff --git a/styles/README.md b/styles/README.md new file mode 100644 index 0000000..0058d39 --- /dev/null +++ b/styles/README.md @@ -0,0 +1,13 @@ +# Gold Styles Gallery + +## Dark + +`gold -s dark` + +![Gold Dark Style](https://github.com/charmbracelet/gold/raw/master/styles/dark.png) + +## Light + +`gold -s light` + +![Gold Light Style](https://github.com/charmbracelet/gold/raw/master/styles/light.png) diff --git a/styles/dark.json b/styles/dark.json new file mode 100644 index 0000000..492d538 --- /dev/null +++ b/styles/dark.json @@ -0,0 +1,75 @@ +{ + "document": { + "indent": 4, + "background_color": "234", + "prefix": "\n", + "suffix": "\n" + }, + "link": { + "color": "123", + "underline": true, + "prefix": "(", + "suffix": ")" + }, + "link_text": { + "color": "123", + "bold": true + }, + "image": { + "color": "123", + "prefix": "[📷 ", + "suffix": "]" + }, + "image_text": { + "color": "8" + }, + "heading": { + "prefix": "\n", + "margin": 4, + "color": "15", + "background_color": "57" + }, + "h1": { + "prefix": "\n=> ", + "suffix": " <=", + "margin": 2, + "bold": true, + "background_color": "69" + }, + "h2": { + "prefix": "\n# " + }, + "table": { + "margin": 4 + }, + "paragraph": { + "margin": 4, + "color": "15", + "background_color": "235" + }, + "code": { + "color": "200" + }, + "code_block": { + "margin": 4, + "color": "200", + "theme": "solarized-dark" + }, + "emph": { + "italic": true + }, + "strong": { + "bold": true + }, + "list": { + "margin": 4, + "color": "15", + "background_color": "52" + }, + "item": { + "prefix": "• " + }, + "enumeration": { + "prefix": ". " + } +} diff --git a/styles/dark.png b/styles/dark.png new file mode 100644 index 0000000..aee8706 Binary files /dev/null and b/styles/dark.png differ diff --git a/styles/light.json b/styles/light.json new file mode 100644 index 0000000..6b9d53d --- /dev/null +++ b/styles/light.json @@ -0,0 +1,40 @@ +{ + "link": { + "color": "245", + "underline": true, + "prefix": "(", + "suffix": ")" + }, + "link_text": { + "color": "235", + "bold": true + }, + "image": { + "color": "245", + "prefix": "[Image: ", + "suffix": "]" + }, + "image_text": { + "color": "235" + }, + "heading": { + "bold": true, + "color": "1" + }, + "code": { + "color": "235" + }, + "code_block": { + "color": "235", + "theme": "solarized-light" + }, + "emph": { + "italic": true + }, + "strong": { + "bold": true + }, + "item": { + "prefix": "• " + } + } diff --git a/styles/light.png b/styles/light.png new file mode 100644 index 0000000..25a120e Binary files /dev/null and b/styles/light.png differ