Check output device is a terminal: Difference between revisions
Content added Content deleted
m (→{{header|PHP}}) |
(Scala solution added) |
||
Line 366: | Line 366: | ||
}</lang> |
}</lang> |
||
=={{header|Scala}}== |
|||
{{Works with|Ubuntu|14.04}} |
|||
<lang scala>import org.fusesource.jansi.internal.CLibrary._ |
|||
object IsATty extends App { |
|||
var enabled = true |
|||
def apply(enabled: Boolean): Boolean = { |
|||
// We must be on some unix variant.. |
|||
try { |
|||
enabled && isatty(STDOUT_FILENO) == 1 |
|||
} |
|||
catch { |
|||
case ignore: Throwable => |
|||
ignore.printStackTrace() |
|||
false |
|||
} |
|||
} |
|||
println("tty " + apply(true)) |
|||
}</lang> |
|||
=={{header|Tcl}}== |
=={{header|Tcl}}== |
||
To detect whether output is going to a terminal in Tcl, you check whether the <code>stdout</code> channel looks like a serial line (as those are indistinguishable from terminals). The simplest way of doing that is to see whether you can read the <tt>-mode</tt> or <code>-xchar</code> channel options, which are only present on serial channels: |
To detect whether output is going to a terminal in Tcl, you check whether the <code>stdout</code> channel looks like a serial line (as those are indistinguishable from terminals). The simplest way of doing that is to see whether you can read the <tt>-mode</tt> or <code>-xchar</code> channel options, which are only present on serial channels: |