Skip to content
Snippets Groups Projects
Commit f3bc6d70 authored by Rob Swindell's avatar Rob Swindell :speech_balloon:
Browse files

Auto-detect the screen width when the width option isn't specified

This fixes the center/right justification options for terminals not exactly
80 columns in width.
parent 2f71e82a
No related branches found
No related tags found
No related merge requests found
...@@ -129,7 +129,7 @@ function loadfont(fn_arg) { ...@@ -129,7 +129,7 @@ function loadfont(fn_arg) {
if (this.opt && opt.info) { if (this.opt && opt.info) {
writeln("index: " + opt.index); writeln("index: " + opt.index);
writeln("font: " + font.name); writeln("font: " + font.name);
writeln("char list: "); write("char list: ");
} }
// Determine overall font height and validate glyph addresses // Determine overall font height and validate glyph addresses
...@@ -380,11 +380,19 @@ function output(str, font) { ...@@ -380,11 +380,19 @@ function output(str, font) {
} }
} }
var width = this.opt && opt.width;
if (!width) {
if (js.global.console) // Auto-detect screen width, when possible
width = console.screen_columns;
else
width = DEFAULT_WIDTH;
}
// Calculate padding for justification // Calculate padding for justification
if (this.opt && opt.justify === CENTER_JUSTIFY) { if (this.opt && opt.justify === CENTER_JUSTIFY) {
padding = Math.floor((opt.width - linewidth) / 2); padding = Math.floor((width - linewidth) / 2);
} else if (this.opt && opt.justify === RIGHT_JUSTIFY) { } else if (this.opt && opt.justify === RIGHT_JUSTIFY) {
padding = opt.width - linewidth; padding = width - linewidth;
} }
// Ensure padding is not negative // Ensure padding is not negative
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment