12 |
12 |
13 |
13 |
14 object Progress { |
14 object Progress { |
15 /* output */ |
15 /* output */ |
16 |
16 |
17 sealed abstract class Output { def message: Message } |
17 sealed abstract class Msg { |
|
18 def verbose: Boolean |
|
19 def show_theory: Msg |
|
20 def message: Message |
|
21 } |
|
22 |
|
23 type Output = List[Msg] |
18 |
24 |
19 enum Kind { case writeln, warning, error_message } |
25 enum Kind { case writeln, warning, error_message } |
20 sealed case class Message( |
26 sealed case class Message( |
21 kind: Kind, |
27 kind: Kind, |
22 text: String, |
28 text: String, |
23 verbose: Boolean = false |
29 override val verbose: Boolean = false |
24 ) extends Output { |
30 ) extends Msg { |
|
31 override def show_theory: Msg = this |
25 override def message: Message = this |
32 override def message: Message = this |
26 |
33 |
27 def output_text: String = |
34 def output_text: String = |
28 kind match { |
35 kind match { |
29 case Kind.writeln => Output.writeln_text(text) |
36 case Kind.writeln => Output.writeln_text(text) |
36 |
43 |
37 sealed case class Theory( |
44 sealed case class Theory( |
38 theory: String, |
45 theory: String, |
39 session: String = "", |
46 session: String = "", |
40 percentage: Option[Int] = None, |
47 percentage: Option[Int] = None, |
41 total_time: Time = Time.zero |
48 total_time: Time = Time.zero, |
42 ) extends Output { |
49 override val verbose: Boolean = true |
43 def message: Message = |
50 ) extends Msg { |
|
51 override def show_theory: Msg = copy(verbose = false) |
|
52 override def message: Message = |
44 Message(Kind.writeln, print_session + print_theory + print_percentage + print_total_time, |
53 Message(Kind.writeln, print_session + print_theory + print_percentage + print_total_time, |
45 verbose = true) |
54 verbose = verbose) |
46 |
55 |
47 def print_session: String = if_proper(session, session + ": ") |
56 def print_session: String = if_proper(session, session + ": ") |
48 def print_theory: String = "theory " + theory |
57 def print_theory: String = "theory " + theory |
49 def print_percentage: String = |
58 def print_percentage: String = |
50 percentage match { case None => "" case Some(p) => " " + p + "%" } |
59 percentage match { case None => "" case Some(p) => " " + p + "%" } |
107 status_theories = Nil |
116 status_theories = Nil |
108 theories.foreach(theory) |
117 theories.foreach(theory) |
109 status_theories = theories |
118 status_theories = theories |
110 } |
119 } |
111 |
120 |
112 override def output(message: Progress.Message): Unit = synchronized { |
121 override def output(msgs: Progress.Output): Unit = synchronized { |
113 if (do_output(message)) { |
122 if (msgs.exists(do_output)) { |
114 val theories = status_clear() |
123 val theories = status_clear() |
115 super.output(message) |
124 super.output(msgs) |
116 status_output(theories) |
125 status_output(theories) |
117 } |
126 } |
118 } |
127 } |
119 |
128 |
120 override def nodes_status(nodes_status: Progress.Nodes_Status): Unit = synchronized { |
129 override def nodes_status(nodes_status: Progress.Nodes_Status): Unit = synchronized { |
128 class Progress { |
137 class Progress { |
129 def now(): Date = Date.now() |
138 def now(): Date = Date.now() |
130 val start: Date = now() |
139 val start: Date = now() |
131 |
140 |
132 def verbose: Boolean = false |
141 def verbose: Boolean = false |
133 final def do_output(message: Progress.Message): Boolean = !message.verbose || verbose |
142 final def do_output(msg: Progress.Msg): Boolean = !msg.verbose || verbose |
134 |
143 |
135 def output(message: Progress.Message): Unit = {} |
144 def output(msgs: Progress.Output): Unit = {} |
|
145 |
|
146 final def output_text(msgs: Progress.Output, terminate: Boolean = false): String = { |
|
147 val lines = msgs.flatMap(msg => if (do_output(msg)) Some(msg.message.output_text) else None) |
|
148 if (terminate) Library.terminate_lines(lines) else cat_lines(lines) |
|
149 } |
136 |
150 |
137 final def echo(msg: String, verbose: Boolean = false): Unit = |
151 final def echo(msg: String, verbose: Boolean = false): Unit = |
138 output(Progress.Message(Progress.Kind.writeln, msg, verbose = verbose)) |
152 output(List(Progress.Message(Progress.Kind.writeln, msg, verbose = verbose))) |
139 final def echo_warning(msg: String, verbose: Boolean = false): Unit = |
153 final def echo_warning(msg: String, verbose: Boolean = false): Unit = |
140 output(Progress.Message(Progress.Kind.warning, msg, verbose = verbose)) |
154 output(List(Progress.Message(Progress.Kind.warning, msg, verbose = verbose))) |
141 final def echo_error_message(msg: String, verbose: Boolean = false): Unit = |
155 final def echo_error_message(msg: String, verbose: Boolean = false): Unit = |
142 output(Progress.Message(Progress.Kind.error_message, msg, verbose = verbose)) |
156 output(List(Progress.Message(Progress.Kind.error_message, msg, verbose = verbose))) |
143 |
157 |
144 final def echo_if(cond: Boolean, msg: String): Unit = if (cond) echo(msg) |
158 final def echo_if(cond: Boolean, msg: String): Unit = if (cond) echo(msg) |
145 |
159 |
146 def theory(theory: Progress.Theory): Unit = output(theory.message) |
160 final def theory(theory: Progress.Theory): Unit = output(List(theory)) |
|
161 |
147 def nodes_status(nodes_status: Progress.Nodes_Status): Unit = {} |
162 def nodes_status(nodes_status: Progress.Nodes_Status): Unit = {} |
148 |
163 |
149 final def capture[A](e: => A, msg: String, err: Throwable => String): Exn.Result[A] = { |
164 final def capture[A](e: => A, msg: String, err: Throwable => String): Exn.Result[A] = { |
150 echo(msg) |
165 echo(msg) |
151 try { Exn.Res(e) } |
166 try { Exn.Res(e) } |
196 override def status_enabled: Boolean = detailed |
211 override def status_enabled: Boolean = detailed |
197 override def status_hide(theories: List[Progress.Theory]): Unit = synchronized { |
212 override def status_hide(theories: List[Progress.Theory]): Unit = synchronized { |
198 Output.delete_lines(theories.length, stdout = !stderr) |
213 Output.delete_lines(theories.length, stdout = !stderr) |
199 } |
214 } |
200 |
215 |
201 override def output(message: Progress.Message): Unit = synchronized { |
216 override def output(msgs: Progress.Output): Unit = synchronized { |
202 if (do_output(message)) { |
217 for (msg <- msgs if do_output(msg)) { |
203 Output.output(message.output_text, stdout = !stderr, include_empty = true) |
218 Output.output(msg.message.output_text, stdout = !stderr, include_empty = true) |
204 } |
219 } |
205 } |
220 } |
206 |
221 |
207 override def toString: String = super.toString + ": console" |
222 override def toString: String = super.toString + ": console" |
208 } |
223 } |
209 |
224 |
210 class File_Progress(path: Path, override val verbose: Boolean = false) |
225 class File_Progress(path: Path, override val verbose: Boolean = false) |
211 extends Progress { |
226 extends Progress { |
212 override def output(message: Progress.Message): Unit = synchronized { |
227 override def output(msgs: Progress.Output): Unit = synchronized { |
213 if (do_output(message)) File.append(path, message.output_text + "\n") |
228 val txt = output_text(msgs, terminate = true) |
|
229 if (txt.nonEmpty) File.append(path, txt) |
214 } |
230 } |
215 |
231 |
216 override def toString: String = super.toString + ": " + path.toString |
232 override def toString: String = super.toString + ": " + path.toString |
217 } |
233 } |