Check input device is a terminal: Difference between revisions

Scala solution added
No edit summary
(Scala solution added)
Line 307:
}</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}}==
Tcl automatically detects whether <tt>stdin</tt> is coming from a terminal (or a socket) and sets up the channel to have the correct type. One of the configuration options of a terminal channel is <tt>-mode</tt> (used to configure baud rates on a real serial terminal) so we simply detect whether the option is present.
Anonymous user