diff options
-rw-r--r-- | README.md | 11 | ||||
-rw-r--r-- | flags.go | 1 | ||||
-rw-r--r-- | internal/logging/logging.go | 35 | ||||
-rw-r--r-- | main.go | 26 |
4 files changed, 57 insertions, 16 deletions
@@ -31,18 +31,19 @@ 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 -- [ ] Make the tabs interface prettier with [lipgloss][1] (similar to tabs in [soft-serve][2]) -- [ ] Notify user of successful copy to clipboard (or failure) +- [ ] Refactor the code to streamline and centralize lipgloss styles - [ ] Unit-test color conversions near edge case colors - [ ] Warn the user if the terminal is too small (and refuse to render) +- [ ] Publish release to mainstream repositories (AUR, Homebrew, etc...) +- [x] Add a "cmd" mode to manually input colors - [x] Add a [help bubble][3] at the bottom of the interface to show available keybindings +- [x] Add an input flag to pass specific color as a starting value - [x] Add Box-drawing to the picker and the previewer - [x] Implement copying to clipboard for various formats (rgb, hex, hsl, cymk, etc...) - [X] Make sliders reach the correct length on init/tab without pressing `j`,`k` - [x] Make the preview windows prettier (perhaps same width as the sliders) - +- [x] Make the tabs interface prettier with [lipgloss][1] (similar to tabs in [soft-serve][2]) +- [x] Notify user of successful copy to clipboard (or failure) [1]: https://github.com/charmbracelet/lipgloss [2]: https://github.com/charmbracelet/soft-serve @@ -11,7 +11,6 @@ var AppFlags []cli.Flag = []cli.Flag{ Name: flagLogfile, Aliases: []string{"l"}, Usage: "Log file", - Value: "/dev/null", // Don't log by default }, &cli.StringFlag{ Name: "color", diff --git a/internal/logging/logging.go b/internal/logging/logging.go new file mode 100644 index 0000000..71f0334 --- /dev/null +++ b/internal/logging/logging.go @@ -0,0 +1,35 @@ +package logging + +import ( + "log/slog" + "os" + + "github.com/ChausseBenjamin/termpicker/internal/util" +) + +type logSink struct{} + +func (l logSink) Write(p []byte) (n int, err error) { + return len(p), nil +} + +func Setup(filepath string) *os.File { + if filepath != "" { + logFile, err := os.Create(filepath) + if err != nil { + slog.Error("Failed to create log file", util.ErrKey, err.Error()) + os.Exit(1) + } + + handler := slog.NewJSONHandler(logFile, nil) + slog.SetDefault(slog.New(handler)) + + return logFile + } else { + // Since app is a TUI, logging to stdout/stderr would break the UI + // So we disable it by default + handler := slog.NewJSONHandler(logSink{}, nil) + slog.SetDefault(slog.New(handler)) + return nil + } +} @@ -3,23 +3,23 @@ package main import ( "log/slog" "os" + "time" + "github.com/ChausseBenjamin/termpicker/internal/logging" "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() +var ( // Set by the build system + version = "DEVELOPMENT-SNAPSHOT" + date = "" +) - handler := slog.NewJSONHandler(logFile, nil) - slog.SetDefault(slog.New(handler)) +func AppAction(ctx *cli.Context) error { + logfile := logging.Setup(ctx.String("logfile")) + defer logfile.Close() slog.Info("Starting Termpicker") @@ -37,11 +37,17 @@ func AppAction(ctx *cli.Context) error { } func main() { + compileDate, _ := time.Parse(time.RFC3339, date) app := &cli.App{ Name: "Termpicker", Usage: "A terminal-based color picker", Action: AppAction, - Flags: AppFlags, + Authors: []*cli.Author{ + {Name: "Benjamin Chausse", Email: "benjamin@chausse.xyz"}, + }, + Version: version, + Flags: AppFlags, + Compiled: compileDate, } if err := app.Run(os.Args); err != nil { slog.Error("Program crashed", util.ErrKey, err.Error()) |