Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
!test/golden/**/*.png
!examples/*.svg
/result
freeze
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ Screenshots can be customized with `--flags` or [Configuration](#configuration)
- [`-o`](#output), [`--output`](#output): Output location for .svg, .png, .jpg.
- [`-c`](#configuration), [`--config`](#configuration): Base configuration file or template.
- [`-t`](#theme), [`--theme`](#theme): Theme to use for syntax highlighting.
- [`-l`](#language), [`--language`](#language): Language to apply to code
- [`-l`](#language), [`--language`](#language): Languages to apply to code
- [`-w`](#window), [`--window`](#window): Display window controls.
- [`-m`](#margin), [`--margin`](#margin): Apply margin to the window.
- [`-p`](#padding), [`--padding`](#padding): Apply padding to the code.
Expand Down Expand Up @@ -126,6 +126,12 @@ cat artichoke.hs | freeze --language haskell
<img alt="output of freeze command, Haskell code block" src="./test/golden/svg/haskell.svg" width="600" />
</a>

`freeze` also allows multi-language highlighting. Only two languages are supported.

```bash
freeze main.go --language go,c
```

### Theme

Change the color theme.
Expand Down
8 changes: 4 additions & 4 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ type Config struct {
Height float64 `json:"height" help:"Height of terminal window." short:"H" group:"Window"`

// Settings
Config string `json:"config,omitempty" help:"Base configuration file or template." short:"c" group:"Settings" default:"default" placeholder:"base"`
Interactive bool `hidden:"" json:",omitempty" help:"Use an interactive form for configuration options." short:"i" group:"Settings"`
Language string `json:"language,omitempty" help:"Language of code file." short:"l" group:"Settings" placeholder:"go"`
Theme string `json:"theme" help:"Theme to use for syntax highlighting." short:"t" group:"Settings" placeholder:"charm"`
Config string `json:"config,omitempty" help:"Base configuration file or template." short:"c" group:"Settings" default:"default" placeholder:"base"`
Interactive bool `hidden:"" json:",omitempty" help:"Use an interactive form for configuration options." short:"i" group:"Settings"`
Language []string `json:"language,omitempty" help:"Languages of code file. Allows upto two languages." short:"l" group:"Settings" placeholder:"go"`
Theme string `json:"theme" help:"Theme to use for syntax highlighting." short:"t" group:"Settings" placeholder:"charm"`

Output string `json:"output,omitempty" help:"Output location for {{.svg}}, {{.png}}, or {{.webp}}." short:"o" group:"Settings" default:"" placeholder:"freeze.svg"`
Execute string `json:"-" help:"Capture output of command execution." short:"x" group:"Settings" default:""`
Expand Down
16 changes: 12 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ func main() {
input, err = in.ReadInput(os.Stdin)
lexer = lexers.Analyse(input)
} else if config.Execute != "" {
config.Language = "ansi"
config.Language[0] = "ansi"
} else {
input, err = in.ReadFile(config.Input)
if err != nil {
Expand All @@ -159,8 +159,16 @@ func main() {
lexer = lexers.Get(config.Input)
}

if config.Language != "" {
lexer = lexers.Get(config.Language)
if config.Language[0] != "" && len(config.Language) == 1 {
lexer = lexers.Get(config.Language[0])
} else if len(config.Language) == 2 {
language := lexers.Get(config.Language[0])
root := lexers.Get(config.Language[1])
lexer = chroma.DelegatingLexer(root, language)
}

if len(config.Language) > 2 {
printErrorFatal("languages can only be two", errors.New("--language can have only two inputs"))
}

// adjust for 1-indexing
Expand All @@ -169,7 +177,7 @@ func main() {
}

var strippedInput string = ansi.Strip(input)
isAnsi := strings.ToLower(config.Language) == "ansi" || strippedInput != input
isAnsi := strings.ToLower(config.Language[0]) == "ansi" || strippedInput != input
strippedInput = cut(strippedInput, config.Lines)

if !isAnsi && lexer == nil {
Expand Down