]> gitweb.factorcode.org Git - factor.git/blob - extra/webapps/fjsc/www/termlib/faq.html
5adb516b0759a00993700868ff7f7501407daafb
[factor.git] / extra / webapps / fjsc / www / termlib / faq.html
1 <HTML>\r
2 <HEAD>\r
3         <TITLE>mass:werk termlib faq</TITLE>\r
4 \r
5 <STYLE TYPE="text/css">\r
6 body,p,a,td {\r
7         font-family: courier,fixed,swiss,sans-serif;\r
8         font-size: 12px;\r
9         color: #cccccc;\r
10 }\r
11 .lh13 {\r
12         line-height: 13px;\r
13 }\r
14 .lh15 {\r
15         line-height: 15px;\r
16 }\r
17 pre {\r
18         font-family: courier,fixed,swiss,sans-serif;\r
19         color: #ccffaa;\r
20         font-size: 12px;\r
21         line-height: 15px;\r
22 }\r
23 .prop {\r
24         font-family: courier,fixed,swiss,sans-serif;\r
25         color: #bbee99;\r
26         font-size: 12px;\r
27         line-height: 15px;\r
28 }\r
29 h1 {\r
30         font-family: courier,fixed,swiss,sans-serif;\r
31         font-size: 16px;\r
32         color: #cccccc;\r
33 }\r
34 b.quest {\r
35         font-family: courier,fixed,swiss,sans-serif;\r
36         font-size: 14px;\r
37         font-weight: bold;\r
38         color: #bbee99;\r
39 }\r
40 a,a:link,a:visited {\r
41         text-decoration: none;\r
42         color: #77dd11;\r
43 }\r
44 a:hover {\r
45         text-decoration: underline;\r
46         color: #77dd11;\r
47 }\r
48 a:active {\r
49         text-decoration: underline;\r
50         color: #dddddd;\r
51 }\r
52 \r
53 @media print {\r
54         body { background-color: #ffffff; }\r
55         body,p,a,td {\r
56                 font-family: courier,fixed,swiss,sans-serif;\r
57                 font-size: 12px;\r
58                 color: #000000;\r
59         }\r
60         .lh13 {\r
61                 line-height: 13px;\r
62         }\r
63         .lh15 {\r
64                 line-height: 15px;\r
65         }\r
66         pre,.prop {\r
67                 font-family: courier,fixed,swiss,sans-serif;\r
68                 font-size: 12px;\r
69                 color: #000000;\r
70                 line-height: 15px;\r
71         }\r
72         h1 {\r
73                 font-family: courier,fixed,swiss,sans-serif;\r
74                 font-size: 16px;\r
75                 color: #000000;\r
76         }\r
77         b.quest {\r
78                 font-family: courier,fixed,swiss,sans-serif;\r
79                 font-size: 14px;\r
80                 font-weight: bold;\r
81                 color: #000000;\r
82         }\r
83         a,a:link,a:visited {\r
84                 text-decoration: none;\r
85                 color: #000000;\r
86         }\r
87         a:hover {\r
88                 text-decoration: underline;\r
89                 color: #000000;\r
90         }\r
91         a:active {\r
92                 text-decoration: underline;\r
93                 color: #000000;\r
94         }\r
95 }\r
96 </STYLE>\r
97 </HEAD>\r
98 \r
99 \r
100 <BODY BGCOLOR="#222222" LINK="#77dd11" TEXT="#cccccc" ALINK="#dddddd" VLINK="#77dd11"\r
101 TOPMARGIN="0" BOTTOMMARGIN="0" LEFTMARGIN="0" RIGHTMARGIN="0" MARGINHEIGHT="0" MARGINWIDTH="0"><A NAME="top"></A>\r
102 \r
103 <TABLE BORDER="0" CELLSPACING="20" CELLPADDING="0" ALIGN="center">\r
104 <TR>\r
105         <TD NOWRAP><A HREF="index.html">termlib.js home</A></TD>\r
106         <TD>|</TD>\r
107         <TD NOWRAP><A HREF="multiterm_test.html">multiple terminal test</A></TD>\r
108         <TD>|</TD>\r
109         <TD NOWRAP><A HREF="parser_sample.html">sample parser</A></TD>\r
110         <TD>|</TD>\r
111         <TD NOWRAP>faq</TD>\r
112         <TD>|</TD>\r
113         <TD NOWRAP><A HREF="readme.txt" TITLE="readme.txt (text/plain)">documentation</A></TD>\r
114 </TR>\r
115 </TABLE>\r
116 \r
117 <TABLE BORDER="0" CELLSPACING="20" CELLPADDING="0" WIDTH="700" ALIGN="center">\r
118         <TR><TD>\r
119                 <H1>frequently asked questions</H1>\r
120         </TD></TR>\r
121         <TR><TD CLASS="lh13">\r
122 &nbsp;<BR>\r
123         <UL>\r
124         <LI CLASS="lh15"><A HREF="#chrome">Can I add chrome to the terminal? (e.g. a window header, a close box)</A></LI>\r
125         <LI CLASS="lh15"><A HREF="#embed">How can I embed a terminal relative to my HTML layout?</A></LI>\r
126         <LI CLASS="lh15"><A HREF="#syntax">I pasted your sample code and just got an error. - ???</A></LI>\r
127         <LI CLASS="lh15"><A HREF="#keyboard">I can't get any input, but I don't get any erros too.</A></LI>\r
128         <LI CLASS="lh15"><A HREF="#keylock">How can I temporary disable the keyboard handlers?</A></LI>\r
129         <LI CLASS="lh15"><A HREF="#linesranges">How can I set the cusor to the start / the end of the command line?</A></LI>\r
130         <LI CLASS="lh15"><A HREF="#historyunique">How can I limit the command history to unique entries only?</A></LI>\r
131         <LI CLASS="lh15"><A HREF="#rebuild">How can I change my color theme on the fly?</A></LI>\r
132         <LI CLASS="lh15"><A HREF="#connect">How can I connect to a server?</A></LI>\r
133         </UL>\r
134         </TD></TR>\r
135         <TR><TD CLASS="lh13"><A NAME="chrome"></A>\r
136 &nbsp;<BR>\r
137 <B CLASS="quest">Can I add chrome to the terminal? (e.g. a window header, a close box)</B><BR><BR>\r
138 \r
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>\r
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>\r
141 \r
142 To calculate the dimensions of the terminal use this formula:<BR><BR>\r
143 \r
144 width:&nbsp; 2 * frameWidth + conf.cols * &lt;width of &nbsp;&gt; + 2 * 2px padding (left and right)<BR>\r
145 height: 2 * frameWidth + conf.rows * conf.rowHeight + 2 * 2px padding (top and bottom).<BR><BR>\r
146 \r
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 &quot;readme.txt&quot;).<BR><BR>\r
148 \r
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>\r
150 \r
151 p.e.:<PRE>\r
152   &lt;div id=&quot;myTerminal1&quot; style=&quot;position:absolute; top:100px; left:100px;&quot;&gt;\r
153      &lt;table class=&quot;termChrome&quot;&gt;\r
154         &lt;tbody&gt;\r
155         &lt;tr&gt;\r
156            &lt;td class=&quot;termTitle&quot;&gt;terminal 1&lt;/td&gt;\r
157         &lt;/tr&gt;\r
158         &lt;tr&gt;\r
159            &lt;td class=&quot;termBody&quot;&gt;&lt;div id=&quot;termDiv1&quot; style=&quot;position:relative&quot;&gt;&lt;/div&gt;&lt;/td&gt;\r
160         &lt;/tr&gt;\r
161         &lt;/tbody&gt;\r
162      &lt;/table&gt;\r
163    &lt;/div&gt;\r
164 \r
165    // get a terminal for this\r
166 \r
167    var term1 = new Terminal(\r
168                  {\r
169                    x: 0,\r
170                    y: 0,\r
171                    id: 1,\r
172                    termDiv: &quot;termDiv1&quot;,\r
173                    handler: myTermHandler\r
174                  }\r
175               );\r
176    term1.open();\r
177    \r
178    // and this is how to move the chrome and the embedded terminal\r
179 \r
180    TermGlobals.setElementXY( &quot;myTerminal1&quot;, 200, 80 );\r
181 </PRE>\r
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>\r
183 \r
184 For a demonstration see the <A HREF="chrome_sample.html">Chrome Sample Page</A>.\r
185         </TD></TR>\r
186         <TR><TD CLASS="lh13"><A NAME="embed"></A>\r
187 &nbsp;<BR>\r
188 <B CLASS="quest">How can I embed a terminal relative to my HTML layout?</B><BR><BR>\r
189 \r
190 Define your devision element with attribute &quot;position&quot; set to &quot;relative&quot; and place this inside your layout. Call &quot;new Terminal()&quot; with config-values { x: 0, y: 0 } to leave it at its relative origin.\r
191         </TD></TR>\r
192         <TR><TD CLASS="lh13"><A NAME="syntax"></A>\r
193 &nbsp;<BR>\r
194 <B CLASS="quest">I pasted your sample code and just got an error. - ???</B><BR><BR>\r
195 \r
196 The short examples are kept arbitrarily simple to show the syntax.<BR>\r
197 Make sure that your divison element(s) is/are rendered by the browser before `Terminal.open()' is called.<BR><BR>\r
198 \r
199 Does not work:\r
200 <PRE>  &lt;head&gt;\r
201   &lt;script&gt;\r
202     var term = new Terminal();\r
203     term.open();\r
204   &lt;/script&gt;\r
205   &lt;/head&gt;\r
206 </PRE>\r
207 Does work:\r
208 <PRE>  &lt;head&gt;\r
209   &lt;script&gt;\r
210     var term;\r
211     \r
212     function termOpen() {\r
213        // to be called from outside after compile time\r
214        term = new Terminal();\r
215        term.open();\r
216     }\r
217   &lt;/script&gt;\r
218   &lt;/head&gt;\r
219 </PRE>\r
220 c.f. &quot;readme.txt&quot;<BR>\r
221 (Opening a terminal by clicking a link implies also that the page has currently focus.)<BR><BR>\r
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.\r
223         </TD></TR>\r
224         <TR><TD CLASS="lh13"><A NAME="keyboard"></A>\r
225 &nbsp;<BR>\r
226 <B CLASS="quest">I can't get any input, but I don't get any erros too.</B><BR><BR>\r
227 \r
228 The Terminal object's functionality relies on the browsers ability to generate and handle keyboard events.<BR>\r
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.)\r
230         </TD></TR>\r
231         <TR><TD CLASS="lh13"><A NAME="keylock"></A>\r
232 &nbsp;<BR>\r
233 <B CLASS="quest">How can I temporary disable the keyboard handlers?</B><BR>\r
234 <SPAN CLASS="prop">(The terminal is blocking my HTML form fields, etc.)</SPAN><BR><BR>\r
235 \r
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).\r
237         </TD></TR>\r
238         <TR><TD CLASS="lh13"><A NAME="linesranges"></A>\r
239 &nbsp;<BR>\r
240 <B CLASS="quest">How can I set the cusor to the start / the end of the command line?</B><BR><BR>\r
241 \r
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>\r
243 `<SPAN CLASS="prop">_getLineEnd(&lt;row&gt;, &lt;col&gt;)</SPAN>' returns an array [&lt;row&gt;, &lt;col&gt;] with the position of the last character in the logical input line with ASCII value &gt;= 32 (0x20).<BR><BR>\r
244 `<SPAN CLASS="prop">_getLineStart(&lt;row&gt;, &lt;col&gt;)</SPAN>' returns an array [&lt;row&gt;, &lt;col&gt;] with the position of the first character in the logical input line with ASCII value &gt;= 32 (0x20).<BR><BR>\r
245 Both take a row and a column of a cursor position as arguments.<BR><BR>\r
246 \r
247 p.e.:\r
248 <PRE>\r
249   // jump to the start of the input line\r
250 \r
251   myCtrlHandler() {\r
252      // catch ^A and jump to start of the line\r
253      if (this.inputChar == 1) {\r
254         var firstChar = this._getLineStart(this.r, this.c);\r
255         this.cursorSet(firstChar[0], firstChar[1]);\r
256      }\r
257   }</PRE>\r
258 (Keep in mind that this is not exactly a good example, since some browser actually don't issue a keyboard event for \r
259 &quot;^A&quot;. And other browsers, which do catch such codes, are not very reliable in that.)\r
260         </TD></TR>\r
261         <TR><TD CLASS="lh13"><A NAME="historyunique"></A>\r
262 &nbsp;<BR>\r
263 <B CLASS="quest">How can I limit the command history to unique entries only?</B><BR>\r
264         <SPAN CLASS="prop">(My application effords commands to be commonly repeated.)</SPAN><BR><BR>\r
265 \r
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.\r
267         </TD></TR>\r
268         <TR><TD CLASS="lh13"><A NAME="rebuild"></A>\r
269 &nbsp;<BR>\r
270 <B CLASS="quest">How can I change my color theme on the fly?</B><BR><BR>\r
271 \r
272 With version 1.07 there is a new method `<SPAN CLASS="prop">Terminal.rebuild()</SPAN>'.<BR>\r
273 This method updates the GUI to current config settings while preserving all other state.<BR><BR>\r
274 p.e.:\r
275 <PRE>\r
276    // change color settings on the fly\r
277    // here: set bgColor to white and font style to class &quot;termWhite&quot;\r
278    // method rebuild() updates the GUI without side effects\r
279    // assume var term holds a referene to a Terminal object already active\r
280 \r
281    term.conf.bgColor = '#ffffff';\r
282    term.conf.fontClass = 'termWhite';\r
283    term.rebuild();</PRE>\r
284         </TD></TR>\r
285         <TR><TD CLASS="lh13"><A NAME="connect"></A>\r
286 &nbsp;<BR>\r
287 <B CLASS="quest">How can I connect to a server?</B><BR><BR>\r
288 \r
289 The Terminal object only provides an interface to handle console input and output.<BR>\r
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>\r
291 Handling connections is considered to be out of the realm of the &quot;termlib.js&quot; library.<BR>\r
292 The code you need is in fact quite simple:\r
293 <PRE>\r
294   function connectToHost(url) {\r
295      if (window.XMLHttpRequest) {\r
296         request = new XMLHttpRequest();\r
297      }\r
298      else if (window.ActiveXObject) {\r
299          request = new ActiveXObject('Microsoft.XMLHTTP');\r
300      }\r
301      if (request) {\r
302          request.onreadystatechange = requestChangeHandler;\r
303          request.open('GET', url);\r
304          request.send('');\r
305      }\r
306      else {\r
307         // XMLHttpRequest not implemented\r
308      }\r
309   }\r
310   \r
311   function requestChangeHandler() {\r
312      if (request.readyState == 4) {\r
313         // readyState 4: complete; now test for server's response status\r
314         if (request.status == 200) {\r
315            // response in request.responseText or request.responseXML if XML-code\r
316            // if it's JS-code we could get this by eval(request.responseText)\r
317            // by this we could import whole functions to be used via the terminal\r
318         }\r
319         else {\r
320            // connection error\r
321            // status code and message in request.status and request.statusText\r
322         }\r
323      }\r
324   }\r
325 </PRE>\r
326 You should use this only together with a timer (window.setTimeout()) to handle connection timeouts.<BR>\r
327 Additionally you would need some syntax to authenticate and tell the server what you want.<BR>\r
328 For this purpose you could use the following methods of the XMLHttpRequest object:<BR><BR>\r
329 \r
330         <TABLE BORDER="0" CELLSPACING="0" CELLPADDING="3">\r
331         <TR VALIGN="top"><TD NOWRAP CLASS="prop">setRequestHeader(&quot;<I>headerLabel</I>&quot;, &quot;<I>value</I>&quot;)</TD><TD>set a HTTP header to be sent to the server</TD></TR>\r
332         <TR VALIGN="top"><TD NOWRAP CLASS="prop">getResponseHeader(&quot;<I>headerLabel</I>&quot;)</TD><TD>get a HTTP header sent from the server</TD></TR>\r
333         <TR VALIGN="top"><TD NOWRAP CLASS="prop">open(<I>method</I>, &quot;<I>url</I>&quot; [, <I>asyncFlag</I> [,<BR>&nbsp; &quot;<I>userid</I>&quot; [, &quot;<I>password</I>&quot;]]])</TD><TD>assign the destination properties to the request.<BR>be aware that userid and password are not encrypted!</TD></TR>\r
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>\r
335         <TR VALIGN="top"><TD NOWRAP CLASS="prop">abort()</TD><TD>use this to stop a pending connection</TD></TR>\r
336         </TABLE>\r
337 \r
338         </TD></TR>\r
339         <TR><TD CLASS="lh13">\r
340         &nbsp;<BR>\r
341         Norbert Landsteiner - August 2005<BR>\r
342         <A HREF="http://www.masswerk.at/" TARGET="_blank">http://www.masswerk.at</A>\r
343         </TD></TR>\r
344         <TR><TD CLASS="lh13">\r
345         &nbsp;<BR>\r
346                 <A HREF="#top">&gt; top of page</A>\r
347         </TD></TR>\r
348         <TR><TD CLASS="lh13">\r
349         &nbsp;\r
350         </TD></TR>\r
351 </TABLE>\r
352 \r
353 <DIV ID="termDiv" STYLE="position:absolute; top:20px; left:100px;"></DIV>\r
354 \r
355 </BODY>\r
356 </HTML>