/*
 * @author Ranides Atterwim <ranides@gmail.com>
 * @copyright Ranides Atterwim
 * @license WTFPL
 * @url http://ranides.net/projects/assira
 */
package net.ranides.assira.text.format;

import java.awt.Color;
import java.awt.Font;
import net.ranides.assira.math.Randomizer;
import net.ranides.assira.trace.LoggerUtils;

/**
 *
 * @author ranides
 */
public final class AnsiGenerator {
    
    private AnsiGenerator() {
        // utility class
    }
    
    public static final AnsiScheme SCHEME;
    
    static {
        SCHEME = new AnsiScheme();
        
        SCHEME.setColor(1, new Color(0x888888));
        SCHEME.setColor(2, new Color(0xFFFFFF));
        SCHEME.setColor(3, new Color(0x880000));
        SCHEME.setColor(4, new Color(0xFF0000));
        SCHEME.setColor(5, new Color(0x008800));
        SCHEME.setColor(6, new Color(0x00FF00));
        SCHEME.setColor(7, new Color(0x000088));
        SCHEME.setColor(8, new Color(0x0000FF));
        
        SCHEME.setFont(1, new Font("arial", 0, 12));
        SCHEME.setFont(2, new Font("courier", 0, 12));
        SCHEME.setFont(3, new Font("verdana", 0, 16));
    }
    
    public static AnsiCharSequence make(String value) {
        int n = value.length();
        byte nc = (byte)SCHEME.colors().size();
        byte nf = (byte)SCHEME.fonts().size();
        char ns = 0xFF;
        
        byte[] back = new byte[n];
        byte[] fore = new byte[n];
        char[] flags = new char[n];
        byte[] fonts = new byte[n];
        
        for(int i=0; i<n; i++) {
            back[i] = Randomizer.number(nc);
            fore[i] = Randomizer.number(nc);
            flags[i] = Randomizer.number(ns);
            fonts[i] = Randomizer.number(nf);
        }
        return new AnsiString(
            value.toCharArray(), back, fore, flags, fonts, value.length()
        );
    }
    
    public static void dump(AnsiCharSequence text) {
        for(AnsiRegion item : text.regions(AnsiAttr.CMP_ALL)) {
            LoggerUtils.dump("%s\n", item.toString());
        }
        LoggerUtils.dump("---\n");
    }
}
