From ea95d414fe453392b9ca6433da97cac32435ba43 Mon Sep 17 00:00:00 2001 From: Christopher Jeffrey Date: Sun, 27 Jan 2013 09:06:31 -0600 Subject: [PATCH] refactor attr. --- lib/program.js | 210 +++++++++++++++++-------------------------------- 1 file changed, 71 insertions(+), 139 deletions(-) diff --git a/lib/program.js b/lib/program.js index 77ffdfb..f170326 100644 --- a/lib/program.js +++ b/lib/program.js @@ -554,173 +554,105 @@ Program.prototype.attr = Program.prototype.charAttributes = function(param, val) { switch (param) { case 'normal': - this.write('\x1b[m'); - break; + return this.write('\x1b[m'); case 'bold': - if (val === false) { - this.write('\x1b[22m'); - } else { - this.write('\x1b[1m'); - } - break; + return val === false + ? this.write('\x1b[22m') + : this.write('\x1b[1m'); case 'underlined': - if (val === false) { - this.write('\x1b[24m'); - } else { - this.write('\x1b[4m'); - } - break; + return val === false + ? this.write('\x1b[24m') + : this.write('\x1b[4m'); case 'blink': - if (val === false) { - this.write('\x1b[25m'); - } else { - this.write('\x1b[5m'); - } - break; + return val === false + ? this.write('\x1b[25m') + : this.write('\x1b[5m'); case 'inverse': - if (val === false) { - this.write('\x1b[27m'); - } else { - this.write('\x1b[7m'); - } + return val === false + ? this.write('\x1b[27m') + : this.write('\x1b[7m'); break; case 'invisible': - if (val === false) { - this.write('\x1b[28m'); - } else { - this.write('\x1b[8m'); - } - break; + return val === false + ? this.write('\x1b[28m') + : this.write('\x1b[8m'); case 'invisible': - if (val === false) { - this.write('\x1b[28m'); - } else { - this.write('\x1b[8m'); - } - break; + return val === false + ? this.write('\x1b[28m') + : this.write('\x1b[8m'); case 'black fg': - if (val === false) { - this.write('\x1b[39m'); - break; - } - this.write('\x1b[30m'); - break; + return val === false + ? this.write('\x1b[39m') + : this.write('\x1b[30m'); case 'red fg': - if (val === false) { - this.write('\x1b[39m'); - break; - } - this.write('\x1b[31m'); - break; + return val === false + ? this.write('\x1b[39m') + : this.write('\x1b[31m'); case 'green fg': - if (val === false) { - this.write('\x1b[39m'); - break; - } - this.write('\x1b[32m'); - break; + return val === false + ? this.write('\x1b[39m') + : this.write('\x1b[32m'); case 'yellow fg': - if (val === false) { - this.write('\x1b[39m'); - break; - } - this.write('\x1b[33m'); - break; + return val === false + ? this.write('\x1b[39m') + : this.write('\x1b[33m'); case 'blue fg': - if (val === false) { - this.write('\x1b[39m'); - break; - } - this.write('\x1b[34m'); - break; + return val === false + ? this.write('\x1b[39m') + : this.write('\x1b[34m'); case 'magenta fg': - if (val === false) { - this.write('\x1b[39m'); - break; - } - this.write('\x1b[35m'); - break; + return val === false + ? this.write('\x1b[39m') + : this.write('\x1b[35m'); case 'cyan fg': - if (val === false) { - this.write('\x1b[39m'); - break; - } - this.write('\x1b[36m'); - break; + return val === false + ? this.write('\x1b[39m') + : this.write('\x1b[36m'); case 'white fg': - if (val === false) { - this.write('\x1b[39m'); - break; - } - this.write('\x1b[37m'); - break; + return val === false + ? this.write('\x1b[39m') + : this.write('\x1b[37m'); case 'default fg': - this.write('\x1b[39m'); - break; + return this.write('\x1b[39m'); case 'black bg': - if (val === false) { - this.write('\x1b[49m'); - break; - } - this.write('\x1b[40m'); - break; + return val === false + ? this.write('\x1b[49m') + : this.write('\x1b[40m'); case 'red bg': - if (val === false) { - this.write('\x1b[49m'); - break; - } - this.write('\x1b[41m'); - break; + return val === false + ? this.write('\x1b[49m') + : this.write('\x1b[41m'); case 'green bg': - if (val === false) { - this.write('\x1b[49m'); - break; - } - this.write('\x1b[42m'); - break; + return val === false + ? this.write('\x1b[49m') + : this.write('\x1b[42m'); case 'yellow bg': - if (val === false) { - this.write('\x1b[49m'); - break; - } - this.write('\x1b[43m'); - break; + return val === false + ? this.write('\x1b[49m') + : this.write('\x1b[43m'); case 'blue bg': - if (val === false) { - this.write('\x1b[49m'); - break; - } - this.write('\x1b[44m'); - break; + return val === false + ? this.write('\x1b[49m') + : this.write('\x1b[44m'); case 'magenta bg': - if (val === false) { - this.write('\x1b[49m'); - break; - } - this.write('\x1b[45m'); - break; + return val === false + ? this.write('\x1b[49m') + : this.write('\x1b[45m'); case 'cyan bg': - if (val === false) { - this.write('\x1b[49m'); - break; - } - this.write('\x1b[46m'); - break; + return val === false + ? this.write('\x1b[49m') + : this.write('\x1b[46m'); case 'white bg': - if (val === false) { - this.write('\x1b[49m'); - break; - } - this.write('\x1b[47m'); - break; + return val === false + ? this.write('\x1b[49m') + : this.write('\x1b[47m'); case 'default bg': - this.write('\x1b[49m'); - break; + return this.write('\x1b[49m'); + default: - this.write('\x1b[' + param + 'm'); - break; + return this.write('\x1b[' + param + 'm'); } };