Skip to content

Commit

Permalink
paletterfi add configure
Browse files Browse the repository at this point in the history
  • Loading branch information
cage1016 committed Aug 25, 2022
1 parent f5361de commit 6c658c9
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 21 deletions.
25 changes: 23 additions & 2 deletions .workflow/info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -1685,11 +1685,32 @@ https://github.com/cage1016/alfred-paletter</string>
<key>description</key>
<string>recommend 1 ~ 10</string>
<key>label</key>
<string>Number of Color</string>
<string>Number of Colors</string>
<key>type</key>
<string>textfield</string>
<key>variable</key>
<string>number_of_color</string>
<string>number_of_colors</string>
</dict>
<dict>
<key>config</key>
<dict>
<key>default</key>
<string>10</string>
<key>placeholder</key>
<string>digital</string>
<key>required</key>
<true/>
<key>trim</key>
<true/>
</dict>
<key>description</key>
<string></string>
<key>label</key>
<string>Number of Clipboard Images</string>
<key>type</key>
<string>textfield</string>
<key>variable</key>
<string>number_of_clipboard_images</string>
</dict>
</array>
<key>version</key>
Expand Down
17 changes: 6 additions & 11 deletions alfred/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,14 @@ import (
)

const (
NumberOfColor = "number_of_color"
ColorsHexWithHash = "colors_hex_with_hash"
CopyAllSeparate = "copy_all_separate"
NumberOfColors = "number_of_colors"
NumberOfClipboardImages = "number_of_clipboard_images"
)

func GetNumberOfColor(wf *aw.Workflow) int {
return wf.Config.GetInt(NumberOfColor, 3)
func GetNumberOfColors(wf *aw.Workflow) int {
return wf.Config.GetInt(NumberOfColors, 7)
}

func GetColorsHexWithHash(wf *aw.Workflow) bool {
return wf.Config.GetBool(ColorsHexWithHash)
}

func GetCopyAllSeparate(wf *aw.Workflow) bool {
return wf.Config.GetBool(CopyAllSeparate)
func GetNumberOfClipboard(wf *aw.Workflow) int {
return wf.Config.GetInt(NumberOfClipboardImages, 10)
}
4 changes: 2 additions & 2 deletions cmd/paletter.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,11 @@ var paletterCmd = &cobra.Command{
if r != "" {
nc, _ := strconv.Atoi(strings.TrimSpace(r))
if nc == 0 {
nc = alfred.GetNumberOfColor(wf)
nc = alfred.GetNumberOfColors(wf)
}
cs, _ = paletter.CalculatePalette(obs, nc)
} else {
cs, _ = paletter.CalculatePalette(obs, alfred.GetNumberOfColor(wf))
cs, _ = paletter.CalculatePalette(obs, alfred.GetNumberOfColors(wf))
}
colors := paletter.ColorsFromClusters(cs)

Expand Down
3 changes: 2 additions & 1 deletion cmd/paletterfi.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
aw "github.com/deanishe/awgo"
"github.com/spf13/cobra"

"github.com/cage1016/alfred-paletter/alfred"
"github.com/cage1016/alfred-paletter/lib"
"github.com/cage1016/alfred-paletter/sqlite"
)
Expand Down Expand Up @@ -44,7 +45,7 @@ var aCmd = &cobra.Command{
}
items, err = repo.List(context.Background(), nc)
} else {
items, err = repo.List(context.Background(), 10)
items, err = repo.List(context.Background(), alfred.GetNumberOfClipboard(wf))
}

if err != nil {
Expand Down
5 changes: 0 additions & 5 deletions lib/paletter.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ import (

aw "github.com/deanishe/awgo"
color "github.com/lucasb-eyer/go-colorful"

"github.com/cage1016/alfred-paletter/alfred"
)

const (
Expand Down Expand Up @@ -47,9 +45,6 @@ func (hs HexColors) Hexs() []string {
}

func Hex(wf *aw.Workflow, col color.Color) string {
if alfred.GetColorsHexWithHash(wf) {
return fmt.Sprintf(hexPatternHash, uint8(col.R*255.0+0.5), uint8(col.G*255.0+0.5), uint8(col.B*255.0+0.5))
}
return fmt.Sprintf(hexPattern, uint8(col.R*255.0+0.5), uint8(col.G*255.0+0.5), uint8(col.B*255.0+0.5))
}

Expand Down

0 comments on commit 6c658c9

Please sign in to comment.