Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding option to remove the shadow and window border #115

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
7 changes: 6 additions & 1 deletion internal/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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")
}
29 changes: 21 additions & 8 deletions internal/img/output.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ type Scaffold struct {

defaultForegroundColor color.Color

window bool
drawShadow bool
shadowBaseColor string
shadowRadius uint8
Expand All @@ -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)
Expand All @@ -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,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions internal/img/output_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand All @@ -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())
Expand Down