<commit_before>/*!
 * grunt-svg2png
 * https://github.com/dbushell/grunt-svg2png
 *
 * Copyright (c) 2013 <NAME>
 * Licensed under The MIT License (MIT)
 */

'use strict';

var phantomjs = require('phantomjs'),
    path = require('path'),
    fs = require('fs');

module.exports = function(grunt)
{
    grunt.registerMultiTask('svg2png', 'Rasterize SVG to PNG images using PhantomJS', function()
    {

        var done = this.async(),
            start = new Date(),
            completed = 0,
            files = [],
            total = 0;

        this.data.files.forEach(function(fset)
        {
            var svg = grunt.file.expand(fset, fset.src);

            svg.forEach(function(svg)
            {
                var src = path.resolve(svg),
                    dest,
                    settings;

                if (fset.dest) {
                    dest = path.resolve(fset.dest) + '/' + path.basename(svg);
                } else {
                    dest = src;
                }

                settings = {
                    src: src,
                    dest: dest.replace(/\.svg$/i, '.png')
                };

                files.push(settings);
            });

            total = files.length;
        });

        grunt.log.subhead('Rasterizing SVG to PNG (' + files.length + ' files)...');

        var styles = {

            'bold'          : ['\x1B[1m',  '\x1B[22m'],
            'italic'        : ['\x1B[3m',  '\x1B[23m'],
            'underline'     : ['\x1B[4m',  '\x1B[24m'],
            'inverse'       : ['\x1B[7m',  '\x1B[27m'],
            'strikethrough' : ['\x1B[9m',  '\x1B[29m'],

            'white' : ['\x1B[37m', '\x1B[39m'],
            'grey'  : ['\x1B[90m', '\x1B[39m'],
            'black' : ['\x1B[30m', '\x1B[39m'],

            'blue'    : ['\x1B[34m', '\x1B[39m'],
            'cyan'    : ['\x1B[36m', '\x1B[39m'],
            'green'   : ['\x1B[32m', '\x1B[39m'],
            'magenta' : ['\x1B[35m', '\x1B[39m'],
            'red'     : ['\x1B[31m', '\x1B[39m'],
            'yellow'  : ['\x1B[33m', '\x1B[39m']

        };

        var style = function(str, format)
        {
            return styles[format][0] + str + styles[format][1];
        };

        var update = function()
        {
            if (!total) {
                return;
            }

            process.stdout.clearLine();
            process.stdout.cursorTo(0);

            var str = '',
                arr = [],
                count = total,
                percent = ((100 / total) * completed).toFixed(2);

            str += arr.reverse().join('');
            str += style(percent + "%", 'green') + ' (' + ((new Date() - start) / 1000).toFixed(1) + 's) ';
            process.stdout.write(str);
        };

        var spawn = grunt.util.spawn({
            cmd: phantomjs.path,
            args: [
                    path.resolve(__dirname, 'lib/svg2png.js'),
                    JSON.stringify(files)
                ]
            },
            function(err, result, code)
            {
                grunt.log.write('\n');
                grunt.log.ok('Rasterization complete.');
                done();
            }
        );

        spawn.stdout.on('data', function(buffer)
        {
            try {
                var result = JSON.parse(buffer.toString());
                if (result.status) {
                    completed++;
                    update();
                }
            } catch (e) { }
        });

        update();
    });
};
<commit_msg>Crossplatform console output<commit_after>/*!
 * grunt-svg2png
 * https://github.com/dbushell/grunt-svg2png
 *
 * Copyright (c) 2013 <NAME>
 * Licensed under The MIT License (MIT)
 */

'use strict';

var phantomjs = require('phantomjs'),
    path = require('path'),
    fs = require('fs');

module.exports = function(grunt)
{
    grunt.registerMultiTask('svg2png', 'Rasterize SVG to PNG images using PhantomJS', function()
    {

        var done = this.async(),
            start = new Date(),
            completed = 0,
            files = [],
            total = 0;

        this.data.files.forEach(function(fset)
        {
            var svg = grunt.file.expand(fset, fset.src);

            svg.forEach(function(svg)
            {
                var src = path.resolve(svg),
                    dest,
                    settings;

                if (fset.dest) {
                    dest = path.resolve(fset.dest) + '/' + path.basename(svg);
                } else {
                    dest = src;
                }

                settings = {
                    src: src,
                    dest: dest.replace(/\.svg$/i, '.png')
                };

                files.push(settings);
            });

            total = files.length;
        });

        grunt.log.subhead('Rasterizing SVG to PNG (' + files.length + ' files)...');

        var styles = {

            'bold'          : ['\x1B[1m',  '\x1B[22m'],
            'italic'        : ['\x1B[3m',  '\x1B[23m'],
            'underline'     : ['\x1B[4m',  '\x1B[24m'],
            'inverse'       : ['\x1B[7m',  '\x1B[27m'],
            'strikethrough' : ['\x1B[9m',  '\x1B[29m'],

            'white' : ['\x1B[37m', '\x1B[39m'],
            'grey'  : ['\x1B[90m', '\x1B[39m'],
            'black' : ['\x1B[30m', '\x1B[39m'],

            'blue'    : ['\x1B[34m', '\x1B[39m'],
            'cyan'    : ['\x1B[36m', '\x1B[39m'],
            'green'   : ['\x1B[32m', '\x1B[39m'],
            'magenta' : ['\x1B[35m', '\x1B[39m'],
            'red'     : ['\x1B[31m', '\x1B[39m'],
            'yellow'  : ['\x1B[33m', '\x1B[39m']

        };

        var style = function(str, format)
        {
            return styles[format][0] + str + styles[format][1];
        };

        var update = function()
        {
            if (!total) {
                return;
            }

            var str = '',
                arr = [],
                count = total,
                percent = ((100 / total) * completed).toFixed(2);

            str += style('.', 'green');

            if (completed == count) {
                str += style('\n>> ', 'green') + ((new Date() - start) / 1000).toFixed(1) + 's';
            }

            process.stdout.write(str);
        };

        var spawn = grunt.util.spawn({
            cmd: phantomjs.path,
            args: [
                    path.resolve(__dirname, 'lib/svg2png.js'),
                    JSON.stringify(files)
                ]
            },
            function(err, result, code)
            {
                grunt.log.write('\n');
                grunt.log.ok('Rasterization complete.');
                done();
            }
        );

        spawn.stdout.on('data', function(buffer)
        {
            try {
                var result = JSON.parse(buffer.toString());
                if (result.status) {
                    completed++;
                    update();
                }
            } catch (e) { }
        });

        update();
    });
};

{'fraction_non_alphanumeric': 0.1695639783414078, 'fraction_numerical': 0.028640638358506696, 'mean_word_length': 1.1825248756218905, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 2, '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': '717649', 'n_tokens_mistral': 2344, 'n_tokens_neox': 2151, 'n_words': 378}