-
Notifications
You must be signed in to change notification settings - Fork 18k
proposal: x/term: get terminal name (or some unique id) #58543
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
Comments
is this a native thing that terminals provide or should one be synthesized from... something? |
Honestly, I don't know what's the best way to go about this... For Linux there's https://man7.org/linux/man-pages/man3/ttyname.3.html In case it helps, this is what Jansi provides for Java through JNI and C: https://github.com/fusesource/jansi/tree/master/src/main/native |
Can you write a proposed API with a doc comment? Thanks. |
I'm currently very unfamiliar with the language, so apologies in advance if this is not what you are looking for, but looking at the current API, I think it would something like: //GetName returns the name of the given terminal.
func GetName(fd int) string If the given file descriptor is not a terminal, it could return empty or an error, according to what's considered best practice or following other similar cases in the package. Then for example, assuming the current terminal is $my-command 2> /dev/ttys002
STDIN: /dev/ttys001
STDOUT: /dev/ttys001
STDERR: /dev/ttys002 |
Go rarely uses file descriptors, so it seems odd to pass a file descriptor to a function like this. I mean, file descriptors do exist, of course, but Go programs don't use them routinely. If the goal is only to check whether |
You can also use |
I was basing on the I'll check the options mentioned with someone on my team though to try to test if that would work for us. Thanks. |
Using |
OK, closing this proposal. Please comment if you disagree. Thanks. |
Add a way in golang.org/x/term to get the terminal name or some terminal unique identifier for a given file descriptor.
Otherwise, I don't think it's possible to determine if stdout and stderr go to the same terminal or a different one, so that CLI tools/libraries that provide rich output (spinners, etc.) can repaint correctly.
The text was updated successfully, but these errors were encountered: