From: Christian Heller Date: Tue, 27 Oct 2020 05:13:46 +0000 (+0100) Subject: Distribute long annotation texts onto multiple lines. X-Git-Url: https://plomlompom.com/repos/%7B%7Bprefix%7D%7D/blog?a=commitdiff_plain;h=f969bae68a328ca92c8a5efc3dd825d80df5d062;p=plomrogue2-experiments Distribute long annotation texts onto multiple lines. --- 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) {