Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Mark descriptor as terminal for the -t test



On 2 June 2016 at 06:45, Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx> wrote:
> On May 13, 10:18am, Sebastian Gniazdowski wrote:
> } Subject: Mark descriptor as terminal for the -t test
> }
> } Having a descriptor X, pointing to a file or to a process (with >(cmd)
> } redirection), is it possible to make it look like terminal? For the
> } test -t to pass?
>
> No.  The "is a terminal" state is at the OS level; the descriptor must
> refer to a tty device file.

isatty() is a call that probably all programs use to test for the state

> } The goal is: make this more robust:
> }   exec > >(tee -a ~/$$.out)
> }
> } It works, catches output of commands, however e.g. from vim, message
> } about "output is not to a terminal" appears.
>
> Almost any interactive command will be confused or broken by that usage.
> This is the reason that e.g. the "script" command exists.

A robust program, the script. Recalls asciinema.

Turns out the commands are not so confused. Either they assume there
is no terminal, and strip terminal control codes from output, or
ignore the fact (e.g. vim) and work well.

> I presume this is related to your "ztrace" project.  I fear you're doomed
> to failure with that one, except in a very simple cases.

Turned out the isatty() == 0 is a useful thing. If a program is
capable of stripping his output out of control codes, let it do it. If
not, then it's a problem in general. So I was striving for a more
problematic situation. Could implement use of following program:

http://www.andre-simon.de/doku/ansifilter/en/ansifilter.php

to strip control codes, but have no motivation to do so. The dream of
"reuse output without mouse" is better to be implemented at terminal
level. Ctrl-Space to invoke sophisticated selection and completion
mechanism, to paste-in some part of what terminal has seen up to this
moment. iTerm2 folks did numerous of things in their v3 release, but
there is no reusing of output, no ztrace-like interface.

Best regards,
Sebastian Gniazdowski



Messages sorted by: Reverse Date, Date, Thread, Author