From 9dc1a522e5edde7875b70401f7e012c422d9476f Mon Sep 17 00:00:00 2001 From: ghaiklor Date: Fri, 13 Nov 2015 09:38:52 +0200 Subject: [PATCH] feat(shape): Implements simple text shape --- src/shapes/Text.js | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 src/shapes/Text.js diff --git a/src/shapes/Text.js b/src/shapes/Text.js new file mode 100644 index 0000000..bce9bec --- /dev/null +++ b/src/shapes/Text.js @@ -0,0 +1,31 @@ +import { Shape } from '../Shape'; + +export class Text extends Shape { + /** + * Creates new Text instance + * @constructor + */ + constructor(...args) { + super(...args); + } + + /** + * Renders a shape + * @param {Cursor} cursor + * @returns {Text} + */ + render(cursor) { + let {x, y} = this.getPosition(); + let text = this.getText(); + let background = this.getBackground(); + let foreground = this.getForeground(); + + if (background) cursor.background(background); + if (foreground) cursor.foreground(foreground); + + cursor.setPosition(x, y); + cursor.write(text); + + return this; + } +}