Rev 1620 | Rev 1647 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed
| Rev 1620 | Rev 1644 | ||
|---|---|---|---|
| Line 1... | Line 1... | ||
| 1 | 1 | ||
| 2 | function Console() { } |
- | |
| 3 | - | ||
| 4 |
|
2 | Console_AutoCompleteFunctions = {}; |
| 5 |
|
3 | Console_HelpTexts = {}; |
| 6 | 4 | ||
| 7 | function Console_DoAutocomplete() |
5 | function Console_DoAutocomplete() |
| 8 | { |
6 | { |
| 9 | var name = arguments[0]; |
7 | var name = arguments[0]; |
| 10 | 8 | ||
| 11 | //Log("Console_DoAutocomplete(), name=" + name); |
9 | //Log("Console_DoAutocomplete(), name=" + name); |
| 12 | 10 | ||
| 13 | var result = |
11 | var result = {}; |
| 14 | 12 | ||
| 15 | if (typeof |
13 | if (typeof Console_AutoCompleteFunctions[name] != 'undefined') |
| 16 | { |
14 | { |
| 17 | //Log("calling autocomplete_callback"); |
15 | //Log("calling autocomplete_callback"); |
| 18 | result = |
16 | result = Console_AutoCompleteFunctions[name](arguments); |
| 19 | } |
17 | } |
| 20 | 18 | ||
| 21 | var result_string = ""; |
19 | var result_string = ""; |
| 22 | 20 | ||
| 23 | for (var n = 0; n < result.length; n++) |
21 | for (var n = 0; n < result.length; n++) |
| 24 | { |
22 | { |
| 25 | result_string += result[n] + "\n"; |
23 | result_string += result[n] + "\n"; |
| 26 | } |
24 | } |
| 27 | 25 | ||
| 28 | return result_string; |
26 | return result_string; |
| 29 | } |
27 | } |
| 30 | 28 | ||
| 31 | function |
29 | function Console_RegisterCommand(command, autocomplete_callback) |
| 32 | { |
30 | { |
| 33 | var command_string = command.toString(); |
31 | var command_string = command.toString(); |
| 34 | 32 | ||
| 35 | var pos_end = command_string.indexOf("\n") - 1; |
33 | var pos_end = command_string.indexOf("\n") - 1; |
| 36 | var pos_start = command_string.indexOf(" ") + 1; |
34 | var pos_start = command_string.indexOf(" ") + 1; |
| Line 40... | Line 38... | ||
| 40 | var pos_split = full_name.indexOf("("); |
38 | var pos_split = full_name.indexOf("("); |
| 41 | 39 | ||
| 42 | var name = full_name.substr(0, pos_split); |
40 | var name = full_name.substr(0, pos_split); |
| 43 | 41 | ||
| 44 | var argument_string = full_name.substr(pos_split + 1); |
42 | var argument_string = full_name.substr(pos_split + 1); |
| 45 | 43 | ||
| 46 | if (argument_string.length > 0) |
44 | if (argument_string.length > 0) |
| 47 | { |
45 | { |
| 48 | argument_string = argument_string.replace(/,/g, ""); |
46 | argument_string = argument_string.replace(/,/g, ""); |
| 49 | argument_string = "<" + argument_string.replace(/ /g, "> <") + ">"; |
47 | argument_string = "<" + argument_string.replace(/ /g, "> <") + ">"; |
| 50 | } |
48 | } |
| 51 | 49 | ||
| 52 | if ( |
50 | if (ConsoleExport_RegisterCommand(name)) |
| 53 | { |
51 | { |
| 54 |
|
52 | Console_HelpTexts[name] = argument_string; |
| 55 | 53 | ||
| 56 | 54 | ||
| 57 | if (autocomplete_callback) |
55 | if (autocomplete_callback) |
| 58 | { |
56 | { |
| 59 |
|
57 | Console_AutoCompleteFunctions[name] = autocomplete_callback; |
| 60 | } |
58 | } |
| 61 | 59 | ||
| 62 | return true; |
60 | return true; |
| 63 | } |
61 | } |
| 64 | 62 | ||
| 65 | return false; |
63 | return false; |
| 66 | } |
64 | } |
| 67 | 65 | ||
| 68 | function |
66 | function Console_StandardAutocomplete() |
| 69 | { |
67 | { |
| 70 | // First argument is the command line split |
68 | // First argument is the command line split |
| 71 | var command_line_parts = arguments[0]; |
69 | var command_line_parts = arguments[0]; |
| 72 | 70 | ||
| 73 | // command_line_parts[0] == command name |
71 | // command_line_parts[0] == command name |
| Line 81... | Line 79... | ||
| 81 | return arguments[arg_index + 1]; |
79 | return arguments[arg_index + 1]; |
| 82 | } |
80 | } |
| 83 | 81 | ||
| 84 | return new Array(); |
82 | return new Array(); |
| 85 | } |
83 | } |
| - | 84 | ||
| - | 85 | ||
| 86 | 86 | ||
| 87 | function help_complete(args) |
87 | function help_complete(args) |
| 88 | { |
88 | { |
| 89 | var result = |
89 | var result = {}; |
| 90 | 90 | ||
| 91 | var arg_index = args.length - 1; |
91 | var arg_index = args.length - 1; |
| 92 | 92 | ||
| 93 | if (arg_index == 1) // command name |
93 | if (arg_index == 1) // command name |
| 94 | { |
94 | { |
| 95 | for (var n in |
95 | for (var n in Console_HelpTexts) |
| 96 | { |
96 | { |
| 97 | result.push(n); |
97 | result.push(n); |
| 98 | } |
98 | } |
| 99 | } |
99 | } |
| 100 | 100 | ||
| Line 106... | Line 106... | ||
| 106 | if (!command_name) |
106 | if (!command_name) |
| 107 | { |
107 | { |
| 108 | command_name = "help"; |
108 | command_name = "help"; |
| 109 | } |
109 | } |
| 110 | 110 | ||
| 111 | if (typeof |
111 | if (typeof Console_HelpTexts[command_name] != 'undefined') |
| 112 | { |
112 | { |
| 113 | var result = ""; |
113 | var result = ""; |
| 114 | 114 | ||
| 115 | if ( |
115 | if (Console_AutoCompleteFunctions[command_name]) |
| 116 | { |
116 | { |
| 117 | result += "Argument autocompletion enabled for " + command_name + "\n"; |
117 | result += "Argument autocompletion enabled for " + command_name + "\n"; |
| 118 | } |
118 | } |
| 119 | 119 | ||
| 120 | result += "Syntax: " + command_name + " " + |
120 | result += "Syntax: " + command_name + " " + Console_HelpTexts[command_name] + "\n"; |
| 121 | 121 | ||
| 122 | return result; |
122 | return result; |
| 123 | } |
123 | } |
| 124 | 124 | ||
| 125 | return "No help for " + command_name + " found\n"; |
125 | return "No help for " + command_name + " found\n"; |
| 126 | } |
126 | } |
| 127 |
|
127 | Console_RegisterCommand(help, help_complete); |
| 128 | 128 | ||
| 129 | var prompt_requests = |
129 | var prompt_requests = {}; |
| 130 | var prompt_request_counter = 0; |
130 | var prompt_request_counter = 0; |
| 131 | 131 | ||
| 132 | function prompt(question, callback, text) |
132 | function prompt(question, callback, text) |
| 133 | { |
133 | { |
| 134 | var id = prompt_request_counter++; |
134 | var id = prompt_request_counter++; |