write-string and write-char work with streams
[jscl.git] / jscl.html
1 <!doctype html>
2 <html>
3   <head>
4     <style>
5      /* The console container element */
6     body { background-color: black; font-size: 16px; font-family: Courier; overflow: hidden; padding: 0 0 0 0;}
7     #console {
8       position: absolute;
9       top: 0px;
10       bottom: 0px;
11       left: 0px;
12       right: 0px;
13       background-color:black;
14     }
15
16     .parents {
17         font-weight: bold;
18     }
19
20     /* The inner console element. */
21     .jqconsole {
22         padding: 10px;
23     }
24     /* The cursor. */
25     .jqconsole-cursor {
26         background-color: gray;
27     }
28     /* The cursor color when the console looses focus. */
29     .jqconsole-blurred .jqconsole-cursor {
30         background-color: #666;
31     }
32     /* The current prompt text color */
33     .jqconsole-prompt {
34         color: White;
35     }
36     /* The command history */
37     .jqconsole-old-prompt {
38         color: White;
39         font-weight: normal;
40     }
41     /* The text color when in input mode. */
42     .jqconsole-input {
43         color: White;
44     }
45     /* Previously entered input. */
46     .jqconsole-old-input {
47         color: White;
48         font-weight: normal;
49     }
50     /* The text color of the output. */
51     .jqconsole-output {
52         color: green;
53     }
54     .jqconsole-return, .jqconsole-header {
55         color: gray;
56     }
57     .jqconsole-error {
58         color: red;
59     }
60 </style>
61   </head>
62
63   <body>
64     <div id="console"></div>
65     <script src="jscl.js" type="text/javascript"></script>
66     <script src="jquery.js" type="text/javascript" charset="utf-8"></script>
67     <script src="jqconsole.min.js" type="text/javascript" charset="utf-8"></script>
68     <script>
69       var jqconsole;
70       $(function () {
71         jqconsole = $('#console').jqconsole('Welcome to JSCL!\n\n', '');
72         jqconsole.RegisterMatching('(', ')', 'parents');
73         if (localStorage.getItem("jqhist"))
74            jqconsole.SetHistory(JSON.parse(localStorage.getItem("jqhist")));
75       
76         lisp.write = function(str){
77            jqconsole.Write(xstring(str), 'jqconsole-output', false);
78            return str;
79         }
80
81         var startPrompt = function () {
82           // Start the prompt with history enabled.
83           jqconsole.Write(lisp.evalString('(CL:PACKAGE-NAME CL:*PACKAGE*)') + '> ', 'jqconsole-prompt');
84           jqconsole.Prompt(true, function (input) {
85             // Output input with the class jqconsole-return.
86             if (input[0] != ','){
87                 try {
88                     var vs = lisp.evalInput(input);
89                     // for (var i=0; i<vs.length; i++){
90                        jqconsole.Write(lisp.print(vs) + '\n', 'jqconsole-return');
91                        localStorage.setItem("jqhist", JSON.stringify(jqconsole.GetHistory()));
92                     // }
93                 } catch(error) {
94                     var msg = error.message || error || 'Unknown error';
95                     if (typeof(msg) != 'string') msg = xstring(msg);
96                     jqconsole.Write('ERROR: ' + msg + '\n', 'jqconsole-error');
97                 }
98             } else
99                 jqconsole.Write(lisp.compileString(input.slice(1)) + '\n', 'jqconsole-return');
100
101             // Restart the prompt.
102             startPrompt();
103           }, function(input){
104             try {
105                 lisp.read(input[0]==','? input.slice(1): input);
106             } catch(error) {
107                 return 0;
108             }
109             return false;
110           });
111         };
112         startPrompt();
113       });
114     </script>
115   </body>
116 </html>