Ejemplo n.º 1
0
    row.forEach(function (col, c)
    {
        // leave room for left and right padding.
        col.width = widths[c]
        if (_this.wrap) wrapped = wrap.hard(_this._negatePadding(col))(col.text).split('\n')
        else wrapped = col.text.split('\n')

        // add top and bottom padding.
        if (col.padding) {
            for (i = 0; i < (col.padding[top] || 0); i++) wrapped.unshift('')
            for (i = 0; i < (col.padding[bottom] || 0); i++) wrapped.push('')
        }

        wrapped.forEach(function (str, r)
        {
            if (!rrows[r]) rrows.push([])

            rrow = rrows[r]

            for (var i = 0; i < c; i++) {
                if (rrow[i] === undefined) rrow.push('')
            }
            rrow.push(str)
        })
    })
Ejemplo n.º 2
0
Archivo: args.js Proyecto: ethul/pulp
function wrap(s, indent) {
  var w = require("wordwrap").hard;
  if (process.stdout.columns) {
    return w(indent, process.stdout.columns)(s);
  } else {
    return indent ? (new Array(indent + 1).join(" ")) + s : s;
  }
}
Ejemplo n.º 3
0
getPixels(args[0], function(err, pixels) {
  if(err) {
    console.log("Bad image path")
    return
  }
  var red   = pixels.pick(null, null, 0);
  //var green = image.pick(null, null, 1);
  //var blue  = image.pick(null, null, 2);
  var braille = brailleEncode.encode(red.data);
  var wrapper = wrap.hard(pixels.shape[0]);
  console.log(wrapper(braille));
});
Ejemplo n.º 4
0
  reportFormat.forEach(function (item) {
    var title = item[0] + ':';
    var field = item[1];
    var formatter = item[2] || defaultFormat;

    var value = getProperty(data, field);
    if (formatter instanceof Array) {
      outfn(spaces(indentation) + toWidth(title, headerWidth));
      doReport(indentation + headerWidth, formatter, value, outfn);
    } else {
      var leftIndentation = 'verbose: '.length + indentation + headerWidth;
      var formatted = wrap.hard(leftIndentation, maxWidth)(formatter(value));
      formatted = spaces(indentation) + toWidth(title, headerWidth) +
        formatted.slice(leftIndentation);
      outfn(formatted);
    }
  });
