src/Pure/System/progress.scala
author wenzelm
Sat Oct 08 22:36:22 2016 +0200 (2016-10-08)
changeset 64117 c2b41b073d8a
parent 64049 ac3ed62c53c3
child 64201 c3edc64e219d
permissions -rw-r--r--
build_history log files with formal meta info;
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@64049
    13
  def echo_if(cond: Boolean, msg: String) { if (cond) echo(msg) }
wenzelm@61276
    14
  def theory(session: String, theory: String) {}
wenzelm@61276
    15
  def stopped: Boolean = false
wenzelm@61276
    16
  override def toString: String = if (stopped) "Progress(stopped)" else "Progress"
wenzelm@61276
    17
}
wenzelm@61276
    18
wenzelm@61276
    19
object Ignore_Progress extends Progress
wenzelm@61276
    20
wenzelm@64117
    21
class Console_Progress(verbose: Boolean = false, stderr: Boolean = false) extends Progress
wenzelm@61276
    22
{
wenzelm@64117
    23
  override def echo(msg: String)
wenzelm@64117
    24
  {
wenzelm@64117
    25
    if (stderr) Console.err.println(msg) else Console.println(msg)
wenzelm@64117
    26
  }
wenzelm@64117
    27
wenzelm@61276
    28
  override def theory(session: String, theory: String): Unit =
wenzelm@61276
    29
    if (verbose) echo(session + ": theory " + theory)
wenzelm@61276
    30
wenzelm@61276
    31
  @volatile private var is_stopped = false
wenzelm@61276
    32
  def interrupt_handler[A](e: => A): A = POSIX_Interrupt.handler { is_stopped = true } { e }
wenzelm@61276
    33
  override def stopped: Boolean =
wenzelm@61276
    34
  {
wenzelm@61276
    35
    if (Thread.interrupted) is_stopped = true
wenzelm@61276
    36
    is_stopped
wenzelm@61276
    37
  }
wenzelm@61276
    38
}