summaryrefslogtreecommitdiff
path: root/main.go
diff options
context:
space:
mode:
authorBenjamin Chausse <benjamin@chausse.xyz>2024-11-25 16:45:33 -0500
committerGitHub <noreply@github.com>2024-11-25 16:45:33 -0500
commit821c198fe6700a9e9e9eb07ab6922e7bde7f2bfb (patch)
tree33f696ab2dfa433bc1513fd44b313419b74cc812 /main.go
parentbad902e67b98a2630ff4396f846a223e3eed6a7a (diff)
Accept initial color using -c flag (#14)
Diffstat (limited to 'main.go')
-rw-r--r--main.go36
1 files changed, 31 insertions, 5 deletions
diff --git a/main.go b/main.go
index 241adcf..4f61c75 100644
--- a/main.go
+++ b/main.go
@@ -4,8 +4,10 @@ import (
"log/slog"
"os"
+ "github.com/ChausseBenjamin/termpicker/internal/colors"
"github.com/ChausseBenjamin/termpicker/internal/picker"
"github.com/ChausseBenjamin/termpicker/internal/switcher"
+ "github.com/ChausseBenjamin/termpicker/internal/userinput"
"github.com/ChausseBenjamin/termpicker/internal/util"
tea "github.com/charmbracelet/bubbletea"
"github.com/urfave/cli/v2"
@@ -23,10 +25,34 @@ func AppAction(ctx *cli.Context) error {
slog.SetDefault(slog.New(handler))
slog.Info("Starting Termpicker")
- rgb := picker.RGB()
- cmyk := picker.CMYK()
- hsl := picker.HSL()
- sw := switcher.New([]picker.Model{*rgb, *cmyk, *hsl})
+
+ sw := switcher.New([]picker.Model{
+ *picker.RGB(),
+ *picker.CMYK(),
+ *picker.HSL(),
+ })
+
+ if colorStr := ctx.String("color"); colorStr != "" {
+ color, err := userinput.ParseColor(colorStr)
+ if err != nil {
+ slog.Error("Failed to parse color", util.ErrKey, err)
+ sw.NewNotice(err.Error())
+ } else {
+ pc := color.ToPrecise()
+ switch color.(type) {
+ case colors.RGB:
+ sw.UpdatePicker(0, pc)
+ sw.SetActive(0)
+ case colors.CMYK:
+ sw.UpdatePicker(1, pc)
+ sw.SetActive(1)
+ case colors.HSL:
+ sw.UpdatePicker(2, pc)
+ sw.SetActive(2)
+ }
+ }
+ }
+
p := tea.NewProgram(sw)
if _, err := p.Run(); err != nil {
return err
@@ -36,7 +62,7 @@ func AppAction(ctx *cli.Context) error {
func main() {
app := &cli.App{
- Name: "TermPicker",
+ Name: "Termpicker",
Usage: "A terminal-based color picker",
Action: AppAction,
Flags: AppFlags,