-
-
Notifications
You must be signed in to change notification settings - Fork 366
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
Support --colour auto #224
Comments
Pulling a new dependency makes me sad. I would skip auto (or make it always never), for the sake of keeping yay less bloated. Playing with syscalls seems a tad overkill for something as simple as colour which is already "enough" supported. |
Gotcha |
Another easy way would me to just check if TERM environment variable contains "color". This should work in most cases. |
That will not work. the
|
It may be trickier to figure out whether a specific terminal supports color, but it should be easy to detect whether stdout is a TTY. In C, the I found a Go example which uses |
As I mentioned in my initial post I did consider the syscall option. My problems with a syscall is that I don't really think high level applications should be making syscalls, that's the standard library's job. Also I don't really want to be importing unsafe outside of go-alpm. Another thing is that syscalls are OS specific. Pacman is OS agnostic so I think Yay should at least try to be too. Not that I have tried Yay on another OS or really expect much of an user base there, I have no idea what the user numbers are for projects like Arch Hurd and pacBSD. http://golang.org/x/crypto/ssh/terminal provides implementations for BSD and a couple others at least. But doing all that just for colour settings seems like a bit much. |
That's a philosophical argument rather than a practical one. Why would the syscall package exist at all if not for letting applications use features which aren't exposed by the standard library? Passing arguments to syscalls is one of the explicit examples for using unsafe.
This is fair, but doesn't mean Yay can only support the lowest common denominator. Since (I assume) the vast majority of Yay usage is on Arch Linux, why not support a useful auto for Linux, and hard-code auto=never for other OSes? At a minimum, can the Pacman color setting be mentioned in the Yay manpage? I had to get frustrated and confused enough to go googling and reading stuff on Github to figure out why I sometimes got color from Yay and sometimes didn't on different machines. |
Can we take a step back and focus on this then? This issue was just for dealing with the |
To add though I do agree with you on adding some extra info to the man page. Although not specifically about color settings but more of a general "yay will inherit settings from pacman.conf". |
Thinking about it because we read the colour value through pacman.conf we could do the |
I wasn't aware, so that could be it. Was that change relatively recent? Here was my experience as a user:
If expanding the man page, I would recomend including the word "color" at least somewhere so that it can be searched for. Maybe like "yay will inherit settings from pacman.conf (e.g. color, xxx, yyy)" |
I also like the idea of embedding |
It was this pr that did it #113. I would have expected everyone wanting Yay to be in colour would already have Pacman colour enabled I did not expect the confusion it created. It was also added to the readme: Frequently Asked Questions
But yes mentioning it in the man page is a thing that should be done.
It's pretty set in stone that:
Everything discussed about this is an implementation problem, the behaviour apart from |
Sounds good to me. I opened a PR for a man page comment if you're happy with that wording. (edit: looks like you were since it got merged while I was typing out this comment) For
and then checking Thanks for making Yay a great tool, I'm definitely happy having switched from yaourt. |
Yeah it looked good, should probably add to it a bit though to include info on vcs.json and the aur package list cache but this is fine for now. With the c stuff you'll probably have to import unsafe as well that's why I would like to have this implemented in go-alpm somehow because we already use a bunch of c and unsafe stuff. I'd rather keep that stuff out of Yay if I can. |
I don't think unsafe is required to use C, unless cgo automatically does that under the hood. Ultimately, isn't the result the same regardless of whether the C calls are in go-alpm or Yay since all the Go code gets linked into the main executable? IMHO an isatty wrapper wouldn't make much sense in go-alpm because it's not really related to libalpm, but I won't argue about how you and @Jguer want to architect your project.
The glibc implementations of isatty and the underlying tcgetattr only use stack variables/pointers which Go would never touch, so that doesn't seem "unsafe" to me. |
go-alpm also handles the pacman config parsing even though it doesn't really have anything to do with libalpm. So if we added it to go-alpm it would be part of that. I don't know how to feel about it mainly because it feels wrong to include a whole other language just for the tiniest feature. I get that's not exactly a great argument. I'd probably prefer http://golang.org/x/crypto/ssh/terminal over c but I would probably give the OK for either if @Jguer does too. |
Fair point about the pacman config parsing. My take is that wrapping isatty isn't really adding a whole other language since C is already used in go-alpm. If yay really was pure Go, that would be a different story. Using golang.org/x/crypto/ssh/terminal (which also pulls in golang.org/x/sys/unix) would be a lot of extra overhead just for the IsTerminal function, but it might be worthwhile if Yay would use more of its features like abstracting out the color escape codes (though it looks like vt100 is all that's supported anyway) |
I added a more fleshed out FILES section over at #230 now that I'm done with other stuff. Feel free to check it out and tell me what you think. |
The pacman.conf man page describes the
It's unexpected for yay to read that option and interpret it differently. It also leads to unexpected behavior when running, say: yay -Si musl pacman yay | grep "^URL"
|
Sorry to jump aboard the discussion for a detail : I'm more interested in the --color=never option (in order to script things more easily). thx ! |
|
thx ! didn't even try to tell the truth. Didn't see it in the --help so I didn't even try any further. |
For the sake of consistency I would like Yay to support the same colour flags as pacman
--color always|auto|never
. Currently Yay reads the colour setting from pacman's config but is totally unaffected by the flags.Implementing
always
andnever
is pretty straightforward.auto
on the other hand checks if we are outputting to a terminal and only enables colour if we are.Implementing this is a little more difficult. The best way I can see to do that is to pull in a new dependency: http://golang.org/x/crypto/ssh/terminal. It's not part of the standard library but it is at least from golang.org.
Then again a whole dependency for a tiny feature? It does kind of seem like a waste. I know we're trying to keep dependencies to a minimum.
Implementing this ourselves would require a system call which I would rather stay away from.
We could just implement it 'incorrectly' and have auto to be the same as never or the same as always.
What do you think?
The text was updated successfully, but these errors were encountered: