src/Pure/General/output.scala
author wenzelm
Mon, 02 Dec 2024 22:16:29 +0100
changeset 81541 5335b1ca6233
parent 80817 e31ebb2be437
permissions -rw-r--r--
more elementary operation Term.variant_bounds: only for bounds vs. frees, no consts, no tfrees;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
57453
77d13a98f1c8 clarified quasi-generic PIDE;
wenzelm
parents: 56831
diff changeset
     1
/*  Title:      Pure/General/output.scala
56782
433cf57550fa more systematic Isabelle output, like in classic Isabelle/ML (without markup);
wenzelm
parents:
diff changeset
     2
    Author:     Makarius
433cf57550fa more systematic Isabelle output, like in classic Isabelle/ML (without markup);
wenzelm
parents:
diff changeset
     3
77500
bbb78dba6f68 tuned signature;
wenzelm
parents: 75393
diff changeset
     4
Console output channels.
56782
433cf57550fa more systematic Isabelle output, like in classic Isabelle/ML (without markup);
wenzelm
parents:
diff changeset
     5
*/
433cf57550fa more systematic Isabelle output, like in classic Isabelle/ML (without markup);
wenzelm
parents:
diff changeset
     6
433cf57550fa more systematic Isabelle output, like in classic Isabelle/ML (without markup);
wenzelm
parents:
diff changeset
     7
package isabelle
433cf57550fa more systematic Isabelle output, like in classic Isabelle/ML (without markup);
wenzelm
parents:
diff changeset
     8
433cf57550fa more systematic Isabelle output, like in classic Isabelle/ML (without markup);
wenzelm
parents:
diff changeset
     9
75393
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 73340
diff changeset
    10
object Output {
80817
e31ebb2be437 clarified signature;
wenzelm
parents: 80480
diff changeset
    11
  def writeln_text(msg: String): String = Protocol_Message.clean_output(msg)
65828
02dd430d80c5 tuned signature;
wenzelm
parents: 64370
diff changeset
    12
71647
7b0656fa783b clarified signature;
wenzelm
parents: 71164
diff changeset
    13
  def warning_prefix(s: String): String = Library.prefix_lines("### ", s)
80817
e31ebb2be437 clarified signature;
wenzelm
parents: 80480
diff changeset
    14
  def warning_text(msg: String): String = warning_prefix(Protocol_Message.clean_output(msg))
65828
02dd430d80c5 tuned signature;
wenzelm
parents: 64370
diff changeset
    15
77501
2d8815f98537 tuned signature;
wenzelm
parents: 77500
diff changeset
    16
  def error_message_prefix(s: String): String = Library.prefix_lines("*** ", s)
80817
e31ebb2be437 clarified signature;
wenzelm
parents: 80480
diff changeset
    17
  def error_message_text(msg: String): String =
e31ebb2be437 clarified signature;
wenzelm
parents: 80480
diff changeset
    18
    error_message_prefix(Protocol_Message.clean_output(msg))
59671
9715eb8e9408 more precise position information in Isabelle/Scala, with YXML markup as in Isabelle/ML;
wenzelm
parents: 57453
diff changeset
    19
77500
bbb78dba6f68 tuned signature;
wenzelm
parents: 75393
diff changeset
    20
  def output(s: String, stdout: Boolean = false, include_empty: Boolean = false): Unit =
bbb78dba6f68 tuned signature;
wenzelm
parents: 75393
diff changeset
    21
    if (s.nonEmpty || include_empty) {
bbb78dba6f68 tuned signature;
wenzelm
parents: 75393
diff changeset
    22
      if (stdout) Console.print(s + "\n") else Console.err.print(s + "\n")
62553
d2e0d626fb96 tuned signature;
wenzelm
parents: 62297
diff changeset
    23
    }
d2e0d626fb96 tuned signature;
wenzelm
parents: 62297
diff changeset
    24
77500
bbb78dba6f68 tuned signature;
wenzelm
parents: 75393
diff changeset
    25
  def writeln(msg: String, stdout: Boolean = false, include_empty: Boolean = false): Unit =
bbb78dba6f68 tuned signature;
wenzelm
parents: 75393
diff changeset
    26
    output(writeln_text(msg), stdout = stdout, include_empty = include_empty)
62553
d2e0d626fb96 tuned signature;
wenzelm
parents: 62297
diff changeset
    27
77500
bbb78dba6f68 tuned signature;
wenzelm
parents: 75393
diff changeset
    28
  def warning(msg: String, stdout: Boolean = false, include_empty: Boolean = false): Unit =
bbb78dba6f68 tuned signature;
wenzelm
parents: 75393
diff changeset
    29
    output(warning_text(msg), stdout = stdout, include_empty = include_empty)
bbb78dba6f68 tuned signature;
wenzelm
parents: 75393
diff changeset
    30
bbb78dba6f68 tuned signature;
wenzelm
parents: 75393
diff changeset
    31
  def error_message(msg: String, stdout: Boolean = false, include_empty: Boolean = false): Unit =
bbb78dba6f68 tuned signature;
wenzelm
parents: 75393
diff changeset
    32
    output(error_message_text(msg), stdout = stdout, include_empty = include_empty)
56782
433cf57550fa more systematic Isabelle output, like in classic Isabelle/ML (without markup);
wenzelm
parents:
diff changeset
    33
}