diff --git a/internal/cmd/root.go b/internal/cmd/root.go index 1456c55..8a5e12b 100644 --- a/internal/cmd/root.go +++ b/internal/cmd/root.go @@ -111,7 +111,10 @@ window including all terminal colors and text decorations. buf.Write(bytes) } - var scaffold = img.NewImageCreator() + var noShadow, _ = cmd.Flags().GetBool("no-shadow") + var noWindow, _ = cmd.Flags().GetBool("no-window") + var scaffold = img.NewImageCreator(!noShadow, !noWindow) + if err := scaffold.AddContent(&buf); err != nil { return err } @@ -180,6 +183,8 @@ func init() { rootCmd.Flags().SortFlags = false rootCmd.Flags().BoolP("edit", "e", false, "edit content before the creating screenshot") rootCmd.Flags().BoolP("show-cmd", "c", false, "include command in screenshot") + rootCmd.Flags().BoolP("no-window", "w", false, "Remove the window border") + rootCmd.Flags().BoolP("no-shadow", "s", false, "Remove the shadow effect") rootCmd.Flags().BoolP("version", "v", false, "show version") rootCmd.Flags().StringP("filename", "f", "out.png", "filename of the screenshot") } diff --git a/internal/img/output.go b/internal/img/output.go index 82a5be7..c911463 100644 --- a/internal/img/output.go +++ b/internal/img/output.go @@ -51,6 +51,7 @@ type Scaffold struct { defaultForegroundColor color.Color + window bool drawShadow bool shadowBaseColor string shadowRadius uint8 @@ -68,9 +69,14 @@ type Scaffold struct { tabSpaces int } -func NewImageCreator() Scaffold { +func NewImageCreator(shadow bool, window bool) Scaffold { f := 2.0 + margin := 0. + if shadow{ + margin = f * 48 + } + fontRegular, _ := truetype.Parse(fonts.HackRegular) fontBold, _ := truetype.Parse(fonts.HackBold) fontItalic, _ := truetype.Parse(fonts.HackItalic) @@ -86,10 +92,11 @@ func NewImageCreator() Scaffold { columns: cols, rows: rows, - margin: f * 48, + margin: margin, padding: f * 24, - drawShadow: true, + window: window, + drawShadow: shadow, shadowBaseColor: "#10101066", shadowRadius: uint8(math.Min(f*16, 255)), shadowOffsetX: f * 16, @@ -176,7 +183,11 @@ func (s *Scaffold) SavePNG(path string) error { xOffset := marginX yOffset := marginY - titleOffset := f(40) + + titleOffset := 0. + if s.window{ + titleOffset = f(40) + } width := contentWidth + 2*marginX + 2*paddingX height := contentHeight + 2*marginY + 2*paddingY + titleOffset @@ -214,10 +225,12 @@ func (s *Scaffold) SavePNG(path string) error { dc.SetLineWidth(f(1)) dc.Stroke() - for i, color := range []string{red, yellow, green} { - dc.DrawCircle(xOffset+paddingX+float64(i)*distance+f(4), yOffset+paddingY+f(4), radius) - dc.SetHexColor(color) - dc.Fill() + if s.window { + for i, color := range []string{red, yellow, green} { + dc.DrawCircle(xOffset+paddingX+float64(i)*distance+f(4), yOffset+paddingY+f(4), radius) + dc.SetHexColor(color) + dc.Fill() + } } // Apply the actual text into the prepared content area of the window diff --git a/internal/img/output_test.go b/internal/img/output_test.go index b801b7d..20a8ddb 100644 --- a/internal/img/output_test.go +++ b/internal/img/output_test.go @@ -47,7 +47,7 @@ var _ = Describe("Creating images", func() { It("should create a PNG file based on provided input", func() { withTempFile(func(name string) { - scaffold := NewImageCreator() + scaffold := NewImageCreator(true, true) err := scaffold.AddContent(strings.NewReader("foobar")) Expect(err).ToNot(HaveOccurred()) @@ -67,7 +67,7 @@ var _ = Describe("Creating images", func() { _, _ = Fprintf(&buf, "\tBlue{Blue}\n") _, _ = Fprintf(&buf, "\tMintCream{MintCream}\n") - scaffold := NewImageCreator() + scaffold := NewImageCreator(true, true) err := scaffold.AddContent(&buf) Expect(err).ToNot(HaveOccurred())