package org.sikuli.script;

import java.awt.*;
import java.awt.event.*;
import java.awt.Robot.*;
import java.awt.image.*;
import java.io.*;
import java.nio.charset.*;
import java.nio.*;
import java.util.*;
import javax.imageio.ImageIO;
import javax.swing.*;


public class SikuliScript {
   public final static int DEFAULT_SERVER_PORT = 7458;

   public SikuliScript() throws AWTException{
   }

   public void setShowActions(boolean flag){
      Settings.ShowActions = flag;
      if(flag){
         if(Settings.MoveMouseDelay < 1f)
            Settings.MoveMouseDelay = 1f;
      }
   }

   public String input(String msg){
      return (String)JOptionPane.showInputDialog(msg);
   }
   
   public int switchApp(String appName){
      if(App.focus(appName) != null)
         return 0;
      return -1;
   }

   public int openApp(String appName){
      if(App.open(appName) != null)
         return 0;
      return -1;
   }

   public int closeApp(String appName){
      return App.close(appName);
   }
   
   public void popup(String message){
      JOptionPane.showMessageDialog(null, message, 
                                    "Sikuli", JOptionPane.PLAIN_MESSAGE);
   }

   public String run(String cmdline){
      String lines="";

      try {
         String line;
         Process p = Runtime.getRuntime().exec(cmdline);
         BufferedReader input = 
            new BufferedReader
            (new InputStreamReader(p.getInputStream()));
         while ((line = input.readLine()) != null) {
            lines = lines + '\n' + line;
         }
      } 
      catch (Exception err) {
         err.printStackTrace();
      }
      return lines;

   }

   private static void startServerMode(int port){
      /*
      SikuliServer serv = new SikuliServer(port);
      serv.start();
      */
   }

   public static void main(String[] args){
      if(args.length == 0 ){
         System.out.println("Usage: sikuli-script [-s] [file.sikuli]");
         return;
      }
      for (int i = 0; i < args.length; i++) {
         if(args[i].equals("-s")){
            startServerMode(DEFAULT_SERVER_PORT);
         }
         else{
            try {
               ScriptRunner runner = new ScriptRunner(args);
               runner.runPython(args[i]);
            }
            catch(IOException e) {
               e.printStackTrace();
            }
         }
      }
   }

}


@@ -252,16 +252,47 @@
 ing.*;%0A%0A
+import org.python.util.jython;%0A
 %0Apublic 
@@ -1828,24 +1828,115 @@
    */%0A   %7D%0A%0A
+   private static void startInteractiveMode(String%5B%5D args)%7B%0A      jython.main(args);%0A   %7D%0A%0A
    public st
@@ -2044,16 +2044,21 @@
 i-script
+ %5B-i%5D
  %5B-s%5D %5Bf
@@ -2231,32 +2231,123 @@
 RT);%0A         %7D%0A
+         else if(args%5Bi%5D.equals(%22-i%22))%7B%0A            startInteractiveMode(args);%0A         %7D%0A
          else%7B%0A 

add interactive mode (-i) to sikuli-script