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

When right justifying and no margin, don't print CRLF (blank lines)

... assume the terminal auto-line-wrapped for us.

Allow a margin (for left or right justification) to be specified in
opt.margin (default: 0).
parent f3bc6d70
No related branches found
No related tags found
No related merge requests found
...@@ -360,7 +360,6 @@ function output(str, font) { ...@@ -360,7 +360,6 @@ function output(str, font) {
var maxheight = font.height; // Use the pre-calculated max height from loadfont var maxheight = font.height; // Use the pre-calculated max height from loadfont
var linewidth = 0; var linewidth = 0;
var len = str.length; var len = str.length;
var padding = 0;
var n = 0; var n = 0;
var out = ""; var out = "";
...@@ -388,16 +387,15 @@ function output(str, font) { ...@@ -388,16 +387,15 @@ function output(str, font) {
width = DEFAULT_WIDTH; width = DEFAULT_WIDTH;
} }
var margin = this.opt && opt.margin ? opt.margin : 0;
var padding = margin;
writeln("Padding: " + padding);
var justify = this.opt ? opt.justify : LEFT_JUSTIFY;
// Calculate padding for justification // Calculate padding for justification
if (this.opt && opt.justify === CENTER_JUSTIFY) { if (justify === CENTER_JUSTIFY) {
padding = Math.floor((width - linewidth) / 2); padding = Math.floor((width - linewidth) / 2);
} else if (this.opt && opt.justify === RIGHT_JUSTIFY) { } else if (justify === RIGHT_JUSTIFY) {
padding = width - linewidth; padding = Math.floor(width - (linewidth + padding));
}
// Ensure padding is not negative
if (padding < 0) {
padding = 0;
} }
// Print each row of the font text // Print each row of the font text
...@@ -435,7 +433,8 @@ function output(str, font) { ...@@ -435,7 +433,8 @@ function output(str, font) {
// End the line and reset color // End the line and reset color
out += reset_color(); out += reset_color();
out += "\r\n"; if(!(justify === RIGHT_JUSTIFY && margin == 0))
out += "\r\n";
} }
return out; return out;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment