1 (* Title: Pure/General/output.ML
2 Author: Makarius, Hagia Maria Sion Abbey (Jerusalem)
4 Isabelle output channels.
7 signature BASIC_OUTPUT =
9 val writeln: string -> unit
10 val tracing: string -> unit
11 val warning: string -> unit
12 val legacy_feature: string -> unit
19 val default_output: string -> output * int
20 val default_escape: output -> string
21 val add_mode: string -> (string -> output * int) -> (output -> string) -> unit
22 val output_width: string -> output * int
23 val output: string -> output
24 val escape: output -> string
25 val raw_stdout: output -> unit
26 val raw_stderr: output -> unit
27 val raw_writeln: output -> unit
28 structure Private_Hooks:
30 val writeln_fn: (output -> unit) Unsynchronized.ref
31 val urgent_message_fn: (output -> unit) Unsynchronized.ref
32 val tracing_fn: (output -> unit) Unsynchronized.ref
33 val warning_fn: (output -> unit) Unsynchronized.ref
34 val error_fn: (output -> unit) Unsynchronized.ref
35 val prompt_fn: (output -> unit) Unsynchronized.ref
36 val status_fn: (output -> unit) Unsynchronized.ref
37 val report_fn: (output -> unit) Unsynchronized.ref
39 val urgent_message: string -> unit
40 val error_msg: string -> unit
41 val prompt: string -> unit
42 val status: string -> unit
43 val report: string -> unit
46 structure Output: OUTPUT =
51 type output = string; (*raw system output*)
53 fun default_output s = (s, size s);
54 fun default_escape (s: output) = s;
57 val default = {output = default_output, escape = default_escape};
58 val modes = Synchronized.var "Output.modes" (Symtab.make [("", default)]);
60 fun add_mode name output escape =
61 Synchronized.change modes (Symtab.update_new (name, {output = output, escape = escape}));
64 (Library.get_first (Symtab.lookup (Synchronized.value modes)) (print_mode_value ()));
67 fun output_width x = #output (get_mode ()) x;
68 val output = #1 o output_width;
70 fun escape x = #escape (get_mode ()) x;
74 (** output channels **)
76 (* raw output primitives -- not to be used in user-space *)
78 fun raw_stdout s = (TextIO.output (TextIO.stdOut, s); TextIO.flushOut TextIO.stdOut);
79 fun raw_stderr s = (TextIO.output (TextIO.stdErr, s); TextIO.flushOut TextIO.stdErr);
81 fun raw_writeln "" = ()
82 | raw_writeln s = raw_stdout (suffix "\n" s); (*atomic output!*)
85 (* Isabelle output channels *)
87 structure Private_Hooks =
89 val writeln_fn = Unsynchronized.ref raw_writeln;
90 val urgent_message_fn = Unsynchronized.ref (fn s => ! writeln_fn s);
91 val tracing_fn = Unsynchronized.ref (fn s => ! writeln_fn s);
92 val warning_fn = Unsynchronized.ref (raw_stdout o suffix "\n" o prefix_lines "### ");
93 val error_fn = Unsynchronized.ref (raw_stdout o suffix "\n" o prefix_lines "*** ");
94 val prompt_fn = Unsynchronized.ref raw_stdout;
95 val status_fn = Unsynchronized.ref (fn _: string => ());
96 val report_fn = Unsynchronized.ref (fn _: string => ());
99 fun writeln s = ! Private_Hooks.writeln_fn (output s);
100 fun urgent_message s = ! Private_Hooks.urgent_message_fn (output s);
101 fun tracing s = ! Private_Hooks.tracing_fn (output s);
102 fun warning s = ! Private_Hooks.warning_fn (output s);
103 fun error_msg s = ! Private_Hooks.error_fn (output s);
104 fun prompt s = ! Private_Hooks.prompt_fn (output s);
105 fun status s = ! Private_Hooks.status_fn (output s);
106 fun report s = ! Private_Hooks.report_fn (output s);
108 fun legacy_feature s = warning ("Legacy feature! " ^ s);
112 structure Basic_Output: BASIC_OUTPUT = Output;