2017-10-17 19:18:31 +02:00
|
|
|
const TextWidget = require('tkwidgets/TextWidget.js');
|
2017-10-15 18:57:09 +02:00
|
|
|
|
2017-10-17 19:18:31 +02:00
|
|
|
class ConsoleWidget extends TextWidget {
|
2017-10-15 18:57:09 +02:00
|
|
|
|
|
|
|
constructor() {
|
|
|
|
super();
|
2017-10-17 19:18:31 +02:00
|
|
|
this.lines_ = [];
|
|
|
|
this.updateText_ = false;
|
|
|
|
this.markdownRendering = false;
|
|
|
|
this.stickToBottom = true;
|
2017-10-17 23:56:22 +02:00
|
|
|
this.maxLines_ = 1000;
|
2017-10-15 18:57:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
get name() {
|
|
|
|
return 'console';
|
|
|
|
}
|
|
|
|
|
2017-10-17 19:18:31 +02:00
|
|
|
get lastLine() {
|
|
|
|
return this.lines_.length ? this.lines_[this.lines_.length-1] : '';
|
|
|
|
}
|
|
|
|
|
|
|
|
addLine(line) {
|
|
|
|
this.lines_.push(line);
|
|
|
|
this.updateText_ = true;
|
|
|
|
this.invalidate();
|
|
|
|
}
|
|
|
|
|
|
|
|
onFocus() {
|
|
|
|
this.stickToBottom = false;
|
|
|
|
super.onFocus();
|
|
|
|
}
|
|
|
|
|
|
|
|
onBlur() {
|
|
|
|
this.stickToBottom = true;
|
|
|
|
super.onBlur();
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
if (this.updateText_) {
|
2017-10-17 23:56:22 +02:00
|
|
|
if (this.lines_.length > this.maxLines_) {
|
|
|
|
this.lines_.splice(0, this.lines_.length - this.maxLines_);
|
|
|
|
}
|
2017-10-17 19:18:31 +02:00
|
|
|
this.text = this.lines_.join("\n");
|
|
|
|
this.updateText_ = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
super.render();
|
2017-10-15 18:57:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = ConsoleWidget;
|