Merge pull request #454 from NuSkooler/text-label-with-mci-codes

Advanced formatting for TextView / %TL MCI code
This commit is contained in:
Bryan Ashby 2022-10-12 02:28:50 +00:00 committed by GitHub
commit 94da8798cf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 51 additions and 75 deletions

View File

@ -6,13 +6,15 @@ 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! * 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. * 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.
* **New Waiting For Caller (WFC)** support via the `wfc.js` module. * **New Waiting For Caller (WFC)** support via the `wfc.js` module.
* 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 new configuration options for `term.checkUtf8Encoding`, `term.checkAnsiHomePosition`, `term.cp437TermList`, and `term.utf8TermList`. More information on these options is available in [UPGRADE](UPGRADE.md).
* Many new system statistics available via the StatLog such as current and average load, memory, etc. * Many new system statistics available via the StatLog such as current and average load, memory, etc.
* Many new MCI codes: `MB`, `MF`, `LA`, `CL`, `UU`, `FT`, `DD`, `FB`, `DB`, `LC`, `LT`, `LD`, and more. See [MCI](./docs/art/mci.md). * Many new MCI codes: `MB`, `MF`, `LA`, `CL`, `UU`, `FT`, `DD`, `FB`, `DB`, `LC`, `LT`, `LD`, and more. See [MCI](./docs/art/mci.md).
* SyncTERM style font support detection. * SyncTERM style font support detection.
* Added a system method to support setting the client encoding from menus, `@systemMethod:setClientEncoding`. * 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. * 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.
* Deprecated Gopher's `messageConferences` configuration key in favor of a easier to deal with `exposedConfAreas` allowing wildcards and exclusions. See [Gopher](./docs/servers/contentservers/gopher.md). * Deprecated Gopher's `messageConferences` configuration key in favor of a easier to deal with `exposedConfAreas` allowing wildcards and exclusions. See [Gopher](./docs/servers/contentservers/gopher.md).
* NNTP write (aka POST) access support for authenticated users over TLS.
* [Advanced MCI formatting](./docs/art/mci.md#mci-formatting)
## 0.0.12-beta ## 0.0.12-beta
* The `master` branch has become mainline. What this means to users is `git pull` will always give you the latest and greatest. Make sure to read [Updating](./docs/admin/updating.md) and keep an eye on `WHATSNEW.md` (this file) and [UPGRADE](UPGRADE.md)! See also [ticket #276](https://github.com/NuSkooler/enigma-bbs/issues/276). * The `master` branch has become mainline. What this means to users is `git pull` will always give you the latest and greatest. Make sure to read [Updating](./docs/admin/updating.md) and keep an eye on `WHATSNEW.md` (this file) and [UPGRADE](UPGRADE.md)! See also [ticket #276](https://github.com/NuSkooler/enigma-bbs/issues/276).

View File

@ -33,7 +33,6 @@ MCIViewFactory.UserViewCodes = [
'ET', 'ET',
'ME', 'ME',
'MT', 'MT',
'PL',
'BT', 'BT',
'VM', 'VM',
'HM', 'HM',
@ -129,21 +128,6 @@ MCIViewFactory.prototype.createFromMCI = function (mci) {
view = new MultiLineEditTextView(options); view = new MultiLineEditTextView(options);
break; break;
// Pre-defined Label (Text View)
// :TODO: Currently no real point of PL -- @method replaces this pretty much... probably remove
case 'PL':
if (mci.args.length > 0) {
options.text = getPredefinedMCIValue(this.client, mci.args[0]);
if (options.text) {
setOption(1, 'textStyle');
setOption(2, 'justify');
setWidth(3);
view = new TextView(options);
}
}
break;
// Button // Button
case 'BT': case 'BT':
if (mci.args.length > 0) { if (mci.args.length > 0) {

View File

@ -22,6 +22,7 @@ const moment = require('moment');
const async = require('async'); const async = require('async');
exports.getPredefinedMCIValue = getPredefinedMCIValue; exports.getPredefinedMCIValue = getPredefinedMCIValue;
exports.getPredefinedMCIFormatObject = getPredefinedMCIFormatObject;
exports.init = init; exports.init = init;
function init(cb) { function init(cb) {
@ -532,3 +533,21 @@ function getPredefinedMCIValue(client, code, extra) {
return value; return value;
} }
} }
function getPredefinedMCIFormatObject(client, text) {
const re = /\{([A-Z]{2})(?:[!:][^}]+)?\}/g;
let m;
const formatObj = {};
while ((m = re.exec(text))) {
const v = getPredefinedMCIValue(client, m[1]);
if (v) {
if (!isNaN(v)) {
formatObj[m[1]] = parseInt(v);
} else {
formatObj[m[1]] = v;
}
}
}
return _.isEmpty(formatObj) ? null : formatObj;
}

View File

@ -11,6 +11,9 @@ const renderSubstr = require('./string_util.js').renderSubstr;
const renderStringLength = require('./string_util.js').renderStringLength; const renderStringLength = require('./string_util.js').renderStringLength;
const pipeToAnsi = require('./color_codes.js').pipeToAnsi; const pipeToAnsi = require('./color_codes.js').pipeToAnsi;
const stripAllLineFeeds = require('./string_util.js').stripAllLineFeeds; const stripAllLineFeeds = require('./string_util.js').stripAllLineFeeds;
const getPredefinedMCIFormatObject =
require('./predefined_mci').getPredefinedMCIFormatObject;
const stringFormat = require('./string_format');
// deps // deps
const util = require('util'); const util = require('util');
@ -153,6 +156,12 @@ TextView.prototype.setText = function (text, redraw) {
text = text.toString(); text = text.toString();
} }
const formatObj = getPredefinedMCIFormatObject(this.client, text);
if (formatObj) {
// expand before converting
text = stringFormat(text, formatObj);
}
this.text = pipeToAnsi(stripAllLineFeeds(text), this.client); // expand MCI/etc. this.text = pipeToAnsi(stripAllLineFeeds(text), this.client); // expand MCI/etc.
if (this.maxLength > 0) { if (this.maxLength > 0) {
this.text = renderSubstr(this.text, 0, this.maxLength); this.text = renderSubstr(this.text, 0, this.maxLength);

View File

@ -92,7 +92,6 @@ collections:
- art/views/horizontal_menu_view.md - art/views/horizontal_menu_view.md
- art/views/mask_edit_text_view.md - art/views/mask_edit_text_view.md
- art/views/multi_line_edit_text_view.md - art/views/multi_line_edit_text_view.md
- art/views/predefined_label_view.md
- art/views/spinner_menu_view.md - art/views/spinner_menu_view.md
- art/views/text_view.md - art/views/text_view.md
- art/views/toggle_menu_view.md - art/views/toggle_menu_view.md

View File

@ -108,7 +108,7 @@ There are many predefined MCI codes that can be used anywhere on the system (pla
| `NM` | Count of new messages **address to the current user** across all message areas in which they have access | | `NM` | Count of new messages **address to the current user** across all message areas in which they have access |
| `NP` | Count of new private mail to the current user | | `NP` | Count of new private mail to the current user |
| `IA` | Indicator as to rather the current user is **available** or not. See also `getStatusAvailIndicators()` in [Themes](themes.md) | | `IA` | Indicator as to rather the current user is **available** or not. See also `getStatusAvailIndicators()` in [Themes](themes.md) |
| `IV` | Indicator as to rather the curent user is **visible** or not. See also `getStatusVisibleIndicators()` in [Themes](themes.md) | | `IV` | Indicator as to rather the current user is **visible** or not. See also `getStatusVisibleIndicators()` in [Themes](themes.md) |
| `PI` | Ingress bytes for the current process (since ENiGMA started up) | | `PI` | Ingress bytes for the current process (since ENiGMA started up) |
| `PE` | Egress bytes for the current process (since ENiGMA started up) | | `PE` | Egress bytes for the current process (since ENiGMA started up) |
@ -123,11 +123,9 @@ Some additional special case codes also exist:
| `XY` | A special code that may be utilized for placement identification when creating menus or to extend an otherwise empty space in an art file down the screen. | | `XY` | A special code that may be utilized for placement identification when creating menus or to extend an otherwise empty space in an art file down the screen. |
> :information_source: More are added all > :information_source: More are added all the time so also check out [core/predefined_mci.js](https://github.com/NuSkooler/enigma-bbs/blob/master/core/mci_view_factory.js) for a full listing.
the time so also check out [core/predefined_mci.js](https://github.com/NuSkooler/enigma-bbs/blob/master/core/mci_view_factory.js)
for a full listing.
:memo: Many codes attempt to pay homage to Oblivion/2, iNiQUiTY, etc. > :memo: Many codes attempt to pay homage to Oblivion/2, iNiQUiTY, etc.
## Views ## Views
@ -146,7 +144,6 @@ a Vertical Menu (`%VM`): Old-school BBSers may recognize this as a lightbar menu
| `FM` | Full Menu | A menu that can go both vertical and horizontal. | See [Full Menu](views/full_menu_view.md) | | `FM` | Full Menu | A menu that can go both vertical and horizontal. | See [Full Menu](views/full_menu_view.md) |
| `SM` | Spinner Menu | A spinner input control | Select *one* from multiple options. See [Spinner Menu](views/spinner_menu_view.md) | | `SM` | Spinner Menu | A spinner input control | Select *one* from multiple options. See [Spinner Menu](views/spinner_menu_view.md) |
| `TM` | Toggle Menu | A toggle menu | Commonly used for Yes/No style input. See [Toggle Menu](views/toggle_menu_view.md)| | `TM` | Toggle Menu | A toggle menu | Commonly used for Yes/No style input. See [Toggle Menu](views/toggle_menu_view.md)|
| `PL` | Predefined Label | Show environment information | See [Predefined Label](views/predefined_label_view.md)|
| `KE` | Key Entry | A *single* key input control | Think hotkeys | | `KE` | Key Entry | A *single* key input control | Think hotkeys |
> :information_source: Peek at [/core/mci_view_factory.js](https://github.com/NuSkooler/enigma-bbs/blob/master/core/mci_view_factory.js) to see additional information. > :information_source: Peek at [/core/mci_view_factory.js](https://github.com/NuSkooler/enigma-bbs/blob/master/core/mci_view_factory.js) to see additional information.
@ -189,7 +186,7 @@ Predefined MCI codes and other Views can have properties set via `menu.hjson` an
| `height` | Sets the height of views such as menus that may be > 1 character in height | | `height` | Sets the height of views such as menus that may be > 1 character in height |
| `width` | Sets the width of a view | | `width` | Sets the width of a view |
| `focus` | If set to `true`, establishes initial focus | | `focus` | If set to `true`, establishes initial focus |
| `text` | (initial) text of a view | | `text` | Set's the view's text if applicable, such as a [TextView](./views/text_view.md) or [EditTextView](./views/edit_text_view.md) amongst others. See [MCI Formatting](#mci-formatting) below for advanced formatting options using the |
| `submit` | If set to `true` any `accept` action upon this view will submit the encompassing **form** | | `submit` | If set to `true` any `accept` action upon this view will submit the encompassing **form** |
| `itemFormat` | Sets the format for a list entry. See [Entry Formatting](#entry-formatting) below | | `itemFormat` | Sets the format for a list entry. See [Entry Formatting](#entry-formatting) below |
| `focusItemFormat` | Sets the format for a focused list entry. See [Entry Formatting](#entry-formatting) below | | `focusItemFormat` | Sets the format for a focused list entry. See [Entry Formatting](#entry-formatting) below |
@ -219,6 +216,21 @@ Standard style types available for `textStyle` and `focusTextStyle`:
### Entry Formatting ### Entry Formatting
Various strings can be formatted using a syntax that allows width & precision specifiers, text styling, etc. Depending on the context, various elements can be referenced by `{name}`. Additional text styles can be supplied as well. The syntax is largely modeled after Python's [string format mini language](https://docs.python.org/3/library/string.html#format-specification-mini-language). Various strings can be formatted using a syntax that allows width & precision specifiers, text styling, etc. Depending on the context, various elements can be referenced by `{name}`. Additional text styles can be supplied as well. The syntax is largely modeled after Python's [string format mini language](https://docs.python.org/3/library/string.html#format-specification-mini-language).
#### MCI Formatting
For more advanced layouts, you may want to apply formatting to MCI codes. In this case, an alternative syntax is supported similar to standard [Entry Formatting](#entry-formatting).
MCI codes can be surrounded by `{` and `}` in the `text` field in your `theme.hjson` for a Text Label (`%TL` aka [Text View](./views/text_view.md)). Some examples:
```hjson
text: "|00|07{BN!stylel33t}" // render board name in "l33t" text
// MCI codes that produce a number can use appropriate stylers as well
text: "|00|07{SD:,}"
// ...or perhaps
text: "|00:07{SD!countWithAbbr}"
```
> :bulb: MCI formatting also applies when programmatically calling [setText()](https://github.com/NuSkooler/enigma-bbs/blob/6710bf8c084487be2ee1d46d72a05d17a7b166f4/core/text_view.js#L148) of [TextView's](./views/text_view.md) and derived views.
### Additional Text Styles ### Additional Text Styles
Some of the text styles mentioned above are also available in the mini format language: Some of the text styles mentioned above are also available in the mini format language:

View File

@ -1,49 +0,0 @@
---
layout: page
title: Predefined Label View
---
## Predefined Label View
A predefined label view supports displaying a predefined MCI label on a screen.
## General Information
> :information_source: A predefined label view is defined with a percent (%) and the characters PL, followed by the view number and then the predefined MCI value in parenthesis. For example: `%PL1(VL)` to display the Version Label. *NOTE*: this is an alternate way of placing MCI codes, as the MCI can also be placed on the art page directly with the code. For example `%VL`. The difference between these is that the PL version can have additional formatting options applied to it.
> :information_source: See *Predefined Codes* in [MCI](../mci.md) for the list of available MCI codes.
> :information_source: See [MCI](../mci.md) for general information on how to use views and common configuration properties available for them.
### Properties
| Property | Description |
|-------------|--------------|
| `textStyle` | Sets the standard (non-focus) text style. See **Text Styles** in [MCI](../mci.md) |
| `justify` | Sets the justification of the MCI value text. Options: left (default), right, center |
| `fillChar` | Specifies a character to fill extra space in the view. Defaults to an empty space |
| `width` | Specifies the width that the value should be displayed in (default 3) |
| `textOverflow` | If the MCI is wider than width, set overflow characters. See **Text Overflow** below |
### Text Overflow
The `textOverflow` option is used to specify what happens when a predefined MCI string is too long to fit in the `width` defined.
> :information_source: If `textOverflow` is not specified at all, a predefined label view can become wider than the `width` if needed to display the MCI value.
> :information_source: Setting `textOverflow` to an empty string `textOverflow: ""` will cause the item to be truncated if necessary without any characters displayed
> :information_source: Otherwise, setting `textOverflow` to one or more characters will truncate the value if necessary and display those characters at the end. i.e. `textOverflow: ...`
## Example
![Example](../../assets/images/predefined_label_view_example1.png "Predefined label")
<details>
<summary>Configuration fragment (expand to view)</summary>
<div markdown="1">
```
PL1: {
textStyle: upper
}
```
</div>
</details>

View File

@ -15,7 +15,7 @@ A text label view supports displaying simple text on a screen.
| Property | Description | | Property | Description |
|-------------|--------------| |-------------|--------------|
| `text` | Sets the text to display on the label | | `text` | Sets the text to display on the label. See [MCI Formatting](../mci.md#mci-formatting) for information for advanced formatting. |
| `textStyle` | Sets the standard (non-focus) text style. See **Text Styles** in [MCI](../mci.md) | | `textStyle` | Sets the standard (non-focus) text style. See **Text Styles** in [MCI](../mci.md) |
| `width` | Sets the width of a view to display horizontally (default 15)| | `width` | Sets the width of a view to display horizontally (default 15)|
| `justify` | Sets the justification of the text in the view. Options: left (default), right, center | | `justify` | Sets the justification of the text in the view. Options: left (default), right, center |