From af6a9b8fbbd68058da1a4db816ecc0f5d2278cc1 Mon Sep 17 00:00:00 2001 From: Luke Rhodes Date: Sun, 18 Mar 2018 00:14:29 +1100 Subject: [PATCH] Improved terminal text coloring to support dark terminal windows --- accessories/aircon.js | 24 ++++++++++++------------ accessories/switchMulti.js | 2 +- accessories/switchMultiRepeat.js | 2 +- accessories/switchRepeat.js | 2 +- helpers/sendData.js | 12 ++++++------ 5 files changed, 21 insertions(+), 21 deletions(-) diff --git a/accessories/aircon.js b/accessories/aircon.js index eaf80c54..858493dc 100644 --- a/accessories/aircon.js +++ b/accessories/aircon.js @@ -87,15 +87,15 @@ class AirConAccessory extends BroadlinkRMAccessory { // Check required properties if (config.pseudoDeviceTemperature) { - assert.isBelow(config.pseudoDeviceTemperature, config.maxTemperature + 1, `\x1b[31m[CONFIG ERROR] \x1b[33mpseudoDeviceTemperature\x1b[30m (${config.pseudoDeviceTemperature}) must be less than the maxTemperature (${config.maxTemperature})`) - assert.isAbove(config.pseudoDeviceTemperature, config.minTemperature - 1, `\x1b[31m[CONFIG ERROR] \x1b[33mpseudoDeviceTemperature\x1b[30m (${config.pseudoDeviceTemperature}) must be more than the minTemperature (${config.minTemperature})`) + assert.isBelow(config.pseudoDeviceTemperature, config.maxTemperature + 1, `\x1b[31m[CONFIG ERROR] \x1b[33mpseudoDeviceTemperature\x1b[0m (${config.pseudoDeviceTemperature}) must be less than the maxTemperature (${config.maxTemperature})`) + assert.isAbove(config.pseudoDeviceTemperature, config.minTemperature - 1, `\x1b[31m[CONFIG ERROR] \x1b[33mpseudoDeviceTemperature\x1b[0m (${config.pseudoDeviceTemperature}) must be more than the minTemperature (${config.minTemperature})`) } // minTemperature can't be more than 10 or HomeKit throws a fit - assert.isBelow(config.minTemperature, 11, `\x1b[31m[CONFIG ERROR] \x1b[33mminTemperature\x1b[30m (${config.minTemperature}) must be <= 10`) + assert.isBelow(config.minTemperature, 11, `\x1b[31m[CONFIG ERROR] \x1b[33mminTemperature\x1b[0m (${config.minTemperature}) must be <= 10`) // maxTemperature > minTemperature - assert.isBelow(config.minTemperature, config.maxTemperature, `\x1b[31m[CONFIG ERROR] \x1b[33mmaxTemperature\x1b[30m (${config.minTemperature}) must be more than minTemperature (${config.minTemperature})`) + assert.isBelow(config.minTemperature, config.maxTemperature, `\x1b[31m[CONFIG ERROR] \x1b[33mmaxTemperature\x1b[0m (${config.minTemperature}) must be more than minTemperature (${config.minTemperature})`) } reset () { @@ -260,7 +260,7 @@ class AirConAccessory extends BroadlinkRMAccessory { let mode = hexData['pseudo-mode']; - if (mode) assert.oneOf(mode, [ 'heat', 'cool', 'auto' ], '\x1b[31m[CONFIG ERROR] \x1b[33mpseudo-mode\x1b[30m should be one of "heat", "cool" or "auto"'); + if (mode) assert.oneOf(mode, [ 'heat', 'cool', 'auto' ], '\x1b[31m[CONFIG ERROR] \x1b[33mpseudo-mode\x1b[0m should be one of "heat", "cool" or "auto"'); if (!mode) { if (state.targetTemperature < state.currentTemperature) { @@ -292,10 +292,10 @@ class AirConAccessory extends BroadlinkRMAccessory { const defaultTemperature = (temperature >= heatTemperature) ? defaultHeatTemperature : defaultCoolTemperature; hexData = data[`temperature${defaultTemperature}`]; - assert(hexData, `\x1b[31m[CONFIG ERROR] \x1b[30m You need to provide a hex code for the following temperature: - \x1b[33m{ "temperature${temperature}": { "data": "HEXCODE", "pseudo-mode" : "heat/cool" } }\x1b[30m + assert(hexData, `\x1b[31m[CONFIG ERROR] \x1b[0m You need to provide a hex code for the following temperature: + \x1b[33m{ "temperature${temperature}": { "data": "HEXCODE", "pseudo-mode" : "heat/cool" } }\x1b[0m or provide the default temperature: - \x1b[33m { "temperature${defaultTemperature}": { "data": "HEXCODE", "pseudo-mode" : "heat/cool" } }\x1b[30m`); + \x1b[33m { "temperature${defaultTemperature}": { "data": "HEXCODE", "pseudo-mode" : "heat/cool" } }\x1b[0m`); this.log(`${name} Update to default temperature (${defaultTemperature})`); @@ -363,8 +363,8 @@ class AirConAccessory extends BroadlinkRMAccessory { log(`${name} onTemperature (${temperature})`); - assert.isBelow(temperature, config.maxTemperature + 1, `\x1b[31m[CONFIG ERROR] \x1b[33mmaxTemperature\x1b[30m (${config.maxTemperature}) must be more than the reported temperature (${temperature})`) - assert.isAbove(temperature, config.minTemperature - 1, `\x1b[31m[CONFIG ERROR] \x1b[33mminTemperature\x1b[30m (${config.maxTemperature}) must be less than the reported temperature (${temperature})`) + assert.isBelow(temperature, config.maxTemperature + 1, `\x1b[31m[CONFIG ERROR] \x1b[33mmaxTemperature\x1b[0m (${config.maxTemperature}) must be more than the reported temperature (${temperature})`) + assert.isAbove(temperature, config.minTemperature - 1, `\x1b[31m[CONFIG ERROR] \x1b[33mminTemperature\x1b[0m (${config.maxTemperature}) must be less than the reported temperature (${temperature})`) this.processQueuedTemperatureCallbacks(temperature); } @@ -417,13 +417,13 @@ class AirConAccessory extends BroadlinkRMAccessory { fs.readFile(temperatureFilePath, 'utf8', (err, temperature) => { if (err) { - log(`\x1b[31m[ERROR] \x1b[30m${name} updateTemperatureFromFile\n\n${err.message}`); + log(`\x1b[31m[ERROR] \x1b[0m${name} updateTemperatureFromFile\n\n${err.message}`); return; } if (!temperature || temperature.trim().length === 0) { - log(`\x1b[31m[ERROR] \x1b[30m${name} updateTemperatureFromFile (no temperature found)`); + log(`\x1b[31m[ERROR] \x1b[0m${name} updateTemperatureFromFile (no temperature found)`); return; } diff --git a/accessories/switchMulti.js b/accessories/switchMulti.js index 971d51c4..d6b1f9d2 100644 --- a/accessories/switchMulti.js +++ b/accessories/switchMulti.js @@ -65,7 +65,7 @@ class SwitchMultiAccessory extends SwitchAccessory { const { data, log, name, config, serviceManagerType } = this; setTimeout(() => { - log(`\x1b[33m[Warning] \x1b[30m${name}: The "switch-multi" accessory is now deprecated and shall be removed in the future. Check out the updated "switch" documentation at http://github.com/lprhodes/homebridge-broadlink-rm`); + log(`\x1b[33m[Warning] \x1b[0m${name}: The "switch-multi" accessory is now deprecated and shall be removed in the future. Check out the updated "switch" documentation at http://github.com/lprhodes/homebridge-broadlink-rm`); }, 1600) this.serviceManager = new ServiceManagerTypes[serviceManagerType](name, Service.Switch, this.log); diff --git a/accessories/switchMultiRepeat.js b/accessories/switchMultiRepeat.js index a7da2e39..282dfee4 100644 --- a/accessories/switchMultiRepeat.js +++ b/accessories/switchMultiRepeat.js @@ -94,7 +94,7 @@ class SwitchMultiAccessory extends SwitchAccessory { const { data, log, name, config, serviceManagerType } = this; setTimeout(() => { - log(`\x1b[33m[Warning] \x1b[30m${name}: The "switch-multi-repeat" accessory is now deprecated and shall be removed in the future. Check out the updated "switch" documentation at http://github.com/lprhodes/homebridge-broadlink-rm`); + log(`\x1b[33m[Warning] \x1b[0m${name}: The "switch-multi-repeat" accessory is now deprecated and shall be removed in the future. Check out the updated "switch" documentation at http://github.com/lprhodes/homebridge-broadlink-rm`); }, 1600) this.serviceManager = new ServiceManagerTypes[serviceManagerType](name, Service.Switch, this.log); diff --git a/accessories/switchRepeat.js b/accessories/switchRepeat.js index c028764d..c640a4e7 100644 --- a/accessories/switchRepeat.js +++ b/accessories/switchRepeat.js @@ -61,7 +61,7 @@ class SwitchRepeatAccessory extends SwitchAccessory { const { data, log, name, config, serviceManagerType } = this; setTimeout(() => { - log(`\x1b[33m[Warning] \x1b[30m${name}: The "switch-repeat" accessory is now deprecated and shall be removed in the future. Check out the updated "switch" documentation at http://github.com/lprhodes/homebridge-broadlink-rm`); + log(`\x1b[33m[Warning] \x1b[0m${name}: The "switch-repeat" accessory is now deprecated and shall be removed in the future. Check out the updated "switch" documentation at http://github.com/lprhodes/homebridge-broadlink-rm`); }, 1600) this.serviceManager = new ServiceManagerTypes[serviceManagerType](name, Service.Switch, this.log); diff --git a/helpers/sendData.js b/helpers/sendData.js index 1cacdf2b..cb3452be 100644 --- a/helpers/sendData.js +++ b/helpers/sendData.js @@ -4,7 +4,7 @@ const { getDevice } = require('./getDevice'); const convertProntoCode = require('./convertProntoCode') module.exports = ({ host, hexData, log, name, debug }) => { - assert(hexData && typeof hexData === 'string', `\x1b[31m[ERROR]: \x1b[30m${name} sendData (HEX value is missing)`); + assert(hexData && typeof hexData === 'string', `\x1b[31m[ERROR]: \x1b[0m${name} sendData (HEX value is missing)`); // Check for pronto code if (hexData.substring(0, 4) === '0000') { @@ -12,7 +12,7 @@ module.exports = ({ host, hexData, log, name, debug }) => { hexData = convertProntoCode(hexData) if (debug) log(`${name} sendHex (Pronto code successfuly converted: "${hexData}")`); - if (!hexData) return log(`\x1b[31m[ERROR] \x1b[30m${name} sendData (A Pronto code was detected however its conversion to a Broadlink code failed.)`); + if (!hexData) return log(`\x1b[31m[ERROR] \x1b[0m${name} sendData (A Pronto code was detected however its conversion to a Broadlink code failed.)`); } @@ -20,13 +20,13 @@ module.exports = ({ host, hexData, log, name, debug }) => { const device = getDevice({ host, log }); if (!device) { - if (!host) return log(`\x1b[31m[ERROR] \x1b[30m${name} sendData (no auto-discovered device found and no "host" option set)`); + if (!host) return log(`\x1b[31m[ERROR] \x1b[0m${name} sendData (no auto-discovered device found and no "host" option set)`); - return log(`\x1b[31m[ERROR] \x1b[30m${name} sendData (no device found at ${host})`); + return log(`\x1b[31m[ERROR] \x1b[0m${name} sendData (no device found at ${host})`); } - if (!device.sendData) return log(`\x1b[31m[ERROR] \x1b[30mThe device at ${device.host.address} (${device.host.macAddress}) doesn't support the sending of IR or RF codes.`); - if (hexData.includes('5aa5aa555')) return log('\x1b[31m[ERROR] \x1b[30mThis type of hex code (5aa5aa555...) is no longer valid. Use the included "Learn Code" accessory to find new (decrypted) codes.'); + if (!device.sendData) return log(`\x1b[31m[ERROR] \x1b[0mThe device at ${device.host.address} (${device.host.macAddress}) doesn't support the sending of IR or RF codes.`); + if (hexData.includes('5aa5aa555')) return log('\x1b[31m[ERROR] \x1b[0mThis type of hex code (5aa5aa555...) is no longer valid. Use the included "Learn Code" accessory to find new (decrypted) codes.'); const hexDataBuffer = new Buffer(hexData, 'hex'); device.sendData(hexDataBuffer, debug, hexData);