termlib.js home | multiple terminals | parser | faq | documentation | samples

frequently asked questions

 
 
Can I add chrome to the terminal? (e.g. a window header, a close box)

Not by the means of the Terminal object's interface (since there are way too many things that you may possibly want to add).
The Terminal object allows you to specify the background color, the frame color, the frame's width and the font class used. If you want to add more chrome, you must align this in a separate division element.

To calculate the dimensions of the terminal use this formula:

width:  2 * frameWidth + conf.cols * <width of  > + 2 * 2px padding (left and right)
height: 2 * frameWidth + conf.rows * conf.rowHeight + 2 * 2px padding (top and bottom).

Or you could get the empirical values for width and height by calling a terminal's `getDimensions()' method, once the terminal is open. (see documentation in "readme.txt").

Finnally, you could obviously embed the terminal's division element in your custom chrome layout (see below). [This will not be compatible to Netscape 4.]

p.e.:
  <div id="myTerminal1" style="position:absolute; top:100px; left:100px;">
     <table class="termChrome">
     	<tbody>
        <tr>
           <td class="termTitle">terminal 1</td>
        </tr>
        <tr>
           <td class="termBody"><div id="termDiv1" style="position:relative"></div></td>
        </tr>
     	</tbody>
     </table>
   </div>

   // get a terminal for this

   var term1 = new Terminal(
                 {
                   x: 0,
                   y: 0,
                   id: 1,
                   termDiv: "termDiv1",
                   handler: myTermHandler
                 }
              );
   term1.open();
   
   // and this is how to move the chrome and the embedded terminal

   TermGlobals.setElementXY( "myTerminal1", 200, 80 );
To keep track of the instance for any widgets use the terminal's `id' property. (You must set this in the configuration object to a unique value for this purpose.)

For a demonstration see the Chrome Sample Page.
 
How can I embed a terminal relative to my HTML layout?

Define your devision element with attribute "position" set to "relative" and place this inside your layout. Call "new Terminal()" with config-values { x: 0, y: 0 } to leave it at its relative origin.
 
I pasted your sample code and just got an error. - ???

The short examples are kept arbitrarily simple to show the syntax.
Make sure that your divison element(s) is/are rendered by the browser before `Terminal.open()' is called.

Does not work:
  <head>
  <script>
    var term = new Terminal();
    term.open();
  </script>
  </head>
Does work:
  <head>
  <script>
    var term;
    
    function termOpen() {
       // to be called from outside after compile time
       term = new Terminal();
       term.open();
    }
  </script>
  </head>
c.f. "readme.txt"
(Opening a terminal by clicking a link implies also that the page has currently focus.)

With v.1.01 and higher this doesn't cause an error any more.
`Terminal.prototype.open()' now returns a value for success.
 
I can't get any input, but I don't get any erros too.

The Terminal object's functionality relies on the browsers ability to generate and handle keyboard events.
Sadly some browsers lack a full implementation of the event model. (e.g. Konquerer [khtml] and early versions of Apple Safari, which is a descendant of khtml.)
 
How can I temporary disable the keyboard handlers?
(The terminal is blocking my HTML form fields, etc.)

With version 1.03 there's a global property `TermGlobals.keylock'. Set this to `true' to disable the keyboard handlers without altering any other state. Reset it to `false' to continue with your terminal session(s).
 
How can I set the cusor to the start / the end of the command line?

In case you need to implement a shortcut (like ^A of some UN*X-shells) to jump to the beginning or the end of the current input line, there are two private instance methods you could utilize:

`_getLineEnd(<row>, <col>)' returns an array [<row>, <col>] with the position of the last character in the logical input line with ASCII value >= 32 (0x20).

`_getLineStart(<row>, <col>)' returns an array [<row>, <col>] with the position of the first character in the logical input line with ASCII value >= 32 (0x20).

Both take a row and a column of a cursor position as arguments.

p.e.:
  // jump to the start of the input line

  myCtrlHandler() {
     // catch ^A and jump to start of the line
     if (this.inputChar == 1) {
        var firstChar = this._getLineStart(this.r, this.c);
        this.cursorSet(firstChar[0], firstChar[1]);
     }
  }
