From a42f6a8e37d291ed341a2110c4dc46b5aabc54b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Deuc=D0=B5?= <shurd@sasktel.net> Date: Mon, 3 Mar 2025 18:13:53 -0500 Subject: [PATCH] Add CTRL-S to "save" This simply writes changed values to ctrl/textedit.ini, you can copy these into the appropriate text.ini or text.dat. I haven't dug in to see if text.dat has different encoding than ini or anything, and I think that if you want to use this to build a full text.dat, you would want to do it a bit at a time, so a follow- on utility to convert text.ini to text.dat is likely the easiest way to do this stuff. --- exec/textedit.js | 33 +++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/exec/textedit.js b/exec/textedit.js index e8b0bb0e2a..be91c429d6 100644 --- a/exec/textedit.js +++ b/exec/textedit.js @@ -11,6 +11,7 @@ var msglens = []; var displaywith = 0; var inprow = (console.screen_columns < 80) ? 18 : 17; var ch; +var modified = {}; // TODO: This should be in a separate (JSON) file... var details = { @@ -139,8 +140,6 @@ console.cleartoeos = function(attr) function format_entry(str) { - // bbs.command_str = '@'; - // .replace(/@/g, "@U+40:@@") return str.replace(/[\x00-\x1F\x80-\x9F\\]/g, function(match) { switch(match) { case '\n': @@ -407,12 +406,27 @@ function get_msgnum() console.attributes = 7; } +function track_mod() +{ + if (modified[msg] === undefined) { + modified[msg] = {original: bbs.text(msg), modified: true}; + } +} + +function check_undone() +{ + if (modified[msg] !== undefined && msgstr === modified[msg].original) { + delete modified[msg]; + } +} + get_tvals(); newmsg(); var done = false; var skip_redraw = false; var forcectrl = false; var tmp; +var sfile; while (!done) { if (!skip_redraw) redraw(msgstr, msg); @@ -464,15 +478,28 @@ while (!done) { break; case ctrl('Z'): bbs.revert_text(msg); + if (modified[msg] !== undefined) + delete modified[msg]; newmsg(); break; case ctrl('Q'): done = true; break; + case ctrl('S'): + sfile = new File("textedit.ini"); + if (!sfile.open(sfile.exists ? 'r+':'w+')) + break; + for (tmp in modified) { + sfile.iniSetValue(null, tnames[tmp], bbs.text(tmp)); + } + sfile.close(); + break; case '\b': if (pos) { + track_mod(); msgstr = msgstr.slice(0, pos - 1) + msgstr.slice(pos); bbs.replace_text(msg, msgstr); + check_undone(); pos--; newmsg(false); } @@ -543,8 +570,10 @@ while (!done) { default: if (ch < ' ' && !forcectrl) break; + track_mod(); msgstr = msgstr.slice(0, pos) + ch + msgstr.slice(pos); bbs.replace_text(msg, msgstr); + check_undone(); pos++; newmsg(false); break; -- GitLab