Updates to drawing, additional props, friendly IP addrs, etc.

This commit is contained in:
Bryan Ashby
2022-06-10 16:08:22 -06:00
parent 1ba866f2ca
commit ba5775adc9
8 changed files with 59 additions and 9 deletions

View File

@@ -577,7 +577,9 @@ Client.prototype.isLocal = function() {
Client.prototype.friendlyRemoteAddress = function() {
// convert any :ffff: IPv4's to 32bit version
return this.remoteAddress.replace(/^::ffff:/, '')
return this.remoteAddress
.replace(/^::ffff:/, '')
.replace(/^::1$/, 'localhost');
}
///////////////////////////////////////////////////////////////////////////////

View File

@@ -123,7 +123,7 @@ function addNewClient(client, clientSock) {
connInfo.family = clientSock.localFamily;
}
client.log.info(connInfo, `Client connected (${connInfo.port}/${connInfo.serverName})`);
client.log.info(connInfo, `Client connected (${connInfo.serverName}/${connInfo.port})`);
Events.emit(
Events.getSystemEvents().ClientConnected,

View File

@@ -121,7 +121,7 @@ const PREDEFINED_MCI_GENERATORS = {
UD : function themeId(client) { return userStatAsString(client, UserProps.ThemeId, ''); },
UC : function loginCount(client) { return userStatAsCountString(client, UserProps.LoginCount, 0); },
ND : function connectedNode(client) { return client.node.toString(); },
IP : function clientIpAddress(client) { return client.remoteAddress.friendlyRemoteAddress() },
IP : function clientIpAddress(client) { return client.friendlyRemoteAddress() },
ST : function serverName(client) { return client.session.serverName; },
FN : function activeFileBaseFilterName(client) {
const activeFilter = FileBaseFilters.getActiveFilter(client);
@@ -370,7 +370,7 @@ function getPredefinedMCIValue(client, code, extra) {
try {
value = generator(client, extra);
} catch(e) {
Log.error( { code : code, exception : e.message }, 'Exception caught generating predefined MCI value' );
Log.error( { code : code, exception : e.message }, `Failed generating predefined MCI value (${code})` );
}
return value;

View File

@@ -83,6 +83,15 @@ function VerticalMenuView(options) {
self.client.term.write(`${ansi.goto(item.row, self.position.col)}${text}`);
this.setRenderCacheItem(index, text, item.focused);
};
this.drawRemovedItem = function(index) {
if (index <= this.items.length - 1) {
return;
}
const row = this.position.row + index;
this.client.term.rawWrite(`${ansi.goto(row, this.position.col)}${ansi.normal()}${this.fillChar.repeat(this.dimens.width)}`)
};
}
util.inherits(VerticalMenuView, MenuView);
@@ -123,6 +132,11 @@ VerticalMenuView.prototype.redraw = function() {
this.drawItem(i);
}
}
const remain = Math.max(0, this.dimens.height - this.items.length);
for (let i = this.items.length; i < remain; ++i) {
this.drawRemovedItem(i);
}
};
VerticalMenuView.prototype.setHeight = function(height) {

View File

@@ -1,5 +1,6 @@
// ENiGMA½
const { MenuModule } = require('./menu_module');
const stringFormat = require('./string_format');
const {
getActiveConnectionList,
@@ -33,6 +34,7 @@ const MciViewIds = {
main : {
nodeStatus : 1,
quickLogView : 2,
nodeStatusSelection : 3,
customRangeStart : 10,
}
@@ -119,7 +121,7 @@ exports.getModule = class WaitingForCallerModule extends MenuModule {
);
},
(callback) => {
const quickLogView = this.viewControllers.main.getView(MciViewIds.main.quickLogView);
const quickLogView = this.getView('main', MciViewIds.main.quickLogView);
if (!quickLogView) {
return callback(null);
}
@@ -138,6 +140,20 @@ exports.getModule = class WaitingForCallerModule extends MenuModule {
});
}
const nodeStatusView = this.getView('main', MciViewIds.main.nodeStatus);
const nodeStatusSelectionView = this.getView('main', MciViewIds.main.nodeStatusSelection);
const nodeStatusSelectionFormat = this.config.nodeStatusSelectionFormat || '{text}';
if (nodeStatusView && nodeStatusSelectionView) {
nodeStatusView.on('index update', index => {
const item = nodeStatusView.getItems()[index];
if (item) {
nodeStatusSelectionView.setText(stringFormat(nodeStatusSelectionFormat, item));
// :TODO: Update view
// :TODO: this is not triggered by key-presses (1, 2, ...) -- we need to handle that as well
}
});
}
return callback(null);
},
(callback) => {
@@ -354,10 +370,15 @@ exports.getModule = class WaitingForCallerModule extends MenuModule {
const [availIndicator, visIndicator] = this._getStatusStrings(ac.isAvailable, ac.isVisible);
const timeOn = ac.timeOn || moment.duration(0);
return Object.assign(ac, {
availIndicator,
visIndicator,
timeOn : _.upperFirst((ac.timeOn || moment.duration(0)).humanize()), // make friendly
timeOnMinutes : timeOn.asMinutes(),
timeOn : _.upperFirst(timeOn.humanize()), // make friendly
affils : ac.affils || 'N/A',
realName : ac.realName || 'N/A',
});
});