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

« back to all changes in this revision

Viewing changes to console/console.js

  • Committer: drtomc
  • Date: 2008-01-30 21:05:02 UTC
  • Revision ID: svn-v3-trunk0:2b9c9e99-6f39-0410-b283-7f802c844ae2:trunk:337
Make trampoline use the path canonicalization code.
Add a makefile. This is only half a solution to the build issue, but it's
a start.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
var magic;
2
 
 
3
 
function make_query_string(pagename, args)
4
 
{
5
 
    var first = true;
6
 
    var qs = pagename;
7
 
    for (key in obj)
8
 
    {
9
 
        vals = obj[key];
 
1
var magic = 'xyzzy';
 
2
 
 
3
function historyUp()
 
4
{
 
5
    if (this.cursor >= 0)
 
6
    {
 
7
        this.cursor--;
 
8
    }
 
9
}
 
10
 
 
11
function historyDown()
 
12
{
 
13
    if (this.cursor < this.items.length)
 
14
    {
 
15
        this.cursor++;
 
16
    }
 
17
}
 
18
 
 
19
function historyCurr()
 
20
{
 
21
    if (this.cursor < 0 || this.cursor >= this.items.length)
 
22
    {
 
23
        return "";
 
24
    }
 
25
    return this.items[this.cursor];
 
26
}
 
27
 
 
28
function historyAdd(text)
 
29
{
 
30
    this.items[this.items.length] = text;
 
31
    this.cursor = this.items.length;
 
32
}
 
33
 
 
34
function historyShow()
 
35
{
 
36
    var res = "";
 
37
    if (this.cursor == -1)
 
38
    {
 
39
        res += "[]";
 
40
    }
 
41
    for (var i = 0; i < this.items.length; i++)
 
42
    {
 
43
        if (i == this.cursor)
 
44
        {
 
45
            res += "["
 
46
        }
 
47
        res += this.items[i].toString();
 
48
        if (i == this.cursor)
 
49
        {
 
50
            res += "]"
 
51
        }
 
52
        res += " "
 
53
    }
 
54
    if (this.cursor == this.items.length)
 
55
    {
 
56
        res += "[]";
 
57
    }
 
58
    return res;
 
59
}
 
60
 
 
61
function History()
 
62
{
 
63
    this.items = new Array();
 
64
    this.cursor = -1;
 
65
    this.up = historyUp;
 
66
    this.down = historyDown;
 
67
    this.curr = historyCurr;
 
68
    this.add = historyAdd;
 
69
    this.show = historyShow;
 
70
}
 
71
 
 
72
var hist = new History();
 
73
 
 
74
function make_post_body(args)
 
75
{
 
76
    var qs = '';
 
77
    for (key in args)
 
78
    {
 
79
        vals = args[key];
10
80
        // vals can be an array, to make multiple args with the same name
11
81
        // To handle this, make non-array objects into an array, then loop
12
82
        if (!(vals instanceof Array))
13
83
            vals = [vals];
14
 
        for each (val in vals)
 
84
        var i;
 
85
        for (i=0; i<vals.length; i++)
15
86
        {
16
 
            if (true)
17
 
            {
18
 
                qs += "?";
19
 
                first = false;
20
 
            }
21
 
            else
 
87
            if (i > 0)
22
88
            {
23
89
                qs += "&";
24
90
            }
25
 
            qs += encodeURI(key) + "=" + encodeURI(val);
 
91
            qs += encodeURIComponent(key) + "=" + encodeURIComponent(vals[i]);
26
92
        }
27
93
    }
28
94
    return qs;
29
95
}
30
96
 
31
 
function enter_line(inp)
 
97
function enter_line()
32
98
{
33
 
    var digest = hex_md5(inp + magic);
34
 
    var url = make_query_string("chat", {"digest":digest, "text":inp});
35
 
    var xmlhttp = XMLHttpRequest();
36
 
    xmlhttp.open("POST", url, false);
37
 
    xmlhttp.send("")
38
 
    var res = JSON.parse(xmlhttp..responseText);
39
 
    if (res && res[0])
 
99
    var inp = document.getElementById('inputText');
 
100
    var digest = hex_md5(inp.value + magic);
 
101
    var xmlhttp = new XMLHttpRequest();
 
102
    xmlhttp.open("POST", "chat", false);
 
103
    xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
 
104
    xmlhttp.send(make_post_body({"digest":digest, "text":inp.value}))
 
105
    var res = JSON.parse(xmlhttp.responseText);
 
106
    var output = document.getElementById("output");
 
107
    {
 
108
        var pre = document.createElement("pre");
 
109
        pre.setAttribute("class", "inputMsg");
 
110
        pre.appendChild(document.createTextNode(inp.value + "\n"));
 
111
        output.appendChild(pre);
 
112
    }
 
113
    if (res.hasOwnProperty('okay'))
40
114
    {
41
115
        // Success!
42
 
        // print out the output (res[0])
43
 
        // print out the return value (res[1])
 
116
        // print out the output (res.okay[0])
 
117
        var pre = document.createElement("pre");
 
118
        pre.setAttribute("class", "outputMsg");
 
119
        pre.appendChild(document.createTextNode(res.okay[0]));
 
120
        output.appendChild(pre);
 
121
        // print out the return value (res.okay[1])
 
122
        if (res.okay[1])
 
123
        {
 
124
            var pre = document.createElement("pre");
 
125
            pre.setAttribute("class", "outputMsg");
 
126
            pre.appendChild(document.createTextNode(res.okay[1] + "\n"));
 
127
            output.appendChild(pre);
 
128
        }
44
129
        // set the prompt to >>>
 
130
        var prompt = document.getElementById("prompt");
 
131
        prompt.replaceChild(document.createTextNode(">>> "), prompt.firstChild);
45
132
    }
46
 
    else if (res)
 
133
    else if (res.hasOwnProperty('exc'))
47
134
    {
48
135
        // Failure!
49
 
        // print out the error message (res[2])
 
136
        // print out the error message (res.exc)
 
137
        var pre = document.createElement("pre");
 
138
        pre.setAttribute("class", "errorMsg");
 
139
        pre.appendChild(document.createTextNode(res.exc));
 
140
        output.appendChild(pre);
50
141
    }
51
 
    else
 
142
    else if (res.hasOwnProperty('more'))
52
143
    {
53
144
        // Need more input, so set the prompt to ...
 
145
        var prompt = document.getElementById("prompt");
 
146
        prompt.replaceChild(document.createTextNode("... "), prompt.firstChild);
 
147
    }
 
148
    else {
 
149
        // assert res.hasOwnProperty('input')
 
150
        var prompt = document.getElementById("prompt");
 
151
        prompt.replaceChild(document.createTextNode("+++ "), prompt.firstChild);
 
152
    }
 
153
}
 
154
 
 
155
function catch_input(key)
 
156
{
 
157
    var inp = document.getElementById('inputText');
 
158
    if (key == 13)
 
159
    {
 
160
        enter_line();
 
161
        hist.add(inp.value);
 
162
        inp.value = hist.curr();
 
163
    }
 
164
    if (key == 38)
 
165
    {
 
166
        hist.up();
 
167
        inp.value = hist.curr();
 
168
    }
 
169
    if (key == 40)
 
170
    {
 
171
        hist.down();
 
172
        inp.value = hist.curr();
54
173
    }
55
174
}