console.println("usage: geogig <command> [<args>]"); console.println(); int i = 0; for (String cmd : commandNames) { console.print(Strings.padEnd(cmd, longestCommandLenght, ' ')); i++; if (i % 3 == 0) { console.println(); } else { console.print("\t"); console.flush(); } catch (IOException e) { throw Throwables.propagate(e);
/** * Creates a Console that reads from and writes to the provided streams. * * @param in the console's input stream * @param out the console's output stream */ public Console(InputStream in, OutputStream out) { this.in = in; this.cursorBuffer = new StringBuffer(); this.ansiEnabled = true; this.forceAnsi = false; try { this.ansiSupported = checkAnsiSupported(out, checkOS()); } catch (UnsatisfiedLinkError e) { this.ansiSupported = false; } catch (Throwable e) { this.ansiSupported = false; } if (out instanceof PrintStream) { this.out = (PrintStream) out; } else { boolean autoFlush = true; this.out = new PrintStream(out, autoFlush); } }
protected Ansi newAnsi(Console console) { boolean useColor; switch (color) { case never: useColor = false; break; case always: useColor = true; break; default: useColor = console.isAnsiSupported(); } Ansi ansi = AnsiDecorator.newAnsi(useColor); return ansi; }
/** * This method should be used instead of {@link JCommander#usage()} so the help string is * printed to the cli's {@link #getConsole() console} (and hence to wherever its output is sent) * instead of directly to {@code System.out} */ public void printUsage(JCommander mainCommander) { StringBuilder out = new StringBuilder(); mainCommander.usage(out); Console console = getConsole(); try { console.println(out.toString()); console.flush(); } catch (IOException e) { throw new RuntimeException(e); } }
public CLIContext(URI repoURI, TestPlatform platform) { checkNotNull(repoURI); checkNotNull(platform); this.repositoryURI = repoURI; this.platform = platform; stdIn = new ByteArrayInputStream(new byte[0]); stdOut = new ByteArrayOutputStream(); consoleReader = new Console(stdIn, stdOut).disableAnsi(); geogigCLI = new GeogigCLI(consoleReader); geogigCLI.setPlatform(platform); }
/** * Print a new line, flushing the cursor buffer. * * @throws IOException */ public void println() throws IOException { println(""); }
/** * Moves the console cursor to the beginning of the line (prints a carriage return {@code '\r'} * character) and redraws the contents of the cursor buffer. * * @throws IOException */ public void redrawLine() throws IOException { cursorBuffer.append(CARRIAGE_RETURN); flush(); }
Ansi ansi = AnsiDecorator.newAnsi(console.isAnsiSupported()); Set<Entry<PropertyDescriptor, AttributeDiff>> entries = diffs.entrySet(); Iterator<Entry<PropertyDescriptor, AttributeDiff>> iter = entries.iterator(); console.println(ansi.toString()); } else if (diffEntry.changeType() == ChangeType.ADDED) { NodeRef noderef = diffEntry.getNewObject(); for (int i = 0; i < feature.size(); i++) { Optional<Object> value = feature.get(i); console.println(featureType.descriptors().get(i).getName() + "\t" + TextValueSerializer.asString(value)); console.println();
@Test public void forceAnsiTest() { Console console = new Console(); console.setForceAnsi(true); assertTrue(console.isAnsiSupported()); console.setForceAnsi(false); assertFalse(console.isAnsiSupported()); }
@Test public void testWindows10Detection() { Console console = new Console(); boolean returned = false; try { returned = console.checkAnsiSupported(System.out, "windows 10"); } catch (Throwable er) { returned = true; } assertTrue(returned); }
public static void print(GeoGIG geogig, Console console, DiffSummary<BoundingBox, BoundingBox> diffBounds) throws IOException { BoundingBox left = diffBounds.getLeft(); BoundingBox right = diffBounds.getRight(); Optional<BoundingBox> mergedResult = diffBounds.getMergedResult(); BoundingBox both = new ReferencedEnvelope(); if (mergedResult.isPresent()) { both = mergedResult.get(); } Ansi ansi = AnsiDecorator.newAnsi(console.isAnsiSupported()); ansi.a("left: ").a(bounds(left)).newline(); ansi.a("right: ").a(bounds(right)).newline(); ansi.a("both: ").a(bounds(both)).newline(); ansi.a("CRS: ").a(CRS.toSRS(left.getCoordinateReferenceSystem())).newline(); console.print(ansi.toString()); }
public CLIContext(URI repoURI, TestPlatform platform) { checkNotNull(repoURI); checkNotNull(platform); this.repositoryURI = repoURI; this.platform = platform; stdIn = new ByteArrayInputStream(new byte[0]); stdOut = new ByteArrayOutputStream(); consoleReader = new Console(stdIn, stdOut).disableAnsi(); geogigCLI = new GeogigCLI(consoleReader); geogigCLI.setPlatform(platform); }
/** * This method should be used instead of {@link JCommander#usage()} so the help string is * printed to the cli's {@link #getConsole() console} (and hence to wherever its output is sent) * instead of directly to {@code System.out} */ public void printUsage(JCommander mainCommander) { StringBuilder out = new StringBuilder(); mainCommander.usage(out); Console console = getConsole(); try { console.println(out.toString()); console.flush(); } catch (IOException e) { throw new RuntimeException(e); } }
private void print(Object b) { try { CharSequence line = printFunctor.apply(b); console.println(line); } catch (IOException e) { throw new RuntimeException(e); } }
/** * Moves the console cursor to the beginning of the line (prints a carriage return {@code '\r'} * character) and redraws the contents of the cursor buffer. * * @throws IOException */ public void redrawLine() throws IOException { cursorBuffer.append(CARRIAGE_RETURN); flush(); }
@Override public void print(GeoGIG geogig, Console console, DiffEntry entry) throws IOException { Ansi ansi = AnsiDecorator.newAnsi(console.isAnsiSupported()); final NodeRef newObject = entry.getNewObject(); final NodeRef oldObject = entry.getOldObject(); String oldMode = shortOid(oldObject == null ? ObjectId.NULL : oldObject.getMetadataId()); String newMode = shortOid(newObject == null ? ObjectId.NULL : newObject.getMetadataId()); String oldId = shortOid(oldObject == null ? ObjectId.NULL : oldObject.getObjectId()); String newId = shortOid(newObject == null ? ObjectId.NULL : newObject.getObjectId()); ansi.a(oldMode).a(" "); ansi.a(newMode).a(" "); ansi.a(oldId).a(" "); ansi.a(newId).a(" "); ansi.fg(entry.changeType() == ADDED ? GREEN : (entry.changeType() == MODIFIED ? YELLOW : RED)); char type = entry.changeType().toString().charAt(0); ansi.a(" ").a(type).reset(); ansi.a(" ").a(formatPath(entry)); console.println(ansi.toString()); }
@Test public void testWindows7Detection() throws Throwable { Console console = new Console(); assertFalse(console.checkAnsiSupported(System.out, "windows 7")); } }