11cb0ef41Sopenharmony_civar QRCode = require('./../vendor/QRCode'),
21cb0ef41Sopenharmony_ci    QRErrorCorrectLevel = require('./../vendor/QRCode/QRErrorCorrectLevel'),
31cb0ef41Sopenharmony_ci    black = "\033[40m  \033[0m",
41cb0ef41Sopenharmony_ci    white = "\033[47m  \033[0m",
51cb0ef41Sopenharmony_ci    toCell = function (isBlack) {
61cb0ef41Sopenharmony_ci        return isBlack ? black : white;
71cb0ef41Sopenharmony_ci    },
81cb0ef41Sopenharmony_ci    repeat = function (color) {
91cb0ef41Sopenharmony_ci        return {
101cb0ef41Sopenharmony_ci            times: function (count) {
111cb0ef41Sopenharmony_ci                return new Array(count).join(color);
121cb0ef41Sopenharmony_ci            }
131cb0ef41Sopenharmony_ci        };
141cb0ef41Sopenharmony_ci    },
151cb0ef41Sopenharmony_ci    fill = function(length, value) {
161cb0ef41Sopenharmony_ci        var arr = new Array(length);
171cb0ef41Sopenharmony_ci        for (var i = 0; i < length; i++) {
181cb0ef41Sopenharmony_ci            arr[i] = value;
191cb0ef41Sopenharmony_ci        }
201cb0ef41Sopenharmony_ci        return arr;
211cb0ef41Sopenharmony_ci    };
221cb0ef41Sopenharmony_ci
231cb0ef41Sopenharmony_cimodule.exports = {
241cb0ef41Sopenharmony_ci
251cb0ef41Sopenharmony_ci    error: QRErrorCorrectLevel.L,
261cb0ef41Sopenharmony_ci
271cb0ef41Sopenharmony_ci    generate: function (input, opts, cb) {
281cb0ef41Sopenharmony_ci        if (typeof opts === 'function') {
291cb0ef41Sopenharmony_ci            cb = opts;
301cb0ef41Sopenharmony_ci            opts = {};
311cb0ef41Sopenharmony_ci        }
321cb0ef41Sopenharmony_ci
331cb0ef41Sopenharmony_ci        var qrcode = new QRCode(-1, this.error);
341cb0ef41Sopenharmony_ci        qrcode.addData(input);
351cb0ef41Sopenharmony_ci        qrcode.make();
361cb0ef41Sopenharmony_ci
371cb0ef41Sopenharmony_ci        var output = '';
381cb0ef41Sopenharmony_ci        if (opts && opts.small) {
391cb0ef41Sopenharmony_ci            var BLACK = true, WHITE = false;
401cb0ef41Sopenharmony_ci            var moduleCount = qrcode.getModuleCount();
411cb0ef41Sopenharmony_ci            var moduleData = qrcode.modules.slice();
421cb0ef41Sopenharmony_ci
431cb0ef41Sopenharmony_ci            var oddRow = moduleCount % 2 === 1;
441cb0ef41Sopenharmony_ci            if (oddRow) {
451cb0ef41Sopenharmony_ci                moduleData.push(fill(moduleCount, WHITE));
461cb0ef41Sopenharmony_ci            }
471cb0ef41Sopenharmony_ci
481cb0ef41Sopenharmony_ci            var platte= {
491cb0ef41Sopenharmony_ci                WHITE_ALL: '\u2588',
501cb0ef41Sopenharmony_ci                WHITE_BLACK: '\u2580',
511cb0ef41Sopenharmony_ci                BLACK_WHITE: '\u2584',
521cb0ef41Sopenharmony_ci                BLACK_ALL: ' ',
531cb0ef41Sopenharmony_ci            };
541cb0ef41Sopenharmony_ci
551cb0ef41Sopenharmony_ci            var borderTop = repeat(platte.BLACK_WHITE).times(moduleCount + 3);
561cb0ef41Sopenharmony_ci            var borderBottom = repeat(platte.WHITE_BLACK).times(moduleCount + 3);
571cb0ef41Sopenharmony_ci            output += borderTop + '\n';
581cb0ef41Sopenharmony_ci
591cb0ef41Sopenharmony_ci            for (var row = 0; row < moduleCount; row += 2) {
601cb0ef41Sopenharmony_ci                output += platte.WHITE_ALL;
611cb0ef41Sopenharmony_ci
621cb0ef41Sopenharmony_ci                for (var col = 0; col < moduleCount; col++) {
631cb0ef41Sopenharmony_ci                    if (moduleData[row][col] === WHITE && moduleData[row + 1][col] === WHITE) {
641cb0ef41Sopenharmony_ci                        output += platte.WHITE_ALL;
651cb0ef41Sopenharmony_ci                    } else if (moduleData[row][col] === WHITE && moduleData[row + 1][col] === BLACK) {
661cb0ef41Sopenharmony_ci                        output += platte.WHITE_BLACK;
671cb0ef41Sopenharmony_ci                    } else if (moduleData[row][col] === BLACK && moduleData[row + 1][col] === WHITE) {
681cb0ef41Sopenharmony_ci                        output += platte.BLACK_WHITE;
691cb0ef41Sopenharmony_ci                    } else {
701cb0ef41Sopenharmony_ci                        output += platte.BLACK_ALL;
711cb0ef41Sopenharmony_ci                    }
721cb0ef41Sopenharmony_ci                }
731cb0ef41Sopenharmony_ci
741cb0ef41Sopenharmony_ci                output += platte.WHITE_ALL + '\n';
751cb0ef41Sopenharmony_ci            }
761cb0ef41Sopenharmony_ci
771cb0ef41Sopenharmony_ci            if (!oddRow) {
781cb0ef41Sopenharmony_ci                output += borderBottom;
791cb0ef41Sopenharmony_ci            }
801cb0ef41Sopenharmony_ci        } else {
811cb0ef41Sopenharmony_ci            var border = repeat(white).times(qrcode.getModuleCount() + 3);
821cb0ef41Sopenharmony_ci
831cb0ef41Sopenharmony_ci            output += border + '\n';
841cb0ef41Sopenharmony_ci            qrcode.modules.forEach(function (row) {
851cb0ef41Sopenharmony_ci                output += white;
861cb0ef41Sopenharmony_ci                output += row.map(toCell).join('');
871cb0ef41Sopenharmony_ci                output += white + '\n';
881cb0ef41Sopenharmony_ci            });
891cb0ef41Sopenharmony_ci            output += border;
901cb0ef41Sopenharmony_ci        }
911cb0ef41Sopenharmony_ci
921cb0ef41Sopenharmony_ci        if (cb) cb(output);
931cb0ef41Sopenharmony_ci        else console.log(output);
941cb0ef41Sopenharmony_ci    },
951cb0ef41Sopenharmony_ci
961cb0ef41Sopenharmony_ci    setErrorLevel: function (error) {
971cb0ef41Sopenharmony_ci        this.error = QRErrorCorrectLevel[error] || this.error;
981cb0ef41Sopenharmony_ci    }
991cb0ef41Sopenharmony_ci
1001cb0ef41Sopenharmony_ci};
101