Exemplo n.º 1
1
  public ConsoleManager(GlowServer server) {
    this.server = server;

    // install Ansi code handler, which makes colors work on Windows
    AnsiConsole.systemInstall();

    for (Handler h : logger.getHandlers()) {
      logger.removeHandler(h);
    }

    // used until/unless gui is created
    consoleHandler = new FancyConsoleHandler();
    // consoleHandler.setFormatter(new DateOutputFormatter(CONSOLE_DATE));
    logger.addHandler(consoleHandler);

    // todo: why is this here?
    Runtime.getRuntime().addShutdownHook(new ServerShutdownThread());

    // reader must be initialized before standard streams are changed
    try {
      reader = new ConsoleReader();
    } catch (IOException ex) {
      logger.log(Level.SEVERE, "Exception initializing console reader", ex);
    }
    reader.addCompleter(new CommandCompleter());

    // set system output streams
    System.setOut(new PrintStream(new LoggerOutputStream(Level.INFO), true));
    System.setErr(new PrintStream(new LoggerOutputStream(Level.WARNING), true));
  }
Exemplo n.º 2
0
  public static void main(String... args) {

    ConsoleReader console;
    try {
      console = new ConsoleReader();
      String pattern;
      String iterationsString;
      if (!DEBUG) {
        pattern = console.readLine("Ant Pattern: ");
        iterationsString = console.readLine("Iterations: ");
      } else {
        pattern = DEBUG_PATTERN;
        iterationsString = DEBUG_ITERATIONS;
      }
      verifyPattern(pattern);

      long iterations = verifyIterations(iterationsString);
      LangtonsAnt app = new LangtonsAnt(pattern, iterations);
      app.initColours();
      app.initAnt();
      app.simulate();
      app.render();
    } catch (IOException e) {
      System.out.println("Fatal IO Exception: " + e.getMessage());
      System.exit(1);
    }
  }
Exemplo n.º 3
0
 @Override
 public String promptPassword() throws IOException {
   String prompt = this.console.getPrompt();
   String password = console.readLine("Password: ", new Character('\0'));
   console.setPrompt(prompt);
   return password;
 }
Exemplo n.º 4
0
 private void cleanUp() throws IOException {
   if (_history instanceof PersistentHistory) {
     ((PersistentHistory) _history).flush();
   }
   _console.println();
   _console.flush();
 }
Exemplo n.º 5
0
  /** Executes the map command using the provided options. */
  @Override
  protected void runInternal(GeogitCLI cli) throws IOException {

    if (args == null || args.isEmpty() || args.size() != 1) {
      printUsage(cli);
      throw new CommandFailedException();
    }

    String path = args.get(0);

    geogit = cli.getGeogit();

    ObjectId oldTreeId = geogit.getRepository().workingTree().getTree().getId();

    ObjectId newTreeId = geogit.command(OSMUnmapOp.class).setPath(path).call().getId();

    ConsoleReader console = cli.getConsole();
    if (newTreeId.equals(oldTreeId)) {
      console.println(
          "No differences were found after unmapping.\n"
              + "No changes have been made to the working tree");
    } else {
      // print something?
    }
  }
Exemplo n.º 6
0
  public CHIA(Writer out) throws IOException {
    Preconditions.checkNotNull(out);
    this.out = out;

    this.automataConsole = new CHIAAutomataConsole();
    this.console = new ConsoleReader();
    this.console.setExpandEvents(false);

    console.setPrompt("CHIA> ");
    usage();

    if (ClassLoader.getSystemResource("History.txt") != null) {
      console.setHistory(
          new FileHistory(new File(ClassLoader.getSystemResource("History.txt").getPath())));
    } else {
      out.write("The History file cannot be loaded" + "\n");
    }
    out.write("CHIA Started\n");
    out.flush();
    if (ClassLoader.getSystemResource("log4j.properties") != null) {

      PropertyConfigurator.configure(ClassLoader.getSystemResource("log4j.properties"));
    } else {
      out.write("The logging file cannot be loaded" + "\n");
    }
    out.flush();
  }
Exemplo n.º 7
0
 private void initAdminShell() throws IOException {
   if (_history != null) {
     _console.setHistory(_history);
   }
   _console.addCompleter(_userAdminShell);
   _console.println(_userAdminShell.getHello());
   _console.flush();
 }
