Skip to content

Commit

Permalink
feat: add --theme
Browse files Browse the repository at this point in the history
  • Loading branch information
maaslalani committed Jan 12, 2024
1 parent 732c0ff commit 30043b2
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 17 deletions.
28 changes: 16 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
Capture and share your code on the command line.

<p align="center">
<img alt="output of freeze command, haskell code block" src="https://github.com/charmbracelet/freeze/assets/42545625/6884a2ad-3d8e-4510-ad3d-e935e208d3b8" width="800" />
<img alt="output of freeze command, haskell code block" src="./examples/shadow.svg" width="800" />
</p>

## Tutorial
Expand Down Expand Up @@ -58,17 +58,19 @@ Screenshots can be customized with `--flags`.
There are many different configuration options:

* [`--language`](#language): code language.
* [`--output`](#output): output file.
* [`--font.family`](#font): font family.
* [`--font.size`](#font): font size.
* [`--line-height`](#font): line height.
* [`--radius`](#corner-radius): add corner radius.
* [`--window`](#window): show window controls.
* [`--border`](#border): add a border to the window.
* [`--padding`](#padding): terminal padding.
* [`--margin`](#margin): window margin.
* [`--shadow`](#shadow): add a shadow to the window.
* [`-l, --language`](#language): code language.
* [`-t, --theme`](#theme): theme to use.
* [`-o, --output`](#output): output file.
* [`-r, --radius`](#corner-radius): add corner radius.
* [`-w, --window`](#window): show window controls.
* [`-b, --border`](#border): add a border to the window.
* [`-p, --padding`](#padding): terminal padding.
* [`-m, --margin`](#margin): window margin.
* [`-s, --shadow`](#shadow): add a shadow to the window.
* [` --font.family`](#font): font family.
* [` --font.size`](#font): font size.
* [` --line-height`](#font): line height.


### Language

Expand All @@ -82,6 +84,8 @@ cat artichoke.hs | freeze --language haskell
<br />
<img alt="output of freeze command, haskell code block" src="https://github.com/charmbracelet/freeze/assets/42545625/f3fb212f-6629-4253-9c13-105055a4b6e8" width="600" />

### Theme

### Output

Change the output file location, defaults to `out.svg` or stdout if piped. This
Expand Down
1 change: 1 addition & 0 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ type Configuration struct {
Input string `arg:"" help:"code file to screenshot" optional:""`

Language string `help:"code language" short:"l"`
Theme string `help:"theme" short:"t"`
Output string `help:"output of the image" short:"o" default:"out.svg"`
Window bool `help:"show window controls" short:"w" default:"false"`
Border bool `help:"add an outline to the window" short:"b" default:"false"`
Expand Down
4 changes: 2 additions & 2 deletions examples/border.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/charmbracelet/freeze
go 1.21

require (
github.com/alecthomas/chroma v0.10.0
github.com/alecthomas/chroma v0.10.1-0.20220126230913-d491f1b5c1d2
github.com/alecthomas/kong v0.8.1
github.com/beevik/etree v1.3.0
github.com/charmbracelet/log v0.3.1
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ github.com/alecthomas/assert/v2 v2.1.0 h1:tbredtNcQnoSd3QBhQWI7QZ3XHOVkw1Moklp2o
github.com/alecthomas/assert/v2 v2.1.0/go.mod h1:b/+1DI2Q6NckYi+3mXyH3wFb8qG37K/DuK80n7WefXA=
github.com/alecthomas/chroma v0.10.0 h1:7XDcGkCQopCNKjZHfYrNLraA+M7e0fMiJ/Mfikbfjek=
github.com/alecthomas/chroma v0.10.0/go.mod h1:jtJATyUxlIORhUOFNA9NZDWGAQ8wpxQQqNSB4rjA/1s=
github.com/alecthomas/chroma v0.10.1-0.20220126230913-d491f1b5c1d2 h1:Gg09t2u+C08At6TYucNrD3Cbaq97SUHax84BzQwRTgU=
github.com/alecthomas/chroma v0.10.1-0.20220126230913-d491f1b5c1d2/go.mod h1:jtJATyUxlIORhUOFNA9NZDWGAQ8wpxQQqNSB4rjA/1s=
github.com/alecthomas/kong v0.8.1 h1:acZdn3m4lLRobeh3Zi2S2EpnXTd1mOL6U7xVml+vfkY=
github.com/alecthomas/kong v0.8.1/go.mod h1:n1iCIO2xS46oE8ZfYCNDqdR0b0wZNrXAIAqro/2132U=
github.com/alecthomas/repr v0.1.0 h1:ENn2e1+J3k09gyj2shc0dHr/yjaWSHRlrJ4DPMevDqE=
Expand Down
11 changes: 10 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/alecthomas/chroma"
"github.com/alecthomas/chroma/formatters/svg"
"github.com/alecthomas/chroma/lexers"
"github.com/alecthomas/chroma/styles"
"github.com/alecthomas/kong"
"github.com/beevik/etree"
"github.com/charmbracelet/log"
Expand Down Expand Up @@ -71,7 +72,15 @@ func main() {
log.Fatal(err)
}
buf := &bytes.Buffer{}
err = f.Format(buf, style, it)

fmt.Println(styles.Names())

s, ok := styles.Registry[strings.ToLower(config.Theme)]
if s == nil || !ok {
s = charmStyle
}

err = f.Format(buf, s, it)
if err != nil {
log.Fatal(err)
}
Expand Down
2 changes: 1 addition & 1 deletion style.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package main

import "github.com/alecthomas/chroma"

var style = chroma.MustNewStyle("charm", chroma.StyleEntries{
var charmStyle = chroma.MustNewStyle("charm", chroma.StyleEntries{
chroma.Text: "#C4C4C4",
chroma.Error: "#F1F1F1 bg:#F05B5B",
chroma.Comment: "#676767",
Expand Down

0 comments on commit 30043b2

Please sign in to comment.