Jump to content

Check output device is a terminal: Difference between revisions

Scala solution added
(Scala solution added)
Line 366:
}</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}}==
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:
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.