Ejemplo n.º 1
0
  private static TextConsole createConsoleWithShell(final ConsoleManager conMgr, PrintWriter out)
      throws ShellException {
    final TextConsole console =
        (TextConsole)
            conMgr.createConsole(
                null, ConsoleManager.CreateOptions.TEXT | ConsoleManager.CreateOptions.SCROLLABLE);
    CommandShell commandShell = new CommandShell(console);
    new Thread(commandShell, "command-shell").start();

    out.println("New console created with name: " + console.getConsoleName());

    // FIXME we shouldn't be setting the invoker (and interpreter) via the System Properties
    // object because it is "global" in some operation modes, and we want to be able to
    // control the invoker / interpreter on a per-console basis.
    String invokerName = System.getProperty(CommandShell.INVOKER_PROPERTY_NAME, "");
    // FIXME this is a temporary hack until we decide what to do about these invokers
    if ("thread".equals(invokerName) || "default".equals(invokerName)) {
      PrintWriter err = new PrintWriter(console.getErr());
      err.println(
          "Warning: any commands run in this console via their main(String[]) will "
              + "have the 'wrong' System.out and System.err.");
      err.println("The 'proclet' invoker should give better results.");
      err.println(
          "To use it, type 'exit', run 'set jnode.invoker proclet' "
              + "in the F1 console and run 'console -n' again.");
    }
    return console;
  }
Ejemplo n.º 2
0
  @Override
  public void execute() throws NameNotFoundException, IsolateStartupException, ShellException {
    final PrintWriter out = getOutput().getPrintWriter();
    final ShellManager sm = InitialNaming.lookup(ShellManager.NAME);
    final ConsoleManager conMgr = sm.getCurrentShell().getConsole().getManager();

    boolean listConsoles = FLAG_LIST.isSet();
    boolean newConsole = FLAG_NEW.isSet();
    boolean isolateNewConsole = FLAG_ISOLATED.isSet();
    boolean test = FLAG_TEST.isSet();

    if (listConsoles) {
      conMgr.printConsoles(out);
    } else if (newConsole) {
      if (isolateNewConsole) {
        try {
          Isolate newIsolate =
              new Isolate(ConsoleCommand.IsolatedConsole.class.getName(), new String[0]);
          newIsolate.start();
          out.println("Started new isolated console");
        } catch (IsolateStartupException ex) {
          out.println("Failed to start new isolated console");
          throw ex;
        }
      } else {
        createConsoleWithShell(conMgr, out);
      }
    } else if (test) {
      out.println("test RawTextConsole");
      final TextConsole console =
          (TextConsole)
              conMgr.createConsole(
                  null,
                  ConsoleManager.CreateOptions.TEXT
                      | ConsoleManager.CreateOptions.NO_LINE_EDITTING);
      conMgr.registerConsole(console);
      conMgr.focus(console);
      console.clear();
    }
  }