diff options
Diffstat (limited to 'playground.js')
-rw-r--r-- | playground.js | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/playground.js b/playground.js new file mode 100644 index 0000000..8ea168d --- /dev/null +++ b/playground.js @@ -0,0 +1,54 @@ +// basic playground for testing text editor while developing it + +const { + ui: { + Pane, + form: { + FocusElement + } + }, + util: { + tuiApp + } +} = require('tui-lib') + +const TuiTextEditor = require('./index') + +class AppElement extends FocusElement { + constructor() { + super() + + this.pane = new Pane() + this.addChild(this.pane) + + this.editor = new TuiTextEditor() + this.pane.addChild(this.editor) + } + + selected() { + this.root.select(this.editor) + } + + fixLayout() { + this.fillParent() + this.pane.fillParent() + this.editor.fillParent() + } + + keyPressed(keyBuf) { + if (keyBuf[0] === 0x03) { + this.emit('quitRequested') + } + } +} + +tuiApp(({root, quitProgram}) => { + const app = new AppElement() + + app.on('quitRequested', quitProgram) + + root.addChild(app) + root.select(app) + + setTimeout(() => app.scheduleDrawWithoutPropertyChange()) +}) |