ResultWriter.prototype.writeData = function(message,lineHeader,bold) {
    lineHeader = lineHeader || "";
    if (typeof message === "string") {
        // first, wrap the lines if necessary
        var lines;
        if (this._output.isTTY) {
            lines = wordwrap.hard(this._output.columns - lineHeader.length)(message).split(/\n/);
        } else {
            // Not a TTY, so we don't have to wrap, so
            // just split the lines at delimiters
            lines = message.split(/\n/);
        }
        this.endProgress();
        var prefix = (bold ? (this.boldOn + lineHeader) : lineHeader);
        var suffix = (bold ? (this.boldOff + "\n") : "\n");
        for (var i = 0; i < lines.length; i++) {
            this._output.write(prefix + lines[i] + suffix);
        }
    } else if (message instanceof Error) {
        this.writeData(util.inspect(message) + "\n" + message.stack,lineHeader,bold);
    } else {
        this.writeData(util.inspect(message),lineHeader,bold);
    }
}
Ejemplo n.º 6
0
        socket.on('add_msg', function (data) {

            var ts,
                txt,
                text,
                words,
                pattern,
                pattern_txt,
                logins_constr,
                private_login,
                communities,
                comm_name,
                commn_key,
                clan_row,
                i;

            if (!socket.login) {
                return;
            }

            // check if user got gag in mouth
            ts = Math.round((new Date()).getTime() / 1000);

            if (users_gags[socket.uid] && (users_gags[socket.uid] === 0 || users_gags[socket.uid] > ts)) {

                txt = 'You have been blocked in chat, you will be able to chat only after ' + Math.ceil((users_gags[socket.uid] - ts) / 60) + ' min.';

                sendMessage({
                    type: 'private',
                    to: socket.login,
                    from: 'Senator Gracchus',
                    text: 'private (' + socket.login + ') ' + txt,
                    color: 'black'
                });

                return true;
            }

            console.log('Accepted new message from user ' + socket.login);

            text = data.text;

            // filtering accepted message
            text = text.replace(/^\s+|\s+$/g, ''); // trim
            text = libs.escapeHtml(text); // remove html

            // wrap big strings
            words = text.split(' ');

            for (i = 0; i <= words.length - 1; i += 1) {
                words[i] = wrap.hard(70)(words[i]).split('\n').join(' ');
            }

            text = words.join(' ');

            // replace internal links with text
            text = text.replace(/http:\/\/wglads\.(com|ru)\/game\/[\-a-zA-Z0-9_\.?=\/&]+/i, '(prohibited link)');

            // check if the message is advertising
            pattern_txt = text.replace(/[^a-zA-Z]/i, "");

            if (pattern_txt.match(/(gladiatorsru|fdworldsnet|vk\.com\/app)/i)) {

                txt = 'This is prohibited link, don\'t add it to chat, please :thanks:';

                sendMessage({
                    type: 'private',
                    to: socket.login,
                    from: 'Senator Gracchus',
                    text: 'private (' + socket.login + ') ' + txt,
                    color: 'black'
                });

                return true;
            }

            // if user's level less than 20 and he's writing in private chat
            if (socket.level < 20 && (text.indexOf('private (') >= 0 || text.indexOf('communmity (') >= 0 || text.match(/clan \([a-zA-Z]+\)/i))) {

                txt = 'it\'s too sad, however until 20 level you allowed to chat exclusively in common chat. We all once were in the same circumstances :zdarov: ';

                sendMessage({
                    type: 'private',
                    to: socket.login,
                    from: 'Senator Gracchus',
                    text: 'private (' + socket.login + ') ' + txt,
                    color: 'black'
                });

                return true;
            }

            // if message contains private notation
            if (text.indexOf('private (') >= 0) {

                pattern = /private \(([\-a-zA-Zа-яА-Я0-9_\s]+)\)/g;

                logins_constr = text.match(pattern);

                console.log('- sending to private section');

                if (logins_constr !== null) {

                    for (i = 0; i < logins_constr.length; i += 1) {

                        private_login = logins_constr[i].replace(pattern, "$1");

                        if (private_login !== socket.login) {

                            //console.log('login - '+private_login);
                            sendMessage({
                                type: 'private',
                                to: private_login,
                                from: socket.login,
                                text: text,
                                color: socket.color,
                                is_hidden: data.is_hidden
                            });
                        }
                    }
                    sendMessage({
                        type: 'private',
                        to: socket.login,
                        from: socket.login,
                        text: text,
                        color: socket.color,
                        is_hidden: data.is_hidden
                    });
                    return true;
                }
                return false;
            }

            // if message contain community address
            if (text.indexOf('community (') >= 0) {

                pattern = /community \(([\-a-zA-Zа-яА-Я\s\.]+)\)/g;

                communities = text.match(pattern);

                console.log('- sending to community section');

                if (communities !== null) {

                    if (communities.length > 0) {

                        comm_name = communities[0].replace(pattern, "$1");
                        commn_key = libs.make_md5(comm_name);

                        sendMessage({
                            type: 'community',
                            to: 'comms_' + commn_key,
                            from: socket.login,
                            text: text,
                            color: socket.color,
                            is_hidden: data.is_hidden
                        });
                    }

                    return true;
                }

                return false;
            }

            // if message contain clan issue
            if (text.indexOf('clan (') >= 0) {

                console.log('clan section');

                pattern = /clan \(([a-zA-Z]+)\)/i;
                clan_row = pattern.exec(text);

                //console.log(clan_row);
                if (clan_row !== null) {

                    sendMessage({
                        type: 'clan',
                        to: 'clan_' + clan_row[1],
                        from: socket.login,
                        text: text,
                        color: socket.color,
                        is_hidden: socket.is_hidden
                    });

                    return true;
                }

                return false;
            }

            // if a message to a global chat
            if (data.channel === 'global') {

                sendMessage({
                    type: 'global',
                    to: 'global',
                    from: socket.login,
                    text: text,
                    color: socket.color,
                    is_hidden: data.is_hidden
                });

                return true;
            }

            // if just a regular message to current location chat
            sendMessage({
                type: 'locate',
                to: 'loc_' + socket.locate,
                from: socket.login,
                text: text,
                color: socket.color,
                is_hidden: data.is_hidden
            });
        });
Ejemplo n.º 7
0
 var wrapFns = colWidths.map(function(width) { return wrap.hard(width - 1); });