"""A tty implementation for xonsh"""importosimportsys
[docs]deftty(args,stdin,stdout,stderr):"""A tty command for xonsh."""if"--help"inargs:print(TTY_HELP,file=stdout)return0silent=Falseforiin("-s","--silent","--quiet"):ifiinargs:silent=Trueargs.remove(i)iflen(args)>0:ifnotsilent:foriinargs:print(f"tty: Invalid option: {i}",file=stderr)print("Try 'tty --help' for more information",file=stderr)return2try:fd=stdin.fileno()except:fd=sys.stdin.fileno()ifnotos.isatty(fd):ifnotsilent:print("not a tty",file=stdout)return1ifnotsilent:try:print(os.ttyname(fd),file=stdout)except:return3return0
TTY_HELP="""Usage: tty [OPTION]...Print the file name of the terminal connected to standard input. -s, --silent, --quiet print nothing, only return an exit status --help display this help and exitThis version of tty was written in Python for the xonsh project: http://xon.shBased on tty from GNU coreutils: http://www.gnu.org/software/coreutils/"""