From f2f7f781edac78303e1b536f5da9977f9f30c56a Mon Sep 17 00:00:00 2001 From: Florrie Date: Fri, 17 Jul 2020 18:48:32 -0300 Subject: socket log messages & misc npm updates --- ui.js | 49 ++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 48 insertions(+), 1 deletion(-) (limited to 'ui.js') diff --git a/ui.js b/ui.js index 05e359e..df02edf 100644 --- a/ui.js +++ b/ui.js @@ -5530,6 +5530,10 @@ class Log extends ListScrollForm { } newLogMessage(text) { + if (this.inputs.length === 10) { + this.removeInput(this.inputs[0]) + } + const logMessage = new LogMessage(text) this.addInput(logMessage) this.fixLayout() @@ -5538,4 +5542,47 @@ class Log extends ListScrollForm { } } -class LogMessage extends Button {} +class LogMessage extends FocusElement { + constructor(text) { + super() + + this.label = new LogMessageLabel(text) + this.addChild(this.label) + } + + fixLayout() { + this.w = this.parent.contentW + this.label.w = this.contentW + this.h = this.label.h + } + + clicked(button) { + if (button === 'left') { + this.root.select(this) + return false + } + } +} + +class LogMessageLabel extends WrapLabel { + writeTextTo(writable) { + const w = this.w + const lines = this.getWrappedLines() + for (let i = 0; i < lines.length; i++) { + const text = this.processFormatting(lines[i]) + writable.write(ansi.moveCursor(this.absTop + i, this.absLeft)) + writable.write(text) + const width = ansi.measureColumns(text) + if (width < w && this.textAttributes.length) { + writable.write(ansi.setAttributes([ansi.A_RESET, ...this.textAttributes])) + writable.write(' '.repeat(w - width)) + } + } + } + + set textAttributes(val) {} + + get textAttributes() { + return this.parent.isSelected ? [40] : [] + } +} -- cgit 1.3.0-6-gf8a5