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 --- main.go | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 main.go (limited to 'main.go') 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