| author | wenzelm | 
| Sat, 14 Sep 2013 13:59:57 +0200 | |
| changeset 53634 | ab5d01b69a07 | 
| parent 53403 | c09f4005d6bd | 
| child 54387 | 890e983cb07b | 
| 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: 
40133diff
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: 
17539diff
changeset | 9 | val writeln: string -> unit | 
| 
216692feebab
removed special ERROR handling stuff (transform_error etc.);
 wenzelm parents: 
17539diff
changeset | 10 | val tracing: string -> unit | 
| 
216692feebab
removed special ERROR handling stuff (transform_error etc.);
 wenzelm parents: 
17539diff
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: 
40125diff
changeset | 17 | type output = string | 
| 23660 
18765718cf62
type output = string indicates raw system output;
 wenzelm parents: 
23616diff
changeset | 18 | val default_output: string -> output * int | 
| 
18765718cf62
type output = string indicates raw system output;
 wenzelm parents: 
23616diff
changeset | 19 | val default_escape: output -> string | 
| 
18765718cf62
type output = string indicates raw system output;
 wenzelm parents: 
23616diff
changeset | 20 | val add_mode: string -> (string -> output * int) -> (output -> string) -> unit | 
| 
18765718cf62
type output = string indicates raw system output;
 wenzelm parents: 
23616diff
changeset | 21 | val output_width: string -> output * int | 
| 
18765718cf62
type output = string indicates raw system output;
 wenzelm parents: 
23616diff
changeset | 22 | val output: string -> output | 
| 
18765718cf62
type output = string indicates raw system output;
 wenzelm parents: 
23616diff
changeset | 23 | val escape: output -> string | 
| 44389 
a3b5fdfb04a3
tuned signature -- contrast physical output primitives versus Output.raw_message;
 wenzelm parents: 
44270diff
changeset | 24 | val physical_stdout: output -> unit | 
| 
a3b5fdfb04a3
tuned signature -- contrast physical output primitives versus Output.raw_message;
 wenzelm parents: 
44270diff
changeset | 25 | val physical_stderr: output -> unit | 
| 
a3b5fdfb04a3
tuned signature -- contrast physical output primitives versus Output.raw_message;
 wenzelm parents: 
44270diff
changeset | 26 | val physical_writeln: output -> unit | 
| 51661 | 27 | exception Protocol_Message of Properties.T | 
| 52852 | 28 | structure Internal: | 
| 40133 
b61d52de66f0
more explicit indication of Output.Private_Hooks (still public to accomodate clones of Proof General for now);
 wenzelm parents: 
40132diff
changeset | 29 | sig | 
| 
b61d52de66f0
more explicit indication of Output.Private_Hooks (still public to accomodate clones of Proof General for now);
 wenzelm parents: 
40132diff
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: 
40132diff
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: 
40132diff
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: 
40132diff
changeset | 33 | val warning_fn: (output -> unit) Unsynchronized.ref | 
| 44270 
3eaad39e520c
more careful treatment of exception serial numbers, with propagation to message channel;
 wenzelm parents: 
43760diff
changeset | 34 | 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: 
40132diff
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: 
40132diff
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: 
40132diff
changeset | 37 | val report_fn: (output -> unit) Unsynchronized.ref | 
| 52854 
92932931bd82
more general Output.result: allow to update arbitrary properties;
 wenzelm parents: 
52852diff
changeset | 38 | val result_fn: (Properties.T -> output -> unit) Unsynchronized.ref | 
| 46774 | 39 | 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: 
40132diff
changeset | 40 | end | 
| 40132 
7ee65dbffa31
renamed Output.priority to Output.urgent_message to emphasize its special role more clearly;
 wenzelm parents: 
40131diff
changeset | 41 | val urgent_message: string -> unit | 
| 44270 
3eaad39e520c
more careful treatment of exception serial numbers, with propagation to message channel;
 wenzelm parents: 
43760diff
changeset | 42 | val error_msg': serial * string -> unit | 
| 25845 
c448a5f15f31
added explicit prompt channel (prompt_fn/prompt);
 wenzelm parents: 
