Skip to content

Conversation

sechmann
Copy link

@sechmann sechmann commented Jun 19, 2025

Describe your changes

A common way to source completions from CLIs is using process subsitution like this:

source <(cli completion zsh)

This does however not work currently in fang, because it opens stdin to check background color.

To reproduce the issue:

# Enable completion in example:
sed -i -e '/fang.WithoutCompletions(),/d' example/main.go
cat <(go run ./example/main.go completion zsh)

This hangs forever.

The proposed fix just checks to see if the command we're executing is the completion command, in which case the style / background color does not matter anyways and it skips the check.

Another (probably better) way to fix this would be to detect if we're piping (if that's possible) and not open stdin in that case.

Related issue/discussion:

Checklist before requesting a review

  • I have read CONTRIBUTING.md
  • I have performed a self-review of my code

@sechmann sechmann requested a review from caarlos0 as a code owner June 19, 2025 09:16
@meowgorithm
Copy link
Member

meowgorithm commented Jun 19, 2025

Really good catch. As you suggest, I do think it makes more sense to skip the check entirely if output's not a TTY (as the colors will automatically degrade).

If you're up for that, want to make the change? I’d use term.IsTerminal from the Charm x repo, which backs most of our tooling.

@meowgorithm
Copy link
Member

This should be fixed on main now per the TTY detection I described above.

@caarlos0
Copy link
Member

fixed in #35 🙏🏻

thanks @sechmann ❤️

@sechmann sechmann closed this Jun 19, 2025
@sechmann sechmann deleted the patch-1 branch June 19, 2025 23:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants