3 <TITLE>mass:werk termlib faq</TITLE>
5 <STYLE TYPE="text/css">
7 font-family: courier,fixed,swiss,sans-serif;
18 font-family: courier,fixed,swiss,sans-serif;
24 font-family: courier,fixed,swiss,sans-serif;
30 font-family: courier,fixed,swiss,sans-serif;
35 font-family: courier,fixed,swiss,sans-serif;
41 text-decoration: none;
45 text-decoration: underline;
49 text-decoration: underline;
54 body { background-color: #ffffff; }
56 font-family: courier,fixed,swiss,sans-serif;
67 font-family: courier,fixed,swiss,sans-serif;
73 font-family: courier,fixed,swiss,sans-serif;
78 font-family: courier,fixed,swiss,sans-serif;
84 text-decoration: none;
88 text-decoration: underline;
92 text-decoration: underline;
100 <BODY BGCOLOR="#222222" LINK="#77dd11" TEXT="#cccccc" ALINK="#dddddd" VLINK="#77dd11"
101 TOPMARGIN="0" BOTTOMMARGIN="0" LEFTMARGIN="0" RIGHTMARGIN="0" MARGINHEIGHT="0" MARGINWIDTH="0"><A NAME="top"></A>
103 <TABLE BORDER="0" CELLSPACING="20" CELLPADDING="0" ALIGN="center">
105 <TD NOWRAP><A HREF="index.html">termlib.js home</A></TD>
107 <TD NOWRAP><A HREF="multiterm_test.html">multiple terminal test</A></TD>
109 <TD NOWRAP><A HREF="parser_sample.html">sample parser</A></TD>
113 <TD NOWRAP><A HREF="readme.txt" TITLE="readme.txt (text/plain)">documentation</A></TD>
117 <TABLE BORDER="0" CELLSPACING="20" CELLPADDING="0" WIDTH="700" ALIGN="center">
119 <H1>frequently asked questions</H1>
121 <TR><TD CLASS="lh13">
124 <LI CLASS="lh15"><A HREF="#chrome">Can I add chrome to the terminal? (e.g. a window header, a close box)</A></LI>
125 <LI CLASS="lh15"><A HREF="#embed">How can I embed a terminal relative to my HTML layout?</A></LI>
126 <LI CLASS="lh15"><A HREF="#syntax">I pasted your sample code and just got an error. - ???</A></LI>
127 <LI CLASS="lh15"><A HREF="#keyboard">I can't get any input, but I don't get any erros too.</A></LI>
128 <LI CLASS="lh15"><A HREF="#keylock">How can I temporary disable the keyboard handlers?</A></LI>
129 <LI CLASS="lh15"><A HREF="#linesranges">How can I set the cusor to the start / the end of the command line?</A></LI>
130 <LI CLASS="lh15"><A HREF="#historyunique">How can I limit the command history to unique entries only?</A></LI>
131 <LI CLASS="lh15"><A HREF="#rebuild">How can I change my color theme on the fly?</A></LI>
132 <LI CLASS="lh15"><A HREF="#connect">How can I connect to a server?</A></LI>
135 <TR><TD CLASS="lh13"><A NAME="chrome"></A>
137 <B CLASS="quest">Can I add chrome to the terminal? (e.g. a window header, a close box)</B><BR><BR>
139 Not by the means of the Terminal object's interface (since there are way too many things that you may possibly want to add).<BR>
140 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.<BR><BR>
142 To calculate the dimensions of the terminal use this formula:<BR><BR>
144 width: 2 * frameWidth + conf.cols * <width of > + 2 * 2px padding (left and right)<BR>
145 height: 2 * frameWidth + conf.rows * conf.rowHeight + 2 * 2px padding (top and bottom).<BR><BR>
147 Or you could get the empirical values for width and height by calling a terminal's `<SPAN CLASS="prop">getDimensions()</SPAN>' method, once the terminal is open. (see documentation in "readme.txt").<BR><BR>
149 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.]<BR><BR>
152 <div id="myTerminal1" style="position:absolute; top:100px; left:100px;">
153 <table class="termChrome">
156 <td class="termTitle">terminal 1</td>
159 <td class="termBody"><div id="termDiv1" style="position:relative"></div></td>
165 // get a terminal for this
167 var term1 = new Terminal(
172 termDiv: "termDiv1",
173 handler: myTermHandler
178 // and this is how to move the chrome and the embedded terminal
180 TermGlobals.setElementXY( "myTerminal1", 200, 80 );
182 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.)<BR><BR>
184 For a demonstration see the <A HREF="chrome_sample.html">Chrome Sample Page</A>.
186 <TR><TD CLASS="lh13"><A NAME="embed"></A>
188 <B CLASS="quest">How can I embed a terminal relative to my HTML layout?</B><BR><BR>
190 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.
192 <TR><TD CLASS="lh13"><A NAME="syntax"></A>
194 <B CLASS="quest">I pasted your sample code and just got an error. - ???</B><BR><BR>
196 The short examples are kept arbitrarily simple to show the syntax.<BR>
197 Make sure that your divison element(s) is/are rendered by the browser before `Terminal.open()' is called.<BR><BR>
202 var term = new Terminal();
212 function termOpen() {
213 // to be called from outside after compile time
214 term = new Terminal();
220 c.f. "readme.txt"<BR>
221 (Opening a terminal by clicking a link implies also that the page has currently focus.)<BR><BR>
222 With v.1.01 and higher this doesn't cause an error any more.<BR>`Terminal.prototype.open()' now returns a value for success.
224 <TR><TD CLASS="lh13"><A NAME="keyboard"></A>
226 <B CLASS="quest">I can't get any input, but I don't get any erros too.</B><BR><BR>
228 The Terminal object's functionality relies on the browsers ability to generate and handle keyboard events.<BR>
229 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.)
231 <TR><TD CLASS="lh13"><A NAME="keylock"></A>
233 <B CLASS="quest">How can I temporary disable the keyboard handlers?</B><BR>
234 <SPAN CLASS="prop">(The terminal is blocking my HTML form fields, etc.)</SPAN><BR><BR>
236 With version 1.03 there's a global property `<SPAN CLASS="prop">TermGlobals.keylock</SPAN>'. 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).
238 <TR><TD CLASS="lh13"><A NAME="linesranges"></A>
240 <B CLASS="quest">How can I set the cusor to the start / the end of the command line?</B><BR><BR>
242 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:<BR><BR>
243 `<SPAN CLASS="prop">_getLineEnd(<row>, <col>)</SPAN>' returns an array [<row>, <col>] with the position of the last character in the logical input line with ASCII value >= 32 (0x20).<BR><BR>
244 `<SPAN CLASS="prop">_getLineStart(<row>, <col>)</SPAN>' returns an array [<row>, <col>] with the position of the first character in the logical input line with ASCII value >= 32 (0x20).<BR><BR>
245 Both take a row and a column of a cursor position as arguments.<BR><BR>
249 // jump to the start of the input line
252 // catch ^A and jump to start of the line
253 if (this.inputChar == 1) {
254 var firstChar = this._getLineStart(this.r, this.c);
255 this.cursorSet(firstChar[0], firstChar[1]);
258 (Keep in mind that this is not exactly a good example, since some browser actually don't issue a keyboard event for
259 "^A". And other browsers, which do catch such codes, are not very reliable in that.)
261 <TR><TD CLASS="lh13"><A NAME="historyunique"></A>
263 <B CLASS="quest">How can I limit the command history to unique entries only?</B><BR>
264 <SPAN CLASS="prop">(My application effords commands to be commonly repeated.)</SPAN><BR><BR>
266 With version 1.05 there is a new configuration and control flag `<SPAN CLASS="prop">historyUnique</SPAN>'. All you need is setting this to `true' in your terminal's configuration object.
268 <TR><TD CLASS="lh13"><A NAME="rebuild"></A>
270 <B CLASS="quest">How can I change my color theme on the fly?</B><BR><BR>
272 With version 1.07 there is a new method `<SPAN CLASS="prop">Terminal.rebuild()</SPAN>'.<BR>
273 This method updates the GUI to current config settings while preserving all other state.<BR><BR>
276 // change color settings on the fly
277 // here: set bgColor to white and font style to class "termWhite"
278 // method rebuild() updates the GUI without side effects
279 // assume var term holds a referene to a Terminal object already active
281 term.conf.bgColor = '#ffffff';
282 term.conf.fontClass = 'termWhite';
283 term.rebuild();</PRE>
285 <TR><TD CLASS="lh13"><A NAME="connect"></A>
287 <B CLASS="quest">How can I connect to a server?</B><BR><BR>
289 The Terminal object only provides an interface to handle console input and output.<BR>
290 External connections have to be handled outside the Terminal object. You could use the XMLHttpRequest-Object (and use a communication model like AJAX or JSON) or connect via a frame or iframe element to a foreign host.<BR><BR>
291 Handling connections is considered to be out of the realm of the "termlib.js" library.<BR>
292 The code you need is in fact quite simple:
294 function connectToHost(url) {
295 if (window.XMLHttpRequest) {
296 request = new XMLHttpRequest();
298 else if (window.ActiveXObject) {
299 request = new ActiveXObject('Microsoft.XMLHTTP');
302 request.onreadystatechange = requestChangeHandler;
303 request.open('GET', url);
307 // XMLHttpRequest not implemented
311 function requestChangeHandler() {
312 if (request.readyState == 4) {
313 // readyState 4: complete; now test for server's response status
314 if (request.status == 200) {
315 // response in request.responseText or request.responseXML if XML-code
316 // if it's JS-code we could get this by eval(request.responseText)
317 // by this we could import whole functions to be used via the terminal
321 // status code and message in request.status and request.statusText
326 You should use this only together with a timer (window.setTimeout()) to handle connection timeouts.<BR>
327 Additionally you would need some syntax to authenticate and tell the server what you want.<BR>
328 For this purpose you could use the following methods of the XMLHttpRequest object:<BR><BR>
330 <TABLE BORDER="0" CELLSPACING="0" CELLPADDING="3">
331 <TR VALIGN="top"><TD NOWRAP CLASS="prop">setRequestHeader("<I>headerLabel</I>", "<I>value</I>")</TD><TD>set a HTTP header to be sent to the server</TD></TR>
332 <TR VALIGN="top"><TD NOWRAP CLASS="prop">getResponseHeader("<I>headerLabel</I>")</TD><TD>get a HTTP header sent from the server</TD></TR>
333 <TR VALIGN="top"><TD NOWRAP CLASS="prop">open(<I>method</I>, "<I>url</I>" [, <I>asyncFlag</I> [,<BR> "<I>userid</I>" [, "<I>password</I>"]]])</TD><TD>assign the destination properties to the request.<BR>be aware that userid and password are not encrypted!</TD></TR>
334 <TR VALIGN="top"><TD NOWRAP CLASS="prop">send(<I>content</I>)</TD><TD>transmit a message body (post-string or DOM object)</TD></TR>
335 <TR VALIGN="top"><TD NOWRAP CLASS="prop">abort()</TD><TD>use this to stop a pending connection</TD></TR>
339 <TR><TD CLASS="lh13">
341 Norbert Landsteiner - August 2005<BR>
342 <A HREF="http://www.masswerk.at/" TARGET="_blank">http://www.masswerk.at</A>
344 <TR><TD CLASS="lh13">
346 <A HREF="#top">> top of page</A>
348 <TR><TD CLASS="lh13">
353 <DIV ID="termDiv" STYLE="position:absolute; top:20px; left:100px;"></DIV>