Rev 1649 | Rev 1660 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed
| Rev 1649 | Rev 1657 | ||
|---|---|---|---|
| Line 63... | Line 63... | ||
| 63 | 63 | ||
| 64 | return Console_SetDefaultPrompt(); |
64 | return Console_SetDefaultPrompt(); |
| 65 | } |
65 | } |
| 66 | 66 | ||
| 67 | // User script functions |
67 | // User script functions |
| - | 68 | ||
| - | 69 | function Console_GetClientId() |
|
| - | 70 | { |
|
| - | 71 | return Console_LastClientId; |
|
| - | 72 | } |
|
| - | 73 | ||
| - | 74 | function Console_LogToClient(client_id, text) |
|
| - | 75 | { |
|
| - | 76 | if (client_id) |
|
| - | 77 | { |
|
| - | 78 | return ConsoleExport_LogToClient(client_id, text); |
|
| - | 79 | } |
|
| - | 80 | ||
| - | 81 | return false; |
|
| - | 82 | } |
|
| 68 | 83 | ||
| 69 | function Console_PreventDefaultPrompt() |
84 | function Console_PreventDefaultPrompt() |
| 70 | { |
85 | { |
| 71 | Console_CurrentFunction = null; |
86 | Console_CurrentFunction = null; |
| 72 | } |
87 | } |
| Line 78... | Line 93... | ||
| 78 | 93 | ||
| 79 | function Console_PromptRequest(prompt, callback) |
94 | function Console_PromptRequest(prompt, callback) |
| 80 | { |
95 | { |
| 81 | Console_CurrentFunction = callback; |
96 | Console_CurrentFunction = callback; |
| 82 | return ConsoleExport_PromptRequest(Console_LastClientId, prompt); |
97 | return ConsoleExport_PromptRequest(Console_LastClientId, prompt); |
| 83 | } |
98 | } |
| 84 | 99 | ||
| 85 | function Console_RegisterCommand(command, autocomplete_callback) |
100 | function Console_RegisterCommand(command, autocomplete_callback) |
| 86 | { |
101 | { |
| 87 | var command_string = command.toString(); |
102 | var command_string = command.toString(); |
| 88 | 103 | ||
| 89 | var pos_end = command_string.indexOf("\n") - 1; |
104 | var pos_end = command_string.indexOf("\n") - 1; |
| Line 103... | Line 118... | ||
| 103 | argument_string = "<" + argument_string.replace(/ /g, "> <") + ">"; |
118 | argument_string = "<" + argument_string.replace(/ /g, "> <") + ">"; |
| 104 | } |
119 | } |
| 105 | 120 | ||
| 106 | Console_Functions[name] = { "command" : command, "autocomplete" : autocomplete_callback, "help" : argument_string }; |
121 | Console_Functions[name] = { "command" : command, "autocomplete" : autocomplete_callback, "help" : argument_string }; |
| 107 | return true; |
122 | return true; |
| 108 | } |
123 | } |
| 109 | 124 | ||
| 110 | function Console_StandardAutocomplete() |
125 | function Console_StandardAutocomplete() |
| 111 | { |
126 | { |
| 112 | var arg_index = arguments[0]; |
127 | var arg_index = arguments[0]; |
| 113 | var args = arguments[1]; |
128 | var args = arguments[1]; |
| 114 | 129 | ||
| 115 | if (0 <= arg_index && arg_index < arguments.length - 2) |
130 | if (0 <= arg_index && arg_index < arguments.length - 2) |
| 116 | { |
131 | { |
| 117 | return arguments[arg_index + 2]; |
132 | return arguments[arg_index + 2]; |
| 118 | } |
133 | } |
| 119 | 134 | ||
| 120 | return []; |
135 | return []; |
| 121 | } |
136 | } |
| 122 | 137 | ||
| 123 | // Default call function |
138 | // Default call function |
| 124 | 139 | ||
| 125 | function Console_Shell() |
140 | function Console_Shell() |
| 126 | { |
141 | { |
| 127 | var args = to_array(arguments); |
142 | var args = to_array(arguments); |
| 128 | var name = args.shift(); |
143 | var name = args.shift(); |
| 129 | 144 | ||
| 130 | if (Console_Functions[name] && Console_Functions[name]["command"]) |
145 | if (Console_Functions[name] && Console_Functions[name]["command"]) |
| 131 | { |
146 | { |
| 132 | return Console_Functions[name]["command"].apply(null, Array.prototype.slice.call(args, 0)); |
147 | return Console_Functions[name]["command"].apply(null, Array.prototype.slice.call(args, 0)); |
| - | 148 | } |
|
| - | 149 | else |
|
| - | 150 | { |
|
| - | 151 | Log("\033[31mNo such command found, " + name + ".\033[0m\n"); |
|
| 133 | } |
152 | } |
| 134 | 153 | ||
| 135 | return false; |
154 | return false; |
| 136 | } |
155 | } |
| 137 | Console_RegisterCommand(Console_Shell, function(arg_index, args) { return Console_StandardAutocomplete(arg_index, args, Console_GetFunctionNames()); }); |
156 | Console_RegisterCommand(Console_Shell, function(arg_index, args) { return Console_StandardAutocomplete(arg_index, args, Console_GetFunctionNames()); }); |