diff --git a/examples/artichokes/artichokes.md b/examples/artichokes/artichokes.md new file mode 100644 index 00000000..a4b69143 --- /dev/null +++ b/examples/artichokes/artichokes.md @@ -0,0 +1,68 @@ +Glamour +======= + +A casual introduction. 你好世界! + +## Let’s talk about artichokes + +The _artichoke_ is mentioned as a garden plant in the 8th century BC by Homer +**and** Hesiod. The naturally occurring variant of the artichoke, the cardoon, +which is native to the Mediterranean area, also has records of use as a food +among the ancient Greeks and Romans. Pliny the Elder mentioned growing of +_carduus_ in Carthage and Cordoba. + +> He holds him with a skinny hand, +> ‘There was a ship,’ quoth he. +> ‘Hold off! unhand me, grey-beard loon!’ +> An artichoke, dropt he. + +--Samuel Taylor Coleridge, [The Rime of the Ancient Mariner][rime] + +[rime]: https://poetryfoundation.org/poems/43997/ + +## Other foods worth mentioning + +1. Carrots +1. Celery +1. Tacos + * Soft + * Hard +1. Cucumber + +## Things to eat today + +* [x] Carrots +* [x] Ramen +* [ ] Currywurst + +### Power levels of the aforementioned foods + +| Name | Power | Comment | +| --- | --- | --- | +| Carrots | 9001 | It’s over 9000?! | +| Ramen | 9002 | Also over 9000?! | +| Currywurst | 10000 | What?! | + +## Currying Artichokes + +Here’s a bit of code in [Haskell](https://haskell.org), because we are fancy. +Remember that to compile Haskell you’ll need `ghc`. + +```haskell +module Main where + +import Data.Function ( (&) ) +import Data.List ( intercalculate ) + +hello :: String -> String +hello s = + "Hello, " ++ s ++ "." + +main :: IO () +main = + map hello [ "artichoke", "alcachofa" ] & intercalculate "\n" & putStrLn +``` + +*** + +_Alcachofa_, if you were wondering, is artichoke in Spanish. diff --git a/examples/artichokes/main.go b/examples/artichokes/main.go new file mode 100644 index 00000000..231f154e --- /dev/null +++ b/examples/artichokes/main.go @@ -0,0 +1,45 @@ +package main + +import ( + "embed" + "fmt" + "log" + "os" + + "github.com/charmbracelet/glamour" + "github.com/muesli/termenv" +) + +//go:embed artichokes.md +var f embed.FS + +func main() { + // Provide a style by name (optional) + var style string + if len(os.Args) < 2 { + // check env, if unset then use default style + style = os.Getenv("GLAMOUR_STYLE") + } else { + style = os.Args[1] + } + + // Let's learn a 'lil something about artichokes... + b, err := f.ReadFile("artichokes.md") + if err != nil { + log.Fatal(err) + } + + r, err := glamour.NewTermRenderer( + glamour.WithStandardStyle(style), + glamour.WithColorProfile(termenv.TrueColor), + ) + if err != nil { + log.Fatal(err) + } + md, err := r.RenderBytes(b) + if err != nil { + log.Fatal(err) + } + + fmt.Fprintf(os.Stdout, "%s\n", md) +} diff --git a/gallery.sh b/gallery.sh index d4769f34..36d95008 100755 --- a/gallery.sh +++ b/gallery.sh @@ -1,20 +1,23 @@ #!/bin/bash -for style in ./styles/*.json; do - echo "Generating screenshot for ${style}" - filename="`basename -s .json ${style}`.png" +if ! command -v freeze &> /dev/null; then + echo "freeze not found. Please install freeze to capture images." + echo "https://github.com/charmbracelet/freeze/" + exit 1 +fi - light="" - if [[ $style == *"light"* ]]; then - light="-l" - fi +defaultStyles=("ascii" "auto" "dark" "dracula" "light" "notty" "pink") +for style in "${defaultStyles[@]}"; do + echo "Generating screenshot for ${style}" # take screenshot - ./termshot ${light} -o ./styles/gallery/ -f "$filename" glow -s ${style} - - # add border - convert -bordercolor black -border 16x16 "./styles/gallery/$filename" "./styles/gallery/$filename" + if [[ $style == *"light"* ]]; then + # Provide a light background to images + freeze -x "go run ./examples/artichokes ${style}" -b "#FAFAFA" -o "./styles/gallery/${style}.png" + else + freeze -x "go run ./examples/artichokes ${style}" -o "./styles/gallery/${style}.png" + fi # optimize filesize - pngcrush -ow "./styles/gallery/$filename" + pngcrush -ow "./styles/gallery/$style.png" done diff --git a/styles/gallery/README.md b/styles/gallery/README.md index 39b2580a..e61d7b77 100644 --- a/styles/gallery/README.md +++ b/styles/gallery/README.md @@ -2,18 +2,18 @@ ## Dark -![Glamour Dark Style](https://github.com/charmbracelet/glamour/raw/master/styles/gallery/dark.png) +![Glamour Dark Style](dark.png) ## Light -![Glamour Light Style](https://github.com/charmbracelet/glamour/raw/master/styles/gallery/light.png) +![Glamour Light Style](light.png) ## NoTTY Pronounced _naughty_. -![Glamour NoTTY Style](https://github.com/charmbracelet/glamour/raw/master/styles/gallery/notty.png) +![Glamour NoTTY Style](notty.png) ## Dracula -![Dracula Style](https://github.com/charmbracelet/glamour/raw/master/styles/gallery/dracula.png) +![Dracula Style](dracula.png) diff --git a/styles/gallery/ascii.png b/styles/gallery/ascii.png new file mode 100644 index 00000000..3e16c26e Binary files /dev/null and b/styles/gallery/ascii.png differ diff --git a/styles/gallery/auto.png b/styles/gallery/auto.png new file mode 100644 index 00000000..d62f66fa Binary files /dev/null and b/styles/gallery/auto.png differ diff --git a/styles/gallery/dark.png b/styles/gallery/dark.png index 8467e3e7..d62f66fa 100644 Binary files a/styles/gallery/dark.png and b/styles/gallery/dark.png differ diff --git a/styles/gallery/dracula.png b/styles/gallery/dracula.png index b6722812..5715063a 100644 Binary files a/styles/gallery/dracula.png and b/styles/gallery/dracula.png differ diff --git a/styles/gallery/light.png b/styles/gallery/light.png index d90f63e9..02eea86a 100644 Binary files a/styles/gallery/light.png and b/styles/gallery/light.png differ diff --git a/styles/gallery/notty.png b/styles/gallery/notty.png index e97c3a00..3e16c26e 100644 Binary files a/styles/gallery/notty.png and b/styles/gallery/notty.png differ diff --git a/styles/gallery/pink.png b/styles/gallery/pink.png new file mode 100644 index 00000000..42335e48 Binary files /dev/null and b/styles/gallery/pink.png differ