From fe46976256aa3a5cac9baf745ac1debcb49d00c0 Mon Sep 17 00:00:00 2001 From: Benjamin Chausse Date: Mon, 25 Nov 2024 15:17:02 -0500 Subject: fix: enhance readme, and update notice duration (#12) * Move main.go to root for easy go install ... * Better README * elongate notice duration --- .goreleaser.yaml | 2 +- README.md | 29 ++++++++++++++++++++++----- cmd/termpicker/flags.go | 16 --------------- cmd/termpicker/main.go | 48 --------------------------------------------- flags.go | 16 +++++++++++++++ internal/notices/notices.go | 2 +- main.go | 48 +++++++++++++++++++++++++++++++++++++++++++++ 7 files changed, 90 insertions(+), 71 deletions(-) delete mode 100644 cmd/termpicker/flags.go delete mode 100644 cmd/termpicker/main.go create mode 100644 flags.go create mode 100644 main.go diff --git a/.goreleaser.yaml b/.goreleaser.yaml index 2518c49..ddecc2d 100644 --- a/.goreleaser.yaml +++ b/.goreleaser.yaml @@ -10,7 +10,7 @@ version: 2 before: hooks: [go mod tidy] builds: - - main: ./cmd/termpicker/ + - main: env: [CGO_ENABLED=0] goos: [linux, windows, darwin] archives: diff --git a/README.md b/README.md index ab11cbe..fbdc3c4 100644 --- a/README.md +++ b/README.md @@ -2,18 +2,37 @@ A simple Color Picker Designed for your Terminal -This is very much a work in progress, but the end goal is to be able to -generate and copy colors from the terminal. - Here is a quick demo of what has been done so far:
Termpicker Demo
-Here is my roadmap to reach what I would consider a finished state: +## Features: + +- Preview any color using a truecolor terminal +- Create colors using sliders for RGB, HSL, and CMYK +- Seamlessly convert between color formats (RGB, HSL, CMYK) as you create +- Copy the color to your clipboard in various formats (RGB, HEX, HSL, CMYK) + +## Usage: + +The keybindings are pretty simple and shown in the UI. For a more exhaustive +list, pressing `?` expands the help section to show all available keybindings. + +## Installation + +Just grab the latest release for your platform and install the binary +somewhere in your `PATH`. + +Alternatively, you can install it directly from go with: +```sh +go install github.com/ChausseBenjamin/termpicker@latest +``` + +## Roadmap +- [ ] Add an input flag to pass specific color as a starting value - [ ] Add a "cmd" mode to manually input colors -- [ ] Allow to pass a starting color as an argument when launching the program - [ ] Make the tabs interface prettier with [lipgloss][1] (similar to tabs in [soft-serve][2]) - [ ] Notify user of successful copy to clipboard (or failure) - [ ] Unit-test color conversions near edge case colors diff --git a/cmd/termpicker/flags.go b/cmd/termpicker/flags.go deleted file mode 100644 index 660c053..0000000 --- a/cmd/termpicker/flags.go +++ /dev/null @@ -1,16 +0,0 @@ -package main - -import "github.com/urfave/cli/v2" - -const ( - flagLogfile = "logfile" -) - -var AppFlags []cli.Flag = []cli.Flag{ - &cli.StringFlag{ - Name: flagLogfile, - Aliases: []string{"l"}, - Usage: "Log file", - Value: "/dev/null", // Don't log by default - }, -} diff --git a/cmd/termpicker/main.go b/cmd/termpicker/main.go deleted file mode 100644 index 241adcf..0000000 --- a/cmd/termpicker/main.go +++ /dev/null @@ -1,48 +0,0 @@ -package main - -import ( - "log/slog" - "os" - - "github.com/ChausseBenjamin/termpicker/internal/picker" - "github.com/ChausseBenjamin/termpicker/internal/switcher" - "github.com/ChausseBenjamin/termpicker/internal/util" - tea "github.com/charmbracelet/bubbletea" - "github.com/urfave/cli/v2" -) - -func AppAction(ctx *cli.Context) error { - logFile, err := os.Create(ctx.String(flagLogfile)) - if err != nil { - slog.Error("Failed to create log file", util.ErrKey, err.Error()) - os.Exit(1) - } - defer logFile.Close() - - handler := slog.NewJSONHandler(logFile, nil) - 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}) - p := tea.NewProgram(sw) - if _, err := p.Run(); err != nil { - return err - } - return nil -} - -func main() { - app := &cli.App{ - Name: "TermPicker", - Usage: "A terminal-based color picker", - Action: AppAction, - Flags: AppFlags, - } - if err := app.Run(os.Args); err != nil { - slog.Error("Program crashed", util.ErrKey, err.Error()) - os.Exit(1) - } -} diff --git a/flags.go b/flags.go new file mode 100644 index 0000000..660c053 --- /dev/null +++ b/flags.go @@ -0,0 +1,16 @@ +package main + +import "github.com/urfave/cli/v2" + +const ( + flagLogfile = "logfile" +) + +var AppFlags []cli.Flag = []cli.Flag{ + &cli.StringFlag{ + Name: flagLogfile, + Aliases: []string{"l"}, + Usage: "Log file", + Value: "/dev/null", // Don't log by default + }, +} diff --git a/internal/notices/notices.go b/internal/notices/notices.go index 49fb179..4fbd807 100644 --- a/internal/notices/notices.go +++ b/internal/notices/notices.go @@ -11,7 +11,7 @@ import ( ) const ( - expiryDelay = 1 // seconds + expiryDelay = 3 // seconds ) type NoticeExpiryMsg string diff --git a/main.go b/main.go new file mode 100644 index 0000000..241adcf --- /dev/null +++ b/main.go @@ -0,0 +1,48 @@ +package main + +import ( + "log/slog" + "os" + + "github.com/ChausseBenjamin/termpicker/internal/picker" + "github.com/ChausseBenjamin/termpicker/internal/switcher" + "github.com/ChausseBenjamin/termpicker/internal/util" + tea "github.com/charmbracelet/bubbletea" + "github.com/urfave/cli/v2" +) + +func AppAction(ctx *cli.Context) error { + logFile, err := os.Create(ctx.String(flagLogfile)) + if err != nil { + slog.Error("Failed to create log file", util.ErrKey, err.Error()) + os.Exit(1) + } + defer logFile.Close() + + handler := slog.NewJSONHandler(logFile, nil) + 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}) + p := tea.NewProgram(sw) + if _, err := p.Run(); err != nil { + return err + } + return nil +} + +func main() { + app := &cli.App{ + Name: "TermPicker", + Usage: "A terminal-based color picker", + Action: AppAction, + Flags: AppFlags, + } + if err := app.Run(os.Args); err != nil { + slog.Error("Program crashed", util.ErrKey, err.Error()) + os.Exit(1) + } +} -- cgit v1.2.3