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

Detect when we're connected to a TTY #1

Open
dimo414 opened this issue Feb 2, 2016 · 3 comments
Open

Detect when we're connected to a TTY #1

dimo414 opened this issue Feb 2, 2016 · 3 comments
Labels
enhancement New feature or request minor

Comments

@dimo414
Copy link
Owner

dimo414 commented Feb 2, 2016

Original report by Michael Diamond (Bitbucket: dimo414).


https://github.com/jnr/jnr-posix looks like a promising option; Java doesn't look to have anything reasonable out of the box.

@dimo414
Copy link
Owner Author

dimo414 commented Feb 15, 2016

Original comment by Michael Diamond (Bitbucket: dimo414).


Could also try to support column and line counts, like Python's shutil.get_terminal_width() does; see https://hg.python.org/cpython/file/3.5/Modules/posixmodule.c#l11128 for the Unix implementation.

@dimo414
Copy link
Owner Author

dimo414 commented Feb 15, 2016

Original comment by Michael Diamond (Bitbucket: dimo414).


See also TerminalLineSettings which calls stty -a < /dev/tty to get information about the current tty.

@dimo414
Copy link
Owner Author

dimo414 commented Apr 13, 2016

Original comment by Michael Diamond (Bitbucket: dimo414).


Possible partial solutions include those listed on tldp ($PS1 is set, $- contains i, or perhaps starting a subprocess to call test -t {0,1,2}). On Ubuntu the file descriptors in /dev/fd/are symlinks to /dev/pts/N (and perhaps /dev/ttyN` if attached to a native terminal device?) so checking those symlinks might also be an option.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request minor
Projects
None yet
Development

No branches or pull requests

1 participant