author | wenzelm |
Mon, 11 Jul 2011 22:50:29 +0200 | |
changeset 43760 | ef8375a4dae4 |
parent 43748 | c70bd78ec83c |
child 44270 | 3eaad39e520c |
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 |
22826 | 12 |
val legacy_feature: string -> unit |
14815 | 13 |
end; |
14 |
||
15 |
signature OUTPUT = |
|
16 |
sig |
|
17 |
include BASIC_OUTPUT |
|
40131
7cbebd636e79
explicitly qualify type Output.output, which is a slightly odd internal feature;
wenzelm
parents:
40125
diff
changeset
|
18 |
type output = string |
23660
18765718cf62
type output = string indicates raw system output;
wenzelm
parents:
23616
diff
changeset
|
19 |
val default_output: string -> output * int |
18765718cf62
type output = string indicates raw system output;
wenzelm
parents:
23616
diff
changeset
|
20 |
val default_escape: output -> string |
18765718cf62
type output = string indicates raw system output;
wenzelm
parents:
23616
diff
changeset
|
21 |
val add_mode: string -> (string -> output * int) -> (output -> string) -> unit |
18765718cf62
type output = string indicates raw system output;
wenzelm
parents:
23616
diff
changeset
|
22 |
val output_width: string -> output * int |
18765718cf62
type output = string indicates raw system output;
wenzelm
parents:
23616
diff
changeset
|
23 |
val output: string -> output |
18765718cf62
type output = string indicates raw system output;
wenzelm
parents:
23616
diff
changeset
|
24 |
val escape: output -> string |
39733
6d373e9dcb9d
renamed raw output primitives to emphasize their meaning -- not to be used in user-space;
wenzelm
parents:
38839
diff
changeset
|
25 |
val raw_stdout: output -> unit |
6d373e9dcb9d
renamed raw output primitives to emphasize their meaning -- not to be used in user-space;
wenzelm
parents:
38839
diff
changeset
|
26 |
val raw_stderr: output -> unit |
6d373e9dcb9d
renamed raw output primitives to emphasize their meaning -- not to be used in user-space;
wenzelm
parents:
38839
diff
changeset
|
27 |
val raw_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
|
28 |
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
|
29 |
sig |
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 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
|
31 |
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
|
32 |
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
|
33 |
val warning_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
|
34 |
val error_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 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
|
36 |
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
|
37 |
val report_fn: (output -> unit) Unsynchronized.ref |
43746
a41f618c641d
some support for raw messages, which bypass standard Symbol/YXML decoding;
wenzelm
parents:
43684
diff
changeset
|
38 |
val raw_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 |
25845
c448a5f15f31
added explicit prompt channel (prompt_fn/prompt);
wenzelm
parents:
25686
diff
changeset
|
41 |
val error_msg: string -> unit |
c448a5f15f31
added explicit prompt channel (prompt_fn/prompt);
wenzelm
parents:
25686
diff
changeset
|
42 |
val prompt: string -> unit |
27605 | 43 |
val status: string -> unit |
38236
d8c7be27e01d
explicitly distinguish Output.status (essential feedback) vs. Output.report (useful markup);
wenzelm
parents:
37784
diff
changeset
|
44 |
val report: string -> unit |
43746
a41f618c641d
some support for raw messages, which bypass standard Symbol/YXML decoding;
wenzelm
parents:
43684
diff
changeset
|
45 |
val raw_message: Properties.T -> string -> unit |
14815 | 46 |
end; |
47 |
||
48 |
structure Output: OUTPUT = |
|
49 |
struct |
|
50 |
||
23616 | 51 |
(** print modes **) |
14881 | 52 |
|
23660
18765718cf62
type output = string indicates raw system output;
wenzelm
parents:
23616
diff
changeset
|
53 |
type output = string; (*raw system output*) |
18765718cf62
type output = string indicates raw system output;
wenzelm
parents:
23616
diff
changeset
|
54 |
|
23616 | 55 |
fun default_output s = (s, size s); |
23660
18765718cf62
type output = string indicates raw system output;
wenzelm
parents:
23616
diff
changeset
|
56 |
fun default_escape (s: output) = s; |
14815 | 57 |
|
23616 | 58 |
local |
59 |
val default = {output = default_output, escape = default_escape}; |
|
43684 | 60 |
val modes = Synchronized.var "Output.modes" (Symtab.make [("", default)]); |
23616 | 61 |
in |
43684 | 62 |
fun add_mode name output escape = |
63 |
Synchronized.change modes (Symtab.update_new (name, {output = output, escape = escape})); |
|
23616 | 64 |
fun get_mode () = |
43684 | 65 |
the_default default |
66 |
(Library.get_first (Symtab.lookup (Synchronized.value modes)) (print_mode_value ())); |
|
23616 | 67 |
end; |
14815 | 68 |
|
19265 | 69 |
fun output_width x = #output (get_mode ()) x; |
14815 | 70 |
val output = #1 o output_width; |
23727 | 71 |
|
23616 | 72 |
fun escape x = #escape (get_mode ()) x; |
14815 | 73 |
|
74 |
||
75 |
||
76 |
(** output channels **) |
|
77 |
||
39733
6d373e9dcb9d
renamed raw output primitives to emphasize their meaning -- not to be used in user-space;
wenzelm
parents:
38839
diff
changeset
|
78 |
(* raw output primitives -- not to be used in user-space *) |
14984 | 79 |
|
39733
6d373e9dcb9d
renamed raw output primitives to emphasize their meaning -- not to be used in user-space;
wenzelm
parents:
38839
diff
changeset
|
80 |
fun raw_stdout s = (TextIO.output (TextIO.stdOut, s); TextIO.flushOut TextIO.stdOut); |
6d373e9dcb9d
renamed raw output primitives to emphasize their meaning -- not to be used in user-space;
wenzelm
parents:
38839
diff
changeset
|
81 |
fun raw_stderr s = (TextIO.output (TextIO.stdErr, s); TextIO.flushOut TextIO.stdErr); |
14815 | 82 |
|
39733
6d373e9dcb9d
renamed raw output primitives to emphasize their meaning -- not to be used in user-space;
wenzelm
parents:
38839
diff
changeset
|
83 |
fun raw_writeln "" = () |
6d373e9dcb9d
renamed raw output primitives to emphasize their meaning -- not to be used in user-space;
wenzelm
parents:
38839
diff
changeset
|
84 |
| raw_writeln s = raw_stdout (suffix "\n" s); (*atomic output!*) |
14815 | 85 |
|
14984 | 86 |
|
87 |
(* Isabelle output channels *) |
|
88 |
||
40133
b61d52de66f0
more explicit indication of Output.Private_Hooks (still public to accomodate clones of Proof General for now);
wenzelm
parents:
40132
diff
changeset
|
89 |
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
|
90 |
struct |
b61d52de66f0
more explicit indication of Output.Private_Hooks (still public to accomodate clones of Proof General for now);
wenzelm
parents:
40132
diff
changeset
|
91 |
val writeln_fn = Unsynchronized.ref raw_writeln; |
b61d52de66f0
more explicit indication of Output.Private_Hooks (still public to accomodate clones of Proof General for now);
wenzelm
parents:
40132
diff
changeset
|
92 |
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
|
93 |
val tracing_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
|
94 |
val warning_fn = Unsynchronized.ref (raw_stdout o suffix "\n" o prefix_lines "### "); |
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 error_fn = Unsynchronized.ref (raw_stdout o suffix "\n" o prefix_lines "*** "); |
b61d52de66f0
more explicit indication of Output.Private_Hooks (still public to accomodate clones of Proof General for now);
wenzelm
parents:
40132
diff
changeset
|
96 |
val prompt_fn = Unsynchronized.ref raw_stdout; |
43746
a41f618c641d
some support for raw messages, which bypass standard Symbol/YXML decoding;
wenzelm
parents:
43684
diff
changeset
|
97 |
val status_fn = Unsynchronized.ref (fn _: output => ()); |
a41f618c641d
some support for raw messages, which bypass standard Symbol/YXML decoding;
wenzelm
parents:
43684
diff
changeset
|
98 |
val report_fn = Unsynchronized.ref (fn _: output => ()); |
43760 | 99 |
val raw_message_fn: (Properties.T -> output -> unit) Unsynchronized.ref = |
100 |
Unsynchronized.ref (fn _ => fn _ => raise Fail "Output.raw_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
|
101 |
end; |
14815 | 102 |
|
40133
b61d52de66f0
more explicit indication of Output.Private_Hooks (still public to accomodate clones of Proof General for now);
wenzelm
parents:
40132
diff
changeset
|
103 |
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
|
104 |
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
|
105 |
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
|
106 |
fun warning s = ! Private_Hooks.warning_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 error_msg s = ! Private_Hooks.error_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 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
|
109 |
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
|
110 |
fun report s = ! Private_Hooks.report_fn (output s); |
43746
a41f618c641d
some support for raw messages, which bypass standard Symbol/YXML decoding;
wenzelm
parents:
43684
diff
changeset
|
111 |
fun raw_message props s = ! Private_Hooks.raw_message_fn props (output s); |
15190 | 112 |
|
37784
1d639d28832c
removed impractical tolerate_legacy_features flag;
wenzelm
parents:
32966
diff
changeset
|
113 |
fun legacy_feature s = warning ("Legacy feature! " ^ s); |
22826 | 114 |
|
14815 | 115 |
end; |
116 |
||
32738 | 117 |
structure Basic_Output: BASIC_OUTPUT = Output; |
118 |
open Basic_Output; |