From d2fdcbc0d4f8b4c184ba2b1c3c4b00da3918521f Mon Sep 17 00:00:00 2001 From: Benjamin Chausse Date: Wed, 26 Mar 2025 17:28:58 -0400 Subject: Stylish `--help` + generate manpages (#27) * man page generation * generate VHS Gifs manually * goreleaser packages manpage --- internal/app/app.go | 50 ++++++++++++++++++++++++++++++++++++++++++++ internal/app/description.txt | 23 ++++++++++++++++++++ internal/app/flags.go | 25 ++++++++++++++++++++++ 3 files changed, 98 insertions(+) create mode 100644 internal/app/app.go create mode 100644 internal/app/description.txt create mode 100644 internal/app/flags.go (limited to 'internal/app') diff --git a/internal/app/app.go b/internal/app/app.go new file mode 100644 index 0000000..d0b168d --- /dev/null +++ b/internal/app/app.go @@ -0,0 +1,50 @@ +package app + +import ( + "context" + _ "embed" + "log/slog" + + "github.com/ChausseBenjamin/termpicker/internal/logging" + "github.com/ChausseBenjamin/termpicker/internal/switcher" + tea "github.com/charmbracelet/bubbletea" + "github.com/urfave/cli/v3" +) + +//go:embed description.txt +var Desc string + +func AppAction(ctx context.Context, cmd *cli.Command) error { + logfile := logging.Setup(cmd.String("logfile")) + defer logfile.Close() + + slog.Info("Starting Termpicker") + + sw := switcher.New() + + if colorStr := cmd.String("color"); colorStr != "" { + sw.NewNotice(sw.SetColorFromText(colorStr)) + } + + p := tea.NewProgram(sw) + if _, err := p.Run(); err != nil { + return err + } + return nil +} + +func Command(version string) *cli.Command { + cmd := &cli.Command{ + Name: "termpicker", + Usage: "A terminal-based color picker", + Action: AppAction, + ArgsUsage: "", + Description: Desc, + Authors: []any{"Benjamin Chausse "}, + Version: version, + Flags: AppFlags, + EnableShellCompletion: true, + } + + return cmd +} diff --git a/internal/app/description.txt b/internal/app/description.txt new file mode 100644 index 0000000..cf58bd6 --- /dev/null +++ b/internal/app/description.txt @@ -0,0 +1,23 @@ +Termpicker is a terminal-based application designed to help users select and manipulate colors efficiently. Its keybindings are meant to be intuitive to vim users as it behaves in a modal way: + +Normal mode: + + - h,l: decrease/increase the current slider coarsely by 5% + - H,L: decrease/increase the current slider finely by 1 + - j,k: select the slider below/above + - ,: move to the next/previous tab + - f,b : copy the color as an ANSI foreground/background escape code + - x,r,s,c: copy the color as a hex, rgb, hsl, or cmyk value + - ?: expand/shrink the help menu + - i,: enter Insert mode + - q,: quit the application + +Insert mode: + + Manually type a color. Pressing will cancel/leave insert mode. Anything in + the following formats will be used as a color input when pressing enter: + + - Hex: #rrggbb + - RGB: rgb( r, g, b) + - CMYK: cmyk(c, m, y, k) + - HSL: hsl(h, s, l) diff --git a/internal/app/flags.go b/internal/app/flags.go new file mode 100644 index 0000000..7b3ab5a --- /dev/null +++ b/internal/app/flags.go @@ -0,0 +1,25 @@ +package app + +import "github.com/urfave/cli/v3" + +const ( + flagLogfile = "log-file" +) + +var AppFlags []cli.Flag = []cli.Flag{ + &cli.StringFlag{ + Name: "color", + Aliases: []string{"c"}, + Usage: "Initial color", + Value: "", + DefaultText: "#b7416e", + }, + &cli.StringFlag{ + Name: flagLogfile, + Aliases: []string{"l"}, + Usage: "Log file", + Sources: cli.EnvVars("TERMPICKER_LOG_FILE"), + DefaultText: "/path/to/termpicker-logs.txt", + }, + cli.VersionFlag, +} -- cgit v1.2.3