print_html() table align

ckb

Minion
Staff member
I am trying to create a script with some pretty output, using a table and print_html(). However, I am having trouble getting the cell data aligned to anything other than center.
Is there something I am missing here? The CLI output is always centered.

Code:
void main() {

	string hmi = "<table align=left border=0 cellpadding=0 cellspacing=1 width=300>";

	hmi += "<tr><td colspan=2 align=center bgcolor=silver><b>Top Header</b></td></tr>";
	hmi += "<tr><td width=275 align=left>Item number one</td><td align=center><b><font color=red>55</font></b></td></tr>";
	hmi += "<tr><td width=275 align=left>Item letter B</td><td align=center><b>11</b></td></tr>";
	hmi += "</table>";
	print_html(hmi);

}

gives this: table1.JPG
 

Darzil

Developer
My gut feeling is to use div or span markup with inline CSS, as support for old html standards is slipping (and don't get me started on that).
 

ckb

Minion
Staff member
I had high hopes of the span+css, but replacing the align=left with <span style=\"text-align:left;\"> did not solve the problem.

Code:
hmi += "<tr><td width=275><span style=\"text-align:left;\">Item number one</span></td><td align=center><b><font color=red>55</font></b></td></tr>";
 

Veracity

Developer
Staff member
Since you are interfacing with Java's internal HTML renderer, not a Browser, I would not have high hopes for it supporting "newer" HTML standards. Or even older ones, as you have discovered.

Actually, there is something else going on. If you look at CalendarFrame.java, that creates a table - complete with "align" directives in "td" tags - and uses it to set the text in a UI control. That works.

print_html calls to RequestLogger.print_line which appends the HTML text to KoLConstants.commandBuffer, which is a "StyledChatBuffer" which is a "ChatBuffer".

That class is in lib/net/java/dev/spellcast/utilities/ChatBuffer.java and does a bunch of processing on HTML text. Perhaps it is screwing it up...

Edit: I stuck in logging. It is not screwing up the HTML. But whatever is rendering it in the gCLI doesn't seem to be doing a good job with the align directives, as you note.
 
Last edited:

Bale

Minion
I struggled with a pretty table for output in the CLI once. I found that sometimes it would left align if I told it to do so. Most of the time it would not. After failing to find a pattern that I could report as a bug — I really did try — I finally decided it didn't really matter at all and simply accepted center alignment.
 

ckb

Minion
Staff member
In some other weirdness, I changed something trivial, ran it again, and it was left aligned! And I thought my problems were solved...
Then I ran it again, and it was back to centered.
I guess I will just live with what I get... or make it a relay page.
 

Bale

Minion
In some other weirdness, I changed something trivial, ran it again, and it was left aligned! And I thought my problems were solved...
Then I ran it again, and it was back to centered.

Yup! I've totally been there. That's what I was just talking about in my last post. I completely couldn't replicate it. I tried using "cls" before each execution and it was still inconsistent.
 

ckb

Minion
Staff member
Also, I just made a few adjustment to a related script, with the same code in a few different locations, using multiple print_html() lines.
This printed 7 tables... 3 were left aligned, 4 were center aligned... in the same script! WTF?
I am officially giving up, but that feels ok, especially if it even baffles Bale.
 

Bale

Minion
I'm glad my own puzzlement helps you.

Since it behaves differently when I use cls before execution I didn't think I could possibly come up with a solution. Oddly, the left align happened most frequently immediately after I made a change to the table's layout, but that surely was a coincidence?
 

ckb

Minion
Staff member
Weird... I found nearly the same thing. I made a trivial change (in the width callout) and it was left aligned! Then I ran it again, and it was centered. Maybe it is dependent on the millisecond of the time of day of the month before yesterday?
 
Top