Exemplo n.º 8
0
  private void updateStatus(String statusMessage) {
    try {

      int terminalWidth = reader.getTerminal().getWidth();
      if (statusMessage.length() > terminalWidth) {
        statusMessage = statusMessage.substring(0, terminalWidth - 6) + "...";
      }
      reader.resetPromptLine(null, statusMessage, statusMessage.length());
    } catch (Exception ignored) {
    }
  }
Exemplo n.º 9
0
 @Override
 public void updatePrompt() {
   if (app.isConnected()) {
     String path = app.getContext().getPath().getLastSegment();
     if (path == null) {
       path = "/";
     }
     console.setPrompt("|" + app.getUsername() + "@" + app.getHost() + ":" + path + "> ");
   } else {
     console.setPrompt("|> ");
   }
 }
Exemplo n.º 10
0
 @Override
 public void packageVersionResolutionFailed(FqPackageName packageName) {
   clearProgressBar();
   try {
     reader.println("Could not resolve " + packageName);
     reader.println("Tried:");
     for (String failedDownload : failedDownloads) {
       reader.println("* " + failedDownload);
     }
   } catch (IOException ignored) {
   }
 }
Exemplo n.º 11
0
 private void clearProgressBar() {
   try {
     reader.resetPromptLine("", "", 0);
   } catch (Exception ignored) {
     ignored.printStackTrace();
   }
 }
Exemplo n.º 12
0
 private String colorize(String string) {
   if (string.indexOf(ChatColor.COLOR_CHAR) < 0) {
     return string; // no colors in the message
   } else if ((!jLine || !reader.getTerminal().isAnsiSupported()) && jTerminal == null) {
     return ChatColor.stripColor(string); // color not supported
   } else {
     return string
             .replace(ChatColor.RED.toString(), "\033[1;31m")
             .replace(ChatColor.YELLOW.toString(), "\033[1;33m")
             .replace(ChatColor.GREEN.toString(), "\033[1;32m")
             .replace(ChatColor.AQUA.toString(), "\033[1;36m")
             .replace(ChatColor.BLUE.toString(), "\033[1;34m")
             .replace(ChatColor.LIGHT_PURPLE.toString(), "\033[1;35m")
             .replace(ChatColor.BLACK.toString(), "\033[0;0m")
             .replace(ChatColor.DARK_GRAY.toString(), "\033[1;30m")
             .replace(ChatColor.DARK_RED.toString(), "\033[0;31m")
             .replace(ChatColor.GOLD.toString(), "\033[0;33m")
             .replace(ChatColor.DARK_GREEN.toString(), "\033[0;32m")
             .replace(ChatColor.DARK_AQUA.toString(), "\033[0;36m")
             .replace(ChatColor.DARK_BLUE.toString(), "\033[0;34m")
             .replace(ChatColor.DARK_PURPLE.toString(), "\033[0;35m")
             .replace(ChatColor.GRAY.toString(), "\033[0;37m")
             .replace(ChatColor.WHITE.toString(), "\033[1;37m")
         + "\033[0m";
   }
 }
Exemplo n.º 13
0
  @Override
  public void runInternal(GeogitCLI cli) throws Exception {
    checkState(cli.getGeogit() != null, "Not a geogit repository: " + cli.getPlatform().pwd());
    String ref;
    if (refList.isEmpty()) {
      ref = null;
    } else {
      ref = refList.get(0);
    }
    Iterator<RevObject> iter =
        cli.getGeogit() //
            .command(WalkGraphOp.class)
            .setReference(ref) //
            // .setStrategy(lsStrategy) //
            .call();

    final ConsoleReader console = cli.getConsole();
    if (!iter.hasNext()) {
      if (ref == null) {
        console.println("The working tree is empty");
      } else {
        console.println("The specified path is empty");
      }
      return;
    }

    Function<RevObject, CharSequence> printFunctor =
        new Function<RevObject, CharSequence>() {
          @Override
          public CharSequence apply(RevObject input) {
            if (verbose) {
              return String.format("%s: %s %s", input.getId(), input.getType(), input);
            } else {
              return String.format("%s: %s", input.getId(), input.getType());
            }
          }
        };

    Iterator<CharSequence> lines = Iterators.transform(iter, printFunctor);

    while (lines.hasNext()) {
      console.println(lines.next());
    }
    console.flush();
  }
