First commit of "advanced" MCI formatting via theme.hjson entries allowing mini-formatting langauge to apply
Example: {BN!styleFirstLower} in 'text' property
This commit is contained in:
@@ -22,6 +22,7 @@ const moment = require('moment');
|
||||
const async = require('async');
|
||||
|
||||
exports.getPredefinedMCIValue = getPredefinedMCIValue;
|
||||
exports.getPredefinedMCIFormatObject = getPredefinedMCIFormatObject;
|
||||
exports.init = init;
|
||||
|
||||
function init(cb) {
|
||||
@@ -532,3 +533,21 @@ function getPredefinedMCIValue(client, code, extra) {
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -11,6 +11,9 @@ const renderSubstr = require('./string_util.js').renderSubstr;
|
||||
const renderStringLength = require('./string_util.js').renderStringLength;
|
||||
const pipeToAnsi = require('./color_codes.js').pipeToAnsi;
|
||||
const stripAllLineFeeds = require('./string_util.js').stripAllLineFeeds;
|
||||
const getPredefinedMCIFormatObject =
|
||||
require('./predefined_mci').getPredefinedMCIFormatObject;
|
||||
const stringFormat = require('./string_format');
|
||||
|
||||
// deps
|
||||
const util = require('util');
|
||||
@@ -153,6 +156,12 @@ TextView.prototype.setText = function (text, redraw) {
|
||||
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.
|
||||
if (this.maxLength > 0) {
|
||||
this.text = renderSubstr(this.text, 0, this.maxLength);
|
||||
|
||||
Reference in New Issue
Block a user