25686diff
changeset | 43 | val error_msg: string -> unit | 
| 
c448a5f15f31
added explicit prompt channel (prompt_fn/prompt);
 wenzelm parents: 
25686diff
changeset | 44 | val prompt: string -> unit | 
| 27605 | 45 | val status: string -> unit | 
| 38236 
d8c7be27e01d
explicitly distinguish Output.status (essential feedback) vs. Output.report (useful markup);
 wenzelm parents: 
37784diff
changeset | 46 | val report: string -> unit | 
| 52854 
92932931bd82
more general Output.result: allow to update arbitrary properties;
 wenzelm parents: 
52852diff
changeset | 47 | val result: Properties.T -> string -> unit | 
| 46774 | 48 | val protocol_message: Properties.T -> string -> unit | 
| 51661 | 49 | val try_protocol_message: Properties.T -> string -> unit | 
| 14815 | 50 | end; | 
| 51 | ||
| 52 | structure Output: OUTPUT = | |
| 53 | struct | |
| 54 | ||
| 23616 | 55 | (** print modes **) | 
| 14881 | 56 | |
| 23660 
18765718cf62
type output = string indicates raw system output;
 wenzelm parents: 
23616diff
changeset | 57 | type output = string; (*raw system output*) | 
| 
18765718cf62
type output = string indicates raw system output;
 wenzelm parents: 
23616diff
changeset | 58 | |
| 23616 | 59 | fun default_output s = (s, size s); | 
| 23660 
18765718cf62
type output = string indicates raw system output;
 wenzelm parents: 
23616diff
changeset | 60 | fun default_escape (s: output) = s; | 
| 14815 | 61 | |
| 23616 | 62 | local | 
| 63 |   val default = {output = default_output, escape = default_escape};
 | |
| 43684 | 64 |   val modes = Synchronized.var "Output.modes" (Symtab.make [("", default)]);
 | 
| 23616 | 65 | in | 
| 43684 | 66 | fun add_mode name output escape = | 
| 67 |     Synchronized.change modes (Symtab.update_new (name, {output = output, escape = escape}));
 | |
| 23616 | 68 | fun get_mode () = | 
| 43684 | 69 | the_default default | 
| 70 | (Library.get_first (Symtab.lookup (Synchronized.value modes)) (print_mode_value ())); | |
| 23616 | 71 | end; | 
| 14815 | 72 | |
| 19265 | 73 | fun output_width x = #output (get_mode ()) x; | 
| 14815 | 74 | val output = #1 o output_width; | 
| 23727 | 75 | |
| 23616 | 76 | fun escape x = #escape (get_mode ()) x; | 
| 14815 | 77 | |
| 78 | ||
| 79 | ||
| 80 | (** output channels **) | |
| 81 | ||
| 39733 
6d373e9dcb9d
renamed raw output primitives to emphasize their meaning -- not to be used in user-space;
 wenzelm parents: 
38839diff
changeset | 82 | (* raw output primitives -- not to be used in user-space *) | 
| 14984 | 83 | |
| 44389 
a3b5fdfb04a3
tuned signature -- contrast physical output primitives versus Output.raw_message;
 wenzelm parents: 
44270diff
changeset | 84 | 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: 
44270diff
changeset | 85 | fun physical_stderr s = (TextIO.output (TextIO.stdErr, s); TextIO.flushOut TextIO.stdErr); | 
| 14815 | 86 | |
| 44389 
a3b5fdfb04a3
tuned signature -- contrast physical output primitives versus Output.raw_message;
 wenzelm parents: 
44270diff
changeset | 87 | fun physical_writeln "" = () | 
| 
a3b5fdfb04a3
tuned signature -- contrast physical output primitives versus Output.raw_message;
 wenzelm parents: 
44270diff
changeset | 88 | | physical_writeln s = physical_stdout (suffix "\n" s); (*atomic output!*) | 
| 14815 | 89 | |
| 14984 | 90 | |
| 91 | (* Isabelle output channels *) | |
| 92 | ||
| 51661 | 93 | exception Protocol_Message of Properties.T; | 
| 94 | ||
| 52852 | 95 | structure Internal = | 
| 40133 
b61d52de66f0
more explicit indication of Output.Private_Hooks (still public to accomodate clones of Proof General for now);
 wenzelm parents: 