Exemplo n.º 14
0
  @Override
  public void runInternal(GeogitCLI cli) throws IOException {
    ImmutableList<ObjectId> updatedObjects = cli.getGeogit().command(RebuildGraphOp.class).call();

    final ConsoleReader console = cli.getConsole();
    if (updatedObjects.size() > 0) {
      if (quiet) {
        console.println(updatedObjects.size() + " graph elements (commits) were fixed.");
      } else {
        console.println(
            "The following graph elements (commits) were incomplete or missing and have been fixed:");
        for (ObjectId object : updatedObjects) {
          console.println(object.toString());
        }
      }
    } else {
      console.println("No missing or incomplete graph elements (commits) were found.");
    }
  }
Exemplo n.º 15
0
 /**
  * Executes line.
  *
  * @return false if the users has issued an "exit" command, true otherwise
  */
 protected boolean execute(String line) throws Exception {
   try {
     runCommand(line);
   } catch (ExitException e) {
     return false;
   } catch (CommandException e) {
     console.print(e.getMessage() + System.getProperty("line.separator"));
   }
   return true;
 }
Exemplo n.º 16
0
 @Override
 public void packageResolveFailed(DependencyResolutionException exception) {
   clearProgressBar();
   Artifact artifact = exception.getResult().getRoot().getArtifact();
   try {
     reader.println(
         String.format(
             "Could not resolve dependencies for %s.%s version %s",
             artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion()));
     reader.println("The following artifacts could not be located:");
     for (ArtifactResult result : exception.getResult().getArtifactResults()) {
       if (result.isMissing()) {
         reader.println("* " + result.getRequest().getArtifact());
       }
     }
   } catch (IOException e) {
     e.printStackTrace();
   }
 }
Exemplo n.º 17
0
  public MinecraftServer(OptionSet options, Proxy proxy, File file1) {
    io.netty.util.ResourceLeakDetector.setEnabled(false); // Spigot - disable
    this.d = proxy;
    MinecraftServer.k = this;
    // this.universe = file; // CraftBukkit
    // this.q = new ServerConnection(this); // Spigot
    this.Z = new UserCache(this, file1);
    this.p = this.h();
    // this.convertable = new WorldLoaderServer(file); // CraftBukkit - moved to
    // DedicatedServer.init
    this.V = new YggdrasilAuthenticationService(proxy, UUID.randomUUID().toString());
    this.W = this.V.createMinecraftSessionService();
    this.Y = this.V.createProfileRepository();
    // CraftBukkit start
    this.options = options;
    // Try to see if we're actually running in a terminal, disable jline if not
    if (System.console() == null) {
      System.setProperty("jline.terminal", "jline.UnsupportedTerminal");
      Main.useJline = false;
    }

    try {
      reader = new ConsoleReader(System.in, System.out);
      reader.setExpandEvents(
          false); // Avoid parsing exceptions for uncommonly used event designators
    } catch (Throwable e) {
      try {
        // Try again with jline disabled for Windows users without C++ 2008 Redistributable
        System.setProperty("jline.terminal", "jline.UnsupportedTerminal");
        System.setProperty("user.language", "en");
        Main.useJline = false;
        reader = new ConsoleReader(System.in, System.out);
        reader.setExpandEvents(false);
      } catch (IOException ex) {
        LOGGER.warn((String) null, ex);
      }
    }
    Runtime.getRuntime()
        .addShutdownHook(new org.bukkit.craftbukkit.util.ServerShutdownThread(this));

    this.serverThread = primaryThread = new Thread(this, "Server thread"); // Moved from main
  }
Exemplo n.º 18
0
 @Override
 public void packageLoadSucceeded(FqPackageName name, String version) {
   clearProgressBar();
   try {
     reader.println(
         String.format(
             "Loaded %s.%s version %s.", name.getGroupId(), name.getPackageName(), version));
   } catch (IOException e) {
     e.printStackTrace();
   }
 }
Exemplo n.º 19
0
  public JLineCommandHandler(LaunchServer server) throws IOException {
    super(server);

    // Set reader
    reader = new ConsoleReader();
    reader.setExpandEvents(false);

    // Replace writer
    LogHelper.removeStdOutput();
    LogHelper.addOutput(new JLineOutput());
  }
