Subversion Repositories HomeAutomation

Rev

Rev 1673 | Rev 1681 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed

Rev 1673 Rev 1679
Line -... Line 1...
-
 
1
 
-
 
2
Require
1
 
3
 
2
Console_Functions = {};
4
Console_Functions = {};
3
Console_CurrentFunction = null;
5
Console_CurrentFunction = null;
4
Console_DefaultPrompt = "\033[29;1m[atomic] \033[0m";
6
Console_DefaultPrompt = "\033[29;1m[atomic] \033[0m";
5
Console_LastClientId = null;
7
Console_LastClientId = null;
Line 46... Line 48...
46
 
48
 
47
    var current_function = Console_CurrentFunction;
49
    var current_function = Console_CurrentFunction;
48
    Console_CurrentFunction = Console_Shell;
50
    Console_CurrentFunction = Console_Shell;
49
   
51
   
50
    var result = current_function.apply(null, Array.prototype.slice.call(parts, 0));
52
    var result = current_function.apply(null, Array.prototype.slice.call(parts, 0));
51
   
53
   
52
    if (Console_CurrentFunction == Console_Shell)
54
    if (Console_CurrentFunction == Console_Shell)
53
    {
55
    {
54
        Console_SetDefaultPrompt();
56
        Console_SetDefaultPrompt();
55
    }
57
    }
56
   
58
   
Line 96... Line 98...
96
    Console_CurrentFunction = callback;
98
    Console_CurrentFunction = callback;
97
    return ConsoleExport_PromptRequest(Console_LastClientId, prompt);
99
    return ConsoleExport_PromptRequest(Console_LastClientId, prompt);
98
}
100
}
99
 
101
 
100
function Console_RegisterCommand(command, autocomplete_callback)
102
function Console_RegisterCommand(command, autocomplete_callback)
101
{
103
{
102
    var command_string = command.toString();
104
    var command_string = command.toString();
103
 
105
 
104
    var pos_end = command_string.indexOf("\n") - 1;
106
    var pos_end = command_string.indexOf("\n") - 1;
105
    var pos_start = command_string.indexOf(" ") + 1;
107
    var pos_start = command_string.indexOf(" ") + 1;
106
   
108
   
107
    var full_name = command_string.substr(pos_start, pos_end - pos_start);
109
    var full_name = command_string.substr(pos_start, pos_end - pos_start);
108
   
110
   
109
    var pos_split = full_name.indexOf("(");
111
    var pos_split = full_name.indexOf("(");
110
   
112
   
111
    var name = full_name.substr(0, pos_split);
113
    var name = full_name.substr(0, pos_split);
112
   
114
   
113
    var argument_string = full_name.substr(pos_split + 1);
115
    var argument_string = full_name.substr(pos_split + 1);
114
   
116
   
115
    if (argument_string.length > 0)
117
    if (argument_string.length > 0)
116
    {
118
    {
117
        argument_string = argument_string.replace(/,/g, "");
119
        argument_string = argument_string.replace(/,/g, "");
118
        argument_string = "<" + argument_string.replace(/ /g, "> <") + ">";
120
        argument_string = "<" + argument_string.replace(/ /g, "> <") + ">";
119
    }
121
    }
120
   
122
   
121
    Console_Functions[name] = { "command" : command, "autocomplete" : autocomplete_callback, "help" : argument_string };
123
    Console_Functions[name] = { "command" : command, "autocomplete" : autocomplete_callback, "help" : argument_string };
122
    return true;
124
    return true;
123
}
125
}
124
 
126
 
125
function Console_StandardAutocomplete()
127
function Console_StandardAutocomplete()
126
{
128
{
127
    var arg_index = arguments[0];
129
    var arg_index = arguments[0];
128
    var args = arguments[1];
130
    var args = arguments[1];
129
   
131
   
130
    if (0 <= arg_index && arg_index < arguments.length - 2)
132
    if (0 <= arg_index && arg_index < arguments.length - 2)
131
    {
133
    {
Line 171... Line 173...
171
   
173
   
172
    return result;
174
    return result;
173
}
175
}
174
 
176
 
175
function help(command_name)
177
function help(command_name)
176
{
178
{
177
    if (!command_name)
179
    if (!command_name)
178
    {
180
    {
179
        command_name = "help";
181
        command_name = "help";
180
    }
182
    }
181
   
183
   
182
    if (Console_Functions[command_name] && Console_Functions[command_name]["help"])
184
    if (Console_Functions[command_name] && Console_Functions[command_name]["help"])
183
    {
185
    {
184
        var result = "";
186
        var result = "";
185
 
187
 
186
        if (Console_Functions[command_name] && Console_Functions[command_name]["autocomplete"])
188
        if (Console_Functions[command_name] && Console_Functions[command_name]["autocomplete"])
187
        {
189
        {
188
            result += "Argument autocompletion enabled for " + command_name + "\n";
190
            result += "Argument autocompletion enabled for " + command_name + "\n";
189
        }
191
        }
190
 
192
 
191
        result += "Syntax: " + command_name + " " + Console_Functions[command_name]["help"] + "\n";
193
        result += "Syntax: " + command_name + " " + Console_Functions[command_name]["help"] + "\n";
192
 
194
 
193
        Log(result);
195
        Log(result);
194
        return true;
196
        return true;
195
    }
197
    }
196
 
198
 
197
    Log("\033[31mNo help for " + command_name + " found.\033[0m\n");
199
    Log("\033[31mNo help for " + command_name + " found.\033[0m\n");
198
    return false;
200
    return false;
199
}
201
}
200
Console_RegisterCommand(help, function(arg_index, args) { return Console_StandardAutocomplete(arg_index, args, Console_GetFunctionNames()); });
202
Console_RegisterCommand(help, function(arg_index, args) { return Console_StandardAutocomplete(arg_index, args, Console_GetFunctionNames()); });
201
 
203
 
-
 
204
function version()
-
 
205
{
-
 
206
    Log(SystemExport_Version() + "\n");
-
 
207
    return true;
-
 
208
}
-
 
209
Console_RegisterCommand(version);
-
 
210
 
-
 
211
function license()
-
 
212
{
-
 
213
    Log(SystemExport_License() + "\n");
-
 
214
    return true;
-
 
215
}
-
 
216
Console_RegisterCommand(license);
202
 
217
 
203
function quit()
218
function quit()
204
{
219
{
205
    Log("Goodbye!\n");
220
    Log("Goodbye!\n");
206
   
221