From a8d5e8477982ace10a8e0047f0244aeab605439d Mon Sep 17 00:00:00 2001 From: Bryan Ashby Date: Mon, 15 Jan 2018 16:08:35 -0700 Subject: [PATCH] * Fix justification 'right' vs 'left': They were flipped (durp!). Right aligned is now really that, etc. You may need to update your theme.hjson/similar! --- art/themes/luciano_blocktronics/theme.hjson | 14 ++++++------ core/string_format.js | 6 +++--- core/string_util.js | 24 ++++++++++----------- core/text_view.js | 2 +- core/vertical_menu_view.js | 2 +- 5 files changed, 23 insertions(+), 25 deletions(-) diff --git a/art/themes/luciano_blocktronics/theme.hjson b/art/themes/luciano_blocktronics/theme.hjson index 19f63194..433f8884 100644 --- a/art/themes/luciano_blocktronics/theme.hjson +++ b/art/themes/luciano_blocktronics/theme.hjson @@ -722,15 +722,15 @@ } SM4: { width: 14 - justify: right + justify: left } SM5: { width: 14 - justify: right + justify: left } SM6: { width: 14 - justify: right + justify: left } BT7: { focusTextStyle: first lower @@ -748,15 +748,15 @@ } SM3: { width: 14 - justify: right + justify: left } SM4: { width: 14 - justify: right + justify: left } SM5: { width: 14 - justify: right + justify: left } ET6: { width: 26 @@ -826,7 +826,7 @@ mci: { SM1: { width: 14 - justify: right + justify: left focusTextStyle: first lower } diff --git a/core/string_format.js b/core/string_format.js index eba715d5..38c2047f 100644 --- a/core/string_format.js +++ b/core/string_format.js @@ -122,10 +122,10 @@ function quote(s) { function getPadAlign(align) { return { - '<' : 'right', - '>' : 'left', + '<' : 'left', + '>' : 'right', '^' : 'center', - }[align] || '<'; + }[align] || '>'; } function formatString(value, tokens) { diff --git a/core/string_util.js b/core/string_util.js index a4544754..c846fc38 100644 --- a/core/string_util.js +++ b/core/string_util.js @@ -135,23 +135,21 @@ function stylizeString(s, style) { return s; } -// Based on http://www.webtoolkit.info/ -// :TODO: Look into lodash padLeft, padRight, etc. -function pad(s, len, padChar, dir, stringSGR, padSGR, useRenderLen) { - len = miscUtil.valueWithDefault(len, 0); - padChar = miscUtil.valueWithDefault(padChar, ' '); - dir = miscUtil.valueWithDefault(dir, 'right'); - stringSGR = miscUtil.valueWithDefault(stringSGR, ''); - padSGR = miscUtil.valueWithDefault(padSGR, ''); - useRenderLen = miscUtil.valueWithDefault(useRenderLen, true); +function pad(s, len, padChar, justify, stringSGR, padSGR, useRenderLen) { + len = len || 0; + padChar = padChar || ' '; + justify = justify || 'left'; + stringSGR = stringSGR || ''; + padSGR = padSGR || ''; + useRenderLen = _.isUndefined(useRenderLen) ? true : useRenderLen; const renderLen = useRenderLen ? renderStringLength(s) : s.length; const padlen = len >= renderLen ? len - renderLen : 0; - switch(dir) { + switch(justify) { case 'L' : case 'left' : - s = padSGR + new Array(padlen).join(padChar) + stringSGR + s; + s = `${stringSGR}${s}${padSGR}${Array(padlen).join(padChar)}`; break; case 'C' : @@ -160,13 +158,13 @@ function pad(s, len, padChar, dir, stringSGR, padSGR, useRenderLen) { { const right = Math.ceil(padlen / 2); const left = padlen - right; - s = padSGR + new Array(left + 1).join(padChar) + stringSGR + s + padSGR + new Array(right + 1).join(padChar); + s = `${padSGR}${Array(left + 1).join(padChar)}${stringSGR}${s}${padSGR}${Array(right + 1).join(padChar)}`; } break; case 'R' : case 'right' : - s = stringSGR + s + padSGR + new Array(padlen).join(padChar); + s = `${padSGR}${Array(padlen).join(padChar)}${stringSGR}${s}`; break; default : break; diff --git a/core/text_view.js b/core/text_view.js index 8bd38213..ea9c352a 100644 --- a/core/text_view.js +++ b/core/text_view.js @@ -32,7 +32,7 @@ function TextView(options) { } this.fillChar = miscUtil.valueWithDefault(options.fillChar, ' ').substr(0, 1); - this.justify = options.justify || 'right'; + this.justify = options.justify || 'left'; this.resizable = miscUtil.valueWithDefault(options.resizable, true); this.horizScroll = miscUtil.valueWithDefault(options.horizScroll, true); diff --git a/core/vertical_menu_view.js b/core/vertical_menu_view.js index 847b9407..9fe4cc7d 100644 --- a/core/vertical_menu_view.js +++ b/core/vertical_menu_view.js @@ -14,7 +14,7 @@ exports.VerticalMenuView = VerticalMenuView; function VerticalMenuView(options) { options.cursor = options.cursor || 'hide'; - options.justify = options.justify || 'right'; // :TODO: default to center + options.justify = options.justify || 'left'; MenuView.call(this, options);