Package org.crsh.cli.impl

Examples of org.crsh.cli.impl.Delimiter


            }
          } 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();
                delimiter.escape(value, sb);
                if (completions.get(value)) {
                  sb.append(delimiter.getValue());
                }
                values.add(sb.toString());
              }
              else {
                String commonCompletion = Utils.findLongestCommonPrefix(completions.getValues());
                if (commonCompletion.length() > 0) {
                  delimiter.escape(commonCompletion, sb);
                  values.add(sb.toString());
                }
                else {
                  for (Map.Entry<String, Boolean> entry : completions) {
                    delimiter.escape(entry.getKey(), sb);
                    values.add(sb.toString());
                    sb.setLength(0);
                  }
                }
              }
View Full Code Here


    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
        int width = term.getWidth();

        //
        String completionPrefix = completions.getPrefix();

        // Get the max length
        int max = 0;
        for (String suffix : completions.getValues()) {
          max = Math.max(max, completionPrefix.length() + suffix.length());
        }

        // Separator : use two whitespace like in BASH
        max += 2;

        //
        StringBuilder sb = new StringBuilder().append('\n');
        if (max < width) {
          int columns = width / max;
          int index = 0;
          for (String suffix : completions.getValues()) {
            sb.append(completionPrefix).append(suffix);
            for (int l = completionPrefix.length() + suffix.length();l < max;l++) {
              sb.append(' ');
            }
            if (++index >= columns) {
              index = 0;
              sb.append('\n');
            }
          }
          if (index > 0) {
            sb.append('\n');
          }
        } else {
          for (Iterator<String> i = completions.getValues().iterator();i.hasNext();) {
            String suffix = i.next();
            sb.append(commonCompletion).append(suffix);
            if (i.hasNext()) {
              sb.append('\n');
            }
          }
          sb.append('\n');
        }

        // We propose
        term.append(sb);

        // Rewrite prompt
        writePromptFlush();

        // If we have common completion we append it now
        if (commonCompletion.length() > 0) {
          term.getDirectBuffer().append(delimiter.escape(commonCompletion));
        }
      }
    }
    catch (IOException e) {
      log.log(Level.SEVERE, "Could not write completion", e);
View Full Code Here

    // Find delimiter
    CommandDescriptor<T> foo = this.descriptor;

    TokenizerImpl tokenizer = new TokenizerImpl(s);
    Delimiter delimiter = tokenizer.getEndingDelimiter();
    Parser<T> parser = new Parser<T>(tokenizer, foo, Mode.COMPLETE);

    // Last non separator event
    Event last = null;
    Event.Separator separator = null;
View Full Code Here

TOP

Related Classes of org.crsh.cli.impl.Delimiter

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.