Package org.crsh.cli.impl.completion

Examples of org.crsh.cli.impl.completion.CompletionMatch


            } else {
              log.fine("No process can handle the key event");
            }
          } else if (type.getAsString().equals("complete")) {
            String prefix = event.get("prefix").getAsString();
            CompletionMatch completion = session.shell.complete(prefix);
            Completion completions = completion.getValue();
            Delimiter delimiter = completion.getDelimiter();
            StringBuilder sb = new StringBuilder();
            List<String> values = new ArrayList<String>();
            try {
              if (completions.getSize() == 1) {
                String value = completions.getValues().iterator().next();
View Full Code Here


  public void testCompletion1() throws Exception {
    Controller controller = create(new BaseShell(BaseProcessFactory.ECHO) {
      @Override
      public CompletionMatch complete(String prefix) {
        return new CompletionMatch(Delimiter.EMPTY, Completion.create(new StringBuilder(prefix).reverse().toString(), false));
      }
    });
    controller.assertStart();

    //
View Full Code Here

    }
  }

  private void complete(CharSequence prefix) {
    log.log(Level.FINE, "About to get completions for " + prefix);
    CompletionMatch completion = shell.complete(prefix.toString());
    Completion completions = completion.getValue();
    log.log(Level.FINE, "Completions for " + prefix + " are " + completions);

    //
    Delimiter delimiter = completion.getDelimiter();

    try {
      // Try to find the greatest prefix among all the results
      if (completions.getSize() == 0) {
        // Do nothing
      } else if (completions.getSize() == 1) {
        Map.Entry<String, Boolean> entry = completions.iterator().next();
        Appendable buffer = term.getDirectBuffer();
        String insert = entry.getKey();
        term.getDirectBuffer().append(delimiter.escape(insert));
        if (entry.getValue()) {
          buffer.append(completion.getDelimiter().getValue());
        }
      } else {
        String commonCompletion = Utils.findLongestCommonPrefix(completions.getValues());

        // Format stuff
View Full Code Here

public class CompleteTestCase extends AbstractShellTestCase {

  public void testCommandImplementingCompleter() {
    lifeCycle.bindClass("complete", Commands.Complete.class);
    CompletionMatch completionMatch = assertComplete("complete foo");
    Completion completion = completionMatch.getValue();
    assertEquals("foo", completion.getPrefix());
    assertEquals(Collections.singleton("bar"), completion.getValues());
    assertTrue(completion.get("bar"));
  }
View Full Code Here

  }

  public void testSessionAccess() {
    lifeCycle.bindClass("complete", Commands.CompleteWithSession.class);
    session.put("juu", "juu_value");
    CompletionMatch completionMatch = assertComplete("complete foo");
    Completion completion = completionMatch.getValue();
    assertEquals("foo", completion.getPrefix());
    assertEquals(Collections.singleton("juu_value"), completion.getValues());
    assertTrue(completion.get("juu_value"));
  }
View Full Code Here

    lifeCycle.bindJava("foo", "public class foo extends BaseCommand {}");
    assertInternalError("foo");
  }

  public void testComplete() {
    CompletionMatch match = assertComplete("java_");
    Completion completion = match.getValue();
    assertEquals(1, completion.getSize());
    Map.Entry<String, Boolean> entry = completion.iterator().next();
    assertEquals("command", entry.getKey());
    assertTrue(entry.getValue());
  }
View Full Code Here

      termPrefix = "";
    }

    //
    log.log(Level.FINE, "Retained term prefix is " + termPrefix);
    CompletionMatch completion;
    int pos = termPrefix.indexOf(' ');
    if (pos == -1) {
      Completion.Builder builder = Completion.builder(termPrefix);
      for (Map.Entry<String, String> command : session.getCommands()) {
        String name = command.getKey();
        if (name.startsWith(termPrefix)) {
          builder.add(name.substring(termPrefix.length()), true);
        }
      }
      completion = new CompletionMatch(Delimiter.EMPTY, builder.build());
    } else {
      String commandName = termPrefix.substring(0, pos);
      termPrefix = termPrefix.substring(pos);
      try {
        Command<?> command = session.getCommand(commandName);
        if (command != null) {
          completion = command.complete(new RuntimeContextImpl(session, session.getContext().getAttributes()), termPrefix);
        } else {
          completion = new CompletionMatch(Delimiter.EMPTY, Completion.create());
        }
      }
      catch (CommandException e) {
        log.log(Level.FINE, "Could not create command for completion of " + prefix, e);
        completion = new CompletionMatch(Delimiter.EMPTY, Completion.create());
      }
    }

    //
    return completion;
View Full Code Here

    };
    return new ReplResponse.Invoke(invoker);
  }

  public CompletionMatch complete(ShellSession session, String prefix) {
    return new CompletionMatch(Delimiter.EMPTY, Completion.create());
  }
View Full Code Here

  public void testComplete() throws Exception {
    System.setProperty("foo.bar", "bar");
    System.setProperty("foo.bar2", "bar");
    try {
      CompletionMatch completion = assertComplete("system propget foo");
      assertEquals(2, completion.getValue().getSize());
      assertTrue(completion.getValue().get(".bar") != null);
      assertTrue(completion.getValue().get(".bar2") != null);
    } finally {
      System.clearProperty("foo.bar");
      System.clearProperty("foo.bar2");
    }
  }
View Full Code Here

    this.serverOOS = serverOOS;
  }

  public void testSerialization() throws Exception {

    ServerMessage message = new ServerMessage.Completion(new CompletionMatch(Delimiter.DOUBLE_QUOTE, Completion.create("pref", "ix", true)));
    clientOOS.writeObject(message);
    clientOOS.flush();
    ServerMessage after = (ServerMessage)serverOIS.readObject();
    System.out.println("after = " + after);
View Full Code Here

TOP

Related Classes of org.crsh.cli.impl.completion.CompletionMatch

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.