Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

stdoutisatty: init at 1.0 #345558

Merged
merged 5 commits into from
Oct 6, 2024
Merged

stdoutisatty: init at 1.0 #345558

merged 5 commits into from
Oct 6, 2024

Conversation

bryango
Copy link
Member

@bryango bryango commented Sep 30, 2024

Description of changes

Homepage: https://github.com/lilydjwg/stdoutisatty

It is surprisingly difficult to get consistent, colored outputs in the terminal, especially when commands are piped into a pager. In fact, there is a whole Arch wiki page on related topics:

Among the solutions listed there, stdoutisatty is one of the simplest: it hijacks the isatty function call used by most apps to determine whether stdout is an actual terminal, and always returns 1 (true). With this I can simply do:

stdoutisatty tree | less
cat flake.lock | stdoutisatty jq | less
...

... and enjoy my colorful outputs, without figuring out whatever --color=always type of flags these cli apps may or may not provide for colored outputs. Afaik, there is nothing like this in nixpkgs yet, so I would like to package and maintain it.

Things done

  • Built on platform(s)
    • x86_64-linux
    • aarch64-linux
    • x86_64-darwin
    • aarch64-darwin
  • For non-Linux: Is sandboxing enabled in nix.conf? (See Nix manual)
    • sandbox = relaxed
    • sandbox = true
  • Tested, as applicable:
  • Tested compilation of all packages that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD". Note: all changes have to be committed, also see nixpkgs-review usage
  • Tested basic functionality of all binary files (usually in ./result/bin/)
  • 24.11 Release Notes (or backporting 23.11 and 24.05 Release notes)
    • (Package updates) Added a release notes entry if the change is major or breaking
    • (Module updates) Added a release notes entry if the change is significant
    • (Module addition) Added a release notes entry if adding a new NixOS module
  • Fits CONTRIBUTING.md.

Add a 👍 reaction to pull requests you find important.

@ofborg ofborg bot added 8.has: package (new) This PR adds a new package 11.by: package-maintainer This PR was created by the maintainer of the package it changes 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin 10.rebuild-linux: 1-10 10.rebuild-linux: 1 labels Sep 30, 2024
Homepage: https://github.com/lilydjwg/stdoutisatty

It is surprisingly difficult to get consistent, colored outputs
in the terminal, especially when commands are piped into a pager.
In fact, there is a whole Arch wiki page on related topics:

- https://wiki.archlinux.org/title/Color_output_in_console#Reading_from_stdin

Among the solutions listed there, `stdoutisatty` is one of the simplest:
it hijacks the `isatty` function call used by most apps to determine
whether `stdout` is an actual terminal, and always returns `1 (true)`.
With this I can simply do:

```bash
stdoutisatty tree | less
cat flake.lock | stdoutisatty jq | less
...
```

and enjoy my colorful outputs, without figuring out whatever
`--color=always` type of flags these cli apps may or may not provide
for colored outputs.
@bryango bryango marked this pull request as ready for review October 1, 2024 16:04
@bryango bryango requested a review from NickCao October 2, 2024 02:30
@NickCao
Copy link
Member

NickCao commented Oct 2, 2024

Also, we have faketty for the same purpose: https://github.com/dtolnay/faketty

@bryango
Copy link
Member Author

bryango commented Oct 3, 2024

Also, we have faketty for the same purpose: dtolnay/faketty

Ah, this is awesome! Thank you! And it's Memory Safe (trademark) 😆

So the existence of faketty makes stdoutisatty a lot less relevant... Nonetheless, I have addressed the issues with the packaging in case people are still interested in having it in nixpkgs.

@bryango bryango requested a review from NickCao October 3, 2024 12:25

cmakeFlags = [
# must specify the full path to `libstdoutisatty.so` in the nix store
"-DCMAKE_C_FLAGS=-DLIB_FILE='\"${placeholder "out"}/lib/libstdoutisatty.so\"'"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"-DCMAKE_C_FLAGS=-DLIB_FILE='\"${placeholder "out"}/lib/libstdoutisatty.so\"'"
(lib.cmakeFeature "CMAKE_C_FLAGS" "-DLIB_FILE='\"${placeholder "out"}/lib/libstdoutisatty.so\"'")

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah that's much better! Thank you!

bryango and others added 3 commits October 6, 2024 13:01
The old version may lead to confusing `overrideAttrs` behaviors.
See discussions linked in the PR review comments.

Co-authored-by: Nick Cao <nickcao@nichi.co>
Co-authored-by: Nick Cao <nickcao@nichi.co>
Co-authored-by: Nick Cao <nickcao@nichi.co>
@bryango
Copy link
Member Author

bryango commented Oct 6, 2024

Fixed and squashed some commits (unsquashed: master...7a5f7b9).

@NickCao NickCao merged commit a8335ef into NixOS:master Oct 6, 2024
26 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
8.has: package (new) This PR adds a new package 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin 10.rebuild-linux: 1-10 10.rebuild-linux: 1 11.by: package-maintainer This PR was created by the maintainer of the package it changes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants