termlib.js home | | | multiple terminals | | | parser | | | faq | | | documentation | | | samples |
|
Introducing Style Settings Version 1.4 of "termlib.js" introduces configurations for styles and associated markup. The method TermGlobals.assignStyle() allows you to install a custom style and associated mark up with a single method call. TermGlobals.assignStyle() takes four arguments:
As an example we will install a style "b" for bold and use style #16 (2^4) for this. TermGlobals.assignStyle( 16, 'b', '<b>', '</b>' );
Now we can use our new style and markup in any write() statement like this: myTerm.write('This is %+bBOLD%-b.'); Now as we have installed our new "bold" style, we see that any bold letters are running wider then any plain text using the same letters. Since we want a well behaved terminal output, we'll have definitely to fix this. We will apply some kerning to provide the extra space required for bold letters. To do this, we'll add a "letter-spacing" definition to our CSS rule ".term" (if it's not already there): .term { font-family: "Courier New",courier,fixed,monospace; font-size: 12px; /* ... any other definitions ... */ letter-spacing: 1px; }
(As we can now see, installing a bold style involves some synchronized CSS and HTML coding. This is also the reason why bold is not in the standard set of termlib.js styles.)
As a second example we'll install a small style "m" ("minature", "s" is already in use for strike) with style code 32 (2^5). This should be rendered with font-size: 10px. TermGlobals.assignStyle( 32, 'm', '<span style="font-size:10px; letter-spacing:2px;">', '</span>' ); As above we can now use this in a write() statement like this: myTerm.write('This is %+mSMALL%-m.');
Finally you could define a style as some kind of makro using the HTMl-parts (3rd and 4th argument) for visible information: TermGlobals.assignStyle( 64, 'e', 'ERROR: ', '!' ); myTerm.write('%+eYou did not enter enter a valid number%-e'); // "ERROR: You did not enter enter a valid number!"
Notes: Unlike any other methods TermGlobals.assignStyle() alerts any errors. (Since these alerts should only occure in development phase, this provides an easy debugging facillity without any notice to application users.) You usually would not want to change style #1 (reverse) since this style is used by the cursor in block mode.
|