Subversion Repositories HomeAutomation

Rev

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

Rev 1609 Rev 1610
Line 4... Line 4...
4
Console.autocomplete_callbacks = new Array();
4
Console.autocomplete_callbacks = new Array();
-
 
5
Console.help_text = new Array();
5
 
6
 
6
function Console_DoAutocomplete()
7
function Console_DoAutocomplete()
7
{
8
{
8
    var name = arguments[0];
9
    var name = arguments[0];
9
 
10
 
Line 25... Line 26...
25
    }
26
    }
26
   
27
   
27
    return result_string;
28
    return result_string;
28
}
29
}
29
 
30
 
30
function RegisterConsoleCommand(name, autocomplete_callback)
31
function RegisterConsoleCommand(command, autocomplete_callback)
31
{
32
{
-
 
33
    var command_string = command.toString();
-
 
34
 
-
 
35
    var pos_end = command_string.indexOf("\n") - 1;
-
 
36
    var pos_start = command_string.indexOf(" ") + 1;
-
 
37
   
-
 
38
    var full_name = command_string.substr(pos_start, pos_end - pos_start);
-
 
39
   
-
 
40
    var pos_split = full_name.indexOf("(");
-
 
41
   
-
 
42
    var name = full_name.substr(0, pos_split);
-
 
43
   
-
 
44
    var argument_string = full_name.substr(pos_split + 1);
-
 
45
   
32
    if (Console_RegisterConsoleCommand(name))
46
    if (argument_string.length > 0)
33
    {
47
    {
-
 
48
        argument_string = argument_string.replace(/,/g, "");
-
 
49
        argument_string = "<" + argument_string.replace(/ /g, "> <") + ">";
-
 
50
    }
-
 
51
   
-
 
52
    if (Console_RegisterConsoleCommand(name))
-
 
53
    {
-
 
54
        Console.help_text[name] = argument_string;
-
 
55
       
-
 
56
       
34
        if (autocomplete_callback)
57
        if (autocomplete_callback)
35
        {
58
        {
36
            Console.autocomplete_callbacks[name] = autocomplete_callback;
59
            Console.autocomplete_callbacks[name] = autocomplete_callback;
37
        }
60
        }
38
       
61
       
39
        return true;
62
        return true;
40
    }
63
    }
41
   
64
   
42
    return false;
65
    return false;
-
 
66
}
-
 
67
 
-
 
68
function help_complete(args)
-
 
69
{
-
 
70
    var result = new Array();
-
 
71
   
-
 
72
    var arg_index = args.length - 1;
-
 
73
   
-
 
74
    if (arg_index == 1) // command name
-
 
75
    {
-
 
76
        for (var n in Console.help_text)
-
 
77
        {
-
 
78
            result.push(n);
-
 
79
        }
-
 
80
    }
-
 
81
   
-
 
82
    return result;
-
 
83
}
-
 
84
 
-
 
85
function help(command_name)
-
 
86
{
-
 
87
    if (!command_name)
-
 
88
    {
-
 
89
        command_name = "help";
-
 
90
    }
-
 
91
   
-
 
92
    if (typeof Console.help_text[command_name] != 'undefined')
-
 
93
    {
-
 
94
        var result = "";
-
 
95
       
-
 
96
        if (Console.autocomplete_callbacks[command_name])
-
 
97
        {
-
 
98
            result += "Argument autocompletion enabled for " + command_name + "\n";
-
 
99
        }
-
 
100
       
-
 
101
        result += "Syntax: " + command_name + " " + Console.help_text[command_name] + "\n";
-
 
102
       
-
 
103
        return result;
-
 
104
    }
-
 
105
   
-
 
106
    return "No help for " + command_name + " found\n";
43
}
107
}
-
 
108
RegisterConsoleCommand(help, help_complete);