diff --git a/config.go b/config.go index 09448f0..d86ebb8 100644 --- a/config.go +++ b/config.go @@ -31,6 +31,7 @@ type Config struct { 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"` + Copy bool `json:"copy" help:"Copy the output image to the clipboard." group:"Settings"` 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:""` ExecuteTimeout time.Duration `json:"-" help:"Execution timeout." group:"Settings" default:"10s" prefix:"execute." name:"timeout" hidden:""` diff --git a/interactive.go b/interactive.go index e7916cf..7ea6d8f 100644 --- a/interactive.go +++ b/interactive.go @@ -67,6 +67,11 @@ func runForm(config *Config) (*Config, error) { Prompt(""). Value(&config.Output), + huh.NewConfirm().Title("Clipboard"). + // Description("Copy the output image to the clipboard."). + Inline(true). + Value(&config.Copy), + huh.NewSelect[string]().Title("Theme "). // Description("Theme for syntax highlighting."). Inline(true). diff --git a/main.go b/main.go index 3675a47..6fc14cb 100644 --- a/main.go +++ b/main.go @@ -398,7 +398,7 @@ func main() { } // could not convert with libsvg, try resvg - svgConversionErr = resvgConvert(doc, imageWidth, imageHeight, config.Output) + svgConversionErr = resvgConvert(doc, imageWidth, imageHeight, config.Output, config.Copy) if svgConversionErr != nil { printErrorFatal("Unable to convert SVG to PNG", svgConversionErr) } diff --git a/png.go b/png.go index af0348f..9f83bed 100644 --- a/png.go +++ b/png.go @@ -9,6 +9,7 @@ import ( "github.com/beevik/etree" "github.com/charmbracelet/freeze/font" "github.com/kanrichan/resvg-go" + "golang.design/x/clipboard" ) func libsvgConvert(doc *etree.Document, w, h float64, output string) error { @@ -30,7 +31,7 @@ func libsvgConvert(doc *etree.Document, w, h float64, output string) error { return err } -func resvgConvert(doc *etree.Document, w, h float64, output string) error { +func resvgConvert(doc *etree.Document, w, h float64, output string, copy bool) error { svg, err := doc.WriteToBytes() if err != nil { return err @@ -94,5 +95,12 @@ func resvgConvert(doc *etree.Document, w, h float64, output string) error { if err != nil { return err } + if copy { + err = clipboard.Init() + if err != nil { + return err + } + clipboard.Write(clipboard.FmtImage, png) + } return err }