ascii-chat
Binary v0.15.83-53-gb711d8720
Library lib/v0.3.2-701-gb711d8720
Video chat in your terminal
Loading...
Searching...
No Matches
powershell.h File Reference

PowerShell completion generator. More...

Go to the source code of this file.

Functions

asciichat_error_t completions_generate_powershell (FILE *output)
 Generate PowerShell completion script.

Detailed Description

PowerShell completion generator.

Definition in file powershell.h.

Function Documentation

◆ completions_generate_powershell()

asciichat_error_t completions_generate_powershell ( FILE * output)

Generate PowerShell completion script.

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 { if ($null -ne $_.Value) { $_.Value } "
143 "else { $_.Extent.Text } })\n"
144 " $mode = $null\n"
145 "\n"
146 " foreach ($word in $words) {\n"
147 " if ($word -in @('server', 'client', 'mirror', 'discovery-service', 'mcp-server')) {\n"
148 " $mode = $word\n"
149 " break\n"
150 " }\n"
151 " }\n"
152 "\n"
153 " $binaryOptions = @(\n");
154
155 /* Binary options - use unified display API matching help system */
156 size_t binary_count = 0;
157 const option_descriptor_t *binary_opts = options_registry_get_for_display(MODE_DISCOVERY, true, &binary_count);
158
159 if (binary_opts) {
160 for (size_t i = 0; i < binary_count; i++) {
161 ps_write_option(output, &binary_opts[i]);
162 }
163 SAFE_FREE(binary_opts);
164 }
165
166 fprintf(output, " )\n\n $serverOptions = @(\n");
167
168 /* Server options - use unified display API matching help system */
169 size_t server_count = 0;
170 const option_descriptor_t *server_opts = options_registry_get_for_display(MODE_SERVER, false, &server_count);
171
172 if (server_opts) {
173 for (size_t i = 0; i < server_count; i++) {
174 ps_write_option(output, &server_opts[i]);
175 }
176 SAFE_FREE(server_opts);
177 }
178
179 fprintf(output, " )\n\n $clientOptions = @(\n");
180
181 /* Client options - use unified display API matching help system */
182 size_t client_count = 0;
183 const option_descriptor_t *client_opts = options_registry_get_for_display(MODE_CLIENT, false, &client_count);
184
185 if (client_opts) {
186 for (size_t i = 0; i < client_count; i++) {
187 ps_write_option(output, &client_opts[i]);
188 }
189 SAFE_FREE(client_opts);
190 }
191
192 fprintf(output, " )\n\n $mirrorOptions = @(\n");
193
194 /* Mirror options - use unified display API matching help system */
195 size_t mirror_count = 0;
196 const option_descriptor_t *mirror_opts = options_registry_get_for_display(MODE_MIRROR, false, &mirror_count);
197
198 if (mirror_opts) {
199 for (size_t i = 0; i < mirror_count; i++) {
200 ps_write_option(output, &mirror_opts[i]);
201 }
202 SAFE_FREE(mirror_opts);
203 }
204
205 fprintf(output, " )\n\n $mcpOptions = @(\n");
206 size_t mcp_count = 0;
207 const option_descriptor_t *mcp_opts = options_registry_get_for_display(MODE_MCP_SERVER, false, &mcp_count);
208 for (size_t i = 0; i < mcp_count; i++) {
209 ps_write_option(output, &mcp_opts[i]);
210 }
211 SAFE_FREE(mcp_opts);
212 fprintf(output, " )\n\n $discoverySvcOptions = @(\n");
213
214 /* Discovery-service options */
215 size_t discovery_svc_count = 0;
216 const option_descriptor_t *discovery_svc_opts =
217 options_registry_get_for_display(MODE_DISCOVERY_SERVICE, false, &discovery_svc_count);
218
219 if (discovery_svc_opts) {
220 for (size_t i = 0; i < discovery_svc_count; i++) {
221 ps_write_option(output, &discovery_svc_opts[i]);
222 }
223 SAFE_FREE(discovery_svc_opts);
224 }
225
226 fprintf(
227 output,
228 " )\n"
229 "\n"
230 " $options = $binaryOptions\n"
231 " \n"
232 " if ($mode -eq 'server') {\n"
233 " $options += $serverOptions\n"
234 " } elseif ($mode -eq 'client') {\n"
235 " $options += $clientOptions\n"
236 " } elseif ($mode -eq 'mirror') {\n"
237 " $options += $mirrorOptions\n"
238 " } elseif ($mode -eq 'mcp-server') {\n"
239 " $options += $mcpOptions\n"
240 " } elseif ($mode -eq 'discovery-service') {\n"
241 " $options += $discoverySvcOptions\n"
242 " }\n"
243 "\n"
244 " $previousIndex = $words.Count - 1\n"
245 " if ($wordToComplete) { $previousIndex-- }\n"
246 " $valueOption = $options | Where-Object { $_.Name -eq $words[$previousIndex] } | Select-Object -First 1\n"
247 " if ($valueOption.Values -and -not $wordToComplete.StartsWith('-')) {\n"
248 " $valueOption.Values | Where-Object { $_ -like \"$wordToComplete*\" } | ForEach-Object {\n"
249 " [System.Management.Automation.CompletionResult]::new($_, $_, 'ParameterValue', $valueOption.Description)\n"
250 " }\n"
251 " return\n"
252 " }\n"
253 "\n"
254 " if (-not $mode -and -not $wordToComplete.StartsWith('-')) {\n"
255 " @('server', 'client', 'mirror', 'discovery-service', 'mcp-server') | Where-Object { $_ -like "
256 "\"$wordToComplete*\" } | "
257 "ForEach-Object {\n"
258 " [System.Management.Automation.CompletionResult]::new($_, $_, 'ParameterValue', \"Mode: $_\")\n"
259 " }\n"
260 " } else {\n"
261 " $options | Sort-Object -Property Name -Unique | Where-Object { $_.Name -like \"$wordToComplete*\" } | "
262 "ForEach-Object {\n"
263 " [System.Management.Automation.CompletionResult]::new($_.Name, $_.Name, 'ParameterName', $_.Description)\n"
264 " }\n"
265 " }\n"
266 "}\n"
267 "\n"
268 "Register-ArgumentCompleter -Native -CommandName ascii-chat -ScriptBlock $script:AsciiChatCompleter\n");
269
270 return ASCIICHAT_OK;
271}
#define SET_ERRNO(code,...)
#define SAFE_FREE(ptr)
Definition common.h:377
@ ASCIICHAT_OK
Definition error_codes.h:46
@ ERROR_INVALID_PARAM
@ MODE_CLIENT
Client mode - network client options.
Definition options.h:921
@ MODE_MCP_SERVER
Model Context Protocol rendering server.
Definition options.h:925
@ MODE_DISCOVERY_SERVICE
Discovery server mode - session management and WebRTC signaling.
Definition options.h:923
@ MODE_SERVER
Server mode - network server options.
Definition options.h:920
@ MODE_MIRROR
Mirror mode - local webcam viewing (no network).
Definition options.h:922
@ MODE_DISCOVERY
Discovery mode - participant that can dynamically become host.
Definition options.h:924
const option_descriptor_t * options_registry_get_for_display(asciichat_mode_t mode, bool for_binary_help, size_t *num_options)
Get options for help/completions display with unified filtering.
Definition public_api.c:279
The complete registry entry for one command-line/configuration option.
Definition builder.h:249