~azzar1/unity/add-show-desktop-key

« back to all changes in this revision

Viewing changes to console/console.js

  • Committer: drtomc
  • Date: 2008-01-13 20:27:18 UTC
  • Revision ID: svn-v3-trunk0:2b9c9e99-6f39-0410-b283-7f802c844ae2:trunk:212
Gosh, it all looks pretty simple in the end!
TODO: handle exit/^C correctly

Show diffs side-by-side

added added

removed removed

Lines of Context:
131
131
    var inp = document.getElementById('inputText');
132
132
    var digest = hex_md5(inp.value + magic);
133
133
    var xmlhttp = new XMLHttpRequest();
134
 
    alert(inp.value);
135
134
    xmlhttp.open("POST", "chat", false);
136
135
    xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
137
136
    xmlhttp.send(make_post_body({"digest":digest, "text":inp.value}))
143
142
        pre.appendChild(document.createTextNode(inp.value + "\n"));
144
143
        output.appendChild(pre);
145
144
    }
146
 
    if (res && res[0])
 
145
    if (res.hasOwnProperty('okay'))
147
146
    {
148
147
        // Success!
149
 
        // print out the output (res[0])
 
148
        // print out the output (res.okay[0])
150
149
        var pre = document.createElement("pre");
151
150
        pre.setAttribute("class", "outputMsg");
152
 
        pre.appendChild(document.createTextNode(res[0]));
 
151
        pre.appendChild(document.createTextNode(res.okay[0]));
153
152
        output.appendChild(pre);
154
 
        // print out the return value (res[1])
155
 
        if (res[1])
 
153
        // print out the return value (res.okay[1])
 
154
        if (res.okay[1])
156
155
        {
157
156
            var pre = document.createElement("pre");
158
157
            pre.setAttribute("class", "outputMsg");
159
 
            pre.appendChild(document.createTextNode(res[1] + "\n"));
 
158
            pre.appendChild(document.createTextNode(res.okay[1] + "\n"));
160
159
            output.appendChild(pre);
161
160
        }
162
161
        // set the prompt to >>>
163
162
        var prompt = document.getElementById("prompt");
164
163
        prompt.replaceChild(document.createTextNode(">>> "), prompt.firstChild);
165
164
    }
166
 
    else if (res)
 
165
    else if (res.hasOwnProperty('exc'))
167
166
    {
168
167
        // Failure!
169
 
        // print out the error message (res[2])
 
168
        // print out the error message (res.exc)
170
169
        var pre = document.createElement("pre");
171
170
        pre.setAttribute("class", "errorMsg");
172
 
        pre.appendChild(document.createTextNode(res[2]));
 
171
        pre.appendChild(document.createTextNode(res.exc));
173
172
        output.appendChild(pre);
174
173
    }
175
 
    else
 
174
    else if (res.hasOwnProperty('more'))
176
175
    {
177
176
        // Need more input, so set the prompt to ...
178
177
        var prompt = document.getElementById("prompt");
179
178
        prompt.replaceChild(document.createTextNode("... "), prompt.firstChild);
180
179
    }
 
180
    else {
 
181
        // assert res.hasOwnProperty('input')
 
182
        var prompt = document.getElementById("prompt");
 
183
        prompt.replaceChild(document.createTextNode("+++ "), prompt.firstChild);
 
184
    }
181
185
}
182
186
 
183
187
function catch_input(key)