summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.github/workflows/vhs.yml2
-rw-r--r--.gitignore66
-rw-r--r--.goreleaser.yaml24
-rw-r--r--flags.go21
-rw-r--r--go.mod18
-rw-r--r--go.sum38
-rw-r--r--internal/app/app.go50
-rw-r--r--internal/app/description.txt23
-rw-r--r--internal/app/flags.go25
-rw-r--r--internal/documentation/documentation.go38
-rw-r--r--internal/logging/discard.go25
-rw-r--r--internal/logging/logging.go8
-rw-r--r--main.go37
13 files changed, 288 insertions, 87 deletions
diff --git a/.github/workflows/vhs.yml b/.github/workflows/vhs.yml
index 15f5a33..776d317 100644
--- a/.github/workflows/vhs.yml
+++ b/.github/workflows/vhs.yml
@@ -1,8 +1,6 @@
---
name: vhs
on:
- push:
- branches: [master]
workflow_dispatch:
permissions:
contents: write
diff --git a/.gitignore b/.gitignore
index f5d3659..8c64ab4 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,3 +1,67 @@
+# App specific
+
*.json
+termpicker
+termpicker.1
coverage.txt
-dist/
+
+# General
+.DS_Store
+.AppleDouble
+.LSOverride
+
+# Icon must end with two \r
+Icon
+
+# Thumbnails
+._*
+
+# Files that might appear in the root of a volume
+.DocumentRevisions-V100
+.fseventsd
+.Spotlight-V100
+.TemporaryItems
+.Trashes
+.VolumeIcon.icns
+.com.apple.timemachine.donotpresent
+
+# Directories potentially created on remote AFP share
+.AppleDB
+.AppleDesktop
+Network Trash Folder
+Temporary Items
+.apdiskdist/
+
+*~
+
+# temporary files which can be created if a process still has a handle open of a deleted file
+.fuse_hidden*
+
+# KDE directory preferences
+.directory
+
+# Linux trash folder which might appear on any partition or disk
+.Trash-*
+
+# .nfs files are created when an open file is removed but is still being accessed
+.nfs*
+
+# Swap
+[._]*.s[a-v][a-z]
+!*.svg # comment out if you don't need vector files
+[._]*.sw[a-p]
+[._]s[a-rt-v][a-z]
+[._]ss[a-gi-z]
+[._]sw[a-p]
+
+# Session
+Session.vim
+Sessionx.vim
+
+# Temporary
+.netrwhist
+*~
+# Auto-generated tag files
+tags
+# Persistent undo
+[._]*.un~
diff --git a/.goreleaser.yaml b/.goreleaser.yaml
index 86fda49..3e69947 100644
--- a/.goreleaser.yaml
+++ b/.goreleaser.yaml
@@ -8,14 +8,30 @@
# vim: set ts=2 sw=2 tw=0 fo=cnqoj
version: 2
before:
- hooks: [go mod tidy]
+ hooks: [go mod tidy, go generate ./..., 'echo building {{.Version}}']
+upx:
+ # Whether to enable it or not.
+ - enabled: true
+ # Filter by GOOS.
+ goos: [linux, windows, darwin]
+ # Filter by GOARCH.
+ goarch: [arm, amd64, i386, arm64, aarch64]
+ # Compress argument.
+ # Valid options are from '1' (faster) to '9' (better), and 'best'.
+ compress: best
+ # Whether to try LZMA (slower).
+ lzma: false
builds:
- main:
env: [CGO_ENABLED=0]
- ldflags: -s -w -X main.version={{.Version}} -X main.commit={{.Commit}} -X main.date={{.Date}}
+ ldflags: -s -w -X main.version={{.Version}}
goos: [linux, windows, darwin]
archives:
- - format: tar.gz
+ - formats: tar.gz
+ files:
+ - LICENSE
+ - src: ./internal/documentation/*.1
+ strip_parent: true
# this name template makes the OS and Arch compatible with the results of `uname`.
name_template: >-
{{ .ProjectName }}_
@@ -27,7 +43,7 @@ archives:
# use zip for windows archives
format_overrides:
- goos: windows
- format: zip
+ formats: zip
changelog:
sort: asc
filters:
diff --git a/flags.go b/flags.go
deleted file mode 100644
index a7eb37f..0000000
--- a/flags.go
+++ /dev/null
@@ -1,21 +0,0 @@
-package main
-
-import "github.com/urfave/cli/v3"
-
-const (
- flagLogfile = "logfile"
-)
-
-var AppFlags []cli.Flag = []cli.Flag{
- &cli.StringFlag{
- Name: flagLogfile,
- Aliases: []string{"l"},
- Usage: "Log file",
- },
- &cli.StringFlag{
- Name: "color",
- Aliases: []string{"c"},
- Usage: "Initial color",
- Value: "",
- },
-}
diff --git a/go.mod b/go.mod
index 5de072d..5178dcb 100644
--- a/go.mod
+++ b/go.mod
@@ -7,17 +7,21 @@ require (
github.com/charmbracelet/bubbles v0.20.0
github.com/charmbracelet/bubbletea v1.2.3
github.com/charmbracelet/harmonica v0.2.0
- github.com/charmbracelet/lipgloss v1.0.0
- github.com/charmbracelet/x/ansi v0.4.5
+ github.com/charmbracelet/lipgloss v1.1.0
+ github.com/charmbracelet/x/ansi v0.8.0
github.com/hashicorp/go-uuid v1.0.3
github.com/lucasb-eyer/go-colorful v1.2.0
- github.com/muesli/termenv v0.15.2
+ github.com/muesli/termenv v0.16.0
+ github.com/urfave/cli-docs/v3 v3.0.0-alpha6
github.com/urfave/cli/v3 v3.0.0-beta1
)
require (
github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect
+ github.com/charmbracelet/colorprofile v0.2.3-0.20250311203215-f60798e515dc // indirect
+ github.com/charmbracelet/x/cellbuf v0.0.13-0.20250311204145-2c3ea96c31dd // indirect
github.com/charmbracelet/x/term v0.2.1 // indirect
+ github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect
github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/mattn/go-localereader v0.0.1 // indirect
@@ -25,7 +29,9 @@ require (
github.com/muesli/ansi v0.0.0-20230316100256-276c6243b2f6 // indirect
github.com/muesli/cancelreader v0.2.2 // indirect
github.com/rivo/uniseg v0.4.7 // indirect
- golang.org/x/sync v0.9.0 // indirect
- golang.org/x/sys v0.27.0 // indirect
- golang.org/x/text v0.8.0 // indirect
+ github.com/russross/blackfriday/v2 v2.1.0 // indirect
+ github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e // indirect
+ golang.org/x/sync v0.12.0 // indirect
+ golang.org/x/sys v0.31.0 // indirect
+ golang.org/x/text v0.23.0 // indirect
)
diff --git a/go.sum b/go.sum
index 5db4ae7..3e2b563 100644
--- a/go.sum
+++ b/go.sum
@@ -6,14 +6,20 @@ github.com/charmbracelet/bubbles v0.20.0 h1:jSZu6qD8cRQ6k9OMfR1WlM+ruM8fkPWkHvQW
github.com/charmbracelet/bubbles v0.20.0/go.mod h1:39slydyswPy+uVOHZ5x/GjwVAFkCsV8IIVy+4MhzwwU=
github.com/charmbracelet/bubbletea v1.2.3 h1:d9MdMsANIYZB5pE1KkRqaUV6GfsiWm+/9z4fTuGVm9I=
github.com/charmbracelet/bubbletea v1.2.3/go.mod h1:Qr6fVQw+wX7JkWWkVyXYk/ZUQ92a6XNekLXa3rR18MM=
+github.com/charmbracelet/colorprofile v0.2.3-0.20250311203215-f60798e515dc h1:4pZI35227imm7yK2bGPcfpFEmuY1gc2YSTShr4iJBfs=
+github.com/charmbracelet/colorprofile v0.2.3-0.20250311203215-f60798e515dc/go.mod h1:X4/0JoqgTIPSFcRA/P6INZzIuyqdFY5rm8tb41s9okk=
github.com/charmbracelet/harmonica v0.2.0 h1:8NxJWRWg/bzKqqEaaeFNipOu77YR5t8aSwG4pgaUBiQ=
github.com/charmbracelet/harmonica v0.2.0/go.mod h1:KSri/1RMQOZLbw7AHqgcBycp8pgJnQMYYT8QZRqZ1Ao=
-github.com/charmbracelet/lipgloss v1.0.0 h1:O7VkGDvqEdGi93X+DeqsQ7PKHDgtQfF8j8/O2qFMQNg=
-github.com/charmbracelet/lipgloss v1.0.0/go.mod h1:U5fy9Z+C38obMs+T+tJqst9VGzlOYGj4ri9reL3qUlo=
-github.com/charmbracelet/x/ansi v0.4.5 h1:LqK4vwBNaXw2AyGIICa5/29Sbdq58GbGdFngSexTdRM=
-github.com/charmbracelet/x/ansi v0.4.5/go.mod h1:dk73KoMTT5AX5BsX0KrqhsTqAnhZZoCBjs7dGWp4Ktw=
+github.com/charmbracelet/lipgloss v1.1.0 h1:vYXsiLHVkK7fp74RkV7b2kq9+zDLoEU4MZoFqR/noCY=
+github.com/charmbracelet/lipgloss v1.1.0/go.mod h1:/6Q8FR2o+kj8rz4Dq0zQc3vYf7X+B0binUUBwA0aL30=
+github.com/charmbracelet/x/ansi v0.8.0 h1:9GTq3xq9caJW8ZrBTe0LIe2fvfLR/bYXKTx2llXn7xE=
+github.com/charmbracelet/x/ansi v0.8.0/go.mod h1:wdYl/ONOLHLIVmQaxbIYEC/cRKOQyjTkowiI4blgS9Q=
+github.com/charmbracelet/x/cellbuf v0.0.13-0.20250311204145-2c3ea96c31dd h1:vy0GVL4jeHEwG5YOXDmi86oYw2yuYUGqz6a8sLwg0X8=
+github.com/charmbracelet/x/cellbuf v0.0.13-0.20250311204145-2c3ea96c31dd/go.mod h1:xe0nKWGd3eJgtqZRaN9RjMtK7xUYchjzPr7q6kcvCCs=
github.com/charmbracelet/x/term v0.2.1 h1:AQeHeLZ1OqSXhrAWpYUtZyX1T3zVxfpZuEQMIQaGIAQ=
github.com/charmbracelet/x/term v0.2.1/go.mod h1:oQ4enTYFV7QN4m0i9mzHrViD7TQKvNEEkHUMCmsxdUg=
+github.com/cpuguy83/go-md2man/v2 v2.0.2 h1:p1EgwI/C7NhT0JmVkwCD2ZBK8j4aeHQX2pMHHBfMQ6w=
+github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f h1:Y/CXytFA4m6baUTXGLOoWe4PQhGxaX0KpnayAqC48p4=
@@ -32,24 +38,32 @@ github.com/muesli/ansi v0.0.0-20230316100256-276c6243b2f6 h1:ZK8zHtRHOkbHy6Mmr5D
github.com/muesli/ansi v0.0.0-20230316100256-276c6243b2f6/go.mod h1:CJlz5H+gyd6CUWT45Oy4q24RdLyn7Md9Vj2/ldJBSIo=
github.com/muesli/cancelreader v0.2.2 h1:3I4Kt4BQjOR54NavqnDogx/MIoWBFa0StPA8ELUXHmA=
github.com/muesli/cancelreader v0.2.2/go.mod h1:3XuTXfFS2VjM+HTLZY9Ak0l6eUKfijIfMUZ4EgX0QYo=
-github.com/muesli/termenv v0.15.2 h1:GohcuySI0QmI3wN8Ok9PtKGkgkFIk7y6Vpb5PvrY+Wo=
-github.com/muesli/termenv v0.15.2/go.mod h1:Epx+iuz8sNs7mNKhxzH4fWXGNpZwUaJKRS1noLXviQ8=
+github.com/muesli/termenv v0.16.0 h1:S5AlUN9dENB57rsbnkPyfdGuWIlkmzJjbFf0Tf5FWUc=
+github.com/muesli/termenv v0.16.0/go.mod h1:ZRfOIKPFDYQoDFF4Olj7/QJbW60Ol/kL1pU3VfY/Cnk=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
github.com/rivo/uniseg v0.4.7 h1:WUdvkW8uEhrYfLC4ZzdpI2ztxP1I582+49Oc5Mq64VQ=
github.com/rivo/uniseg v0.4.7/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88=
+github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk=
+github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
+github.com/urfave/cli-docs/v3 v3.0.0-alpha6 h1:w/l/N0xw1rO/aHRIGXJ0lDwwYFOzilup1qGvIytP3BI=
+github.com/urfave/cli-docs/v3 v3.0.0-alpha6/go.mod h1:p7Z4lg8FSTrPB9GTaNyTrK3ygffHZcK3w0cU2VE+mzU=
github.com/urfave/cli/v3 v3.0.0-beta1 h1:6DTaaUarcM0wX7qj5Hcvs+5Dm3dyUTBbEwIWAjcw9Zg=
github.com/urfave/cli/v3 v3.0.0-beta1/go.mod h1:FnIeEMYu+ko8zP1F9Ypr3xkZMIDqW3DR92yUtY39q1Y=
-golang.org/x/sync v0.9.0 h1:fEo0HyrW1GIgZdpbhCRO0PkJajUS5H9IFUztCgEo2jQ=
-golang.org/x/sync v0.9.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
+github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e h1:JVG44RsyaB9T2KIHavMF/ppJZNG9ZpyihvCd0w101no=
+github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e/go.mod h1:RbqR21r5mrJuqunuUZ/Dhy/avygyECGrLceyNeo4LiM=
+golang.org/x/exp v0.0.0-20220909182711-5c715a9e8561 h1:MDc5xs78ZrZr3HMQugiXOAkSZtfTpbJLDr/lwfgO53E=
+golang.org/x/exp v0.0.0-20220909182711-5c715a9e8561/go.mod h1:cyybsKvd6eL0RnXn6p/Grxp8F5bW7iYuBgsNCOHpMYE=
+golang.org/x/sync v0.12.0 h1:MHc5BpPuC30uJk597Ri8TV3CNZcTLu6B6z4lJy+g6Jw=
+golang.org/x/sync v0.12.0/go.mod h1:1dzgHSNfp02xaA81J2MS99Qcpr2w7fw1gpm99rleRqA=
golang.org/x/sys v0.0.0-20210809222454-d867a43fc93e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
-golang.org/x/sys v0.27.0 h1:wBqf8DvsY9Y/2P8gAfPDEYNuS30J4lPHJxXSb/nJZ+s=
-golang.org/x/sys v0.27.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
-golang.org/x/text v0.8.0 h1:57P1ETyNKtuIjB4SRd15iJxuhj8Gc416Y78H3qgMh68=
-golang.org/x/text v0.8.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8=
+golang.org/x/sys v0.31.0 h1:ioabZlmFYtWhL+TRYpcnNlLwhyxaM9kWTDEmfnprqik=
+golang.org/x/sys v0.31.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=
+golang.org/x/text v0.23.0 h1:D71I7dUrlY+VX0gQShAThNGHFxZ13dGLBHQLVl1mJlY=
+golang.org/x/text v0.23.0/go.mod h1:/BLNzu4aZCJ1+kcD0DNRotWKage4q2rGVAg4o22unh4=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
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,
+}
diff --git a/internal/documentation/documentation.go b/internal/documentation/documentation.go
new file mode 100644
index 0000000..3744eb0
--- /dev/null
+++ b/internal/documentation/documentation.go
@@ -0,0 +1,38 @@
+/*
+ * This package isn't the actual termpicker app.
+ * To avoid importing packages which aren't needed at runtime,
+ * some auto-generation functionalities is offloaded to here so
+ * it can be done with access to the rest of the code-base but
+ * without bloating the final binary. For example,
+ * generating bash+zsh auto-completion scripts isn't needed in
+ * the final binary if those script are generated before hand.
+ * Same goes for manpages. This file is meant to be run automatically
+ * to easily package new releases. Same goes for manpages which is the
+ * only feature currently in here.
+ */
+package main
+
+//go:generate go run . > termpicker.1
+
+import (
+ _ "embed"
+ "log/slog"
+ "os"
+
+ "github.com/ChausseBenjamin/termpicker/internal/app"
+ docs "github.com/urfave/cli-docs/v3"
+)
+
+func main() {
+ // version doesn't show up in the man page...
+ a := app.Command("")
+
+ man, err := docs.ToManWithSection(a, 1)
+ if err != nil {
+ slog.Error("failed to generate man page",
+ slog.Any("error_message", err),
+ )
+ os.Exit(1)
+ }
+ os.WriteFile("termpicker.1", []byte(man), 0644)
+}
diff --git a/internal/logging/discard.go b/internal/logging/discard.go
new file mode 100644
index 0000000..e827287
--- /dev/null
+++ b/internal/logging/discard.go
@@ -0,0 +1,25 @@
+package logging
+
+import (
+ "context"
+ "log/slog"
+)
+
+// DiscardHandler discards all log output. DiscardHandler.Enabled returns false for all Levels.
+type DiscardHandler struct{}
+
+func (d DiscardHandler) Enabled(ctx context.Context, level slog.Level) bool {
+ return false
+}
+
+func (d DiscardHandler) Handle(ctx context.Context, record slog.Record) error {
+ return nil
+}
+
+func (d DiscardHandler) WithAttrs(attrs []slog.Attr) slog.Handler {
+ return d
+}
+
+func (d DiscardHandler) WithGroup(name string) slog.Handler {
+ return d
+}
diff --git a/internal/logging/logging.go b/internal/logging/logging.go
index 71f0334..054b303 100644
--- a/internal/logging/logging.go
+++ b/internal/logging/logging.go
@@ -7,12 +7,6 @@ import (
"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)
@@ -28,7 +22,7 @@ func Setup(filepath string) *os.File {
} 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)
+ handler := DiscardHandler{}
slog.SetDefault(slog.New(handler))
return nil
}
diff --git a/main.go b/main.go
index f8dacf8..9ce095b 100644
--- a/main.go
+++ b/main.go
@@ -5,46 +5,15 @@ import (
"log/slog"
"os"
- "github.com/ChausseBenjamin/termpicker/internal/logging"
- "github.com/ChausseBenjamin/termpicker/internal/switcher"
+ "github.com/ChausseBenjamin/termpicker/internal/app"
"github.com/ChausseBenjamin/termpicker/internal/util"
- tea "github.com/charmbracelet/bubbletea"
- "github.com/urfave/cli/v3"
)
-// Set by the build system
var version = "compiled"
-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 main() {
- app := &cli.Command{
- Name: "Termpicker",
- Usage: "A terminal-based color picker",
- Action: AppAction,
- Authors: []any{"Benjamin Chausse <benjamin@chausse.xhz>"},
- Version: version,
- Flags: AppFlags,
- EnableShellCompletion: true,
- }
- if err := app.Run(context.Background(), os.Args); err != nil {
+ cmd := app.Command(version)
+ if err := cmd.Run(context.Background(), os.Args); err != nil {
slog.Error("Program crashed", util.ErrKey, err.Error())
os.Exit(1)
}