Exemplo n.º 20
0
 public void run() {
   ConsoleReader console = null;
   try {
     console = new ConsoleReader(in, out);
     console.println(WELCOME_MESSAGE);
     String statement = null;
     while ((statement = console.readLine(PROMPT)) != null) {
       if ("exit".equals(statement.trim())) {
         return;
       } else {
         try {
           dynJS.eval(context, statement);
         } catch (DynJSException e) {
           console.println(e.getClass().getSimpleName());
           console.println(e.getLocalizedMessage());
           console.println("Error parsing statement: " + statement.toString());
         } catch (Exception e) {
           e.printStackTrace(new PrintWriter(out));
         }
       }
     }
   } catch (IOException e) {
     e.printStackTrace();
   }
 }
Exemplo n.º 21
0
  private AccessToken getNewAccessToken(
      ConnectionConfig connectionInfo, PrintStream output, boolean debug) throws IOException {

    AuthenticationClient authenticationClient = getAuthenticationClient(connectionInfo);

    Properties properties = new Properties();
    properties.put(
        BasicAuthenticationClient.VERIFY_SSL_CERT_PROP_NAME,
        String.valueOf(clientConfig.isVerifySSLCert()));

    // obtain new access token via manual user input
    output.printf(
        "Authentication is enabled in the CDAP instance: %s.\n", connectionInfo.getHostname());
    ConsoleReader reader = new ConsoleReader();
    for (Credential credential : authenticationClient.getRequiredCredentials()) {
      String prompt = "Please, specify " + credential.getDescription() + "> ";
      String credentialValue;
      if (credential.isSecret()) {
        credentialValue = reader.readLine(prompt, '*');
      } else {
        credentialValue = reader.readLine(prompt);
      }
      properties.put(credential.getName(), credentialValue);
    }

    authenticationClient.configure(properties);
    AccessToken accessToken = authenticationClient.getAccessToken();

    if (accessToken != null) {
      if (saveAccessToken(accessToken, connectionInfo.getHostname()) && debug) {
        output.printf(
            "Saved access token to %s\n",
            getAccessTokenFile(connectionInfo.getHostname()).getAbsolutePath());
      }
    }

    return accessToken;
  }
Exemplo n.º 22
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();
      }
    }
  }
Exemplo n.º 23
0
 @Override
 public void start(Application app) throws IOException {
   super.start(app);
   updatePrompt();
   // register completors
   console.addCompleter(new CompositeCompletor(this, app.getCommandRegistry()));
   String line = console.readLine();
   while (line != null) {
     line = line.trim();
     try {
       if (line.length() > 0) {
         if (!execute(line)) {
           break;
         }
         // println();
       }
     } catch (Exception e) {
       e.printStackTrace();
     }
     line = console.readLine();
   }
   console.print("Bye");
   console.println();
 }
Exemplo n.º 24
0
 private String colorize(String string) {
   if (string.indexOf(ChatColor.COLOR_CHAR) < 0) {
     return string; // no colors in the message
   } else if (!jLine || !reader.getTerminal().isAnsiSupported()) {
     return ChatColor.stripColor(string); // color not supported
   } else {
     // colorize or strip all colors
     for (ChatColor color : colors) {
       if (replacements.containsKey(color)) {
         string = string.replaceAll("(?i)" + color.toString(), replacements.get(color));
       } else {
         string = string.replaceAll("(?i)" + color.toString(), "");
       }
     }
     return string + Ansi.ansi().reset().toString();
   }
 }
