Package org.fusesource.jansi

Examples of org.fusesource.jansi.Ansi


                    .setNewVersion(Suppliers.ofInstance(diffEntry.getNewObject()))
                    .setOldVersion(Suppliers.ofInstance(diffEntry.getOldObject())).call();

            Map<PropertyDescriptor, AttributeDiff> diffs = diff.getDiffs();

            Ansi ansi = AnsiDecorator.newAnsi(console.getTerminal().isAnsiSupported());
            Set<Entry<PropertyDescriptor, AttributeDiff>> entries = diffs.entrySet();
            Iterator<Entry<PropertyDescriptor, AttributeDiff>> iter = entries.iterator();
            while (iter.hasNext()) {
                Entry<PropertyDescriptor, AttributeDiff> entry = iter.next();
                PropertyDescriptor pd = entry.getKey();
                AttributeDiff ad = entry.getValue();
                if (ad instanceof GeometryAttributeDiff
                        && ad.getType() == org.locationtech.geogig.api.plumbing.diff.AttributeDiff.TYPE.MODIFIED
                        && !noGeom) {
                    GeometryAttributeDiff gd = (GeometryAttributeDiff) ad;
                    ansi.fg(YELLOW);
                    ansi.a(pd.getName()).a(": ");
                    ansi.reset();
                    String text = gd.getDiff().getDiffCoordsString();
                    for (int i = 0; i < text.length(); i++) {
                        if (text.charAt(i) == '(') {
                            ansi.fg(GREEN);
                            ansi.a(text.charAt(i));
                        } else if (text.charAt(i) == '[') {
                            ansi.fg(RED);
                            ansi.a(text.charAt(i));
                        } else if (text.charAt(i) == ']' || text.charAt(i) == ')') {
                            ansi.a(text.charAt(i));
                            ansi.reset();
                        } else if (text.charAt(i) == LCSGeometryDiffImpl.INNER_RING_SEPARATOR
                                .charAt(0)
                                || text.charAt(i) == LCSGeometryDiffImpl.SUBGEOM_SEPARATOR
                                        .charAt(0)) {
                            ansi.fg(BLUE);
                            ansi.a(text.charAt(i));
                            ansi.reset();
                        } else {
                            ansi.a(text.charAt(i));
                        }
                    }
                    ansi.reset();
                    ansi.newline();
                } else {
                    ansi.fg(ad.getType() == org.locationtech.geogig.api.plumbing.diff.AttributeDiff.TYPE.ADDED ? GREEN
                            : (ad.getType() == org.locationtech.geogig.api.plumbing.diff.AttributeDiff.TYPE.REMOVED ? RED
                                    : YELLOW));
                    ansi.a(pd.getName()).a(": ").a(ad.toString());
                    ansi.reset();
                    ansi.newline();
                }
            }
            console.println(ansi.toString());
        } else if (diffEntry.changeType() == ChangeType.ADDED) {
            NodeRef noderef = diffEntry.getNewObject();
            RevFeatureType featureType = geogig.command(RevObjectParse.class)
                    .setObjectId(noderef.getMetadataId()).call(RevFeatureType.class).get();
            Optional<RevObject> obj = geogig.command(RevObjectParse.class)
View Full Code Here


            break;
        default:
            useColor = terminal.isAnsiSupported();
        }

        Ansi ansi = AnsiDecorator.newAnsi(useColor, target);
        return ansi;
    }
View Full Code Here

            break;
        default:
            useColor = terminal.isAnsiSupported();
        }

        Ansi ansi = AnsiDecorator.newAnsi(useColor);
        return ansi;
    }