40132diff
changeset | 96 | struct | 
| 44389 
a3b5fdfb04a3
tuned signature -- contrast physical output primitives versus Output.raw_message;
 wenzelm parents: 
44270diff
changeset | 97 | val writeln_fn = Unsynchronized.ref physical_writeln; | 
| 53403 
c09f4005d6bd
some explicit indication of Proof General legacy;
 wenzelm parents: 
52854diff
changeset | 98 | val urgent_message_fn = Unsynchronized.ref (fn s => ! writeln_fn s); (*Proof General legacy*) | 
| 40133 
b61d52de66f0
more explicit indication of Output.Private_Hooks (still public to accomodate clones of Proof General for now);
 wenzelm parents: 
40132diff
changeset | 99 | 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: 
46774diff
changeset | 100 | 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: 
46774diff
changeset | 101 | 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: 
44270diff
changeset | 102 | val prompt_fn = Unsynchronized.ref physical_stdout; | 
| 43746 
a41f618c641d
some support for raw messages, which bypass standard Symbol/YXML decoding;
 wenzelm parents: 
43684diff
changeset | 103 | val status_fn = Unsynchronized.ref (fn _: output => ()); | 
| 
a41f618c641d
some support for raw messages, which bypass standard Symbol/YXML decoding;
 wenzelm parents: 
43684diff
changeset | 104 | val report_fn = Unsynchronized.ref (fn _: output => ()); | 
| 52854 
92932931bd82
more general Output.result: allow to update arbitrary properties;
 wenzelm parents: 
52852diff
changeset | 105 | val result_fn = Unsynchronized.ref (fn _: Properties.T => fn _: output => ()); | 
| 46774 | 106 | val protocol_message_fn: (Properties.T -> output -> unit) Unsynchronized.ref = | 
| 51661 | 107 | Unsynchronized.ref (fn props => fn _ => raise Protocol_Message props); | 
| 40133 
b61d52de66f0
more explicit indication of Output.Private_Hooks (still public to accomodate clones of Proof General for now);
 wenzelm parents: 
40132diff
changeset | 108 | end; | 
| 14815 | 109 | |
| 52852 | 110 | fun writeln s = ! Internal.writeln_fn (output s); | 
| 53403 
c09f4005d6bd
some explicit indication of Proof General legacy;
 wenzelm parents: 
52854diff
changeset | 111 | fun urgent_message s = ! Internal.urgent_message_fn (output s); (*Proof General legacy*) | 
| 52852 | 112 | fun tracing s = ! Internal.tracing_fn (output s); | 
| 113 | fun warning s = ! Internal.warning_fn (output s); | |
| 114 | fun error_msg' (i, s) = ! Internal.error_fn (i, output s); | |
| 44270 
3eaad39e520c
more careful treatment of exception serial numbers, with propagation to message channel;
 wenzelm parents: 
43760diff
changeset | 115 | fun error_msg s = error_msg' (serial (), s); | 
| 52852 | 116 | fun prompt s = ! Internal.prompt_fn (output s); | 
| 117 | fun status s = ! Internal.status_fn (output s); | |
| 118 | fun report s = ! Internal.report_fn (output s); | |
| 52854 
92932931bd82
more general Output.result: allow to update arbitrary properties;
 wenzelm parents: 
52852diff
changeset | 119 | fun result props s = ! Internal.result_fn props (output s); | 
| 52852 | 120 | fun protocol_message props s = ! Internal.protocol_message_fn props (output s); | 
| 51661 | 121 | fun try_protocol_message props s = protocol_message props s handle Protocol_Message _ => (); | 
| 15190 | 122 | |
| 14815 | 123 | end; | 
| 124 | ||
| 32738 | 125 | structure Basic_Output: BASIC_OUTPUT = Output; | 
| 126 | open Basic_Output; |