mirror of
https://github.com/charmbracelet/glow
synced 2024-12-14 06:02:27 +00:00
Embed styles in gold library
This commit is contained in:
parent
27e0e0878a
commit
292f06052f
9 changed files with 3 additions and 196 deletions
15
README.md
15
README.md
|
@ -36,21 +36,10 @@ You can supply a JSON stylesheet with the `-s` flag:
|
|||
|
||||
## Example Output
|
||||
|
||||
![Gold Dark Style](https://github.com/charmbracelet/gold/raw/master/cmd/gold/styles/dark.png)
|
||||
![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/cmd/gold/styles/README.md)!
|
||||
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!
|
||||
|
|
14
gallery.sh
14
gallery.sh
|
@ -1,14 +0,0 @@
|
|||
#!/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
|
30
main.go
30
main.go
|
@ -11,11 +11,9 @@ import (
|
|||
"path/filepath"
|
||||
|
||||
"github.com/mattn/go-isatty"
|
||||
"github.com/rakyll/statik/fs"
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
"github.com/charmbracelet/gold"
|
||||
_ "github.com/charmbracelet/gold/cmd/gold/statik"
|
||||
)
|
||||
|
||||
var (
|
||||
|
@ -92,27 +90,6 @@ func readerFromArg(s string) (*Source, error) {
|
|||
return &Source{r, u}, err
|
||||
}
|
||||
|
||||
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 execute(cmd *cobra.Command, args []string) error {
|
||||
var arg string
|
||||
if len(args) > 0 {
|
||||
|
@ -127,12 +104,7 @@ func execute(cmd *cobra.Command, args []string) error {
|
|||
|
||||
r := gold.NewPlainTermRenderer()
|
||||
if isatty.IsTerminal(os.Stdout.Fd()) {
|
||||
json, err := loadStyle(style)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
r, err = gold.NewTermRendererFromBytes(json)
|
||||
r, err = gold.NewTermRenderer(style)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -1,12 +0,0 @@
|
|||
// 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\xce\xba\x85O\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00 \x00 \x00dark.jsonUT\x05\x00\x015\x91\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\xe0q<W\xd1\xfcC\xc7\x07\xc7\x8a#/\x91\xaf\x96)\xd7\xdf\xe6\xc2F\x93@.\xacH-\x9e\x0d\x06m\xcf<W\xb6\xa8\x8e\x817\xa1;\xcd-A7\xd9im\x15G\xf9\x08\xe2Lp\xacBf\xd0qC\xd2q%\x8b\xef\xb7Y;\xb4\xf1\x89\xa4\xeeW\xc9\xda\x1dS\xdb/\x07\xc3\xa2\x0bv\xa0S{\xfbx~\x8b\xf6\x06\xc6k@\xee\xa45)\xf3\xf9\xd6\x9am\xb2\xaf\x00\x00\x00\xff\xffPK\x07\x08\x9e\x12\xa9mU\x01\x00\x00n\x04\x00\x00PK\x03\x04\x14\x00\x08\x00\x08\x00\x13x\x82O\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\n\x00 \x00light.jsonUT\x05\x00\x01\x16'\xe5]\x84\x91MN\xc40\x0c\x85\xf7s\n\xcb+\x90\xca\x82\xbfMo\xc0\x19\x10\x1au\x1aOc\xe1$\xa3\xd4\x95F $\xce\xc2\xd18 \n\x14\x920-,\xba\xa8\xf3\xfc\xbeg\xfby\x03\x00\x80\xc2\xfe\x11[\xf8\xfa\x03\xc0>H\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\xce\xba\x85O\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\x015\x91\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)
|
||||
}
|
|
@ -1,13 +0,0 @@
|
|||
# Gold Styles Gallery
|
||||
|
||||
## Dark
|
||||
|
||||
`gold -s dark`
|
||||
|
||||
![Gold Dark Style](https://github.com/charmbracelet/gold/raw/master/cmd/gold/styles/dark.png)
|
||||
|
||||
## Light
|
||||
|
||||
`gold -s light`
|
||||
|
||||
![Gold Light Style](https://github.com/charmbracelet/gold/raw/master/cmd/gold/styles/light.png)
|
|
@ -1,75 +0,0 @@
|
|||
{
|
||||
"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": ". "
|
||||
}
|
||||
}
|
BIN
styles/dark.png
BIN
styles/dark.png
Binary file not shown.
Before Width: | Height: | Size: 74 KiB |
|
@ -1,40 +0,0 @@
|
|||
{
|
||||
"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": "• "
|
||||
}
|
||||
}
|
BIN
styles/light.png
BIN
styles/light.png
Binary file not shown.
Before Width: | Height: | Size: 74 KiB |
Loading…
Reference in a new issue