terminal.js 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. // var Utils = require('./utils')
  2. exports.render = function (qrData, options, cb) {
  3. var size = qrData.modules.size
  4. var data = qrData.modules.data
  5. // var opts = Utils.getOptions(options)
  6. // use same scheme as https://github.com/gtanner/qrcode-terminal because it actually works! =)
  7. var black = '\x1b[40m \x1b[0m'
  8. var white = '\x1b[47m \x1b[0m'
  9. var output = ''
  10. var hMargin = Array(size + 3).join(white)
  11. var vMargin = Array(2).join(white)
  12. output += hMargin + '\n'
  13. for (var i = 0; i < size; ++i) {
  14. output += white
  15. for (var j = 0; j < size; j++) {
  16. // var topModule = data[i * size + j]
  17. // var bottomModule = data[(i + 1) * size + j]
  18. output += data[i * size + j] ? black : white// getBlockChar(topModule, bottomModule)
  19. }
  20. // output += white+'\n'
  21. output += vMargin + '\n'
  22. }
  23. output += hMargin + '\n'
  24. if (typeof cb === 'function') {
  25. cb(null, output)
  26. }
  27. return output
  28. }
  29. /*
  30. exports.renderToFile = function renderToFile (path, qrData, options, cb) {
  31. if (typeof cb === 'undefined') {
  32. cb = options
  33. options = undefined
  34. }
  35. var fs = require('fs')
  36. var utf8 = exports.render(qrData, options)
  37. fs.writeFile(path, utf8, cb)
  38. }
  39. */