From a1d4a90e05215f490d78ca96d04278d245a2a78b Mon Sep 17 00:00:00 2001 From: Nathan Byrd Date: Thu, 28 Jul 2022 15:47:51 -0500 Subject: [PATCH 1/5] Added system menu method to choose encoding --- core/system_menu_method.js | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/core/system_menu_method.js b/core/system_menu_method.js index 2e78f964..73d604a5 100644 --- a/core/system_menu_method.js +++ b/core/system_menu_method.js @@ -16,6 +16,7 @@ const iconv = require('iconv-lite'); exports.login = login; exports.login2FA_OTP = login2FA_OTP; +exports.setClientEncoding = setClientEncoding; exports.logoff = logoff; exports.prevMenu = prevMenu; exports.nextMenu = nextMenu; @@ -241,6 +242,23 @@ function nextArea(callingMenu, formData, extraArgs, cb) { ); } +function setClientEncoding(callingMenu, formData, extraArgs, cb) { + // TODO: Also add other encoding types + const client = callingMenu.client; + let encoding = formData.value.encoding; + + client.log.info( + { encoding: encoding, currentEncoding: client.term.outputEncoding }, + 'Setting client encoding.' + ); + + encoding = encoding || client.term.outputEncoding; + + client.term.outputEncoding = encoding; + + return callingMenu.nextMenu(cb); +} + function sendForgotPasswordEmail(callingMenu, formData, extraArgs, cb) { const username = formData.value.username || callingMenu.client.user.username; From a2e6088238550e565d21b5f35e6c444b9397e1dd Mon Sep 17 00:00:00 2001 From: Nathan Byrd Date: Thu, 28 Jul 2022 16:38:05 -0500 Subject: [PATCH 2/5] Added documentation for the new encoding selection function --- docs/_docs/configuration/menu-hjson.md | 186 +++++++++++++++++++++++++ 1 file changed, 186 insertions(+) diff --git a/docs/_docs/configuration/menu-hjson.md b/docs/_docs/configuration/menu-hjson.md index ab935222..0bc8bcd4 100644 --- a/docs/_docs/configuration/menu-hjson.md +++ b/docs/_docs/configuration/menu-hjson.md @@ -125,6 +125,7 @@ Many built in global/system methods exist. Below are a few. See [system_menu_met | `nextConf` | Sets the users message conference to the next available. | | `prevArea` | Sets the users message area to the previous available. | | `nextArea` | Sets the users message area to the next available. | +| `setClientEncoding` | Sets the client encoding to either cp437 or utf-8. | ## Example Let's look a couple basic menu entries: @@ -362,3 +363,188 @@ newUserApplicationPre: { // note that the rest of this menu is omitted for clarity } ``` + +## Case Study: Manual Encoding Selection + +Enigma½ tries to automatically determine the proper encoding for a client when it connects. Unfortunately, there are cases where the wrong encoding can be selected, resulting in terminal programs that are not supported. If your user base contains users that would like to connect with unsupported clients, one solution is to offer manual encoding selection. + +A new system method has been added to support this, @systemMethod:setClientEncoding. + +### Simple example + +A basic config to use this could look something like the following: + + +```hjson +telnetConnected: { + art: CONNECT + next: clientSelectEncoding + config: { nextTimeout: 1500 } +} + +clientSelectEncoding: { + art: CLTSEL.ASC + next: matrix + config: { interrupt: realtime } + form: { + 0: { + mci: { + HM1: { + submit: true + hotKeys: { U: 0, C: 1 } + hotKeysSubmit: true + focus: true + argName: encoding + items: [ + { + text: U) UTF-8 + data: utf-8 + } + { + text: C) CP437 + data: cp437 + } + ] + } + } + submit: { + *: [ + { + value: { encoding: "utf-8" } + action: @systemMethod:setClientEncoding + } + { + value: { encoding: "cp437" } + action: @systemMethod:setClientEncoding + } + ] + } + } + } +} +``` + +The artfile for this should not contain extended characters, a simple file list +the following should work: + +``` +Choose your encoding: + +%HM1 +``` + +### Auto selection example + +The above example can be further extended to default to the automatically detected encoding by using a slightly more complicated menu system: + + + +```hjson + +telnetConnected: { + art: CONNECT + next: [ + { + acs: EC0 + next: clientSelectCP437 + } + { + next: clientSelectUTF8 + } + ] + config: { nextTimeout: 1500 } +} + +clientSelectUTF8: { + art: CLTSEL.ASC + next: matrix + config: { font: utf-8 + interrupt: realtime + } + form: { + 0: { + mci: { + HM1: { + submit: true + hotKeys: { U: 0, C: 1 } + hotKeysSubmit: true + focus: true + argName: encoding + focusItemIndex: 0 + items: [ + { + text: U) UTF-8 + data: utf-8 + } + { + text: C) CP437 + data: cp437 + } + ] + } + } + submit: { + *: [ + { + value: { encoding: "utf-8" } + action: @systemMethod:setClientEncoding + } + { + value: { encoding: "cp437" } + action: @systemMethod:setClientEncoding + } + ] + } + } + } +} + +clientSelectCP437: { + art: CLTSEL.ASC + next: matrix + config: { font: cp437 + interrupt: realtime + } + form: { + 0: { + mci: { + HM1: { + submit: true + hotKeys: { U: 0, C: 1 } + hotKeysSubmit: true + focus: true + argName: encoding + focusItemIndex: 1 + items: [ + { + text: U) UTF-8 + data: utf-8 + } + { + text: C) CP437 + data: cp437 + } + ] + } + } + submit: { + *: [ + { + value: { encoding: "utf-8" } + action: @systemMethod:setClientEncoding + } + { + value: { encoding: "cp437" } + action: @systemMethod:setClientEncoding + } + ] + } + } + } +} + +Use the same artfile as the previous example. + +*Note*: This example can be shortened by using @reference sections if desired. + +The `acs:` sections above will send the user to a different menu depending on whether they have encoding CP437 using `EC0` or anything else sent to the UTF8 menu. From there `focusItemIndex` chooses the default item. From c799f1f73c70ea4a80b3cca266f052856e5f9d9e Mon Sep 17 00:00:00 2001 From: Nathan Byrd Date: Sun, 31 Jul 2022 12:53:34 -0500 Subject: [PATCH 3/5] Code review changes --- core/client_term.js | 4 ++++ core/system_menu_method.js | 7 ------- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/core/client_term.js b/core/client_term.js index b65690e0..253e5dd3 100644 --- a/core/client_term.js +++ b/core/client_term.js @@ -42,6 +42,10 @@ function ClientTerminal(output) { }, set: function (enc) { if (iconv.encodingExists(enc)) { + Log.info( + { encoding: enc, currentEncoding: outputEncoding }, + 'Setting client encoding.' + ); outputEncoding = enc; } else { Log.warn({ encoding: enc }, 'Unknown encoding'); diff --git a/core/system_menu_method.js b/core/system_menu_method.js index 73d604a5..56479f8b 100644 --- a/core/system_menu_method.js +++ b/core/system_menu_method.js @@ -247,13 +247,6 @@ function setClientEncoding(callingMenu, formData, extraArgs, cb) { const client = callingMenu.client; let encoding = formData.value.encoding; - client.log.info( - { encoding: encoding, currentEncoding: client.term.outputEncoding }, - 'Setting client encoding.' - ); - - encoding = encoding || client.term.outputEncoding; - client.term.outputEncoding = encoding; return callingMenu.nextMenu(cb); From 4baba90fc4744a32c79b00dd69d8e13856f4a954 Mon Sep 17 00:00:00 2001 From: Nathan Byrd Date: Sun, 31 Jul 2022 13:17:51 -0500 Subject: [PATCH 4/5] Documentation changes --- WHATSNEW.md | 1 + docs/_docs/configuration/menu-hjson.md | 31 ++++++-------------------- 2 files changed, 8 insertions(+), 24 deletions(-) diff --git a/WHATSNEW.md b/WHATSNEW.md index 1595d32f..b4b2a08f 100644 --- a/WHATSNEW.md +++ b/WHATSNEW.md @@ -6,6 +6,7 @@ This document attempts to track **major** changes and additions in ENiGMA½. For * Removed terminal `cursor position reports` from most locations in the code. This should greatly increase the number of terminal programs that work with Enigma 1/2. For more information, see [Issue #222](https://github.com/NuSkooler/enigma-bbs/issues/222). This may also resolve other issues, such as [Issue #365](https://github.com/NuSkooler/enigma-bbs/issues/365), and [Issue #320](https://github.com/NuSkooler/enigma-bbs/issues/320). Anyone that previously had terminal incompatibilities please re-check and let us know! * Bumped up the minimum [Node.js](https://nodejs.org/en/) version to v14. This will allow more expressive Javascript programming syntax with ECMAScript 2020 to improve the development experience. * Added new configuration options for `term.checkUtf8Encoding`, `term.checkAnsiHomePostion`, `term.cp437TermList`, and `term.utf8TermList`. More information on these options is available in [UPGRADE](UPGRADE.md). +* Added a system method to support setting the client encoding from menus, `@systemMethod:setClientEncoding`. * Many additional backward-compatible bug fixes since the first release of 0.0.12-beta. See the [project repository](https://github.com/NuSkooler/enigma-bbs) for more information. ## 0.0.12-beta diff --git a/docs/_docs/configuration/menu-hjson.md b/docs/_docs/configuration/menu-hjson.md index 0bc8bcd4..f68accc7 100644 --- a/docs/_docs/configuration/menu-hjson.md +++ b/docs/_docs/configuration/menu-hjson.md @@ -76,7 +76,7 @@ Menus may also support more than one layout type by using a *MCI key*. A MCI key For more information on views and associated MCI codes, see [MCI Codes](../art/mci.md). ## Submit Handlers -When a form is submitted, it's data is matched against a *submit handler*. When a match is found, it's *action* is performed. +When a form is submitted, it's data is matched against a *submit handler*. When a match is found, it's *action* is performed. Note: Setting the value explicitly to null matches against any value. ### Submit Actions Submit actions are declared using the `action` member of a submit handler block. Actions can be kick off system/global or local-to-module methods, launch other menus, etc. @@ -368,7 +368,7 @@ newUserApplicationPre: { Enigma½ tries to automatically determine the proper encoding for a client when it connects. Unfortunately, there are cases where the wrong encoding can be selected, resulting in terminal programs that are not supported. If your user base contains users that would like to connect with unsupported clients, one solution is to offer manual encoding selection. -A new system method has been added to support this, @systemMethod:setClientEncoding. +This can be accomplished with the system method `@systemMethod:setClientEncoding`. ### Simple example @@ -385,7 +385,6 @@ telnetConnected: { clientSelectEncoding: { art: CLTSEL.ASC next: matrix - config: { interrupt: realtime } form: { 0: { mci: { @@ -410,11 +409,7 @@ clientSelectEncoding: { submit: { *: [ { - value: { encoding: "utf-8" } - action: @systemMethod:setClientEncoding - } - { - value: { encoding: "cp437" } + value: { encoding: null } action: @systemMethod:setClientEncoding } ] @@ -458,9 +453,7 @@ telnetConnected: { clientSelectUTF8: { art: CLTSEL.ASC next: matrix - config: { font: utf-8 - interrupt: realtime - } + config: { font: utf-8 } form: { 0: { mci: { @@ -486,11 +479,7 @@ clientSelectUTF8: { submit: { *: [ { - value: { encoding: "utf-8" } - action: @systemMethod:setClientEncoding - } - { - value: { encoding: "cp437" } + value: { encoding: null } action: @systemMethod:setClientEncoding } ] @@ -502,9 +491,7 @@ clientSelectUTF8: { clientSelectCP437: { art: CLTSEL.ASC next: matrix - config: { font: cp437 - interrupt: realtime - } + config: { font: cp437 } form: { 0: { mci: { @@ -530,11 +517,7 @@ clientSelectCP437: { submit: { *: [ { - value: { encoding: "utf-8" } - action: @systemMethod:setClientEncoding - } - { - value: { encoding: "cp437" } + value: { encoding: null } action: @systemMethod:setClientEncoding } ] From 40d38c55d7bbc14d2e829fe330f928bb44b3b442 Mon Sep 17 00:00:00 2001 From: Nathan Byrd Date: Sun, 31 Jul 2022 13:29:01 -0500 Subject: [PATCH 5/5] Additional documentation change --- docs/_docs/configuration/menu-hjson.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/_docs/configuration/menu-hjson.md b/docs/_docs/configuration/menu-hjson.md index f68accc7..acf49a52 100644 --- a/docs/_docs/configuration/menu-hjson.md +++ b/docs/_docs/configuration/menu-hjson.md @@ -125,7 +125,7 @@ Many built in global/system methods exist. Below are a few. See [system_menu_met | `nextConf` | Sets the users message conference to the next available. | | `prevArea` | Sets the users message area to the previous available. | | `nextArea` | Sets the users message area to the next available. | -| `setClientEncoding` | Sets the client encoding to either cp437 or utf-8. | +| `setClientEncoding` | Sets the client encoding (such as cp437 and utf-8.) | ## Example Let's look a couple basic menu entries: