diff --git a/example/ping b/example/ping index cc505f4..3defe2c 100755 --- a/example/ping +++ b/example/ping @@ -79,7 +79,11 @@ var score = new blessed.Box({ top: 0, left: 4, height: 3, - width: 20, + width: 26, + border: { + type: 'ascii' + }, + align: 'center', bold: true }); @@ -109,6 +113,7 @@ var text = new blessed.Box({ left: 1, right: 1, height: 1, + align: 'center', content: 'Waiting for players to connect...' }); diff --git a/lib/widget.js b/lib/widget.js index 4127131..13d55e7 100644 --- a/lib/widget.js +++ b/lib/widget.js @@ -1022,16 +1022,17 @@ Box.prototype.render = function(stop) { } if (this.align === 'center' || this.align === 'right') { - var width = this.width - (this.border ? 2 : 0); + //var width = this.width - (this.border ? 2 : 0); + var width = this.width; var ncontent = content.split('\n')[0].replace(/\x1b\[[^m]*m/g, ''); if (ncontent.length < width) { - var s = width - 1 - ncontent.length - 1; + var s = width - ncontent.length; if (this.align === 'center') { //xi_ += s / 2 | 0; - content = Array(s / 2 | 0).join(' ') + content; + content = Array(((s / 2 | 0) - (this.border ? 1 : 0)) + 1).join(' ') + content; } else { //xi_ += s; - content = Array(s).join(' ') + content; + content = Array((s - (this.border ? 2 : 0)) + 1).join(' ') + content; } } } @@ -1208,16 +1209,17 @@ Text.prototype.render = function(stop) { } if (this.align === 'center' || this.align === 'right') { - var width = this.width - (this.border ? 2 : 0); + //var width = this.width - (this.border ? 2 : 0); + var width = this.width; var ncontent = content.split('\n')[0].replace(/\x1b\[[^m]*m/g, ''); if (ncontent.length < width) { - var s = width - 1 - ncontent.length - 1; + var s = width - ncontent.length; if (this.align === 'center') { //xi_ += s / 2 | 0; - content = Array(s / 2 | 0).join(' ') + content; + content = Array(((s / 2 | 0) - (this.border ? 1 : 0)) + 1).join(' ') + content; } else { //xi_ += s; - content = Array(s).join(' ') + content; + content = Array((s - (this.border ? 2 : 0)) + 1).join(' ') + content; } } }