I am developing a Scala script which runs in a Bash script (on a Linux machine). In order to have a sophisticated user interface, I need to always now the exact terminal size.
So how can I get terminal window size (rows, columns) change events? Programs like mc (Midnight Commander) seem to react immediately on window size changes. I want this too :)
Update: With the help of larsks and Thomas Dickey I was able to find a solution, which looks like this:
import sun.misc.{Signal, SignalHandler}
Signal.handle(new Signal("WINCH"), TerminalSizeChangedHandler)
object TerminalSizeChangedHandler extends SignalHandler
{
override def handle(sig: Signal)
{
println("terminal size changed");
}
}
The dowside is, that it's relying on sun.misc classes. If someone shows me an equally simple solution without sun.misc, it would make be even more happy :)