Exemplo n.º 25
0
  private void runAsciiMode() throws IOException {
    Ansi.setEnabled(_useColors);
    while (true) {
      String prompt = Ansi.ansi().bold().a(_userAdminShell.getPrompt()).boldOff().toString();
      Object result;
      try {
        String str = _console.readLine(prompt);
        try {
          if (str == null) {
            throw new CommandExitException();
          }
          result = _userAdminShell.executeCommand(str);
        } catch (IllegalArgumentException e) {
          result = e.toString();
        } catch (SerializationException e) {
          result = "There is a bug here, please report to [email protected]";
          _logger.error("This must be a bug, please report to [email protected].", e);
        } catch (CommandSyntaxException e) {
          result = e;
        } catch (CommandExitException e) {
          break;
        } catch (CommandPanicException e) {
          result =
              "Command '"
                  + str
                  + "' triggered a bug ("
                  + e.getTargetException()
                  + "); the service log file contains additional information. Please "
                  + "contact [email protected].";
        } catch (CommandException e) {
          result = e.getMessage();
        } catch (NoRouteToCellException e) {
          result = "Cell name does not exist or cell is not started: " + e.getMessage();
          _logger.warn(
              "The cell the command was sent to is no " + "longer there: {}", e.getMessage());
        } catch (RuntimeException e) {
          result =
              String.format(
                  "Command '%s' triggered a bug (%s); please"
                      + " locate this message in the log file of the admin service and"
                      + " send an email to [email protected] with this line and the"
                      + " following stack-trace",
                  str, e);
          _logger.error((String) result, e);
        }
      } catch (InterruptedIOException e) {
        _console.getCursorBuffer().clear();
        _console.println();
        result = null;
      } catch (InterruptedException e) {
        _console.println("^C");
        _console.flush();
        _console.getCursorBuffer().clear();
        result = null;
      } catch (IOException e) {
        throw e;
      } catch (Exception e) {
        result = e.getMessage();
        if (result == null) {
          result = e.getClass().getSimpleName() + ": (null)";
        }
      }

      if (result != null) {
        if (result instanceof CommandSyntaxException) {
          CommandSyntaxException e = (CommandSyntaxException) result;
          Ansi sb = Ansi.ansi();
          sb.fg(RED).a("Syntax error: ").a(e.getMessage()).newline();
          String help = e.getHelpText();
          if (help != null) {
            sb.fg(CYAN);
            sb.a("Help : ").newline();
            sb.a(help);
          }
          _console.println(sb.reset().toString());
        } else {
          String s;
          s = Strings.toMultilineString(result);
          if (!s.isEmpty()) {
            _console.println(s);
            _console.flush();
          }
        }
      }
      _console.flush();
    }
  }
Exemplo n.º 26
0
  @Override
  public void runInternal(GeogigCLI cli) throws IOException {
    checkParameter(patchFiles.size() < 2, "Only one single patch file accepted");
    checkParameter(!patchFiles.isEmpty(), "No patch file specified");

    ConsoleReader console = cli.getConsole();
    GeoGIG geogig = cli.getGeogig();

    File patchFile = new File(patchFiles.get(0));
    checkParameter(patchFile.exists(), "Patch file cannot be found");
    FileInputStream stream;
    try {
      stream = new FileInputStream(patchFile);
    } catch (FileNotFoundException e1) {
      throw new CommandFailedException("Can't open patch file " + patchFile, e1);
    }
    BufferedReader reader = null;
    try {
      reader = new BufferedReader(new InputStreamReader(stream, "UTF-8"));
    } catch (UnsupportedEncodingException e) {
      Closeables.closeQuietly(reader);
      Closeables.closeQuietly(stream);
      throw new CommandFailedException("Error reading patch file " + patchFile, e);
    }
    Patch patch = PatchSerializer.read(reader);
    Closeables.closeQuietly(reader);
    Closeables.closeQuietly(stream);

    if (reverse) {
      patch = patch.reversed();
    }

    if (summary) {
      console.println(patch.toString());
    } else if (check) {
      VerifyPatchResults verify =
          cli.getGeogig().command(VerifyPatchOp.class).setPatch(patch).call();
      Patch toReject = verify.getToReject();
      Patch toApply = verify.getToApply();
      if (toReject.isEmpty()) {
        console.println("Patch can be applied.");
      } else {
        console.println("Error: Patch cannot be applied\n");
        console.println("Applicable entries:\n");
        console.println(toApply.toString());
        console.println("\nConflicting entries:\n");
        console.println(toReject.toString());
      }
    } else {
      try {
        Patch rejected =
            geogig.command(ApplyPatchOp.class).setPatch(patch).setApplyPartial(reject).call();
        if (reject) {
          if (rejected.isEmpty()) {
            console.println("Patch applied succesfully");
          } else {
            int accepted = patch.count() - rejected.count();
            StringBuilder sb = new StringBuilder();
            File file = new File(patchFile.getAbsolutePath() + ".rej");
            sb.append("Patch applied only partially.\n");
            sb.append(Integer.toString(accepted) + " changes were applied.\n");
            sb.append(Integer.toString(rejected.count()) + " changes were rejected.\n");
            BufferedWriter writer = Files.newWriter(file, Charsets.UTF_8);
            PatchSerializer.write(writer, patch);
            writer.flush();
            writer.close();
            sb.append(
                "Patch file with rejected changes created at " + file.getAbsolutePath() + "\n");
            throw new CommandFailedException(sb.toString());
          }
        } else {
          console.println("Patch applied succesfully");
        }
      } catch (CannotApplyPatchException e) {
        throw new CommandFailedException(e);
      }
    }
  }
