Skip to content

Commit

Permalink
Merge pull request #20 from skanehira/main
Browse files Browse the repository at this point in the history
Support clipboard
  • Loading branch information
matsuyoshi30 authored Jul 3, 2021
2 parents 17b81a4 + 594ed96 commit 2c4fc9c
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 4 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ FLAGS:
-f, --font <FONT> Specify font eg. 'Hack-Bold'
-l, --language <LANG> The language for syntax highlighting eg. 'go'
-s, --style <STYLE> The style for syntax highlighting eg. 'dracula'
-c, --clip Copy image to clipboard
--list-styles List all available styles for syntax highlighting
--list-fonts List all available fonts in your system
--no-line-number Hide the line number
Expand Down Expand Up @@ -60,6 +61,11 @@ Generate image without window control bar
germanium --no-window-access-bar -o main.png main.go
```

Generate image and copy to clipboard

```
germanium --no-window-access-bar -o main.png main.go -c
```

## Install

Expand Down
22 changes: 18 additions & 4 deletions cli/cli.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
package cli

import (
"bytes"
"fmt"
"io"
"os"
"path/filepath"

flags "github.com/jessevdk/go-flags"
"github.com/alecthomas/chroma/styles"
flags "github.com/jessevdk/go-flags"
"github.com/matsuyoshi30/germanium"
"github.com/skanehira/clipboard-image/v2"
)

var name = "germanium"
Expand Down Expand Up @@ -92,9 +94,15 @@ func run(r io.Reader, filename string) error {
if err != nil {
return err
}
out, err := os.Create(filepath.Join(currentDir, opts.Output))
if err != nil {
return err
var out io.ReadWriter

if opts.Clipboard {
out = &bytes.Buffer{}
} else {
out, err = os.Create(filepath.Join(currentDir, opts.Output))
if err != nil {
return err
}
}

face, err := germanium.LoadFont(opts.Font)
Expand All @@ -120,5 +128,11 @@ func run(r io.Reader, filename string) error {
return err
}

if opts.Clipboard {
if err := clipboard.Write(out); err != nil {
return err
}
}

return nil
}
1 change: 1 addition & 0 deletions cli/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ type Options struct {
Font string `short:"f" long:"font" default:"Hack-Regular" description:"Specify font eg. 'Hack-Bold'"`
Language string `short:"l" long:"language" description:"The language for syntax highlighting"`
Style string `short:"s" long:"style" description:"The style for syntax highlighting"`
Clipboard bool `short:"c" long:"clip" description:"Copy image to clipboard"`
ListStyles bool `long:"list-styles" description:"List all available styles for syntax highlighting"`
ListFonts bool `long:"list-fonts" description:"List all available fonts in your system"`
NoLineNum bool `long:"no-line-number" description:"Hide the line number"`
Expand Down
1 change: 1 addition & 0 deletions cli/usage.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ FLAGS:
-f, --font <FONT> Specify font eg. 'Hack-Bold'
-l, --language <LANG> The language for syntax highlighting eg. 'go'
-s, --style <STYLE> The style for syntax highlighting eg. 'dracula'
-c, --clip Copy image to clipboard
--list-styles List all available styles for syntax highlighting
--list-fonts List all available fonts in your system
--no-line-number Hide the line number
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ require (
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0
github.com/jessevdk/go-flags v1.5.0
github.com/sergi/go-diff v1.2.0 // indirect
github.com/skanehira/clipboard-image/v2 v2.0.0
golang.org/x/image v0.0.0-20210220032944-ac19c3e999fb
golang.org/x/sys v0.0.0-20210412220455-f1c623a9e750 // indirect
)
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZN
github.com/sergi/go-diff v1.0.0/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAmXWZgo=
github.com/sergi/go-diff v1.2.0 h1:XU+rvMAioB0UC3q1MFrIQy4Vo5/4VsRDQQXHsEya6xQ=
github.com/sergi/go-diff v1.2.0/go.mod h1:STckp+ISIX8hZLjrqAeVduY0gWCT9IjLuqbuNXdaHfM=
github.com/skanehira/clipboard-image/v2 v2.0.0 h1:Kp+RNOgIlgzDkP3EskwuBnM0Fk4sc+HgcWE5RC+PnNI=
github.com/skanehira/clipboard-image/v2 v2.0.0/go.mod h1:NXSYl4FJinIUFKJfeP1lGz8DIEUYjnEqwdMZ777S1E0=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
Expand Down

0 comments on commit 2c4fc9c

Please sign in to comment.