コード例 #1
0
    private CommandContextImpl(jline.ConsoleReader console) {
      this.console = console;

      console.setUseHistory(true);
      String userHome = SecurityActions.getSystemProperty("user.home");
      File historyFile = new File(userHome, ".jboss-cli-history");
      try {
        console.getHistory().setHistoryFile(historyFile);
      } catch (IOException e) {
        System.err.println(
            "Failed to setup the history file "
                + historyFile.getAbsolutePath()
                + ": "
                + e.getLocalizedMessage());
      }

      this.history = new HistoryImpl();
      operationCandidatesProvider = new DefaultOperationCandidatesProvider(this);

      operationHandler = new OperationRequestHandler();

      cmdCompleter = new CommandCompleter(cmdRegistry, this);
    }
コード例 #2
0
  /**
   * @param args the command line arguments
   * @throws Exception
   */
  @SuppressWarnings("unchecked")
  public static void main(String[] args) throws Exception {

    if (args.length == 0) {
      fail();
    }
    OpenCVJNILoader.load(); // Loads the OpenCV JNI (java native interface)
    //		File servo =
    // ScriptingEngine.fileFromGit("https://github.com/NeuronRobotics/BowlerStudioVitamins.git",
    //							"BowlerStudioVitamins/stl/servo/smallservo.stl");
    //
    //		ArrayList<CSG>  cad = (ArrayList<CSG>
    // )ScriptingEngine.inlineGistScriptRun("4814b39ee72e9f590757", "javaCad.groovy" , null);
    //		System.out.println(servo.exists()+" exists: "+servo);

    boolean startLoadingScripts = false;
    Object ret = null;
    for (String s : args) {
      if (startLoadingScripts) {
        try {

          ret = ScriptingEngine.inlineFileScriptRun(new File(s), null);
        } catch (Error e) {
          e.printStackTrace();
          fail();
        }
      }
      if (s.contains("script") || s.contains("-s")) {
        startLoadingScripts = true;
      }
    }
    startLoadingScripts = false;

    for (String s : args) {

      if (startLoadingScripts) {
        try {
          ret = ScriptingEngine.inlineFileScriptRun(new File(s), (ArrayList<Object>) ret);
        } catch (Error e) {
          e.printStackTrace();
          fail();
        }
      }
      if (s.contains("pipe") || s.contains("-p")) {
        startLoadingScripts = true;
      }
    }
    boolean runShell = false;
    ShellType shellTypeStorage = ShellType.GROOVY;
    for (String s : args) {

      if (runShell) {
        try {
          shellTypeStorage = ShellType.getFromSlug(s);
        } catch (Exception e) {
          shellTypeStorage = ShellType.GROOVY;
        }
        break;
      }
      if (s.contains("repl") || s.contains("-r")) {
        runShell = true;
      }
    }

    System.out.println("Starting Bowler REPL in langauge: " + shellTypeStorage.getNameOfShell());
    // sample from
    // http://jline.sourceforge.net/testapidocs/src-html/jline/example/Example.html

    if (!Terminal.getTerminal().isSupported()) {
      System.out.println("Terminal not supported " + Terminal.getTerminal());
    }
    // Terminal.getTerminal().initializeTerminal();

    ConsoleReader reader = new ConsoleReader();
    reader.addTriggeredAction(
        Terminal.CTRL_C,
        e -> {
          System.exit(0);
        });

    if (!historyFile.exists()) {
      historyFile.createNewFile();
      reader.getHistory().addToHistory("println SDKBuildInfo.getVersion()");
      reader.getHistory().addToHistory("for(int i=0;i<100;i++) { println dyio.getValue(0) }");
      reader.getHistory().addToHistory("dyio.setValue(0,128)");
      reader.getHistory().addToHistory("println dyio.getValue(0)");
      reader
          .getHistory()
          .addToHistory(
              "ScriptingEngine.inlineGistScriptRun(\"d4312a0787456ec27a2a\", \"helloWorld.groovy\" , null)");
      reader
          .getHistory()
          .addToHistory(
              "DeviceManager.addConnection(new DyIO(ConnectionDialog.promptConnection()),\"dyio\")");
      reader
          .getHistory()
          .addToHistory(
              "DeviceManager.addConnection(new DyIO(new SerialConnection(\"/dev/DyIO0\")),\"dyio\")");
      reader.getHistory().addToHistory("BowlerKernel.speak(\"Text to speech works like this\")");
      reader.getHistory().addToHistory("println \"Hello world!\"");
      writeHistory(reader.getHistory().getHistoryList());
    } else {
      List<String> history = loadHistory();
      for (String h : history) {
        reader.getHistory().addToHistory(h);
      }
    }
    reader.setBellEnabled(false);
    reader.setDebug(new PrintWriter(new FileWriter("writer.debug", true)));

    Runtime.getRuntime()
        .addShutdownHook(
            new Thread() {
              @Override
              public void run() {

                writeHistory(reader.getHistory().getHistoryList());
              }
            });

    // SpringApplication.run(SpringBowlerUI.class, new String[]{});

    String line;
    try {
      while ((line = reader.readLine("Bowler " + shellTypeStorage.getNameOfShell() + "> "))
          != null) {
        if (line.equalsIgnoreCase("quit") || line.equalsIgnoreCase("exit")) {
          break;
        }
        if (line.equalsIgnoreCase("history") || line.equalsIgnoreCase("h")) {
          List<String> h = reader.getHistory().getHistoryList();
          for (String s : h) {
            System.out.println(s);
          }
          continue;
        }
        if (line.startsWith("shellType")) {
          try {
            shellTypeStorage = ShellType.getFromSlug(line.split(" ")[1]);
          } catch (Exception e) {
            shellTypeStorage = ShellType.GROOVY;
          }
          continue;
        }
        try {
          ret = ScriptingEngine.inlineScriptStringRun(line, null, shellTypeStorage);
          if (ret != null) System.out.println(ret);
        } catch (Error e) {
          e.printStackTrace();
        } catch (Exception e) {
          e.printStackTrace();
        }
      }
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
コード例 #3
0
ファイル: KeyBinding.java プロジェクト: Titousensei/sisyphus
  public static void main(String[] args) {
    KeyBinding bind;
    if ("-tsv".equals(args[0])) {
      bind = loadKeyBindingFromTsv(args[1], args[2], args[3]);
      bind.save(args[4]);
      return;
    } else {
      try {
        bind = KeyBinding.load(args[0]);
      } catch (LoadingException ex) {
        throw new RuntimeException(ex);
      }
    }

    if ("-value".equals(args[1])) {
      KeyBinding ret = KeyBinding.newLike(bind);
      Output out = new OutputKeyBinding(ret);

      Pusher p = new Pusher();
      for (int i = 2; i < args.length; i++) {
        p.onlyIf(new IfEquals(bind.getColumnName(1), args[i]), out);
      }
      p.push(new InputKeyBinding(bind));
      ret.dumpTsv(System.out);
    } else if ("-count".equals(args[1])) {
      Pusher p = new Pusher();
      for (int i = 2; i < args.length; i++) {
        p.onlyIf(new IfEquals(bind.getColumnName(1), args[i]), new BreakAfter(args[i]));
      }
      p.push(new InputKeyBinding(bind));
    } else if ("-dump".equals(args[1])) {
      bind.dumpTsv(System.out);
    } else if ("-prompt".equals(args[1])) {
      try {
        jline.ConsoleReader reader = new jline.ConsoleReader();
        reader.setBellEnabled(false);
        reader.getHistory().setHistoryFile(new File(".KeyBinding.history"));
        String line = null;
        System.err.println("=== Enter Keys ===");
        while ((line = reader.readLine("keys> ")) != null) {
          if (!line.trim().isEmpty()) {
            for (String k : line.split("\\s+")) {
              System.out.print(k);
              System.out.print('\t');
              if (bind.contains(k)) {
                System.out.print(bind.get(k));
              } else {
                System.out.print("false");
              }
              System.out.println();
            }
          }
        }
      } catch (IOException ioex) {
        ioex.printStackTrace();
      }
    } else {
      int i = 1;
      if ("-key".equals(args[1])) {
        i = 2;
      }
      for (; i < args.length; i++) {
        System.out.print(args[i]);
        System.out.print('\t');
        if (bind.contains(args[i])) {
          System.out.print(bind.get(args[i]));
        } else {
          System.out.print("false");
        }
        System.out.println();
      }
    }
  }