From f969bae68a328ca92c8a5efc3dd825d80df5d062 Mon Sep 17 00:00:00 2001 From: Christian Heller Date: Tue, 27 Oct 2020 06:13:46 +0100 Subject: [PATCH] Distribute long annotation texts onto multiple lines. --- new2/rogue_chat_nocanvas_monochrome.html | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/new2/rogue_chat_nocanvas_monochrome.html b/new2/rogue_chat_nocanvas_monochrome.html index 863de8c..512b835 100644 --- a/new2/rogue_chat_nocanvas_monochrome.html +++ b/new2/rogue_chat_nocanvas_monochrome.html @@ -186,18 +186,24 @@ let tui = { terminal.write(terminal.rows - 1, terminal.cols / 2, '> ' + this.input_line); } }, - log_msg: function(msg) { - let line_length = (terminal.cols / 2); + msg_into_lines_of_width: function(msg, width) { let chunk = ""; + let lines = []; for (let i = 0, x = 0; i < msg.length; i++, x++) { - if (x >= line_length) { - this.log.unshift(chunk); + if (x >= width) { + lines.unshift(chunk); chunk = ""; x = 0; }; chunk += msg[i]; } - this.log.unshift(chunk); + lines.unshift(chunk); + return lines; + }, + log_msg: function(msg) { + let line_length = (terminal.cols / 2); + let chunk = ""; + this.log = this.msg_into_lines_of_width(msg, terminal.cols / 2).concat(this.log); while (this.log.length > terminal.rows - 2) { this.log.pop(); }; @@ -232,7 +238,8 @@ let tui = { }, draw_info: function() { terminal.drawBox(1, terminal.cols / 2, terminal.rows - 2, terminal.cols / 2); - let lines = explorer.get_info(); + let lines = this.msg_into_lines_of_width(explorer.get_info(), terminal.cols / 2); + lines.reverse(); for (let y = 1, i = 0; y < terminal.rows && i < lines.length; y++, i++) { terminal.write(y, terminal.cols / 2, lines[i]); } @@ -355,9 +362,9 @@ let explorer = { }, get_info: function() { if (this.position in this.info_db) { - return [this.info_db[this.position]]; + return this.info_db[this.position]; } else { - return ['waiting …']; + return 'waiting …'; } }, annotate: function(msg) { -- 2.30.2