View Full Code Here

                        .setRefSpec(ref).call();
                if (opt.isPresent()) {
                    RevFeatureType ft = opt.get();
                    ImmutableList<PropertyDescriptor> attribs = ft.sortedDescriptors();
                    RevFeature feature = (RevFeature) revObject;
                    Ansi ansi = super.newAnsi(console.getTerminal());
                    ansi.a(ref).newline();
                    ansi.a(feature.getId().toString()).newline();
                    ImmutableList<Optional<Object>> values = feature.getValues();
                    int i = 0;
                    for (Optional<Object> value : values) {
                        PropertyDescriptor attrib = attribs.get(i);
                        ansi.a(attrib.getName()).newline();
                        PropertyType attrType = attrib.getType();
                        String typeName = FieldType.forBinding(attrType.getBinding()).name();
                        if (attrType instanceof GeometryType) {
                            GeometryType gt = (GeometryType) attrType;
                            CoordinateReferenceSystem crs = gt.getCoordinateReferenceSystem();
                            String crsText = CrsTextSerializer.serialize(crs);
                            ansi.a(typeName).a(" ").a(crsText).newline();
                        } else {
                            ansi.a(typeName).newline();
                        }
                        ansi.a(value.or("[NULL]").toString()).newline();
                        i++;
                    }
                    console.println(ansi.toString());
                } else {
                    CharSequence s = geogig.command(CatObject.class)
                            .setObject(Suppliers.ofInstance(revObject)).call();
                    console.println(s);
                }
View Full Code Here

                        .setRefSpec(ref).call();
                if (opt.isPresent()) {
                    RevFeatureType ft = opt.get();
                    ImmutableList<PropertyDescriptor> attribs = ft.sortedDescriptors();
                    RevFeature feature = (RevFeature) revObject;
                    Ansi ansi = super.newAnsi(console.getTerminal());
                    ansi.newline().fg(Color.YELLOW).a("ID:  ").reset()
                            .a(feature.getId().toString()).newline();
                    ansi.fg(Color.YELLOW).a("FEATURE TYPE ID:  ").reset().a(ft.getId().toString())
                            .newline().newline();
                    ansi.a("ATTRIBUTES  ").newline();
                    ansi.a("----------  ").newline();
                    ImmutableList<Optional<Object>> values = feature.getValues();
                    int i = 0;
                    for (Optional<Object> value : values) {
                        ansi.fg(Color.YELLOW).a(attribs.get(i).getName() + ": ").reset();
                        ansi.a(value.or("[NULL]").toString()).newline();
                        i++;
                    }
                    console.println(ansi.toString());
                } else {
                    CharSequence s = geogig.command(CatObject.class)
                            .setObject(Suppliers.ofInstance(revObject)).call();
                    console.println(s);
                }

            } else if (revObject instanceof RevTree) {
                RevTree tree = (RevTree) revObject;
                Optional<RevFeatureType> opt = geogig.command(ResolveFeatureType.class)
                        .setRefSpec(ref).call();
                checkParameter(opt.isPresent(),
                        "Refspec must resolve to a commit, tree, feature or feature type");
                RevFeatureType ft = opt.get();
                Ansi ansi = super.newAnsi(console.getTerminal());

                ansi.fg(Color.YELLOW).a("TREE ID:  ").reset().a(tree.getId().toString()).newline();
                ansi.fg(Color.YELLOW).a("SIZE:  ").reset().a(Long.toString(tree.size())).newline();
                ansi.fg(Color.YELLOW).a("NUMBER Of SUBTREES:  ").reset()
                        .a(Integer.toString(tree.numTrees()).toString()).newline();

                printFeatureType(ansi, ft, true);

                console.println(ansi.toString());
            } else if (revObject instanceof RevCommit) {
                RevCommit commit = (RevCommit) revObject;
                Ansi ansi = super.newAnsi(console.getTerminal());
                ansi.a(Strings.padEnd("Commit:", 15, ' ')).fg(Color.YELLOW)
                        .a(commit.getId().toString()).reset().newline();
                ansi.a(Strings.padEnd("Author:", 15, ' ')).fg(Color.GREEN)
                        .a(formatPerson(commit.getAuthor())).reset().newline();
                ansi.a(Strings.padEnd("Committer:", 15, ' ')).fg(Color.GREEN)
                        .a(formatPerson(commit.getAuthor())).reset().newline();
                ansi.a(Strings.padEnd("Author date:", 15, ' ')).a("(").fg(Color.RED)
                        .a(estimateSince(geogig.getPlatform(), commit.getAuthor().getTimestamp()))
                        .reset().a(") ").a(new Date(commit.getAuthor().getTimestamp())).newline();
                ansi.a(Strings.padEnd("Committer date:", 15, ' '))
                        .a("(")
                        .fg(Color.RED)
                        .a(estimateSince(geogig.getPlatform(), commit.getCommitter().getTimestamp()))
                        .reset().a(") ").a(new Date(commit.getCommitter().getTimestamp()))
                        .newline();
                ansi.a(Strings.padEnd("Subject:", 15, ' ')).a(commit.getMessage()).newline();
                console.println(ansi.toString());
            } else if (revObject instanceof RevFeatureType) {
                Ansi ansi = super.newAnsi(console.getTerminal());
                printFeatureType(ansi, (RevFeatureType) revObject, false);
                console.println(ansi.toString());
            } else {
                throw new InvalidParameterException(
                        "Refspec must resolve to a commit, tree, feature or feature type");
            }
            console.println();
View Full Code Here

                        sb.append(" ").append(
                                TextValueSerializer.asString(Optional.of((Object) value.orNull())));
                    }
                    console.println(sb.toString());
                } else {
                    Ansi ansi = newAnsi(console.getTerminal());
                    ansi.fg(GREEN).a(attrib + ": ").reset();
                    if (!noValues) {
                        String s = value.isPresent() ? value.get().toString() : "NULL";
                        ansi.fg(YELLOW).a(s).a(" ").reset();
                    }
                    ansi.a(commit.getId().toString().substring(0, 7)).a(" ");
                    ansi.a(commit.getAuthor().getName().or("")).a(" ");
                    ansi.a(commit.getAuthor().getEmail().or("")).a(" ");
                    SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
                    String date = formatter.format(new Date(commit.getAuthor().getTimestamp()
                            + commit.getAuthor().getTimeZoneOffset()));
                    ansi.a(date);
                    console.println(ansi.toString());
                }
            }
        } catch (BlameException e) {
            switch (e.statusCode) {
            case FEATURE_NOT_FOUND:
View Full Code Here

        final int largest = verbose ? largestLenght(branches) : 0;

        for (Ref branchRef : branches) {
            final String branchRefName = branchRef.getName();

            Ansi ansi = newAnsi(console.getTerminal());

            if ((currentHead instanceof SymRef)
                    && ((SymRef) currentHead).getTarget().equals(branchRefName)) {
                ansi.a("* ").fg(Color.GREEN);
            } else {
                ansi.a("  ");
            }
            // print unqualified names for local branches
            String branchName = refDisplayString(branchRef);
            ansi.a(branchName);
            ansi.reset();

            if (verbose) {
                ansi.a(Strings.repeat(" ", 1 + (largest - branchName.length())));
                ansi.a(branchRef.getObjectId().toString().substring(0, 7)).a(" ");

                Optional<RevCommit> commit = findCommit(geogig, branchRef);
                if (commit.isPresent()) {
                    ansi.a(messageTitle(commit.get()));
                }
            }

            console.println(ansi.toString());
        }
    }
View Full Code Here

        StringBuilder sb = new StringBuilder();
        return newAnsi(ansiSupported, sb);
    }

    public static Ansi newAnsi(boolean ansiSupported, StringBuilder sb) {
        Ansi ansi = new Ansi(sb);
        ansiSupported &= null != System.console();
        if (ansiSupported) {
            return ansi;
        }
View Full Code Here

        checkParameter(!Strings.isNullOrEmpty(message) || commitToReuse != null || amend,
                "No commit message provided");

        ConsoleReader console = cli.getConsole();

        Ansi ansi = newAnsi(console.getTerminal());

        RevCommit commit;
        try {
            CommitOp commitOp = geogig.command(CommitOp.class).setMessage(message).setAmend(amend);
            if (commitTimestamp != null && !Strings.isNullOrEmpty(commitTimestamp)) {
                Long millis = geogig.command(ParseTimestamp.class).setString(commitTimestamp)
                        .call();
                commitOp.setCommitterTimestamp(millis.longValue());
            }

            if (commitToReuse != null) {
                Optional<ObjectId> commitId = geogig.command(RevParse.class)
                        .setRefSpec(commitToReuse).call();
                checkParameter(commitId.isPresent(), "Provided reference does not exist");
                TYPE type = geogig.command(ResolveObjectType.class).setObjectId(commitId.get())
                        .call();
                checkParameter(TYPE.COMMIT.equals(type),
                        "Provided reference does not resolve to a commit");
                commitOp.setCommit(geogig.getRepository().getCommit(commitId.get()));
            }
            commit = commitOp.setPathFilters(pathFilters)
                    .setProgressListener(cli.getProgressListener()).call();
        } catch (NothingToCommitException noChanges) {
            throw new CommandFailedException(noChanges.getMessage(), noChanges);
        }
        final ObjectId parentId = commit.parentN(0).or(ObjectId.NULL);

        console.println("[" + commit.getId() + "] " + commit.getMessage());

        console.print("Committed, counting objects...");
        Iterator<DiffEntry> diff = geogig.command(DiffOp.class).setOldVersion(parentId)
                .setNewVersion(commit.getId()).call();

        int adds = 0, deletes = 0, changes = 0;
        DiffEntry diffEntry;
        while (diff.hasNext()) {
            diffEntry = diff.next();
            switch (diffEntry.changeType()) {
            case ADDED:
                ++adds;
                break;
            case REMOVED:
                ++deletes;
                break;
            case MODIFIED:
                ++changes;
                break;
            }
        }

        ansi.fg(Color.GREEN).a(adds).reset().a(" features added, ").fg(Color.YELLOW).a(changes)
                .reset().a(" changed, ").fg(Color.RED).a(deletes).reset().a(" deleted.").reset()
                .newline();

        console.print(ansi.toString());
    }
View Full Code Here

        ConsoleReader console = cli.getConsole();

        final GeoGIG geogig = cli.getGeogig();

        Ansi ansi = newAnsi(console.getTerminal());

        if (abort) {
            Optional<Ref> ref = geogig.command(RefParse.class).setName(Ref.ORIG_HEAD).call();
            if (!ref.isPresent()) {
                throw new CommandFailedException("There is no merge to abort <ORIG_HEAD missing>.");
            }

            geogig.command(ResetOp.class).setMode(ResetMode.HARD)
                    .setCommit(Suppliers.ofInstance(ref.get().getObjectId())).call();
            console.println("Merge aborted successfully.");
            return;
        }

        RevCommit commit;
        try {
            MergeOp merge = geogig.command(MergeOp.class);
            merge.setOurs(ours).setTheirs(theirs).setNoCommit(noCommit);
            merge.setMessage(message).setProgressListener(cli.getProgressListener());
            for (String commitish : commits) {
                Optional<ObjectId> commitId;
                commitId = geogig.command(RevParse.class).setRefSpec(commitish).call();
                checkParameter(commitId.isPresent(), "Commit not found '%s'", commitish);
                merge.addCommit(Suppliers.ofInstance(commitId.get()));
            }
            MergeReport report = merge.call();
            commit = report.getMergeCommit();
        } catch (RuntimeException e) {
            if (e instanceof NothingToCommitException || e instanceof IllegalArgumentException
                    || e instanceof IllegalStateException) {
                throw new CommandFailedException(e.getMessage(), e);
            }
            throw e;
        }
        final ObjectId parentId = commit.parentN(0).or(ObjectId.NULL);

        console.println("[" + commit.getId() + "] " + commit.getMessage());

        console.print("Committed, counting objects...");
        Iterator<DiffEntry> diff = geogig.command(DiffOp.class).setOldVersion(parentId)
                .setNewVersion(commit.getId()).call();

        int adds = 0, deletes = 0, changes = 0;
        DiffEntry diffEntry;
        while (diff.hasNext()) {
            diffEntry = diff.next();
            switch (diffEntry.changeType()) {
            case ADDED:
                ++adds;
                break;
            case REMOVED:
                ++deletes;
                break;
            case MODIFIED:
                ++changes;
                break;
            }
        }

        ansi.fg(Color.GREEN).a(adds).reset().a(" features added, ").fg(Color.YELLOW).a(changes)
                .reset().a(" changed, ").fg(Color.RED).a(deletes).reset().a(" deleted.").reset()
                .newline();

        console.print(ansi.toString());
    }
View Full Code Here

TOP

Related Classes of org.fusesource.jansi.Ansi

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.