diff options
author | Benjamin Chausse <benjamin@chausse.xyz> | 2025-03-26 17:28:58 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-03-26 17:28:58 -0400 |
commit | d2fdcbc0d4f8b4c184ba2b1c3c4b00da3918521f (patch) | |
tree | 6f4ba628fffb5e6d84f2eaa756345d3307abab77 /internal/app | |
parent | cd9338e0d6cf582f9ea8028661ac3729e408f3bf (diff) |
Stylish `--help` + generate manpages (#27)v1.3.7
* man page generation
* generate VHS Gifs manually
* goreleaser packages manpage
Diffstat (limited to 'internal/app')
-rw-r--r-- | internal/app/app.go | 50 | ||||
-rw-r--r-- | internal/app/description.txt | 23 | ||||
-rw-r--r-- | internal/app/flags.go | 25 |
3 files changed, 98 insertions, 0 deletions
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 <benjamin@chausse.xyz>"}, + 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 + - <Tab>,<S-Tab>: 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,<cmd>: enter Insert mode + - q,<C-c>: 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, +} |