src/Pure/Tools/print_operation.scala
author wenzelm
Wed, 23 Dec 2020 23:19:09 +0100
changeset 72993 6ead333e450d
parent 72215 8f9cffa78112
child 75393 87ebf5a50283
permissions -rw-r--r--
more robust defaults: spurious problems with parallel invocations and interrupts;

/*  Title:      Pure/Tools/print_operation.scala
    Author:     Makarius

Print operations as asynchronous query.
*/

package isabelle


object Print_Operation
{
  def get(session: Session): List[(String, String)] =
    session.get_protocol_handler(classOf[Handler]) match {
      case Some(h) => h.get
      case _ => Nil
    }


  /* protocol handler */

  class Handler extends Session.Protocol_Handler
  {
    private val print_operations = Synchronized[List[(String, String)]](Nil)

    def get: List[(String, String)] = print_operations.value

    override def init(session: Session): Unit =
      session.protocol_command(Markup.PRINT_OPERATIONS)

    private def put(msg: Prover.Protocol_Output): Boolean =
    {
      val ops =
      {
        import XML.Decode._
        list(pair(string, string))(Symbol.decode_yxml(msg.text))
      }
      print_operations.change(_ => ops)
      true
    }

    override val functions = List(Markup.PRINT_OPERATIONS -> put)
  }
}