61276
|
1 |
/* Title: Pure/System/progress.scala
|
|
2 |
Author: Makarius
|
|
3 |
|
|
4 |
Progress context for system processes.
|
|
5 |
*/
|
|
6 |
|
|
7 |
package isabelle
|
|
8 |
|
|
9 |
|
64201
|
10 |
import java.io.{File => JFile}
|
|
11 |
|
|
12 |
|
61276
|
13 |
class Progress
|
|
14 |
{
|
|
15 |
def echo(msg: String) {}
|
64049
|
16 |
def echo_if(cond: Boolean, msg: String) { if (cond) echo(msg) }
|
61276
|
17 |
def theory(session: String, theory: String) {}
|
64909
|
18 |
|
65826
|
19 |
def echo_warning(msg: String) { echo(Output.warning_text(msg)) }
|
|
20 |
def echo_error(msg: String) { echo(Output.error_text(msg)) }
|
|
21 |
|
61276
|
22 |
def stopped: Boolean = false
|
|
23 |
override def toString: String = if (stopped) "Progress(stopped)" else "Progress"
|
64201
|
24 |
|
|
25 |
def bash(script: String,
|
|
26 |
cwd: JFile = null,
|
|
27 |
env: Map[String, String] = Isabelle_System.settings(),
|
|
28 |
redirect: Boolean = false,
|
|
29 |
echo: Boolean = false): Process_Result =
|
|
30 |
{
|
|
31 |
Isabelle_System.bash(script, cwd = cwd, env = env, redirect = redirect,
|
|
32 |
progress_stdout = echo_if(echo, _),
|
|
33 |
progress_stderr = echo_if(echo, _))
|
|
34 |
}
|
61276
|
35 |
}
|
|
36 |
|
64909
|
37 |
object No_Progress extends Progress
|
61276
|
38 |
|
64117
|
39 |
class Console_Progress(verbose: Boolean = false, stderr: Boolean = false) extends Progress
|
61276
|
40 |
{
|
64117
|
41 |
override def echo(msg: String)
|
|
42 |
{
|
|
43 |
if (stderr) Console.err.println(msg) else Console.println(msg)
|
|
44 |
}
|
|
45 |
|
61276
|
46 |
override def theory(session: String, theory: String): Unit =
|
|
47 |
if (verbose) echo(session + ": theory " + theory)
|
|
48 |
|
|
49 |
@volatile private var is_stopped = false
|
|
50 |
def interrupt_handler[A](e: => A): A = POSIX_Interrupt.handler { is_stopped = true } { e }
|
|
51 |
override def stopped: Boolean =
|
|
52 |
{
|
|
53 |
if (Thread.interrupted) is_stopped = true
|
|
54 |
is_stopped
|
|
55 |
}
|
|
56 |
}
|