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
Provide a way to find out if given stdio stream is attached to a terminal #2789
Comments
This comment was originally written by ladicek@gmail.com Quick note about tests: I'm not familliar with Dart testing, and I can't currently imagine a way to test this feature. If I'd run a testing Dart script from Dart test, then it would never be attached to a terminal, so I could only test a half of it. But maybe that's better than nothing, so I'll take a look at it. |
This comment was originally written by ladicek@gmail.com OK, adding second version of the patch with a simple test. Attachment: |
In stdio.dart we already have the function _getStdioHandleType that calls a native function to determine whether a file descriptor is bound to a terminal, pipe, file or socket. We should leverage that either by adding a general function to get the type of a stream class StreamType { StreamType streamType(stream) { or add a type getter to the InputStream and OutputStream interfaces. The problem with the general function is that it will not be able to handle new stream types. E.g we already have the list input and output streams. If we have the type getter on the stream interfaces it would be possible to add new types, e.g. // List stream implementation file. static final StreamType _listStreamType = const StreamType("LIST"); class ListInputStream implements InputStream { ... StreamType type() => _listStreamType; ... Set owner to @sgjesse. |
This comment was originally written by ladicek@gmail.com AFAIU, _getStdioHandleType returns "terminal" everytime the stream is attached to a character device: if (S_ISCHR(buf.st_mode)) return kTerminal; I don't really understand POSIX, but I don't think that when S_ISCHR() is true, isatty() is also true. I'll leave the decision up to you. |
Added this to the Later milestone. |
Lack of this is feature appears to be at the root of some ugly output when I invoke the web ui compiler from the editor. In the editor, if I run build.dart manually (ie, I click "run") for a web ui app, I get the following: dart --enable-checked-mode build.dart Total time spent on web/books.html -- �[32m239 ms�[0mThe web ui compiler is coloring its output, which is nice on terminals, but is not nice elsewhere. It would be great for the compiler to know whether it's in a terminal or not. Any chance of getting this soonish? |
Added Started label. |
Fixed in https://code.google.com/p/dart/source/detail?r=16839. Added Fixed label. |
Removed Area-IO label. |
This issue was originally filed by ladicek@gmail.com
Sometimes, it's good to know if a given stdio stream (stdout, most likely) is attached to a terminal. For example, the dart2js compiler output contains ANSI codes for coloring, which is nice for human, but if you redirect the output to a file (or a pipe, whatever), then it's a mess. This situation could be easily fixed, provided that there is a way to find out if stdout is actually attached to a terminal or not.
I'm attaching a patch against the Dart VM that uses 'isatty' on Unices and '_isatty' on Windows (but I'm not sure that _isatty is the right way, see the comment in file_win.cc). Please, let me know if you agree with this change, so that I can issue a pull request, or if you want to discuss it some more.
Attachment:
0001-added-an-isTerminal-function-to-dart-io-for-testing-.patch (4.61 KB)
The text was updated successfully, but these errors were encountered: