<commit_before>// -*- mode:java; tab-width:4; c-basic-offset:4; indent-tabs-mode:nil -*-

#if !TOPLEVEL
package coopy;
#end

/**
 *
 * Decorate a diff being displayed on a console.  Colors, glyphs, any
 * other eye-candy we like.
 *
 */
class TerminalDiffRender {
    private var codes: Map<String,String>;
    private var tt: TableText;
    private var csv: Csv;
    private var v: View;

    public function new() {
    }

    /**
     *
     * Generate a string with appropriate ANSI colors for a given diff.
     *
     * @param t a tabular diff (perhaps generated by `TableDiff.hilite`)
     * @return the diff in text form, with inserted color codes
     *
     */
    public function render(t: Table) : String {
        csv  = new Csv();
        var result: String = "";
        var w : Int = t.width;
        var h : Int = t.height;
        var txt : String = "";
        v = t.getCellView();
        tt = new TableText(t);

        codes = new Map<String,String>();
        codes.set("header","\x1b[0;1m");
        codes.set("spec","\x1b[35;1m");
        codes.set("add","\x1b[32;1m");
        codes.set("conflict","\x1b[33;1m");
        codes.set("modify","\x1b[34;1m");
        codes.set("remove","\x1b[31;1m");
        codes.set("minor","\x1b[2m");
        codes.set("done","\x1b[0m");

        var sizes = pickSizes(t);

        for (y in 0...h) {
            for (x in 0...w) {
                if (x>0) {
                    txt += codes["minor"] + "," + codes["done"];
                }
                txt += getText(x,y,true);<commit_msg>make alignment in colored diffs optional<commit_after>// -*- mode:java; tab-width:4; c-basic-offset:4; indent-tabs-mode:nil -*-

#if !TOPLEVEL
package coopy;
#end

/**
 *
 * Decorate a diff being displayed on a console.  Colors, glyphs, any
 * other eye-candy we like.
 *
 */
class TerminalDiffRender {
    private var codes: Map<String,String>;
    private var tt: TableText;
    private var csv: Csv;
    private var v: View;
    private var align_columns : Bool;

    public function new() {
        align_columns = true;
    }


    /**
     *
     * @param enable choose whether columns should be aligned by padding
     *
     */
    public function alignColumns(enable: Bool) {
        align_columns = enable;
    }

    /**
     *
     * Generate a string with appropriate ANSI colors for a given diff.
     *
     * @param t a tabular diff (perhaps generated by `TableDiff.hilite`)
     * @return the diff in text form, with inserted color codes
     *
     */
    public function render(t: Table) : String {
        csv  = new Csv();
        var result: String = "";
        var w : Int = t.width;
        var h : Int = t.height;
        var txt : String = "";
        v = t.getCellView();
        tt = new TableText(t);

        codes = new Map<String,String>();
        codes.set("header","\x1b[0;1m");
        codes.set("spec","\x1b[35;1m");
        codes.set("add","\x1b[32;1m");
        codes.set("conflict","\x1b[33;1m");
        codes.set("modify","\x1b[34;1m");
        codes.set("remove","\x1b[31;1m");
        codes.set("minor","\x1b[2m");
        codes.set("done","\x1b[0m");

        var sizes = null;
        if (align_columns) sizes = pickSizes(t);

        for (y in 0...h) {
            for (x in 0...w) {
                if (x>0) {
                    txt += codes["minor"] + "," + codes["done"];
                }
                txt += getText(x,y,true);
{'fraction_non_alphanumeric': 0.15706806282722513, 'fraction_numerical': 0.01861547411285631, 'mean_word_length': 1.972342264477096, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2983071', 'n_tokens_mistral': 1172, 'n_tokens_neox': 1121, 'n_words': 294}