Пример #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;
  }
Пример #2
0
 /**
  * This will be the entry point for the isolate.
  *
  * @param args
  */
 public static void main(String[] args) {
   try {
     final ShellManager sm = InitialNaming.lookup(ShellManager.NAME);
     final ConsoleManager conMgr = sm.getCurrentShell().getConsole().getManager();
     final PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
     TextConsole console = createConsoleWithShell(conMgr, out);
     System.setIn(new ReaderInputStream(console.getIn()));
     System.setOut(new PrintStream(new WriterOutputStream(console.getOut(), false), true));
     System.setErr(new PrintStream(new WriterOutputStream(console.getErr(), false), true));
   } catch (Exception ex) {
     // FIXME
     System.out.println("Problem creating the isolated console");
     ex.printStackTrace(System.err);
   }
 }
Пример #3
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();
    }
  }
Пример #4
0
  /** Set up the pager's console and command pipe. */
  private void setup() throws NameNotFoundException, IOException {
    ShellManager sm = InitialNaming.lookup(ShellManager.NAME);
    manager = (TextScreenConsoleManager) sm.getCurrentShell().getConsole().getManager();
    console =
        manager.createConsole(
            "page",
            (ConsoleManager.CreateOptions.TEXT
                | ConsoleManager.CreateOptions.STACKED
                | ConsoleManager.CreateOptions.NO_LINE_EDITTING
                | ConsoleManager.CreateOptions.NO_SYSTEM_OUT_ERR));
    manager.focus(console);

    pageHeight = console.getDeviceHeight() - 1;
    pageWidth = console.getDeviceWidth();
    pageSize = pageHeight * pageWidth;
    tabSize = console.getTabSize();

    pw = new PipedWriter();
    pr = new PipedReader();
    pr.connect(pw);

    console.addKeyboardListener(this);
  }
Пример #5
0
 private void erasePrompt() {
   console.clearRow(this.pageHeight);
 }
Пример #6
0
 private void prompt(String text) {
   console.clearRow(this.pageHeight);
   console.setChar(0, this.pageHeight, text.toCharArray(), DEFAULT_COLOR);
   console.setCursor(0, this.pageHeight);
 }
Пример #7
0
  /**
   * Do the paging, reading commands from our private console input pipe to figure out what to do
   * next.
   *
   * @param r the source of data to be paged.
   * @throws IOException
   */
  private void pager() throws IOException {
    // Output first page.
    console.clear();
    bottomLineNo = -1;
    boolean exit = false;
    nextPage();

    // Process commands until we reach the EOF on the data source or
    // the command pipe.
    while (!exit) {
      prompt();
      int ch = pr.read();
      erasePrompt();
      switch (ch) {
        case -1:
          exit = true;
          break;
        case ' ':
        case 'f':
          if (lineStore.isLastLineNo(bottomLineNo)) {
            exit = true;
          } else {
            nextPage();
          }
          break;
        case 'b':
          prevPage();
          break;
        case 'k':
        case 'y':
          prevLine();
          break;
        case '\n':
          if (lineStore.isLastLineNo(bottomLineNo)) {
            exit = true;
          } else {
            nextLine();
          }
          break;
        case 'u':
          prevScreenLine();
          break;
        case 'd':
          nextScreenLine();
          break;
        case '<':
          gotoPage(0);
          break;
        case '>':
          gotoLastPage();
          break;
        case '/':
          searchForwards();
          break;
        case '?':
          searchBackwards();
          break;
        case '\004': // ^D
        case 'q':
          exit = true;
          break;
        case 'h':
          help();
        default:
          // ignore
      }
    }
  }