image.js 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /**
  2. * image.js - image element for blessed
  3. * Copyright (c) 2013-2015, Christopher Jeffrey and contributors (MIT License).
  4. * https://github.com/chjj/blessed
  5. */
  6. /**
  7. * Modules
  8. */
  9. var Node = require('./node');
  10. var Box = require('./box');
  11. /**
  12. * Image
  13. */
  14. function Image(options) {
  15. if (!(this instanceof Node)) {
  16. return new Image(options);
  17. }
  18. options = options || {};
  19. options.type = options.itype || options.type || 'ansi';
  20. Box.call(this, options);
  21. if (options.type === 'ansi' && this.type !== 'ansiimage') {
  22. var ANSIImage = require('./ansiimage');
  23. Object.getOwnPropertyNames(ANSIImage.prototype).forEach(function(key) {
  24. if (key === 'type') return;
  25. Object.defineProperty(this, key,
  26. Object.getOwnPropertyDescriptor(ANSIImage.prototype, key));
  27. }, this);
  28. ANSIImage.call(this, options);
  29. return this;
  30. }
  31. if (options.type === 'overlay' && this.type !== 'overlayimage') {
  32. var OverlayImage = require('./overlayimage');
  33. Object.getOwnPropertyNames(OverlayImage.prototype).forEach(function(key) {
  34. if (key === 'type') return;
  35. Object.defineProperty(this, key,
  36. Object.getOwnPropertyDescriptor(OverlayImage.prototype, key));
  37. }, this);
  38. OverlayImage.call(this, options);
  39. return this;
  40. }
  41. throw new Error('`type` must either be `ansi` or `overlay`.');
  42. }
  43. Image.prototype.__proto__ = Box.prototype;
  44. Image.prototype.type = 'image';
  45. /**
  46. * Expose
  47. */
  48. module.exports = Image;