Package jline.console

Examples of jline.console.ConsoleReader


  public void doit(PrintWriter out, Blur.Iface client, String[] args) throws CommandException, TException,
      BlurException {
    try {
      doitInternal(out, client, args);
    } finally {
      ConsoleReader reader = this.getConsoleReader();
      if (reader != null) {
        reader.setPrompt(Main.PROMPT);
      }
    }
  }
View Full Code Here


    String sizesStr = properties.getProperty("top.sizes");
    Set<String> sizes = new HashSet<String>(Arrays.asList(resolveShortNames(sizesStr.split(","), properties)));
    Set<String> keys = new HashSet<String>(metricNames.values());

    ConsoleReader reader = this.getConsoleReader();
    if (reader != null) {
      Terminal terminal = reader.getTerminal();
      _height = terminal.getHeight() - 2;
      _width = terminal.getWidth() - 2;
      try {
        reader.setPrompt("");
        reader.clearScreen();
      } catch (IOException e) {
        if (Main.debug) {
          e.printStackTrace();
        }
      }

      startCommandWatcher(reader, quit, help, this);
    }

    List<String> shardServerList = new ArrayList<String>(client.shardServerList(cluster));
    Collections.sort(shardServerList);
    Map<String, AtomicReference<Client>> shardClients = setupClients(shardServerList);

    String shardServerLabel = properties.getProperty(TOP_SHARD_SERVER_SHORTNAME);
    int longestServerName = Math.max(getSizeOfLongestKey(shardClients), shardServerLabel.length());

    StringBuilder header = new StringBuilder("%" + longestServerName + "s");
    for (int i = 1; i < labels.length; i++) {
      header.append(" %10s");
    }

    do {
      int lineCount = 0;
      StringBuilder output = new StringBuilder();
      if (quit.get()) {
        return;
      } else if (help.get()) {
        showHelp(output, labels, helpMap);
      } else {
        output.append(truncate(String.format(header.toString(), (Object[]) labels)) + "\n");
        lineCount++;
        SERVER: for (Entry<String, AtomicReference<Client>> e : new TreeMap<String, AtomicReference<Client>>(
            shardClients).entrySet()) {
          String shardServer = e.getKey();
          AtomicReference<Client> ref = e.getValue();
          Map<String, Metric> metrics = getMetrics(shardServer, ref, keys);
          if (metrics == null) {
            String line = String.format("%" + longestServerName + "s*%n", shardServer);
            output.append(line);
            lineCount++;
            if (tooLong(lineCount)) {
              break SERVER;
            }
          } else {
            Object[] cols = new Object[labels.length];
            int c = 0;
            cols[c++] = shardServer;
            StringBuilder sb = new StringBuilder("%" + longestServerName + "s");

            for (int i = 1; i < labels.length; i++) {
              String mn = metricNames.get(labels[i]);
              Metric metric = metrics.get(mn);
              Double value;
              if (metric == null) {
                value = null;
              } else {
                Map<String, Double> doubleMap = metric.getDoubleMap();
                value = doubleMap.get("oneMinuteRate");
                if (value == null) {
                  value = doubleMap.get("value");
                }
              }
              if (value == null) {
                value = 0.0;
              }
              cols[c++] = humanize(value, sizes.contains(mn));
              sb.append(" %10s");
            }
            output.append(truncate(String.format(sb.toString(), cols)) + "\n");
            lineCount++;
            if (tooLong(lineCount)) {
              break SERVER;
            }
          }
        }
      }
      if (reader != null) {
        try {
          reader.clearScreen();
        } catch (IOException e) {
          if (Main.debug) {
            e.printStackTrace();
          }
        }
      }
      out.print(output.toString());
      out.flush();
      if (reader != null) {
        try {
          synchronized (this) {
            wait(3000);
          }
        } catch (InterruptedException e) {
          return;
        }
        Terminal terminal = reader.getTerminal();
        _height = terminal.getHeight() - 2;
        _width = terminal.getWidth() - 2;

        List<String> currentShardServerList = new ArrayList<String>(client.shardServerList(cluster));
        Collections.sort(currentShardServerList);
View Full Code Here

  }

  private void doitInternal(PrintWriter outPw, Blur.Iface client, String[] args) throws FinishedException,
      BlurException, TException {

    ConsoleReader reader = getConsoleReader();
    int totalWidth = 200;
    if (reader != null) {
      totalWidth = reader.getTerminal().getWidth() - 2;
    }

    int[] cols = new int[2];
    cols[0] = 20;
    cols[1] = totalWidth - cols[0];
    ColumnBasedPrintWriter out = new ColumnBasedPrintWriter(outPw, cols);
    if (reader != null) {
      Terminal terminal = reader.getTerminal();
      out.setLineLimit(terminal.getHeight() - 2);
    }
    CommandLine cmd = parse(args, outPw);
    if (cmd == null) {
      return;
View Full Code Here

    }
    _width = 100;
    if (commandLine.hasOption(QueryCommandHelper.WIDTH)) {
      _width = Integer.parseInt(commandLine.getOptionValue(QueryCommandHelper.WIDTH));
    }
    ConsoleReader reader = getConsoleReader();
    if (reader == null) {
      throw new BlurException("This command can only be run with a proper jline environment.", null, ErrorType.UNKNOWN);
    }

    long s = System.nanoTime();
    BlurResults blurResults = client.query(tablename, blurQuery);
    long e = System.nanoTime();
    long timeInNanos = e - s;
    if (blurResults.getTotalResults() == 0) {
      out.println("No results found in [" + timeInNanos / 1000000.0 + " ms].");
      return;
    }

    String prompt = reader.getPrompt();
    reader.setPrompt("");
    final TableDisplay tableDisplay = new TableDisplay(reader);
    tableDisplay.setDescription(white(blurResults.getTotalResults() + " results found in [" + timeInNanos / 1000000.0
        + " ms].  " + getFetchMetaData(blurResults)));
    tableDisplay.setSeperator(" ");
    try {

      final AtomicBoolean viewing = new AtomicBoolean(true);

      tableDisplay.addKeyHook(new Runnable() {
        @Override
        public void run() {
          synchronized (viewing) {
            viewing.set(false);
            viewing.notify();
            tableDisplay.setStopReadingInput(true);
          }
        }
      }, 'q');

      RenderType type = getRenderRype(blurResults);
      switch (type) {
      case ROW_MULTI_FAMILY:
        renderRowMultiFamily(tableDisplay, blurResults);
        break;
      case ROW_SINGLE_FAMILY:
        renderRowSingleFamily(tableDisplay, blurResults);
        break;
      default:
        break;
      }

      while (viewing.get()) {
        synchronized (viewing) {
          try {
            viewing.wait();
          } catch (InterruptedException ex) {
            throw new RuntimeException(ex);
          }
        }
      }
    } finally {
      try {
        tableDisplay.close();
      } catch (IOException ex) {
        if (Main.debug) {
          ex.printStackTrace();
        }
      }
      try {
        Thread.sleep(100);
      } catch (InterruptedException ex) {
        if (Main.debug) {
          ex.printStackTrace();
        }
      }
      try {
        reader.setPrompt("");
        reader.clearScreen();
      } catch (IOException ex) {
        if (Main.debug) {
          ex.printStackTrace();
        }
      }
      out.write("\u001B[0m");
      out.flush();
      reader.setPrompt(prompt);
    }
  }
View Full Code Here

    }

    try {
      Blur.Iface client = BlurClient.getClient(cliShellOptions.getControllerConnectionString());
      if (cliShellOptions.isShell()) {
        ConsoleReader reader = new ConsoleReader();
        PrintWriter out = new PrintWriter(reader.getOutput());
        setConsoleReader(commands, reader);
        setPrompt(client, reader, cliShellOptions.getControllerConnectionString(), out);

        List<Completer> completors = new LinkedList<Completer>();

        // completors.add(new StringsCompleter(commands.keySet()));
        // completors.add(new FileNameCompleter());
        completors.add(new CommandCompletor(commands, client));

        for (Completer c : completors) {
          reader.addCompleter(c);
        }

        reader.setCompletionHandler(new ShowDiffsOnlyCompletionHandler());

        String line;
        try {
          while ((line = reader.readLine()) != null) {
            line = line.trim();
            // ignore empty lines and comments
            if (line.length() == 0 || line.startsWith("#")) {
              continue;
            }
View Full Code Here

  private static class ResetCommand extends Command {

    @Override
    public void doit(PrintWriter out, Blur.Iface client, String[] args) throws CommandException, TException,
        BlurException {
      ConsoleReader reader = getConsoleReader();
      if (reader != null) {
        try {
          reader.setPrompt("");
          reader.clearScreen();
        } catch (IOException e) {
          if (debug) {
            e.printStackTrace();
          }
          throw new CommandException(e.getMessage());
View Full Code Here

    //
    // for (int i = 0; i < 100; i++) {
    // System.out.println("\u001B[0m" + i + "\u001B[" + i + "mfoo");
    // }

    ConsoleReader reader = new ConsoleReader();
    TableDisplay tableDisplay = new TableDisplay(reader);
    tableDisplay.setSeperator("|");
    // Random random = new Random();
    int maxX = 20;
    int maxY = 100;
View Full Code Here

   * Creates new jline ConsoleReader.
   *
   * @return a jline ConsoleReader instance
   */
  protected ConsoleReader createConsoleReader() {
    ConsoleReader consoleReader = null;
    try {
      consoleReader = new ConsoleReader();
      consoleReader.setPrompt(getPrompt());
      history = new FileHistory(getHistoryFile());
      consoleReader.setHistory(history);
    } catch (IOException e) {
      throw new IllegalStateException("Cannot create jline console reader", e);
    }
    return consoleReader;
  }
View Full Code Here

        this.consoleInput = new ConsoleInputStream();
        this.session = processor.createSession(this.consoleInput, this.out, this.err);
        this.session.put("SCOPE", "shell:osgi:*");
        this.closeCallback = closeCallback;

        reader = new ConsoleReader(this.consoleInput,
                                   this.out,
                                   this.terminal);

        final File file = getHistoryFile();
        try {
View Full Code Here

        this.consoleInput = new ConsoleInputStream();
        this.session = processor.createSession(this.consoleInput, this.out, this.err);
        this.session.put("SCOPE", "shell:osgi:*");
        this.closeCallback = closeCallback;

        reader = new ConsoleReader(null,
                                   this.consoleInput,
                                   this.out,
                                   this.terminal,
                                   encoding);

View Full Code Here

TOP

Related Classes of jline.console.ConsoleReader

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.