author | wenzelm |
Thu, 13 Dec 2012 19:53:55 +0100 | |
changeset 50505 | 33c92722cc3d |
parent 50503 | 50f141b34bb7 |
child 51661 | 92e58b76dbb1 |
permissions | -rw-r--r-- |
14815 | 1 |
(* Title: Pure/General/output.ML |
2 |
Author: Makarius, Hagia Maria Sion Abbey (Jerusalem) |
|
3 |
||
42012
2c3fe3cbebae
structure Timing: covers former start_timing/end_timing and Output.timeit etc;
wenzelm
parents:
40133
diff
changeset
|
4 |
Isabelle output channels. |
14815 | 5 |
*) |
6 |
||
7 |
signature BASIC_OUTPUT = |
|
8 |
sig |
|
18682
216692feebab
removed special ERROR handling stuff (transform_error etc.);
wenzelm
parents:
17539
diff
changeset
|
9 |
val writeln: string -> unit |
216692feebab
removed special ERROR handling stuff (transform_error etc.);
wenzelm
parents:
17539
diff
changeset
|
10 |
val tracing: string -> unit |
216692feebab
removed special ERROR handling stuff (transform_error etc.);
wenzelm
parents:
17539
diff
changeset
|
11 |
val warning: string -> unit |
14815 | 12 |
end; |
13 |
||
14 |
signature OUTPUT = |
|
15 |
sig |
|
16 |
include BASIC_OUTPUT |
|
40131
7cbebd636e79
explicitly qualify type Output.output, which is a slightly odd internal feature;
wenzelm
parents:
40125
diff
changeset
|
17 |
type output = string |
23660
18765718cf62
type output = string indicates raw system output;
wenzelm
parents:
23616
diff
changeset
|
18 |
val default_output: string -> output * int |
18765718cf62
type output = string indicates raw system output;
wenzelm
parents:
23616
diff
changeset
|
19 |
val default_escape: output -> string |
18765718cf62
type output = string indicates raw system output;
wenzelm
parents:
23616
diff
changeset
|
20 |
val add_mode: string -> (string -> output * int) -> (output -> string) -> unit |
18765718cf62
type output = string indicates raw system output;
wenzelm
parents:
23616
diff
changeset
|
21 |
val output_width: string -> output * int |
18765718cf62
type output = string indicates raw system output;
wenzelm
parents:
23616
diff
changeset
|
22 |
val output: string -> output |
18765718cf62
type output = string indicates raw system output;
wenzelm
parents:
23616
diff
changeset
|
23 |
val escape: output -> string |
44389
a3b5fdfb04a3
tuned signature -- contrast physical output primitives versus Output.raw_message;
wenzelm
parents:
44270
diff
changeset
|
24 |
val physical_stdout: output -> unit |
a3b5fdfb04a3
tuned signature -- contrast physical output primitives versus Output.raw_message;
wenzelm
parents:
44270
diff
changeset
|
25 |
val physical_stderr: output -> unit |
a3b5fdfb04a3
tuned signature -- contrast physical output primitives versus Output.raw_message;
wenzelm
parents:
44270
diff
changeset
|
26 |
val physical_writeln: output -> unit |
40133
b61d52de66f0
more explicit indication of Output.Private_Hooks (still public to accomodate clones of Proof General for now);
wenzelm
parents:
40132
diff
changeset
|
27 |
structure Private_Hooks: |
b61d52de66f0
more explicit indication of Output.Private_Hooks (still public to accomodate clones of Proof General for now);
wenzelm
parents:
40132
diff
changeset
|
28 |
sig |
b61d52de66f0
more explicit indication of Output.Private_Hooks (still public to accomodate clones of Proof General for now);
wenzelm
parents:
40132
diff
changeset
|
29 |
val writeln_fn: (output -> unit) Unsynchronized.ref |
b61d52de66f0
more explicit indication of Output.Private_Hooks (still public to accomodate clones of Proof General for now);
wenzelm
parents:
40132
diff
changeset
|
30 |
val urgent_message_fn: (output -> unit) Unsynchronized.ref |
b61d52de66f0
more explicit indication of Output.Private_Hooks (still public to accomodate clones of Proof General for now);
wenzelm
parents:
40132
diff
changeset
|
31 |
val tracing_fn: (output -> unit) Unsynchronized.ref |
b61d52de66f0
more explicit indication of Output.Private_Hooks (still public to accomodate clones of Proof General for now);
wenzelm
parents:
40132
diff
changeset
|
32 |
val warning_fn: (output -> unit) Unsynchronized.ref |
44270
3eaad39e520c
more careful treatment of exception serial numbers, with propagation to message channel;
wenzelm
parents:
43760
diff
changeset
|
33 |
val error_fn: (serial * output -> unit) Unsynchronized.ref |
40133
b61d52de66f0
more explicit indication of Output.Private_Hooks (still public to accomodate clones of Proof General for now);
wenzelm
parents:
40132
diff
changeset
|
34 |
val prompt_fn: (output -> unit) Unsynchronized.ref |
b61d52de66f0
more explicit indication of Output.Private_Hooks (still public to accomodate clones of Proof General for now);
wenzelm
parents:
40132
diff
changeset
|
35 |
val status_fn: (output -> unit) Unsynchronized.ref |
b61d52de66f0
more explicit indication of Output.Private_Hooks (still public to accomodate clones of Proof General for now);
wenzelm
parents:
40132
diff
changeset
|
36 |
val report_fn: (output -> unit) Unsynchronized.ref |
50503
50f141b34bb7
enable Isabelle/ML to produce uninterpreted result messages as well;
wenzelm
parents:
49647
diff
changeset
|
37 |
val result_fn: (serial * output -> unit) Unsynchronized.ref |
46774 | 38 |
val protocol_message_fn: (Properties.T -> output -> unit) Unsynchronized.ref |
40133
b61d52de66f0
more explicit indication of Output.Private_Hooks (still public to accomodate clones of Proof General for now);
wenzelm
parents:
40132
diff
changeset
|
39 |
end |
40132
7ee65dbffa31
renamed Output.priority to Output.urgent_message to emphasize its special role more clearly;
wenzelm
parents:
40131
diff
changeset
|
40 |
val urgent_message: string -> unit |
44270
3eaad39e520c
more careful treatment of exception serial numbers, with propagation to message channel;
wenzelm
parents:
43760
diff
changeset
|
41 |
val error_msg': serial * string -> unit |
25845
c448a5f15f31
added explicit prompt channel (prompt_fn/prompt);
wenzelm
parents:
25686
diff
changeset
|
42 |
val error_msg: string -> unit |
c448a5f15f31
added explicit prompt channel (prompt_fn/prompt);
wenzelm
parents:
25686
diff
changeset
|
43 |
val prompt: string -> unit |
27605 | 44 |
val status: string -> unit |
38236
d8c7be27e01d
explicitly distinguish Output.status (essential feedback) vs. Output.report (useful markup);
wenzelm
parents:
37784
diff
changeset
|
45 |
val report: string -> unit |
50503
50f141b34bb7
enable Isabelle/ML to produce uninterpreted result messages as well;
wenzelm
parents:
49647
diff
changeset
|
46 |
val result: serial * string -> unit |
46774 | 47 |
val protocol_message: Properties.T -> string -> unit |
14815 | 48 |
end; |
49 |
||
50 |
structure Output: OUTPUT = |
|
51 |
struct |
|
52 |
||
23616 | 53 |
(** print modes **) |
14881 | 54 |
|
23660
18765718cf62
type output = string indicates raw system output;
wenzelm
parents:
23616
diff
changeset
|
55 |
type output = string; (*raw system output*) |
18765718cf62
type output = string indicates raw system output;
wenzelm
parents:
23616
diff
changeset
|
56 |
|
23616 | 57 |
fun default_output s = (s, size s); |
23660
18765718cf62
type output = string indicates raw system output;
wenzelm
parents:
23616
diff
changeset
|
58 |
fun default_escape (s: output) = s; |
14815 | 59 |
|
23616 | 60 |
local |
61 |
val default = {output = default_output, escape = default_escape}; |
|
43684 | 62 |
val modes = Synchronized.var "Output.modes" (Symtab.make [("", default)]); |
23616 | 63 |
in |
43684 | 64 |
fun add_mode name output escape = |
65 |
Synchronized.change modes (Symtab.update_new (name, {output = output, escape = escape})); |
|
23616 | 66 |
fun get_mode () = |
43684 | 67 |
the_default default |
68 |
(Library.get_first (Symtab.lookup (Synchronized.value modes)) (print_mode_value ())); |
|
23616 | 69 |
end; |
14815 | 70 |
|
19265 | 71 |
fun output_width x = #output (get_mode ()) x; |
14815 | 72 |
val output = #1 o output_width; |
23727 | 73 |
|
23616 | 74 |
fun escape x = #escape (get_mode ()) x; |
14815 | 75 |
|
76 |
||
77 |
||
78 |
(** output channels **) |
|
79 |
||
39733
6d373e9dcb9d
renamed raw output primitives to emphasize their meaning -- not to be used in user-space;
wenzelm
parents:
38839
diff
changeset
|
80 |
(* raw output primitives -- not to be used in user-space *) |
14984 | 81 |
|
44389
a3b5fdfb04a3
tuned signature -- contrast physical output primitives versus Output.raw_message;
wenzelm
parents:
44270
diff
changeset
|
82 |
fun physical_stdout s = (TextIO.output (TextIO.stdOut, s); TextIO.flushOut TextIO.stdOut); |
a3b5fdfb04a3
tuned signature -- contrast physical output primitives versus Output.raw_message;
wenzelm
parents:
44270
diff
changeset
|
83 |
fun physical_stderr s = (TextIO.output (TextIO.stdErr, s); TextIO.flushOut TextIO.stdErr); |
14815 | 84 |
|
44389
a3b5fdfb04a3
tuned signature -- contrast physical output primitives versus Output.raw_message;
wenzelm
parents:
44270
diff
changeset
|
85 |
fun physical_writeln "" = () |
a3b5fdfb04a3
tuned signature -- contrast physical output primitives versus Output.raw_message;
wenzelm
parents:
44270
diff
changeset
|
86 |
| physical_writeln s = physical_stdout (suffix "\n" s); (*atomic output!*) |
14815 | 87 |
|
14984 | 88 |
|
89 |
(* Isabelle output channels *) |
|
90 |
||
40133
b61d52de66f0
more explicit indication of Output.Private_Hooks (still public to accomodate clones of Proof General for now);
wenzelm
parents:
40132
diff
changeset
|
91 |
structure Private_Hooks = |
b61d52de66f0
more explicit indication of Output.Private_Hooks (still public to accomodate clones of Proof General for now);
wenzelm
parents:
40132
diff
changeset
|
92 |
struct |
44389
a3b5fdfb04a3
tuned signature -- contrast physical output primitives versus Output.raw_message;
wenzelm
parents:
44270
diff
changeset
|
93 |
val writeln_fn = Unsynchronized.ref physical_writeln; |
40133
b61d52de66f0
more explicit indication of Output.Private_Hooks (still public to accomodate clones of Proof General for now);
wenzelm
parents:
40132
diff
changeset
|
94 |
val urgent_message_fn = Unsynchronized.ref (fn s => ! writeln_fn s); |
b61d52de66f0
more explicit indication of Output.Private_Hooks (still public to accomodate clones of Proof General for now);
wenzelm
parents:
40132
diff
changeset
|
95 |
val tracing_fn = Unsynchronized.ref (fn s => ! writeln_fn s); |
47999
3ffd885abe00
ignore empty messages even on tty, e.g. relevant for Isabelle_System.bash_output err output;
wenzelm
parents:
46774
diff
changeset
|
96 |
val warning_fn = Unsynchronized.ref (physical_writeln o prefix_lines "### "); |
3ffd885abe00
ignore empty messages even on tty, e.g. relevant for Isabelle_System.bash_output err output;
wenzelm
parents:
46774
diff
changeset
|
97 |
val error_fn = Unsynchronized.ref (fn (_: serial, s) => physical_writeln (prefix_lines "*** " s)); |
44389
a3b5fdfb04a3
tuned signature -- contrast physical output primitives versus Output.raw_message;
wenzelm
parents:
44270
diff
changeset
|
98 |
val prompt_fn = Unsynchronized.ref physical_stdout; |
43746
a41f618c641d
some support for raw messages, which bypass standard Symbol/YXML decoding;
wenzelm
parents:
43684
diff
changeset
|
99 |
val status_fn = Unsynchronized.ref (fn _: output => ()); |
a41f618c641d
some support for raw messages, which bypass standard Symbol/YXML decoding;
wenzelm
parents:
43684
diff
changeset
|
100 |
val report_fn = Unsynchronized.ref (fn _: output => ()); |
50503
50f141b34bb7
enable Isabelle/ML to produce uninterpreted result messages as well;
wenzelm
parents:
49647
diff
changeset
|
101 |
val result_fn = Unsynchronized.ref (fn _: serial * output => ()); |
46774 | 102 |
val protocol_message_fn: (Properties.T -> output -> unit) Unsynchronized.ref = |
103 |
Unsynchronized.ref (fn _ => fn _ => raise Fail "Output.protocol_message undefined in TTY mode"); |
|
40133
b61d52de66f0
more explicit indication of Output.Private_Hooks (still public to accomodate clones of Proof General for now);
wenzelm
parents:
40132
diff
changeset
|
104 |
end; |
14815 | 105 |
|
40133
b61d52de66f0
more explicit indication of Output.Private_Hooks (still public to accomodate clones of Proof General for now);
wenzelm
parents:
40132
diff
changeset
|
106 |
fun writeln s = ! Private_Hooks.writeln_fn (output s); |
b61d52de66f0
more explicit indication of Output.Private_Hooks (still public to accomodate clones of Proof General for now);
wenzelm
parents:
40132
diff
changeset
|
107 |
fun urgent_message s = ! Private_Hooks.urgent_message_fn (output s); |
b61d52de66f0
more explicit indication of Output.Private_Hooks (still public to accomodate clones of Proof General for now);
wenzelm
parents:
40132
diff
changeset
|
108 |
fun tracing s = ! Private_Hooks.tracing_fn (output s); |
b61d52de66f0
more explicit indication of Output.Private_Hooks (still public to accomodate clones of Proof General for now);
wenzelm
parents:
40132
diff
changeset
|
109 |
fun warning s = ! Private_Hooks.warning_fn (output s); |
44270
3eaad39e520c
more careful treatment of exception serial numbers, with propagation to message channel;
wenzelm
parents:
43760
diff
changeset
|
110 |
fun error_msg' (i, s) = ! Private_Hooks.error_fn (i, output s); |
3eaad39e520c
more careful treatment of exception serial numbers, with propagation to message channel;
wenzelm
parents:
43760
diff
changeset
|
111 |
fun error_msg s = error_msg' (serial (), s); |
40133
b61d52de66f0
more explicit indication of Output.Private_Hooks (still public to accomodate clones of Proof General for now);
wenzelm
parents:
40132
diff
changeset
|
112 |
fun prompt s = ! Private_Hooks.prompt_fn (output s); |
b61d52de66f0
more explicit indication of Output.Private_Hooks (still public to accomodate clones of Proof General for now);
wenzelm
parents:
40132
diff
changeset
|
113 |
fun status s = ! Private_Hooks.status_fn (output s); |
b61d52de66f0
more explicit indication of Output.Private_Hooks (still public to accomodate clones of Proof General for now);
wenzelm
parents:
40132
diff
changeset
|
114 |
fun report s = ! Private_Hooks.report_fn (output s); |
50503
50f141b34bb7
enable Isabelle/ML to produce uninterpreted result messages as well;
wenzelm
parents:
49647
diff
changeset
|
115 |
fun result (i, s) = ! Private_Hooks.result_fn (i, output s); |
46774 | 116 |
fun protocol_message props s = ! Private_Hooks.protocol_message_fn props (output s); |
15190 | 117 |
|
14815 | 118 |
end; |
119 |
||
32738 | 120 |
structure Basic_Output: BASIC_OUTPUT = Output; |
121 |
open Basic_Output; |