(Keep in mind that this is not exactly a good example, since some browser actually don't issue a keyboard event for "^A". And other browsers, which do catch such codes, are not very reliable in that.)
 
How can I limit the command history to unique entries only?
(My application effords commands to be commonly repeated.)

With version 1.05 there is a new configuration and control flag `historyUnique'. All you need is setting this to `true' in your terminal's configuration object.
 
How can I change my color theme on the fly?

With version 1.07 there is a new method `Terminal.rebuild()'.
This method updates the GUI to current config settings while preserving all other state.

p.e.:
   // change color settings on the fly
   // here: set bgColor to white and font style to class "termWhite"
   // method rebuild() updates the GUI without side effects
   // assume var term holds a referene to a Terminal object already active

   term.conf.bgColor = '#ffffff';
   term.conf.fontClass = 'termWhite';
   term.rebuild();
 
How can I import text to terminal instance?

Have a look at the Text Import Sample Page.

This page features three different methods for the import of single line and multiline text.
 
Is there support for color?

Starting with version 1.2 there is built in support for color styles aside from the configureable front and background colors.

For details have a look at the Color Sample Page.
 
Is there any support for text wrapping?

Starting with version 1.3 there is built in support for automatic text wrapping with the write() method.

You may enabel text wrapping using the instance method wrapOn() and disable wrapping using the instance method wrapOff(). Wrapping is off by default.
You may also set the property "wrapping" of the configuration object to true at start up to turn wrapping globally on. Or change the value of the boolean flag "wrapping" at run time.

"termlib.js" even supports conditional/soft word breaks: Use the <form feed>-character ("\f" == ASCII 12) for a conditional word break.

Wrapping behaviors are configured on a per-character basis in TermGlobals.wrapChars.

Have a look at the Text Wrap Sample Page.
 
Isn't there any way to use bold output or any other custom styles?

Starting with version 1.4 there is built in support for custom styles and markup.

Have a look at the Style Settings Sample Page for an example using a custom "b" style for bold.
 
How can I connect to a server? (AJAX Handling)

"termlib.js" comes with tightly integrated functionallity for client-server remote communication tasks via XMLHttpRequests (commonly known as AJAX or JSON).

All you have to do, is call the send( <options> ) method and return.
The request (might it succeed or fail) will come back to your callback-handler with your Terminal instance set as the this object.

example:
  // assume we are inside a handler
  // ("this" refers to an instance of Terminal)
  
  this.send(
    {
      url:      "my_service.cgi",
      method:   "post",
      data:     myDataObject,
      callback: mySocketCallback
    }
  );
  return;
  
  function mySocketCallback() {
    if (this.socket.succes) {
       // status 200 OK
       this.write("Server said:\n" + this.socket.responseText);
    }
    else if (this.socket.errno) {
       // connection failed
       this.write("Connection error: " + this.socket.errstring);
    }
    else {
       // connection succeeded, but server returned other status than 2xx
       this.write("Server returned: " +
                  this.socket.status + " " + this.socket.statusText);
    }
    this.prompt()
  }
Have a look at the Socket Sample Page for detailed information.

You may consider to enable the optional ANSI-mapping to desplay texts formated using ANSI-escape sequences.


For better understanding, here is the basic layout of a generic XMLHttpRequest and its handling:
  function connectToHost(url) {
     // create a request object
     if (window.XMLHttpRequest) {
        // create a standard XMLHttpRequest
        request = new XMLHttpRequest();
     }
     else if (window.ActiveXObject) {
         // XMLHttpRequest not supported, try Active X
         request = new ActiveXObject('Microsoft.XMLHTTP');
     }
     if (request) {
         request.onreadystatechange = requestChangeHandler;
         request.open('GET', url);
         request.send('');
     }
     else {
        // XMLHttpRequest not implemented
     }
  }
  
  function requestChangeHandler() {
     if (request.readyState == 4) {
        // readyState 4: complete; now test for server's response status
        if (request.status == 200) {
           // response in request.responseText or request.responseXML if XML-code
           // if it's JS-code we could get this by eval(request.responseText)
           // by this we could import whole functions to be used via the terminal
        }
        else {
           // connection error
           // status code and message in request.status and request.statusText
        }
     }
  }
The details of the communication can be controlled by the following methods of the XMLHttpRequest object:

setRequestHeader("headerLabel", "value")set a HTTP header to be sent to the server
getResponseHeader("headerLabel")get a HTTP header sent from the server
open(method, "url" [, asyncFlag [,
  "userid" [, "password"]]])
assign the destination properties to the request.
be aware that userid and password are not encrypted!
send(content)transmit a message body (post-string or DOM object)
abort()use this to stop a pending connection
 
Are there any real world examples of termlib.js at work?

Have a look at these pages:
 
Norbert Landsteiner
http://www.masswerk.at
 
> top of page