+ this.mode = mode;
+ this.empty_input();
+ if (mode == mode_annotate && explorer.position in explorer.info_db) {
+ let info = explorer.info_db[explorer.position];
+ if (info != "(none)") {
+ this.add_to_input(explorer.info_db[explorer.position]);
+ }
+ }
+ this.full_refresh();
+ },
+ empty_input: function(str) {
+ this.input = "";
+ if (this.mode.has_input_prompt) {
+ this.recalc_input_lines();
+ } else {
+ this.height_input = 0;
+ }
+ },
+ add_to_input: function(str) {
+ if (this.input_prompt.length + this.input.length + str.length > this.window_width * terminal.rows) {
+ return;
+ }
+ this.input += str;
+ this.recalc_input_lines();
+ this.full_refresh();
+ },
+ recalc_input_lines: function() {
+ this.input_lines = this.msg_into_lines_of_width(this.input_prompt + this.input, this.window_width);
+ this.height_input = this.input_lines.length;
+ },
+ shorten_input: function() {
+ if (this.input.length == 0) {
+ terminal.blink_screen();
+ } else {
+ this.input = tui.input.slice(0, -1);
+ this.recalc_input_lines();
+ this.full_refresh();
+ }
+ },
+ 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 >= width) {
+ lines.push(chunk);
+ chunk = "";
+ x = 0;
+ };
+ chunk += msg[i];
+ }
+ lines.push(chunk);
+ return lines;
+ },
+ log_msg: function(msg) {
+ let lines = this.msg_into_lines_of_width(msg, this.window_width);
+ this.log = this.log.concat(lines);
+ while (this.log.length > terminal.rows) {
+ this.log.shift();
+ };
+ this.full_refresh();
+ },
+ log_help: function() {
+ this.log_msg("");
+ this.log_msg("HELP:");
+ this.log_msg("chat mode commands:");
+ this.log_msg(" :nick NAME - re-name yourself to NAME");
+ this.log_msg(" :msg USER TEXT - send TEXT to USER");
+ this.log_msg(" :help - show this help");
+ this.log_msg(" :p or :play - switch to play mode");
+ this.log_msg(" :? or :study - switch to study mode");
+ this.log_msg("commands common to study and play mode:");
+ this.log_msg(" w, a, s, d - move");
+ this.log_msg(" c - switch to chat mode");
+ this.log_msg("commands specific to play mode:");
+ this.log_msg(" e - write following ASCII character");
+ this.log_msg(" f - flatten surroundings");
+ this.log_msg(" ? - switch to study mode");
+ this.log_msg("commands specific to study mode:");
+ this.log_msg(" e - annotate terrain");
+ this.log_msg(" p - switch to play mode");
+ this.log_msg("");