src/Pure/System/progress.scala
author wenzelm
Tue Sep 29 13:54:04 2015 +0200 (2015-09-29)
changeset 61276 8a4bd05c1735
child 64049 ac3ed62c53c3
permissions -rw-r--r--
clarified modules;
wenzelm@61276
     1
/*  Title:      Pure/System/progress.scala
wenzelm@61276
     2
    Author:     Makarius
wenzelm@61276
     3
wenzelm@61276
     4
Progress context for system processes.
wenzelm@61276
     5
*/
wenzelm@61276
     6
wenzelm@61276
     7
package isabelle
wenzelm@61276
     8
wenzelm@61276
     9
wenzelm@61276
    10
class Progress
wenzelm@61276
    11
{
wenzelm@61276
    12
  def echo(msg: String) {}
wenzelm@61276
    13
  def theory(session: String, theory: String) {}
wenzelm@61276
    14
  def stopped: Boolean = false
wenzelm@61276
    15
  override def toString: String = if (stopped) "Progress(stopped)" else "Progress"
wenzelm@61276
    16
}
wenzelm@61276
    17
wenzelm@61276
    18
object Ignore_Progress extends Progress
wenzelm@61276
    19
wenzelm@61276
    20
class Console_Progress(verbose: Boolean = false) extends Progress
wenzelm@61276
    21
{
wenzelm@61276
    22
  override def echo(msg: String) { Console.println(msg) }
wenzelm@61276
    23
  override def theory(session: String, theory: String): Unit =
wenzelm@61276
    24
    if (verbose) echo(session + ": theory " + theory)
wenzelm@61276
    25
wenzelm@61276
    26
  @volatile private var is_stopped = false
wenzelm@61276
    27
  def interrupt_handler[A](e: => A): A = POSIX_Interrupt.handler { is_stopped = true } { e }
wenzelm@61276
    28
  override def stopped: Boolean =
wenzelm@61276
    29
  {
wenzelm@61276
    30
    if (Thread.interrupted) is_stopped = true
wenzelm@61276
    31
    is_stopped
wenzelm@61276
    32
  }
wenzelm@61276
    33
}