From b0260049ba39b55050562017722e455d80d150dc Mon Sep 17 00:00:00 2001 From: Bryan Ashby Date: Thu, 21 Sep 2017 21:23:30 -0600 Subject: [PATCH] Add VTX hyperlink support for URLs --- core/ansi_term.js | 13 ++++++++++++- core/client.js | 7 ++++++- core/config.js | 5 ++++- core/string_format.js | 2 ++ mods/file_area_list.js | 4 ++-- 5 files changed, 26 insertions(+), 5 deletions(-) diff --git a/core/ansi_term.js b/core/ansi_term.js index 8b4094f1..504a1709 100644 --- a/core/ansi_term.js +++ b/core/ansi_term.js @@ -56,7 +56,7 @@ exports.getSyncTERMFontFromAlias = getSyncTERMFontFromAlias; exports.setSyncTermFontWithAlias = setSyncTermFontWithAlias; exports.setCursorStyle = setCursorStyle; exports.setEmulatedBaudRate = setEmulatedBaudRate; - +exports.getVtxHyperlink = getVtxHyperlink; // // See also @@ -485,3 +485,14 @@ function setEmulatedBaudRate(rate) { }[rate] || 0; return 0 === speed ? exports.emulationSpeed() : exports.emulationSpeed(1, speed); } + +function getVtxHyperlink(client, url, text) { + if(!client.terminalSupports('vtx_hyperlink')) { + return ''; + } + + text = text || url; + + url = url.split('').map(c => c.charCodeAt(0)).join(';'); + return `${ESC_CSI}1;${text.length};1;1;${url}\\`; +} \ No newline at end of file diff --git a/core/client.js b/core/client.js index 4501396d..71d7a9ad 100644 --- a/core/client.js +++ b/core/client.js @@ -493,10 +493,15 @@ Client.prototype.defaultHandlerMissingMod = function(err) { }; Client.prototype.terminalSupports = function(query) { + const termClient = this.term.termClient; + switch(query) { case 'vtx_audio' : // https://github.com/codewar65/VTX_ClientServer/blob/master/vtx.txt - return this.termClient === 'vtx'; + return 'vtx' === termClient; + + case 'vtx_hyperlink' : + return termClient === 'vtx'; default : return false; diff --git a/core/config.js b/core/config.js index 85632000..75be7795 100644 --- a/core/config.js +++ b/core/config.js @@ -158,7 +158,10 @@ function getDefaultConfig() { newUserNames : [ 'new', 'apply' ], // Names reserved for applying // :TODO: Mystic uses TRASHCAN.DAT for this -- is there a reason to support something like that? - badUserNames : [ 'sysop', 'admin', 'administrator', 'root', 'all' ], + badUserNames : [ + 'sysop', 'admin', 'administrator', 'root', 'all', + 'areamgr', 'filemgr', 'filefix', 'areafix', 'allfix' + ], }, // :TODO: better name for "defaults"... which is redundant here! diff --git a/core/string_format.js b/core/string_format.js index 297d92b2..7fb7109a 100644 --- a/core/string_format.js +++ b/core/string_format.js @@ -271,8 +271,10 @@ const transformers = { styleMixed : (s) => stylizeString(s, 'mixed'), styleL33t : (s) => stylizeString(s, 'l33t'), + // :TODO: // toMegs(), toKilobytes(), ... // toList(), toCommaList(), + sizeWithAbbr : (n) => formatByteSize(n, true, 2), sizeWithoutAbbr : (n) => formatByteSize(n, false, 2), sizeAbbr : (n) => formatByteSizeAbbr(n), diff --git a/mods/file_area_list.js b/mods/file_area_list.js index 076d2a98..21b5557d 100644 --- a/mods/file_area_list.js +++ b/mods/file_area_list.js @@ -274,7 +274,7 @@ exports.getModule = class FileAreaList extends MenuModule { } else { const webDlExpireTimeFormat = config.webDlExpireTimeFormat || 'YYYY-MMM-DD @ h:mm'; - entryInfo.webDlLink = serveItem.url; + entryInfo.webDlLink = ansi.getVtxHyperlink(this.client, serveItem.url) + serveItem.url; entryInfo.webDlExpire = moment(serveItem.expireTimestamp).format(webDlExpireTimeFormat); } @@ -497,7 +497,7 @@ exports.getModule = class FileAreaList extends MenuModule { const webDlExpireTimeFormat = self.menuConfig.config.webDlExpireTimeFormat || 'YYYY-MMM-DD @ h:mm'; - self.currentFileEntry.entryInfo.webDlLink = url; + self.currentFileEntry.entryInfo.webDlLink = ansi.getVtxHyperlink(self.client, url) + url; self.currentFileEntry.entryInfo.webDlExpire = expireTime.format(webDlExpireTimeFormat); return callback(null);