Exemplo n.º 27
0
 protected void initiateCodeCompletionRules() {
   StringsCompleter sc = new StringsCompleter(palavras);
   console.addCompleter(new ArgumentCompleter(sc, new FileNameCompleter()));
   // console.addCompleter(sc);
 }
Exemplo n.º 28
0
  /** Executes the revlist command using the provided options. */
  @Override
  public void runInternal(GeogigCLI cli) throws IOException {
    checkParameter(!args.commits.isEmpty(), "No starting commit provided");

    geogig = cli.getGeogig();

    LogOp op =
        geogig.command(LogOp.class).setTopoOrder(args.topo).setFirstParentOnly(args.firstParent);

    for (String commit : args.commits) {
      if (commit.contains("..")) {
        checkParameter(
            args.commits.size() == 1, "Only one value accepted when using <since>..<until> syntax");
        List<String> sinceUntil = ImmutableList.copyOf((Splitter.on("..").split(commit)));
        checkParameter(
            sinceUntil.size() == 2 || sinceUntil.size() == 1,
            "Invalid refSpec format, expected [<commit> ...]|[<since>..<until>]: %s",
            commit);
        String sinceRefSpec;
        String untilRefSpec;
        if (sinceUntil.size() == 1) {
          // just until was given
          sinceRefSpec = null;
          untilRefSpec = sinceUntil.get(0);
        } else {
          sinceRefSpec = sinceUntil.get(0);
          untilRefSpec = sinceUntil.get(1);
        }
        if (sinceRefSpec != null) {
          Optional<ObjectId> since;
          since = geogig.command(RevParse.class).setRefSpec(sinceRefSpec).call();
          checkParameter(since.isPresent(), "Object not found '%s'", sinceRefSpec);
          op.setSince(since.get());
        }
        if (untilRefSpec != null) {
          Optional<ObjectId> until;
          until = geogig.command(RevParse.class).setRefSpec(untilRefSpec).call();
          checkParameter(until.isPresent(), "Object not found '%s'", sinceRefSpec);
          op.setUntil(until.get());
        }
      } else {
        Optional<ObjectId> commitId = geogig.command(RevParse.class).setRefSpec(commit).call();
        checkParameter(commitId.isPresent(), "Object not found '%s'", commit);
        checkParameter(
            geogig.getRepository().commitExists(commitId.get()),
            "%s does not resolve to a commit",
            commit);
        op.addCommit(commitId.get());
      }
    }
    if (args.author != null && !args.author.isEmpty()) {
      op.setAuthor(args.author);
    }
    if (args.committer != null && !args.committer.isEmpty()) {
      op.setCommiter(args.committer);
    }
    if (args.skip != null) {
      op.setSkip(args.skip.intValue());
    }
    if (args.limit != null) {
      op.setLimit(args.limit.intValue());
    }
    if (args.since != null || args.until != null) {
      Date since = new Date(0);
      Date until = new Date();
      if (args.since != null) {
        since = new Date(geogig.command(ParseTimestamp.class).setString(args.since).call());
      }
      if (args.until != null) {
        until = new Date(geogig.command(ParseTimestamp.class).setString(args.until).call());
      }
      op.setTimeRange(new Range<Date>(Date.class, since, until));
    }
    if (!args.pathNames.isEmpty()) {
      for (String s : args.pathNames) {
        op.addPath(s);
      }
    }
    Iterator<RevCommit> log = op.call();
    console = cli.getConsole();

    RawPrinter printer = new RawPrinter(args.changed);
    while (log.hasNext()) {
      printer.print(log.next());
      console.flush();
    }
  }
Exemplo n.º 29
0
 @Override
 public void println() throws IOException {
   console.flush();
   console.println();
 }
