Beispiel #1
0
  public void run() {

    //
    String welcome = shell.getWelcome();
    writer.println(welcome);
    writer.flush();

    //
    while (true) {
      String prompt = getPrompt();
      String line;
      try {
        writer.println();
        writer.flush();
        if ((line = reader.readLine(prompt)) == null) {
          break;
        }
      } catch (IOException e) {
        // What should we do other than that ?
        break;
      }

      //
      ShellProcess process = shell.createProcess(line);
      JLineProcessContext context = new JLineProcessContext(this);
      current.set(process);
      try {
        process.execute(context);
        try {
          context.latch.await();
        } catch (InterruptedException ignore) {
          // At the moment
        }
      } finally {
        current.set(null);
      }
      ShellResponse response = context.resp.get();

      //
      if (response instanceof ShellResponse.Cancelled) {
        // Do nothing
      } else if (response instanceof ShellResponse.Close) {
        break;
      } else {
        response.getReader().writeAnsiTo(writer);
        writer.flush();
      }
    }
  }
Beispiel #2
0
 public int complete(String buffer, int cursor, List<CharSequence> candidates) {
   String prefix = buffer.substring(0, cursor);
   CommandCompletion completion = shell.complete(prefix);
   ValueCompletion vc = completion.getValue();
   if (vc.isEmpty()) {
     return -1;
   }
   Delimiter delimiter = completion.getDelimiter();
   for (Map.Entry<String, Boolean> entry : vc) {
     StringBuilder sb = new StringBuilder();
     sb.append(vc.getPrefix());
     try {
       delimiter.escape(entry.getKey(), sb);
       if (entry.getValue()) {
         sb.append(completion.getDelimiter().getValue());
       }
       candidates.add(sb.toString());
     } catch (IOException ignore) {
     }
   }
   return cursor - vc.getPrefix().length();
 }
Beispiel #3
0
 String getPrompt() {
   String prompt = shell.getPrompt();
   return prompt == null ? "% " : prompt;
 }