diff --git a/config.go b/config.go
index 09448f0..cd572e6 100644
--- a/config.go
+++ b/config.go
@@ -30,6 +30,7 @@ type Config struct {
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"`
+ Wrap int `json:"wrap" help:"Wrap lines at a specific width." short:"w" group:"Settings" default:"0" placeholder:"80"`
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:""`
diff --git a/freeze_test.go b/freeze_test.go
index 5409a9f..06b4e43 100644
--- a/freeze_test.go
+++ b/freeze_test.go
@@ -253,6 +253,11 @@ func TestFreezeConfigurations(t *testing.T) {
flags: []string{},
output: "tab",
},
+ {
+ input: "test/input/wrap.go",
+ flags: []string{"--wrap", "80", "--width", "600"},
+ output: "wrap",
+ },
}
err := os.RemoveAll("test/output/svg")
diff --git a/main.go b/main.go
index 3675a47..56f9892 100644
--- a/main.go
+++ b/main.go
@@ -22,6 +22,7 @@ import (
"github.com/charmbracelet/x/exp/term/ansi"
"github.com/charmbracelet/x/exp/term/ansi/parser"
"github.com/mattn/go-isatty"
+ "github.com/muesli/reflow/wordwrap"
)
const (
@@ -172,6 +173,12 @@ func main() {
isAnsi := strings.ToLower(config.Language) == "ansi" || strippedInput != input
strippedInput = cut(strippedInput, config.Lines)
+ // wrap to character limit.
+ if config.Wrap > 0 {
+ strippedInput = wordwrap.String(strippedInput, config.Wrap)
+ input = wordwrap.String(input, config.Wrap)
+ }
+
if !isAnsi && lexer == nil {
printErrorFatal("Language Unknown", errors.New("specify a language with the --language flag"))
}
diff --git a/test/golden/svg/tab.svg b/test/golden/svg/tab.svg
index 4875e76..20c4292 100644
--- a/test/golden/svg/tab.svg
+++ b/test/golden/svg/tab.svg
@@ -10,7 +10,7 @@
}
-package config
+package main
// freeze/issues/50
diff --git a/test/golden/svg/wrap.svg b/test/golden/svg/wrap.svg
new file mode 100644
index 0000000..cca22cd
--- /dev/null
+++ b/test/golden/svg/wrap.svg
@@ -0,0 +1,28 @@
+
+
+
diff --git a/test/input/tab.go b/test/input/tab.go
index 36ca24a..b46679a 100644
--- a/test/input/tab.go
+++ b/test/input/tab.go
@@ -1,4 +1,4 @@
-package config
+package main
// freeze/issues/50
diff --git a/test/input/wrap.go b/test/input/wrap.go
new file mode 100644
index 0000000..5195fd2
--- /dev/null
+++ b/test/input/wrap.go
@@ -0,0 +1,9 @@
+package main
+
+import "fmt"
+
+// freeze/issues/14
+
+func main() {
+ fmt.Println("This is a really long line that is going to go over the 80 character limit. This is a really long line that is going to go over the 80 character limit. This is a really long line that is going to go over the 80 character limit. This is a really long line that is going to go over the 80 character limit.")
+}