Skip to content

Commit

Permalink
Add --color flag
Browse files Browse the repository at this point in the history
Flag `--color` forces colored output, even if stdout is not a terminal.

Motivation
- `grep --color=always`
- `ls --color=always`

Application
- Allows colored text when piping to tools like fzf outside of `zk list --interactive`
  • Loading branch information
sivaplaysmC committed Jan 7, 2025
1 parent fdfd13b commit 2b17e64
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"strings"

"github.com/alecthomas/kong"
"github.com/fatih/color"
"github.com/zk-org/zk/internal/cli"
"github.com/zk-org/zk/internal/cli/cmd"
"github.com/zk-org/zk/internal/core"
Expand All @@ -31,9 +32,10 @@ var root struct {
Edit cmd.Edit `cmd group:"notes" help:"Edit notes matching the given criteria."`
Tag cmd.Tag `cmd group:"notes" help:"Manage the note tags."`

NotebookDir string `type:path placeholder:PATH help:"Turn off notebook auto-discovery and set manually the notebook where commands are run."`
WorkingDir string `short:W type:path placeholder:PATH help:"Run as if zk was started in <PATH> instead of the current working directory."`
NoInput NoInput `help:"Never prompt or ask for confirmation."`
NotebookDir string `type:path placeholder:PATH help:"Turn off notebook auto-discovery and set manually the notebook where commands are run."`
WorkingDir string `short:W type:path placeholder:PATH help:"Run as if zk was started in <PATH> instead of the current working directory."`
NoInput NoInput `help:"Never prompt or ask for confirmation."`
Color ForceColor `help:"Force colored output"`
// ForceInput is a debugging flag overriding the default value of interaction prompts.
ForceInput string `hidden xor:"input"`
Debug bool `default:"0" hidden help:"Print a debug stacktrace on SIGINT."`
Expand All @@ -52,6 +54,14 @@ func (f NoInput) BeforeApply(container *cli.Container) error {
return nil
}

// When enabled, output colored text even if stdout is not a tty.
type ForceColor bool

func (c ForceColor) BeforeApply() error {
color.NoColor = false
return nil
}

// ShowHelp is the default command run. It's equivalent to `zk --help`.
type ShowHelp struct{}

Expand Down

0 comments on commit 2b17e64

Please sign in to comment.