src/Tools/jEdit/src/scala_console.scala
changeset 73367 77ef8bef0593
parent 73340 0ffcad1f6130
child 73702 7202e12cb324
equal deleted inserted replaced
73366:5f388e514ab8 73367:77ef8bef0593
    28   {
    28   {
    29     val buf = new StringBuilder(100)
    29     val buf = new StringBuilder(100)
    30 
    30 
    31     override def flush(): Unit =
    31     override def flush(): Unit =
    32     {
    32     {
    33       val s = buf.synchronized { val s = buf.toString; buf.clear; s }
    33       val s = buf.synchronized { val s = buf.toString; buf.clear(); s }
    34       val str = UTF8.decode_permissive(s)
    34       val str = UTF8.decode_permissive(s)
    35       GUI_Thread.later {
    35       GUI_Thread.later {
    36         if (global_out == null) System.out.print(str)
    36         if (global_out == null) System.out.print(str)
    37         else global_out.writeAttrs(null, str)
    37         else global_out.writeAttrs(null, str)
    38       }
    38       }
    95     extends Request
    95     extends Request
    96 
    96 
    97   private class Interpreter
    97   private class Interpreter
    98   {
    98   {
    99     private val running = Synchronized[Option[Thread]](None)
    99     private val running = Synchronized[Option[Thread]](None)
   100     def interrupt: Unit = running.change(opt => { opt.foreach(_.interrupt); opt })
   100     def interrupt(): Unit = running.change(opt => { opt.foreach(_.interrupt()); opt })
   101 
   101 
   102     private val interp =
   102     private val interp =
   103       Scala.Compiler.context(error = report_error, jar_dirs = JEdit_Lib.directories).
   103       Scala.Compiler.context(error = report_error, jar_dirs = JEdit_Lib.directories).
   104         interpreter(
   104         interpreter(
   105           print_writer = new PrintWriter(console_writer, true),
   105           print_writer = new PrintWriter(console_writer, true),
   144 
   144 
   145   override def closeConsole(console: Console): Unit =
   145   override def closeConsole(console: Console): Unit =
   146   {
   146   {
   147     interpreters.get(console) match {
   147     interpreters.get(console) match {
   148       case Some(interp) =>
   148       case Some(interp) =>
   149         interp.interrupt
   149         interp.interrupt()
   150         interp.thread.shutdown
   150         interp.thread.shutdown()
   151         interpreters -= console
   151         interpreters -= console
   152       case None =>
   152       case None =>
   153     }
   153     }
   154   }
   154   }
   155 
   155 
   175   {
   175   {
   176     interpreters(console).thread.send(Execute(console, out, err, command))
   176     interpreters(console).thread.send(Execute(console, out, err, command))
   177   }
   177   }
   178 
   178 
   179   override def stop(console: Console): Unit =
   179   override def stop(console: Console): Unit =
   180     interpreters.get(console).foreach(_.interrupt)
   180     interpreters.get(console).foreach(_.interrupt())
   181 }
   181 }