Exemplo n.º 30
0
  public ConsoleManager(GlowServer server) {
    this.server = server;

    // install Ansi code handler, which makes colors work on Windows
    AnsiConsole.systemInstall();

    for (Handler h : logger.getHandlers()) {
      logger.removeHandler(h);
    }

    // add log handler which writes to console
    logger.addHandler(new FancyConsoleHandler());

    // reader must be initialized before standard streams are changed
    try {
      reader = new ConsoleReader();
    } catch (IOException ex) {
      logger.log(Level.SEVERE, "Exception initializing console reader", ex);
    }
    reader.addCompleter(new CommandCompleter());

    // set system output streams
    System.setOut(new PrintStream(new LoggerOutputStream(Level.INFO), true));
    System.setErr(new PrintStream(new LoggerOutputStream(Level.WARNING), true));

    // set up colorization replacements
    replacements.put(
        ChatColor.BLACK,
        Ansi.ansi().a(Ansi.Attribute.RESET).fg(Ansi.Color.BLACK).boldOff().toString());
    replacements.put(
        ChatColor.DARK_BLUE,
        Ansi.ansi().a(Ansi.Attribute.RESET).fg(Ansi.Color.BLUE).boldOff().toString());
    replacements.put(
        ChatColor.DARK_GREEN,
        Ansi.ansi().a(Ansi.Attribute.RESET).fg(Ansi.Color.GREEN).boldOff().toString());
    replacements.put(
        ChatColor.DARK_AQUA,
        Ansi.ansi().a(Ansi.Attribute.RESET).fg(Ansi.Color.CYAN).boldOff().toString());
    replacements.put(
        ChatColor.DARK_RED,
        Ansi.ansi().a(Ansi.Attribute.RESET).fg(Ansi.Color.RED).boldOff().toString());
    replacements.put(
        ChatColor.DARK_PURPLE,
        Ansi.ansi().a(Ansi.Attribute.RESET).fg(Ansi.Color.MAGENTA).boldOff().toString());
    replacements.put(
        ChatColor.GOLD,
        Ansi.ansi().a(Ansi.Attribute.RESET).fg(Ansi.Color.YELLOW).boldOff().toString());
    replacements.put(
        ChatColor.GRAY,
        Ansi.ansi().a(Ansi.Attribute.RESET).fg(Ansi.Color.WHITE).boldOff().toString());
    replacements.put(
        ChatColor.DARK_GRAY,
        Ansi.ansi().a(Ansi.Attribute.RESET).fg(Ansi.Color.BLACK).bold().toString());
    replacements.put(
        ChatColor.BLUE, Ansi.ansi().a(Ansi.Attribute.RESET).fg(Ansi.Color.BLUE).bold().toString());
    replacements.put(
        ChatColor.GREEN,
        Ansi.ansi().a(Ansi.Attribute.RESET).fg(Ansi.Color.GREEN).bold().toString());
    replacements.put(
        ChatColor.AQUA, Ansi.ansi().a(Ansi.Attribute.RESET).fg(Ansi.Color.CYAN).bold().toString());
    replacements.put(
        ChatColor.RED, Ansi.ansi().a(Ansi.Attribute.RESET).fg(Ansi.Color.RED).bold().toString());
    replacements.put(
        ChatColor.LIGHT_PURPLE,
        Ansi.ansi().a(Ansi.Attribute.RESET).fg(Ansi.Color.MAGENTA).bold().toString());
    replacements.put(
        ChatColor.YELLOW,
        Ansi.ansi().a(Ansi.Attribute.RESET).fg(Ansi.Color.YELLOW).bold().toString());
    replacements.put(
        ChatColor.WHITE,
        Ansi.ansi().a(Ansi.Attribute.RESET).fg(Ansi.Color.WHITE).bold().toString());
    replacements.put(ChatColor.MAGIC, Ansi.ansi().a(Ansi.Attribute.BLINK_SLOW).toString());
    replacements.put(ChatColor.BOLD, Ansi.ansi().a(Ansi.Attribute.UNDERLINE_DOUBLE).toString());
    replacements.put(
        ChatColor.STRIKETHROUGH, Ansi.ansi().a(Ansi.Attribute.STRIKETHROUGH_ON).toString());
    replacements.put(ChatColor.UNDERLINE, Ansi.ansi().a(Ansi.Attribute.UNDERLINE).toString());
    replacements.put(ChatColor.ITALIC, Ansi.ansi().a(Ansi.Attribute.ITALIC).toString());
    replacements.put(ChatColor.RESET, Ansi.ansi().a(Ansi.Attribute.RESET).toString());
  }