/* This starts the input reader on the standard input and 
   connects it to the default evaluator.

   We might create a new evaluator for symmetry.

   Note that the thread has lowish priority.

   Also not that the object referenced by this
   is in fact the evaluator.
   Another way to retrieve this is via a call to 
   the method 
         evaluator()
*/


/* 
   Declare this outside the local scope of the {...} below
   and hence it persists.
*/

java.lang.Thread readerThread = null;

{  // local scope

   // note that changing this to take no arguments
   // or an input stream will change the prompt.
   // This, will use the line number prompt,
   // not the task number.
   //       local reader = new NumberedInputReader();
//  local reader;
  InputReader reader;
  if(evaluator() instanceof org.omegahat.Environment.IO.PromptSource)
    reader = new org.omegahat.Environment.IO.InputReader((PromptSource)evaluator());
  else
    reader = new org.omegahat.Environment.IO.InputReader(DefaultPromptSource());

  if(evaluator() instanceof org.omegahat.Environment.IO.InputConsumer)
    reader.addInputConsumer(evaluator());
  else 
    reader.addInputConsumer(new org.omegahat.Environment.IO.EvaluatorInputConsumer(evaluator()));

/* We could simply call
     reader.run(); 
   but then this would block and we would never return.
   Instead, we put this into a thread. We can arrange to have it
   as a repeated task for the evaluator, but that is a different model.
   See (document to be written later).
*/  
  readerThread = new java.lang.Thread(reader);


   /*
      note that there are some interactions with GUIs
      if this thread has priority greater than the minimum.
      specifically the q(true) action won't work
      A value any higher than 3 has the effect of not giving
      the GUI thread any time (on a Sparc 20 with display on a Sparc 10)
      Alternatively, we can up the priority for the thread in which the 
      GUI runs. See the file Splash.
    */
  readerThread.setPriority(java.lang.Thread.MIN_PRIORITY);
  readerThread.start();
}

assign(Console.omega.DefaultUserThreadName, readerThread);



/*
Copyright (c) 1998, 1999 The Omega Project for Statistical Computing.
     All rights reserved.

     Redistribution and use in source and binary forms, with or without
     modification, are permitted provided that the following conditions are
     met:

       Redistributions of source code must retain the above copyright notice,
       this list of conditions and the following disclaimer.

       Redistributions in binary form must reproduce the above copyright
       notice, this list of conditions and the following disclaimer in the
       documentation and/or other materials provided with the distribution.

       Neither name of the Omega Project for Statistical Computing nor the 
       names of its contributors may be used to endorse or promote products 
       derived from this software without specific prior written permission.

     THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' AND ANY
     EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
     MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
     SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
     SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
     PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
     STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
     THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
*/
