ascii-chat 0.8.38
Real-time terminal-based video chat with ASCII art conversion
Loading...
Searching...
No Matches
powershell.c File Reference

PowerShell completion script generator. More...

Go to the source code of this file.

Functions

asciichat_error_t completions_generate_powershell (FILE *output)
 

Detailed Description

PowerShell completion script generator.

Definition in file powershell.c.

Function Documentation

◆ completions_generate_powershell()

asciichat_error_t completions_generate_powershell ( FILE *  output)

Definition at line 130 of file powershell.c.

130 {
131 if (!output) {
132 return SET_ERRNO(ERROR_INVALID_PARAM, "Output stream cannot be NULL");
133 }
134
135 fprintf(output, "# PowerShell completion script for ascii-chat\n"
136 "# Generated from options registry - DO NOT EDIT MANUALLY\n"
137 "# Usage: ascii-chat --completions powershell | Out-String | Invoke-Expression\n"
138 "\n"
139 "$script:AsciiChatCompleter = {\n"
140 " param($wordToComplete, $commandAst, $cursorPosition)\n"
141 "\n"
142 " $words = @($commandAst.CommandElements | ForEach-Object { $_.Value })\n"
143 " $mode = $null\n"
144 "\n"
145 " foreach ($word in $words) {\n"
146 " if ($word -in @('server', 'client', 'mirror')) {\n"
147 " $mode = $word\n"
148 " break\n"
149 " }\n"
150 " }\n"
151 "\n"
152 " $binaryOptions = @(\n");
153
154 /* Binary options - use unified display API matching help system */
155 size_t binary_count = 0;
156 const option_descriptor_t *binary_opts = options_registry_get_for_display(MODE_DISCOVERY, true, &binary_count);
157
158 if (binary_opts) {
159 for (size_t i = 0; i < binary_count; i++) {
160 ps_write_option(output, &binary_opts[i]);
161 }
162 SAFE_FREE(binary_opts);
163 }
164
165 fprintf(output, " )\n\n $serverOptions = @(\n");
166
167 /* Server options - use unified display API matching help system */
168 size_t server_count = 0;
169 const option_descriptor_t *server_opts = options_registry_get_for_display(MODE_SERVER, false, &server_count);
170
171 if (server_opts) {
172 for (size_t i = 0; i < server_count; i++) {
173 ps_write_option(output, &server_opts[i]);
174 }
175 SAFE_FREE(server_opts);
176 }
177
178 fprintf(output, " )\n\n $clientOptions = @(\n");
179
180 /* Client options - use unified display API matching help system */
181 size_t client_count = 0;
182 const option_descriptor_t *client_opts = options_registry_get_for_display(MODE_CLIENT, false, &client_count);
183
184 if (client_opts) {
185 for (size_t i = 0; i < client_count; i++) {
186 ps_write_option(output, &client_opts[i]);
187 }
188 SAFE_FREE(client_opts);
189 }
190
191 fprintf(output, " )\n\n $mirrorOptions = @(\n");
192
193 /* Mirror options - use unified display API matching help system */
194 size_t mirror_count = 0;
195 const option_descriptor_t *mirror_opts = options_registry_get_for_display(MODE_MIRROR, false, &mirror_count);
196
197 if (mirror_opts) {
198 for (size_t i = 0; i < mirror_count; i++) {
199 ps_write_option(output, &mirror_opts[i]);
200 }
201 SAFE_FREE(mirror_opts);
202 }
203
204 fprintf(output, " )\n\n $discoverySvcOptions = @(\n");
205
206 /* Discovery-service options */
207 size_t discovery_svc_count = 0;
208 const option_descriptor_t *discovery_svc_opts =
209 options_registry_get_for_display(MODE_DISCOVERY_SERVICE, false, &discovery_svc_count);
210
211 if (discovery_svc_opts) {
212 for (size_t i = 0; i < discovery_svc_count; i++) {
213 ps_write_option(output, &discovery_svc_opts[i]);
214 }
215 SAFE_FREE(discovery_svc_opts);
216 }
217
218 fprintf(output,
219 " )\n"
220 "\n"
221 " $options = $binaryOptions\n"
222 " \n"
223 " if ($mode -eq 'server') {\n"
224 " $options += $serverOptions\n"
225 " } elseif ($mode -eq 'client') {\n"
226 " $options += $clientOptions\n"
227 " } elseif ($mode -eq 'mirror') {\n"
228 " $options += $mirrorOptions\n"
229 " } elseif ($mode -eq 'discovery-service') {\n"
230 " $options += $discoverySvcOptions\n"
231 " }\n"
232 "\n"
233 " if (-not $mode -and -not $wordToComplete.StartsWith('-')) {\n"
234 " @('server', 'client', 'mirror', 'discovery-service') | Where-Object { $_ -like \"$wordToComplete*\" } | "
235 "ForEach-Object {\n"
236 " [System.Management.Automation.CompletionResult]::new($_, $_, 'ParameterValue', \"Mode: $_\")\n"
237 " }\n"
238 " } else {\n"
239 " $options | Where-Object { $_.Name -like \"$wordToComplete*\" } | ForEach-Object {\n"
240 " if ($_.Values) {\n"
241 " $_.Values | ForEach-Object {\n"
242 " [System.Management.Automation.CompletionResult]::new($_, $_, 'ParameterValue', $_.Description)\n"
243 " }\n"
244 " } else {\n"
245 " [System.Management.Automation.CompletionResult]::new($_.Name, $_.Name, 'ParameterValue', "
246 "$_.Description)\n"
247 " }\n"
248 " }\n"
249 " }\n"
250 "}\n"
251 "\n"
252 "Register-ArgumentCompleter -CommandName ascii-chat -ScriptBlock $script:AsciiChatCompleter\n");
253
254 return ASCIICHAT_OK;
255}
const option_descriptor_t * options_registry_get_for_display(asciichat_mode_t mode, bool for_binary_help, size_t *num_options)
Definition public_api.c:323

References options_registry_get_for_display().

Referenced by completions_generate_for_shell().