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"; } }
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) { } }
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(); } }
public void run() { try { if (this.init()) { this.ab = ax(); long i = 0L; this.r.setMOTD(new ChatComponentText(this.motd)); this.r.setServerInfo(new ServerPingServerData("1.8", 47)); this.a(this.r); // Spigot start Arrays.fill(recentTps, 20); long lastTick = System.nanoTime(), catchupTime = 0, curTime, wait, tickSection = lastTick; while (this.isRunning) { curTime = System.nanoTime(); wait = TICK_TIME - (curTime - lastTick) - catchupTime; if (wait > 0) { Thread.sleep(wait / 1000000); catchupTime = 0; continue; } else { catchupTime = Math.min(1000000000, Math.abs(wait)); } if (MinecraftServer.currentTick++ % SAMPLE_INTERVAL == 0) { double currentTps = 1E9 / (curTime - tickSection) * SAMPLE_INTERVAL; recentTps[0] = calcTps(recentTps[0], 0.92, currentTps); // 1/exp(5sec/1min) recentTps[1] = calcTps(recentTps[1], 0.9835, currentTps); // 1/exp(5sec/5min) recentTps[2] = calcTps(recentTps[2], 0.9945, currentTps); // 1/exp(5sec/15min) tickSection = curTime; } lastTick = curTime; this.y(); this.Q = true; } // Spigot end } else { this.a((CrashReport) null); } } catch (Throwable throwable) { MinecraftServer.LOGGER.error("Encountered an unexpected exception", throwable); // Spigot Start if (throwable.getCause() != null) { MinecraftServer.LOGGER.error("\tCause of unexpected exception was", throwable.getCause()); } // Spigot End CrashReport crashreport = null; if (throwable instanceof ReportedException) { crashreport = this.b(((ReportedException) throwable).a()); } else { crashreport = this.b(new CrashReport("Exception in server tick loop", throwable)); } File file = new File( new File(this.w(), "crash-reports"), "crash-" + (new SimpleDateFormat("yyyy-MM-dd_HH.mm.ss")).format(new Date()) + "-server.txt"); if (crashreport.a(file)) { MinecraftServer.LOGGER.error( "This crash report has been saved to: " + file.getAbsolutePath()); } else { MinecraftServer.LOGGER.error("We were unable to save this crash report to disk."); } this.a(crashreport); } finally { try { org.spigotmc.WatchdogThread.doStop(); this.stop(); this.isStopped = true; } catch (Throwable throwable1) { MinecraftServer.LOGGER.error("Exception stopping the server", throwable1); } finally { // CraftBukkit start - Restore terminal to original settings try { reader.getTerminal().restore(); } catch (Exception ignored) { } // CraftBukkit end this.x(); } } }
/** * Executes the log command using the provided options. * * @param cli * @throws IOException * @see org.geogit.cli.AbstractCommand#runInternal(org.geogit.cli.GeogitCLI) */ @Override public void runInternal(GeogitCLI cli) throws Exception { final Platform platform = cli.getPlatform(); Preconditions.checkState( cli.getGeogit() != null, "Not a geogit repository: " + platform.pwd().getAbsolutePath()); Preconditions.checkArgument( !(args.summary && args.oneline), "--summary and --oneline cannot be used together"); Preconditions.checkArgument( !(args.stats && args.oneline), "--stats and --oneline cannot be used together"); Preconditions.checkArgument( !(args.stats && args.oneline), "--name-only and --oneline cannot be used together"); geogit = cli.getGeogit(); LogOp op = geogit.command(LogOp.class).setTopoOrder(args.topo).setFirstParentOnly(args.firstParent); refs = Maps.newHashMap(); if (args.decoration) { Optional<Ref> head = geogit.command(RefParse.class).setName(Ref.HEAD).call(); refs.put(head.get().getObjectId(), Ref.HEAD); ImmutableSet<Ref> set = geogit.command(ForEachRef.class).call(); for (Ref ref : set) { ObjectId id = ref.getObjectId(); if (refs.containsKey(id)) { refs.put(id, refs.get(id) + ", " + ref.getName()); } else { refs.put(id, ref.getName()); } } } if (args.all) { ImmutableSet<Ref> refs = geogit.command(ForEachRef.class).call(); List<ObjectId> list = Lists.newArrayList(); for (Ref ref : refs) { list.add(ref.getObjectId()); } Optional<Ref> head = geogit.command(RefParse.class).setName(Ref.HEAD).call(); if (head.isPresent()) { Ref ref = head.get(); if (ref instanceof SymRef) { ObjectId id = ref.getObjectId(); list.remove(id); list.add(id); // put the HEAD ref in the last position, to give it preference } } for (ObjectId id : list) { op.addCommit(id); } } else if (args.branch != null) { Optional<Ref> obj = geogit.command(RefParse.class).setName(args.branch).call(); Preconditions.checkArgument(obj.isPresent(), "Wrong branch name: " + args.branch); op.addCommit(obj.get().getObjectId()); } 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(geogit.command(ParseTimestamp.class).setString(args.since).call()); } if (args.until != null) { until = new Date(geogit.command(ParseTimestamp.class).setString(args.until).call()); if (args.all) { throw new IllegalStateException( "Cannot specify 'until' commit when listing all branches"); } } op.setTimeRange(new Range<Date>(Date.class, since, until)); } if (!args.sinceUntilPaths.isEmpty()) { List<String> sinceUntil = ImmutableList.copyOf((Splitter.on("..").split(args.sinceUntilPaths.get(0)))); Preconditions.checkArgument( sinceUntil.size() == 1 || sinceUntil.size() == 2, "Invalid refSpec format, expected [<until>]|[<since>..<until>]: %s", args.sinceUntilPaths.get(0)); 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 = geogit.command(RevParse.class).setRefSpec(sinceRefSpec).call(); Preconditions.checkArgument(since.isPresent(), "Object not found '%s'", sinceRefSpec); op.setSince(since.get()); } if (untilRefSpec != null) { if (args.all) { throw new IllegalStateException( "Cannot specify 'until' commit when listing all branches"); } Optional<ObjectId> until; until = geogit.command(RevParse.class).setRefSpec(untilRefSpec).call(); Preconditions.checkArgument(until.isPresent(), "Object not found '%s'", sinceRefSpec); op.setUntil(until.get()); } } if (!args.pathNames.isEmpty()) { for (String s : args.pathNames) { op.addPath(s); } } Iterator<RevCommit> log = op.call(); console = cli.getConsole(); Terminal terminal = console.getTerminal(); switch (args.color) { case never: useColor = false; break; case always: useColor = true; break; default: useColor = terminal.isAnsiSupported(); } if (!log.hasNext()) { console.println("No commits to show"); console.flush(); return; } LogEntryPrinter printer; if (args.oneline) { printer = new OneLineConverter(); } else { LOG_DETAIL detail; if (args.summary) { detail = LOG_DETAIL.SUMMARY; } else if (args.names) { detail = LOG_DETAIL.NAMES_ONLY; } else if (args.stats) { detail = LOG_DETAIL.STATS; } else { detail = LOG_DETAIL.NOTHING; } printer = new StandardConverter(detail, geogit.getPlatform()); } while (log.hasNext()) { printer.print(log.next()); console.flush(); } }