@shell-shock/core 0.16.2 → 0.17.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (61) hide show
  1. package/dist/components/command-validation-logic.cjs +1 -1
  2. package/dist/components/command-validation-logic.cjs.map +1 -1
  3. package/dist/components/command-validation-logic.mjs +1 -1
  4. package/dist/components/command-validation-logic.mjs.map +1 -1
  5. package/dist/components/{spawn-builtin.cjs → exec-builtin.cjs} +140 -75
  6. package/dist/components/exec-builtin.cjs.map +1 -0
  7. package/dist/components/exec-builtin.d.cts +12 -0
  8. package/dist/components/exec-builtin.d.cts.map +1 -0
  9. package/dist/components/exec-builtin.d.mts +12 -0
  10. package/dist/components/exec-builtin.d.mts.map +1 -0
  11. package/dist/components/{spawn-builtin.mjs → exec-builtin.mjs} +140 -75
  12. package/dist/components/exec-builtin.mjs.map +1 -0
  13. package/dist/components/index.cjs +3 -2
  14. package/dist/components/index.d.cts +3 -3
  15. package/dist/components/index.d.mts +3 -3
  16. package/dist/components/index.mjs +3 -3
  17. package/dist/components/options-parser-logic.cjs +14 -6
  18. package/dist/components/options-parser-logic.cjs.map +1 -1
  19. package/dist/components/options-parser-logic.d.cts +2 -5
  20. package/dist/components/options-parser-logic.d.cts.map +1 -1
  21. package/dist/components/options-parser-logic.d.mts +2 -5
  22. package/dist/components/options-parser-logic.d.mts.map +1 -1
  23. package/dist/components/options-parser-logic.mjs +14 -6
  24. package/dist/components/options-parser-logic.mjs.map +1 -1
  25. package/dist/components/state-builtin.cjs +43 -8
  26. package/dist/components/state-builtin.cjs.map +1 -1
  27. package/dist/components/state-builtin.d.cts.map +1 -1
  28. package/dist/components/state-builtin.d.mts.map +1 -1
  29. package/dist/components/state-builtin.mjs +44 -9
  30. package/dist/components/state-builtin.mjs.map +1 -1
  31. package/dist/components/utils-builtin.cjs +154 -0
  32. package/dist/components/utils-builtin.cjs.map +1 -1
  33. package/dist/components/utils-builtin.d.cts +5 -1
  34. package/dist/components/utils-builtin.d.cts.map +1 -1
  35. package/dist/components/utils-builtin.d.mts +5 -1
  36. package/dist/components/utils-builtin.d.mts.map +1 -1
  37. package/dist/components/utils-builtin.mjs +155 -2
  38. package/dist/components/utils-builtin.mjs.map +1 -1
  39. package/dist/plugin.cjs +2 -2
  40. package/dist/plugin.cjs.map +1 -1
  41. package/dist/plugin.mjs +2 -2
  42. package/dist/plugin.mjs.map +1 -1
  43. package/dist/resolver/resolve.cjs +1 -1
  44. package/dist/resolver/resolve.cjs.map +1 -1
  45. package/dist/resolver/resolve.mjs +1 -1
  46. package/dist/resolver/resolve.mjs.map +1 -1
  47. package/dist/types/env.cjs +1 -1
  48. package/dist/types/env.cjs.map +1 -1
  49. package/dist/types/env.d.cts +7 -1
  50. package/dist/types/env.d.cts.map +1 -1
  51. package/dist/types/env.d.mts +7 -1
  52. package/dist/types/env.d.mts.map +1 -1
  53. package/dist/types/env.mjs +1 -1
  54. package/dist/types/env.mjs.map +1 -1
  55. package/package.json +16 -16
  56. package/dist/components/spawn-builtin.cjs.map +0 -1
  57. package/dist/components/spawn-builtin.d.cts +0 -12
  58. package/dist/components/spawn-builtin.d.cts.map +0 -1
  59. package/dist/components/spawn-builtin.d.mts +0 -12
  60. package/dist/components/spawn-builtin.d.mts.map +0 -1
  61. package/dist/components/spawn-builtin.mjs.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"state-builtin.mjs","names":[],"sources":["../../src/components/state-builtin.tsx"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Shell Shock\n\n This code was released as part of the Shell Shock project. Shell Shock\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/shell-shock.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/shell-shock\n Documentation: https://docs.stormsoftware.com/projects/shell-shock\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport { code, computed, For, Show, splitProps } from \"@alloy-js/core\";\nimport {\n FunctionDeclaration,\n InterfaceDeclaration,\n InterfaceMember,\n TypeDeclaration,\n VarDeclaration\n} from \"@alloy-js/typescript\";\nimport { Spacing } from \"@powerlines/plugin-alloy/core/components/spacing\";\nimport { usePowerlines } from \"@powerlines/plugin-alloy/core/contexts/context\";\nimport type { BuiltinFileProps } from \"@powerlines/plugin-alloy/typescript/components/builtin-file\";\nimport { BuiltinFile } from \"@powerlines/plugin-alloy/typescript/components/builtin-file\";\nimport {\n TSDoc,\n TSDocInternal,\n TSDocLink,\n TSDocParam,\n TSDocRemarks,\n TSDocReturns\n} from \"@powerlines/plugin-alloy/typescript/components/tsdoc\";\nimport defu from \"defu\";\nimport { computedOptions } from \"../contexts/options\";\nimport { getAppBin } from \"../plugin-utils\";\nimport { getAppTitle } from \"../plugin-utils/context-helpers\";\nimport type { Context } from \"../types\";\nimport { OptionsMember } from \"./options-parser-logic\";\n\nexport function GlobalTypeDefinitions() {\n const context = usePowerlines<Context>();\n\n const options = computed(() => computedOptions(context.options));\n\n return (\n <>\n <TSDoc\n heading={`An object representing the global options available for every command in the ${getAppTitle(\n context,\n true\n )} command-line application.`}\n />\n <InterfaceDeclaration export name=\"GlobalOptions\">\n <For each={Object.values(options.value)} hardline>\n {option => <OptionsMember option={option} />}\n </For>\n </InterfaceDeclaration>\n <Spacing />\n <TSDoc heading=\"The context object for the current command execution, containing the command path and segments.\" />\n <InterfaceDeclaration\n export\n name=\"CommandContext\"\n typeParameters={[\n {\n name: \"THandler\",\n extends: \"(...params: any[]) => any\",\n default: \"any\"\n }\n ]}>\n <TSDoc\n heading={`The full command path as a string. For example, if the user runs \\`${getAppBin(\n context\n )} foo bar\\`, this would be \\`foo bar\\`. This is useful for commands that need to know their full invocation path, such as for help text or for commands that have dynamic behavior based on their position in the command hierarchy.`}\n />\n <InterfaceMember name=\"path\" type=\"string\" />\n <Spacing />\n <TSDoc\n heading={`An array of command path segments. For example, if the user runs \\`${getAppBin(\n context\n )} foo bar\\`, this would be \\`[\"foo\", \"bar\"]\\`. This is useful for commands that need to know their individual path segments, such as for dynamic routing or for commands that have behavior based on specific segments in the command hierarchy.`}\n />\n <InterfaceMember name=\"segments\" type=\"string[]\" />\n <Spacing />\n <TSDoc\n heading={`The parameters for the current command's handler function.`}\n />\n <InterfaceMember name=\"params\" type=\"Parameters<THandler>\" />\n </InterfaceDeclaration>\n <Spacing />\n <TypeDeclaration export name=\"GlobalContextStatus\">\n {code`\"initializing\" | \"preparing\" | \"executing\" | \"completed\"`}\n </TypeDeclaration>\n <Spacing />\n <TSDoc\n heading={`The state object for the ${getAppTitle(context)} application context.`}\n />\n <InterfaceDeclaration export name=\"GlobalContextState\">\n <TSDoc heading=\"The unique identifier for the current execution context.\" />\n <InterfaceMember name=\"executionId\" type=\"string\" />\n <Spacing />\n <TSDoc heading=\"The status of the current execution context.\" />\n <InterfaceMember name=\"status\" type=\"GlobalContextStatus\" />\n <Spacing />\n <TSDoc heading=\"Indicates whether the current execution context has encountered an error.\" />\n <InterfaceMember name=\"isError\" type=\"boolean\" />\n <Spacing />\n <TSDoc heading=\"A map containing arbitrary data associated with the current execution context.\" />\n <InterfaceMember name=\"meta\" type=\"Map<string, unknown>\" />\n </InterfaceDeclaration>\n <Spacing />\n <TSDoc\n heading={`The context object for the ${getAppTitle(context)} application.`}\n />\n <InterfaceDeclaration export name=\"GlobalContext\">\n <TSDoc heading=\"The global options shared across all commands in the application.\" />\n <InterfaceMember name=\"options\" type=\"GlobalOptions\" />\n <Spacing />\n <TSDoc heading=\"The raw command-line arguments passed to the application.\" />\n <InterfaceMember name=\"inputArgs\" type=\"string[]\" />\n <Spacing />\n <TSDoc heading=\"The state of the current execution context.\" />\n <InterfaceMember name=\"state\" type=\"GlobalContextState\" />\n </InterfaceDeclaration>\n </>\n );\n}\n\n/**\n * Generates utilities for detecting terminal color support.\n */\nexport function ArgsUtilities() {\n return (\n <>\n <TSDoc heading=\"Retrieves the command-line arguments from Deno or Node.js environments.\">\n <TSDocRemarks>\n {`This function is only intended for internal use. Please use \\`useArgs()\\` instead.`}\n </TSDocRemarks>\n <Spacing />\n <TSDocInternal />\n <Spacing />\n <TSDocReturns>\n {`An array of command-line arguments from Deno or Node.js environments.`}\n </TSDocReturns>\n </TSDoc>\n <FunctionDeclaration name=\"getInputArgs\" returnType=\"string[]\">\n {code`return ((globalThis as { Deno?: { args: string[] } })?.Deno?.args ?? process.argv ?? []) as string[];`}\n </FunctionDeclaration>\n </>\n );\n}\n\nexport function ContextUtilities() {\n const context = usePowerlines<Context>();\n\n return (\n <>\n <Spacing />\n\n <TSDoc\n heading={`The global ${getAppTitle(context)} application context store instance.`}>\n <TSDocInternal />\n </TSDoc>\n <VarDeclaration export const name=\"unstable_globalStore\">\n {code` new AsyncLocalStorage<GlobalContext>({ name: \"globalStore\" }); `}\n </VarDeclaration>\n <Spacing />\n <TSDoc\n heading={`Get the ${getAppTitle(\n context\n )} application context for the current application.`}>\n <TSDocParam name=\"options\">\n {`The options to use when getting the context. This can include parameters for how to handle missing contexts, such as whether to throw an error or return undefined. By default, if the context is not available, this function will return undefined.`}\n </TSDocParam>\n <TSDocReturns>\n {`The ${getAppTitle(\n context\n )} application context for the current application or undefined if the context is not available.`}\n </TSDocReturns>\n </TSDoc>\n <FunctionDeclaration export name=\"useGlobal\" returnType=\"GlobalContext\">\n {code`return unstable_globalStore.getStore() as GlobalContext;`}\n </FunctionDeclaration>\n <Spacing />\n <TSDoc\n heading={`A utility hook function to get the command-line arguments from the ${getAppTitle(\n context\n )} application context.`}>\n <TSDocReturns>\n {\"An array of command-line arguments from the application context.\"}\n </TSDocReturns>\n </TSDoc>\n <FunctionDeclaration export name=\"useArgs\" returnType=\"string[]\">\n {code`return useGlobal()?.inputArgs ?? getInputArgs();`}\n </FunctionDeclaration>\n <Spacing />\n <TSDoc\n heading={`A utility hook function to get the state of the ${getAppTitle(\n context\n )} application context.`}>\n <TSDocReturns>{\"The state of the application context.\"}</TSDocReturns>\n </TSDoc>\n <FunctionDeclaration\n export\n name=\"useState\"\n returnType=\"GlobalContextState\">\n {code`return useGlobal()?.state;`}\n </FunctionDeclaration>\n <Spacing />\n <TSDoc\n heading={`A utility function to update the state of the ${getAppTitle(\n context\n )} application context.`}>\n <TSDocRemarks>\n {`This function will throw an error if the global context is not available, so it should only be used within a valid context scope, such as within a command handler or within the \\`withGlobal()\\` function.`}\n </TSDocRemarks>\n <Spacing />\n <TSDocParam name=\"update\">\n {`The new state or a function that receives the previous state and returns the new state. This allows for both direct state updates and functional updates based on the previous state.`}\n </TSDocParam>\n </TSDoc>\n <FunctionDeclaration\n export\n name=\"setState\"\n parameters={[\n {\n name: \"update\",\n type: \"Partial<GlobalContextState> | ((prev: GlobalContextState) => GlobalContextState)\"\n }\n ]}>\n {code`const prev = useGlobal()?.state;\n if (!prev) {\n throw new Error(\n \\`The ${getAppTitle(\n context\n )} application context is not available. Make sure to call setState() within a valid context scope.\\`\n );\n }\n\n useGlobal().state = typeof update === \"function\" ? update(prev) : { ...prev, ...update }; `}\n </FunctionDeclaration>\n <Spacing />\n <TSDoc\n heading={`A utility hook function to get the execution ID of the ${getAppTitle(\n context\n )} application context.`}>\n <TSDocReturns>\n {\"The execution ID of the application context.\"}\n </TSDocReturns>\n </TSDoc>\n <FunctionDeclaration export name=\"useExecutionId\" returnType=\"string\">\n {code`return useState().executionId;`}\n </FunctionDeclaration>\n <Spacing />\n <TSDoc\n heading={`A utility hook function to get the metadata of the ${getAppTitle(\n context\n )} application context.`}>\n <TSDocReturns>\n {\"The metadata of the application context.\"}\n </TSDocReturns>\n </TSDoc>\n <FunctionDeclaration\n export\n name=\"useMeta\"\n returnType=\"Map<string, unknown>\">\n {code`return useState().meta;`}\n </FunctionDeclaration>\n <Spacing />\n <TSDoc\n heading={`A utility hook function to get the current status of the ${getAppTitle(\n context\n )} application.`}>\n <TSDocReturns>{\"The current status of the application.\"}</TSDocReturns>\n </TSDoc>\n <FunctionDeclaration\n export\n name=\"useStatus\"\n returnType=\"GlobalContextStatus\">\n {code`return useState().status;`}\n </FunctionDeclaration>\n <Spacing />\n <TSDoc\n heading={`The global ${getAppTitle(context)} - command context store instance.`}>\n <TSDocInternal />\n </TSDoc>\n <VarDeclaration export name=\"unstable_commandStore\">\n {code`new AsyncLocalStorage<CommandContext>({ name: \"commandStore\" });`}\n </VarDeclaration>\n <Spacing />\n <TSDoc\n heading={`Get the ${getAppTitle(context)} - command context for the current application.`}>\n <TSDocReturns>\n {`The ${getAppTitle(context)} - command context for the current application.`}\n </TSDocReturns>\n </TSDoc>\n <FunctionDeclaration export name=\"useCommand\" returnType=\"CommandContext\">\n {code`const result = unstable_commandStore.getStore();\nif (!result) {\n throw new Error(\n \\`The ${getAppTitle(context)} - command context is not available. Make sure to call useCommand() within a valid context scope.\\`\n );\n}\nreturn result;`}\n </FunctionDeclaration>\n <Spacing />\n <TSDoc heading=\"A utility hook function to get the individual segments of the current command path.\">\n <TSDocReturns>{\"An array of command path segments.\"}</TSDocReturns>\n </TSDoc>\n <FunctionDeclaration export name=\"useSegments\" returnType=\"string[]\">\n {code`return useCommand().segments;`}\n </FunctionDeclaration>\n <Spacing />\n <TSDoc heading=\"A utility hook function to get the full command path as a string.\">\n <TSDocReturns>\n {`The full command path as a string. For example, if the user runs \\`${getAppBin(\n context\n )} foo bar\\`, this would return \\`\"foo bar\"\\`. This is useful for commands that need to know their full invocation path, such as for help text or for commands that have dynamic behavior based on their position in the command hierarchy.`}\n </TSDocReturns>\n </TSDoc>\n <FunctionDeclaration export name=\"usePath\" returnType=\"string\">\n {code`return useCommand().path;`}\n </FunctionDeclaration>\n <Spacing />\n <TSDoc heading=\"Checks if a specific flag is present in the command-line arguments.\">\n <TSDocLink>\n {\"https://github.com/sindresorhus/has-flag/blob/main/index.js\"}\n </TSDocLink>\n <TSDocParam name=\"flag\">\n {\n 'The flag (or an array of flags/aliases) to check for, e.g., \"color\", \"no-color\".'\n }\n </TSDocParam>\n <TSDocParam name=\"argv\">\n {\n \"The command-line arguments to check against. Defaults to global Deno args or process args.\"\n }\n </TSDocParam>\n <TSDocReturns>\n {\"True if the flag is present, false otherwise.\"}\n </TSDocReturns>\n </TSDoc>\n <FunctionDeclaration\n export\n name=\"hasFlag\"\n parameters={[\n { name: \"flag\", type: \"string | string[]\" },\n {\n name: \"argv\",\n type: \"string[]\",\n default: \"useArgs()\"\n }\n ]}>\n <VarDeclaration\n const\n name=\"position\"\n type=\"number\"\n initializer={code`(Array.isArray(flag) ? flag : [flag]).reduce((ret, f) => {\n const pos = argv.findIndex(arg => (f.startsWith(\"-\") ? \"\" : (f.length === 1 ? \"-\" : \"--\") + f)?.toLowerCase() === arg?.toLowerCase() || arg?.toLowerCase().startsWith((f.length === 1 ? \"-\" : \"--\") + f + \"=\"));\n return pos !== -1 ? pos : ret;\n }, -1);`}\n />\n <hbr />\n {code`return position !== -1 && argv.indexOf(\"--\") === -1 || position < argv.indexOf(\"--\");`}\n </FunctionDeclaration>\n <Spacing />\n <TSDoc heading=\"A utility function to determine if the help flag is present or if the command is in an error state during preparation.\">\n <TSDocReturns>\n {`True if the help flag is present or if the command is in an error state during preparation, false otherwise. This can be used to conditionally display help text or to alter command behavior when the user is likely seeking help.`}\n </TSDocReturns>\n </TSDoc>\n <FunctionDeclaration export name=\"isHelp\" returnType=\"boolean\">\n {code`return !isCI && (hasFlag([\"help\", \"h\", \"?\"]) || (useStatus() === \"preparing\" && useState().isError)); `}\n </FunctionDeclaration>\n <Spacing />\n <TSDoc\n heading={`A utility function to wrap the ${getAppTitle(\n context\n )} application within the global context scope.`}>\n <TSDocParam name=\"handler\">\n {`The callback function to run within the global context scope. This function will receive the global context as its argument, allowing it to access any properties or utilities defined on the context. The callback function can be asynchronous and can return a value or a promise.`}\n </TSDocParam>\n <TSDocReturns>\n {`The result of the callback function, which can be a value or a promise that resolves to a value.`}\n </TSDocReturns>\n </TSDoc>\n <FunctionDeclaration\n export\n async\n name=\"withGlobal\"\n parameters={[{ name: \"handler\", type: \"() => any\" }]}\n returnType=\"Promise<void>\">\n {code`\n return unstable_globalStore.run({ options: {} as unknown as GlobalOptions, inputArgs: getInputArgs(), state: { executionId: randomUUID(), status: \"initializing\", isError: false, meta: new Map() } as GlobalContextState }, handler);`}\n </FunctionDeclaration>\n <Spacing />\n <TSDoc\n heading={`A utility function to wrap a ${getAppTitle(\n context\n )} application command handler within the command context scope.`}>\n <TSDocParam name=\"handler\">\n {`The callback function to run within the command context scope. This function will receive the command context as its argument, allowing it to access any properties or utilities defined on the context. The callback function can be asynchronous and can return a value or a promise.`}\n </TSDocParam>\n <TSDocReturns>\n {`The result of the callback function, which can be a value or a promise that resolves to a value.`}\n </TSDocReturns>\n </TSDoc>\n <FunctionDeclaration\n export\n async\n name=\"withCommand\"\n typeParameters={[\n {\n name: \"THandler\",\n extends: \"(this: CommandContext, ...params: any[]) => any\",\n default: \"(this: CommandContext, ...params: any[]) => any\"\n }\n ]}\n parameters={[\n { name: \"path\", type: \"string\" },\n { name: \"segments\", type: \"string[]\" },\n { name: \"params\", type: \"Parameters<THandler>\" },\n { name: \"handler\", type: \"THandler\" }\n ]}\n returnType=\"Promise<{ error: string | Error | null }>\">\n {code`setState({ status: \"preparing\", isError: false });\n\n const ctx = { path, segments, params } as CommandContext<THandler>;\n const result = await Promise.resolve(unstable_commandStore.run(ctx, Reflect.apply(handler, ctx, params)));\n if (result instanceof Error || (typeof result === \"object\" && ((result as { error: unknown }).error instanceof Error || typeof (result as { error: unknown }).error === \"string\"))) {\n setState({ status: \"completed\", isError: true });\n return { error: result instanceof Error ? result : (result as { error: Error | string }).error };\n }\n\n setState({ status: \"completed\", isError: false });\n return { error: null }; `}\n </FunctionDeclaration>\n </>\n );\n}\n\nexport interface StateBuiltinProps extends Omit<\n BuiltinFileProps,\n \"id\" | \"description\"\n> {}\n\n/**\n * A built-in module for handling application state utilities in Shell Shock.\n */\nexport function StateBuiltin(props: StateBuiltinProps) {\n const [{ children }, rest] = splitProps(props, [\"children\"]);\n\n return (\n <BuiltinFile\n id=\"state\"\n description=\"A module that provides context hooks and utilities for accessing the application state.\"\n {...rest}\n imports={defu(rest.imports ?? {}, {\n \"node:async_hooks\": [\"AsyncLocalStorage\"],\n \"node:crypto\": [\"randomUUID\"]\n })}\n builtinImports={defu(rest.builtinImports ?? {}, {\n env: [\"isCI\"]\n })}>\n <GlobalTypeDefinitions />\n <Spacing />\n <ArgsUtilities />\n <Spacing />\n <ContextUtilities />\n <Spacing />\n <Show when={Boolean(children)}>{children}</Show>\n </BuiltinFile>\n );\n}\n"],"mappings":";;;;;;;;;;;;;;AAgCA,SAAe,wBAAA;CACb,MAAA,UAAS,eAAA;CACT,MAAA,UAAU,eAAA,gBAAA,QAAA,QAAA,CAAA;AACV,QAAA;EAAA,gBAAY,OAAA,EACZ,IAAA,UAAA;AACI,UAAG,gFAAoD,YAAA,SAAA,KAAA,CAAA;KAE7D,CAAA;EAAM,gBAAkB,sBAAqB;GAC7C,UAAS;GACT,MAAS;GACT,IAAO,WAAO;AACR,WAAG,gBAAsB,KAAE;;AAE1B,aAAS,OAAA,OAAA,QAAuB,MAAC;;;KAGhC,WAAU,WAAU,gBAAK,eAAwB,UAEhD,CAAA;KACJ,CAAA;;GAEF,CAAC;EAAE,gBAAe,SAAO,EAAA,CAAA;EAAA,gBAAwB,OAAQ,EACxD,SAAM,mGACP,CAAC;EAAE,gBAAI,sBAAA;GACN,UAAO;GACP,MAAG;GACH,gBAAG,CAAA;IACD,MAAM;IACN,SAAK;IACL,SAAO;IACR,CAAC;GACF,IAAG,WAAS;AACV,WAAO;KAAA,gBAAa,OAAQ,EAC3B,IAAA,UAAA;AACC,aAAA,sEAAA,UAAA,QAAA,CAAA;QAED,CAAC;KAAA,gBAAgB,iBAAA;MAChB,MAAE;MACF,MAAI;MACL,CAAC;KAAE,gBAAgB,SAAW,EAAE,CAAC;KAAE,gBAAM,OAAA,EACxC,IAAI,UAAU;AACZ,aAAA,sEAAA,UAAA,QAAA,CAAA;QAE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EJ,CAAC;EAAE,gBAAI,qBAAA;GACN,UAAO;GACP,MAAK;GACL,YAAY;GACZ,UAAM,IAAA;GACP,CAAC;EAAE,gBAAe,SAAA,EAAA,CAAA;EAAA,gBAAA,OAAA;GACjB,IAAI,UAAQ;AACV,WAAI,kCAAY,YAAA,QAAA,CAAA;;GAElB,IAAG,WAAA;AACD,WAAE,CAAA,gBAAA,YAAA;KACA,MAAA;KACA,UAAM;KACP,CAAC,EAAA,gBAAgB,cAAA,EAChB,UAAE,oGACH,CAAC,CAAC;;GAEN,CAAC;EAAE,gBAAiB,qBAAsB;GACzC,UAAM;GACN,OAAK;GACL,MAAI;GACJ,YAAY,CAAC;IACX,MAAM;IACN,MAAM;IACP,CAAC;GACF,YAAK;GACL,UAAI,IAAU;;;;;GAGd,IAAI,UAAU;AACZ,WAAO,gCAAgC,YAAA,QAAA,CAAqB;;GAE9D,IAAI,WAAW;AACb,WAAI,CAAA,gBAAsB,YAAY;KACpC,MAAA;;KAED,CAAC,EAAA,gBAAoB,cAAY,EAChC,UAAS,oGACV,CAAC,CAAA;;GAEL,CAAA;EAAA,gBAAA,qBAAA;GACH,UAAA;;GAEA,MAAO;GACL,gBAAgB,CAAA;IACZ,MAAI;IACP,SAAA;;IAED,CAAA;GACE,YAAU;IAAA;KACZ,MAAA;KACI,MAAC;KACL;IAAK;;KAEL,MAAO;KACJ;IAAA;KACC,MAAI;KACJ,MAAA;KACD;IAAE;KACD,MAAA;KACA,MAAG;KACJ;IAAC;GACF,YAAI;GACJ,UAAE,IAAA;;;;;;;;;;;GAWH,CAAA;EAAA"}
1
+ {"version":3,"file":"state-builtin.mjs","names":[],"sources":["../../src/components/state-builtin.tsx"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Shell Shock\n\n This code was released as part of the Shell Shock project. Shell Shock\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/shell-shock.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/shell-shock\n Documentation: https://docs.stormsoftware.com/projects/shell-shock\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport { code, computed, For, Show, splitProps } from \"@alloy-js/core\";\nimport {\n FunctionDeclaration,\n InterfaceDeclaration,\n InterfaceMember,\n TypeDeclaration,\n VarDeclaration\n} from \"@alloy-js/typescript\";\nimport { Spacing } from \"@powerlines/plugin-alloy/core/components/spacing\";\nimport { usePowerlines } from \"@powerlines/plugin-alloy/core/contexts/context\";\nimport type { BuiltinFileProps } from \"@powerlines/plugin-alloy/typescript/components/builtin-file\";\nimport { BuiltinFile } from \"@powerlines/plugin-alloy/typescript/components/builtin-file\";\nimport {\n TSDoc,\n TSDocInternal,\n TSDocLink,\n TSDocParam,\n TSDocRemarks,\n TSDocReturns\n} from \"@powerlines/plugin-alloy/typescript/components/tsdoc\";\nimport defu from \"defu\";\nimport { computedOptions } from \"../contexts/options\";\nimport { getAppBin } from \"../plugin-utils\";\nimport { getAppTitle } from \"../plugin-utils/context-helpers\";\nimport type { Context } from \"../types\";\nimport { OptionsMember, OptionsParserLogic } from \"./options-parser-logic\";\n\nexport function GlobalTypeDefinitions() {\n const context = usePowerlines<Context>();\n\n const options = computed(() => computedOptions(context.options));\n\n return (\n <>\n <TSDoc\n heading={`An object representing the global options available for every command in the ${getAppTitle(\n context,\n true\n )} command-line application.`}\n />\n <InterfaceDeclaration export name=\"GlobalOptions\">\n <For each={Object.values(options.value)} hardline>\n {option => <OptionsMember option={option} />}\n </For>\n </InterfaceDeclaration>\n <Spacing />\n <TSDoc heading=\"The context object for the current command execution, containing the command path and segments.\" />\n <InterfaceDeclaration\n export\n name=\"CommandContext\"\n typeParameters={[\n {\n name: \"THandler\",\n extends: \"(...params: any[]) => any\",\n default: \"any\"\n }\n ]}>\n <TSDoc\n heading={`The full command path as a string. For example, if the user runs \\`${getAppBin(\n context\n )} foo bar\\`, this would be \\`foo bar\\`. This is useful for commands that need to know their full invocation path, such as for help text or for commands that have dynamic behavior based on their position in the command hierarchy.`}\n />\n <InterfaceMember name=\"path\" type=\"string\" />\n <Spacing />\n <TSDoc\n heading={`An array of command path segments. For example, if the user runs \\`${getAppBin(\n context\n )} foo bar\\`, this would be \\`[\"foo\", \"bar\"]\\`. This is useful for commands that need to know their individual path segments, such as for dynamic routing or for commands that have behavior based on specific segments in the command hierarchy.`}\n />\n <InterfaceMember name=\"segments\" type=\"string[]\" />\n <Spacing />\n <TSDoc\n heading={`The parameters for the current command's handler function.`}\n />\n <InterfaceMember name=\"params\" type=\"Parameters<THandler>\" />\n </InterfaceDeclaration>\n <Spacing />\n <TypeDeclaration export name=\"GlobalContextStatus\">\n {code`\"initializing\" | \"preparing\" | \"executing\" | \"completed\"`}\n </TypeDeclaration>\n <Spacing />\n <TSDoc\n heading={`The state object for the ${getAppTitle(context)} application context.`}\n />\n <InterfaceDeclaration export name=\"GlobalContextState\">\n <TSDoc heading=\"The unique identifier for the current execution context.\" />\n <InterfaceMember name=\"executionId\" type=\"string\" />\n <Spacing />\n <TSDoc heading=\"The status of the current execution context.\" />\n <InterfaceMember name=\"status\" type=\"GlobalContextStatus\" />\n <Spacing />\n <TSDoc heading=\"Indicates whether the current execution context has encountered an error.\" />\n <InterfaceMember name=\"isError\" type=\"boolean\" />\n <Spacing />\n <TSDoc heading=\"A map containing arbitrary data associated with the current execution context.\" />\n <InterfaceMember name=\"meta\" type=\"Map<string, unknown>\" />\n </InterfaceDeclaration>\n <Spacing />\n <TSDoc\n heading={`The context object for the ${getAppTitle(context)} application.`}\n />\n <InterfaceDeclaration export name=\"GlobalContext\">\n <TSDoc heading=\"The global options shared across all commands in the application.\" />\n <InterfaceMember name=\"options\" type=\"GlobalOptions\" />\n <Spacing />\n <TSDoc heading=\"The raw command-line arguments passed to the application.\" />\n <InterfaceMember name=\"inputArgs\" type=\"string[]\" />\n <Spacing />\n <TSDoc heading=\"The state of the current execution context.\" />\n <InterfaceMember name=\"state\" type=\"GlobalContextState\" />\n </InterfaceDeclaration>\n </>\n );\n}\n\n/**\n * Generates utilities for detecting terminal color support.\n */\nexport function ArgsUtilities() {\n return (\n <>\n <TSDoc heading=\"Retrieves the command-line arguments from Deno or Node.js environments.\">\n <TSDocRemarks>\n {`This function is only intended for internal use. Please use \\`useArgs()\\` instead.`}\n </TSDocRemarks>\n <Spacing />\n <TSDocInternal />\n <Spacing />\n <TSDocReturns>\n {`An array of command-line arguments from Deno or Node.js environments.`}\n </TSDocReturns>\n </TSDoc>\n <FunctionDeclaration name=\"getInputArgs\" returnType=\"string[]\">\n {code`return ((globalThis as { Deno?: { args: string[] } })?.Deno?.args ?? process.argv ?? []) as string[];`}\n </FunctionDeclaration>\n </>\n );\n}\n\nexport function ContextUtilities() {\n const context = usePowerlines<Context>();\n\n const options = computed(() =>\n Object.fromEntries(context.options.map(option => [option.name, option]))\n );\n\n return (\n <>\n <Spacing />\n\n <TSDoc\n heading={`The global ${getAppTitle(context)} application context store instance.`}>\n <TSDocInternal />\n </TSDoc>\n <VarDeclaration export const name=\"unstable_globalStore\">\n {code` new AsyncLocalStorage<GlobalContext>({ name: \"globalStore\" }); `}\n </VarDeclaration>\n <Spacing />\n <TSDoc\n heading={`Get the ${getAppTitle(\n context\n )} application context for the current application.`}>\n <TSDocReturns>\n {`The ${getAppTitle(\n context\n )} application context for the current application or undefined if the context is not available.`}\n </TSDocReturns>\n </TSDoc>\n <FunctionDeclaration export name=\"useGlobal\" returnType=\"GlobalContext\">\n {code`return unstable_globalStore.getStore() as GlobalContext;`}\n </FunctionDeclaration>\n <Spacing />\n <TSDoc\n heading={`A utility hook function to get the command-line arguments from the ${getAppTitle(\n context\n )} application context.`}>\n <TSDocReturns>\n {\"An array of command-line arguments from the application context.\"}\n </TSDocReturns>\n </TSDoc>\n <FunctionDeclaration export name=\"useArgs\" returnType=\"string[]\">\n {code`return useGlobal()?.inputArgs ?? getInputArgs();`}\n </FunctionDeclaration>\n <Spacing />\n <TSDoc\n heading={`A utility hook function to get the command-line global options from the ${getAppTitle(\n context\n )} application context.`}>\n <TSDocReturns>\n {\n \"An object containing the global options from the application context.\"\n }\n </TSDocReturns>\n </TSDoc>\n <FunctionDeclaration\n export\n name=\"useGlobalOptions\"\n returnType=\"GlobalOptions\">\n {code`return useGlobal()?.options ?? {};`}\n </FunctionDeclaration>\n <Spacing />\n <TSDoc\n heading={`A utility hook function to get the state of the ${getAppTitle(\n context\n )} application context.`}>\n <TSDocReturns>{\"The state of the application context.\"}</TSDocReturns>\n </TSDoc>\n <FunctionDeclaration\n export\n name=\"useState\"\n returnType=\"GlobalContextState\">\n {code`return useGlobal()?.state;`}\n </FunctionDeclaration>\n <Spacing />\n <TSDoc\n heading={`A utility function to update the state of the ${getAppTitle(\n context\n )} application context.`}>\n <TSDocRemarks>\n {`This function will throw an error if the global context is not available, so it should only be used within a valid context scope, such as within a command handler or within the \\`withGlobal()\\` function.`}\n </TSDocRemarks>\n <Spacing />\n <TSDocParam name=\"update\">\n {`The new state or a function that receives the previous state and returns the new state. This allows for both direct state updates and functional updates based on the previous state.`}\n </TSDocParam>\n </TSDoc>\n <FunctionDeclaration\n export\n name=\"setState\"\n parameters={[\n {\n name: \"update\",\n type: \"Partial<GlobalContextState> | ((prev: GlobalContextState) => GlobalContextState)\"\n }\n ]}>\n {code`const prev = useGlobal()?.state;\n if (!prev) {\n throw new Error(\n \\`The ${getAppTitle(\n context\n )} application context is not available. Make sure to call setState() within a valid context scope.\\`\n );\n }\n\n useGlobal().state = typeof update === \"function\" ? update(prev) : { ...prev, ...update }; `}\n </FunctionDeclaration>\n <Spacing />\n <TSDoc\n heading={`A utility hook function to get the execution ID of the ${getAppTitle(\n context\n )} application context.`}>\n <TSDocReturns>\n {\"The execution ID of the application context.\"}\n </TSDocReturns>\n </TSDoc>\n <FunctionDeclaration export name=\"useExecutionId\" returnType=\"string\">\n {code`return useState().executionId;`}\n </FunctionDeclaration>\n <Spacing />\n <TSDoc\n heading={`A utility hook function to get the metadata of the ${getAppTitle(\n context\n )} application context.`}>\n <TSDocReturns>\n {\"The metadata of the application context.\"}\n </TSDocReturns>\n </TSDoc>\n <FunctionDeclaration\n export\n name=\"useMeta\"\n returnType=\"Map<string, unknown>\">\n {code`return useState().meta;`}\n </FunctionDeclaration>\n <Spacing />\n <TSDoc\n heading={`A utility hook function to get the current status of the ${getAppTitle(\n context\n )} application.`}>\n <TSDocReturns>{\"The current status of the application.\"}</TSDocReturns>\n </TSDoc>\n <FunctionDeclaration\n export\n name=\"useStatus\"\n returnType=\"GlobalContextStatus\">\n {code`return useState().status;`}\n </FunctionDeclaration>\n <Spacing />\n <TSDoc\n heading={`The global ${getAppTitle(context)} - command context store instance.`}>\n <TSDocInternal />\n </TSDoc>\n <VarDeclaration export name=\"unstable_commandStore\">\n {code`new AsyncLocalStorage<CommandContext>({ name: \"commandStore\" });`}\n </VarDeclaration>\n <Spacing />\n <TSDoc\n heading={`Get the ${getAppTitle(context)} - command context for the current application.`}>\n <TSDocReturns>\n {`The ${getAppTitle(context)} - command context for the current application.`}\n </TSDocReturns>\n </TSDoc>\n <FunctionDeclaration export name=\"useCommand\" returnType=\"CommandContext\">\n {code`const result = unstable_commandStore.getStore();\nif (!result) {\n throw new Error(\n \\`The ${getAppTitle(context)} - command context is not available. Make sure to call useCommand() within a valid context scope.\\`\n );\n}\nreturn result;`}\n </FunctionDeclaration>\n <Spacing />\n <TSDoc heading=\"A utility hook function to get the individual segments of the current command path.\">\n <TSDocReturns>{\"An array of command path segments.\"}</TSDocReturns>\n </TSDoc>\n <FunctionDeclaration export name=\"useSegments\" returnType=\"string[]\">\n {code`return useCommand().segments;`}\n </FunctionDeclaration>\n <Spacing />\n <TSDoc heading=\"A utility hook function to get the full command path as a string.\">\n <TSDocReturns>\n {`The full command path as a string. For example, if the user runs \\`${getAppBin(\n context\n )} foo bar\\`, this would return \\`\"foo bar\"\\`. This is useful for commands that need to know their full invocation path, such as for help text or for commands that have dynamic behavior based on their position in the command hierarchy.`}\n </TSDocReturns>\n </TSDoc>\n <FunctionDeclaration export name=\"usePath\" returnType=\"string\">\n {code`return useCommand().path;`}\n </FunctionDeclaration>\n <Spacing />\n <TSDoc heading=\"Checks if a specific flag is present in the command-line arguments.\">\n <TSDocLink>\n {\"https://github.com/sindresorhus/has-flag/blob/main/index.js\"}\n </TSDocLink>\n <TSDocParam name=\"flag\">\n {\n 'The flag (or an array of flags/aliases) to check for, e.g., \"color\", \"no-color\".'\n }\n </TSDocParam>\n <TSDocParam name=\"argv\">\n {\n \"The command-line arguments to check against. Defaults to global Deno args or process args.\"\n }\n </TSDocParam>\n <TSDocReturns>\n {\"True if the flag is present, false otherwise.\"}\n </TSDocReturns>\n </TSDoc>\n <FunctionDeclaration\n export\n name=\"hasFlag\"\n parameters={[\n { name: \"flag\", type: \"string | string[]\" },\n {\n name: \"argv\",\n type: \"string[]\",\n default: \"useArgs()\"\n }\n ]}>\n <VarDeclaration\n const\n name=\"position\"\n type=\"number\"\n initializer={code`(Array.isArray(flag) ? flag : [flag]).reduce((ret, f) => {\n const pos = argv.findIndex(arg => (f.startsWith(\"-\") ? \"\" : (f.length === 1 ? \"-\" : \"--\") + f)?.toLowerCase() === arg?.toLowerCase() || arg?.toLowerCase().startsWith((f.length === 1 ? \"-\" : \"--\") + f + \"=\"));\n return pos !== -1 ? pos : ret;\n }, -1);`}\n />\n <hbr />\n {code`return position !== -1 && argv.indexOf(\"--\") === -1 || position < argv.indexOf(\"--\");`}\n </FunctionDeclaration>\n <Spacing />\n <TSDoc heading=\"A utility function to determine if the help flag is present or if the command is in an error state during preparation.\">\n <TSDocReturns>\n {`True if the help flag is present or if the command is in an error state during preparation, false otherwise. This can be used to conditionally display help text or to alter command behavior when the user is likely seeking help.`}\n </TSDocReturns>\n </TSDoc>\n <FunctionDeclaration export name=\"isHelp\" returnType=\"boolean\">\n {code`return !isCI && (hasFlag([\"help\", \"h\", \"?\"]) || (useStatus() === \"preparing\" && useState().isError)); `}\n </FunctionDeclaration>\n <Spacing />\n <TSDoc\n heading={`A utility function to wrap the ${getAppTitle(\n context\n )} application within the global context scope.`}>\n <TSDocParam name=\"handler\">\n {`The callback function to run within the global context scope. This function will receive the global context as its argument, allowing it to access any properties or utilities defined on the context. The callback function can be asynchronous and can return a value or a promise.`}\n </TSDocParam>\n <TSDocReturns>\n {`The result of the callback function, which can be a value or a promise that resolves to a value.`}\n </TSDocReturns>\n </TSDoc>\n <FunctionDeclaration\n export\n async\n name=\"withGlobal\"\n parameters={[{ name: \"handler\", type: \"() => any\" }]}\n returnType=\"Promise<void>\">\n <VarDeclaration\n const\n name=\"args\"\n initializer={code`getInputArgs(); `}\n />\n <Spacing />\n <OptionsParserLogic\n options={options.value}\n appSpecificEnvPrefix={context.config.appSpecificEnvPrefix}\n isCaseSensitive={context.config.isCaseSensitive}\n />\n <Spacing />\n {code`\n return unstable_globalStore.run({ options, inputArgs: args, state: { executionId: randomUUID(), status: \"initializing\", isError: false, meta: new Map() } as GlobalContextState }, handler);`}\n </FunctionDeclaration>\n <Spacing />\n <TSDoc\n heading={`A utility function to wrap a ${getAppTitle(\n context\n )} application command handler within the command context scope.`}>\n <TSDocParam name=\"handler\">\n {`The callback function to run within the command context scope. This function will receive the command context as its argument, allowing it to access any properties or utilities defined on the context. The callback function can be asynchronous and can return a value or a promise.`}\n </TSDocParam>\n <TSDocReturns>\n {`The result of the callback function, which can be a value or a promise that resolves to a value.`}\n </TSDocReturns>\n </TSDoc>\n <FunctionDeclaration\n export\n async\n name=\"withCommand\"\n typeParameters={[\n {\n name: \"THandler\",\n extends: \"(this: CommandContext, ...params: any[]) => any\",\n default: \"(this: CommandContext, ...params: any[]) => any\"\n }\n ]}\n parameters={[\n { name: \"path\", type: \"string\" },\n { name: \"segments\", type: \"string[]\" },\n { name: \"params\", type: \"Parameters<THandler>\" },\n { name: \"handler\", type: \"THandler\" }\n ]}\n returnType=\"Promise<{ error: string | Error | null }>\">\n {code`setState({ status: \"preparing\", isError: false });\n\n const ctx = { path, segments, params } as CommandContext<THandler>;\n const result = await Promise.resolve(unstable_commandStore.run(ctx, Reflect.apply(handler, ctx, params)));\n if (result instanceof Error || (typeof result === \"object\" && ((result as { error: unknown }).error instanceof Error || typeof (result as { error: unknown }).error === \"string\"))) {\n setState({ status: \"completed\", isError: true });\n return { error: result instanceof Error ? result : (result as { error: Error | string }).error };\n }\n\n setState({ status: \"completed\", isError: false });\n return { error: null }; `}\n </FunctionDeclaration>\n </>\n );\n}\n\nexport interface StateBuiltinProps extends Omit<\n BuiltinFileProps,\n \"id\" | \"description\"\n> {}\n\n/**\n * A built-in module for handling application state utilities in Shell Shock.\n */\nexport function StateBuiltin(props: StateBuiltinProps) {\n const [{ children }, rest] = splitProps(props, [\"children\"]);\n\n return (\n <BuiltinFile\n id=\"state\"\n description=\"A module that provides context hooks and utilities for accessing the application state.\"\n {...rest}\n imports={defu(rest.imports ?? {}, {\n \"node:async_hooks\": [\"AsyncLocalStorage\"],\n \"node:crypto\": [\"randomUUID\"]\n })}\n builtinImports={defu(rest.builtinImports ?? {}, {\n env: [\"isCI\", \"env\"]\n })}>\n <GlobalTypeDefinitions />\n <Spacing />\n <ArgsUtilities />\n <Spacing />\n <ContextUtilities />\n <Spacing />\n <Show when={Boolean(children)}>{children}</Show>\n </BuiltinFile>\n );\n}\n"],"mappings":";;;;;;;;;;;;;;AAgCA,SAAe,wBAAA;CACb,MAAA,UAAS,eAAA;CACT,MAAA,UAAU,eAAA,gBAAA,QAAA,QAAA,CAAA;AACV,QAAA;EAAA,gBAAY,OAAA,EACZ,IAAA,UAAA;AACI,UAAG,gFAAoD,YAAA,SAAA,KAAA,CAAA;KAE7D,CAAA;EAAM,gBAAkB,sBAAqB;GAC7C,UAAS;GACT,MAAS;GACT,IAAO,WAAO;AACR,WAAG,gBAAe,KAAA;;AAEjB,aAAS,OAAA,OAAA,QAAuB,MAAC;;;KAGhC,WAAU,WAAU,gBAAK,eAAwB,UAEhD,CAAA;KACJ,CAAA;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,gBAAA,gBAAA;MACC,SAAA;MACA,MAAA;MACA,aAAM,IAAW;MAClB,CAAC;KAAA,gBAAgB,SAAA,EAAA,CAAA;KAAA,gBAAA,oBAAA;MAChB,IAAE,UAAA;AACA,cAAO,QAAE;;MAEX,IAAI,uBAAiB;AACnB,cAAA,QAAA,OAAA;;MAEF,IAAA,kBAAY;AACV,cAAO,QAAQ,OAAO;;MAEzB,CAAC;KAAE,gBAAkB,SAAO,EAAA,CAAA;KAAA,IAAW;;KACA;;GAE3C,CAAC;EAAE,gBAAc,SAAU,EAAK,CAAC;EAAC,gBAAiB,OAAQ;GAC1D,IAAI,UAAM;;;GAGV,IAAI,WAAM;AACR,WAAM,CAAA,gBAAkB,YAAU;KAChC,MAAE;KACF,UAAU;KACX,CAAC,EAAA,gBAAA,cAAA,gHAED,CAAC,CAAA;;GAEL,CAAC;EAAE,gBAAE,qBAAmB;GACvB,UAAE;GACH,OAAA;GACH,MAAA;;IAEM,MAAC;IACL,SAAA;IACI,SAAI;IACP,CAAA;;;KAED,MAAA;KACG,MAAM;KACT;IAAA;KACI,MAAC;KACL,MAAS;;;KAET,MAAO;KACJ,MAAA;KACA;IAAC;KACA,MAAA;KACA,MAAI;KACL;IAAC;GACF,YAAU;GACV,UAAU,IAAA;;;;;;;;;;;GAWX,CAAC;EAAC"}
@@ -210,6 +210,149 @@ function FindSuggestionsDeclaration() {
210
210
  ];
211
211
  }
212
212
  /**
213
+ * Generates utilities for detecting terminal size and whether the process is running in the foreground, which can be used to determine how to render output (e.g., whether to use a progress bar or spinner).
214
+ */
215
+ function TerminalSizeDeclaration() {
216
+ return [
217
+ (0, _alloy_js_core_jsx_runtime.createComponent)(_alloy_js_typescript.VarDeclaration, {
218
+ "export": true,
219
+ "const": true,
220
+ name: "DEFAULT_TERMINAL_COLUMNS",
221
+ doc: "Default number of terminal columns",
222
+ initializer: _alloy_js_core.code`80`
223
+ }),
224
+ (0, _alloy_js_core_jsx_runtime.createComponent)(_powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
225
+ (0, _alloy_js_core_jsx_runtime.createComponent)(_alloy_js_typescript.VarDeclaration, {
226
+ "export": true,
227
+ "const": true,
228
+ name: "DEFAULT_TERMINAL_ROWS",
229
+ doc: "Default number of terminal rows",
230
+ initializer: _alloy_js_core.code`24`
231
+ }),
232
+ (0, _alloy_js_core_jsx_runtime.createComponent)(_powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
233
+ (0, _alloy_js_core_jsx_runtime.createComponent)(_alloy_js_typescript.FunctionDeclaration, {
234
+ name: "isForegroundProcess",
235
+ children: _alloy_js_core.code`if (isLinux) {
236
+ return true;
237
+ }
238
+
239
+ try {
240
+ const statContents = readFileSync("/proc/self/stat", "utf8");
241
+ const closingParenthesisIndex = statContents.lastIndexOf(') ');
242
+
243
+ if (closingParenthesisIndex === -1) {
244
+ return false;
245
+ }
246
+
247
+ const statFields = statContents.slice(closingParenthesisIndex + 2).trim().split(/\\s+/);
248
+ const processGroupId = Number.parseInt(statFields[2], 10);
249
+ const foregroundProcessGroupId = Number.parseInt(statFields[5], 10);
250
+
251
+ if (Number.isNaN(processGroupId) || Number.isNaN(foregroundProcessGroupId)) {
252
+ return false;
253
+ }
254
+
255
+ if (foregroundProcessGroupId <= 0) {
256
+ return false;
257
+ }
258
+
259
+ return processGroupId === foregroundProcessGroupId;
260
+ } catch {
261
+ return false;
262
+ } `
263
+ }),
264
+ (0, _alloy_js_core_jsx_runtime.createComponent)(_powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
265
+ (0, _alloy_js_core_jsx_runtime.createComponent)(_alloy_js_typescript.FunctionDeclaration, {
266
+ name: "tput",
267
+ children: _alloy_js_core.code`try {
268
+ const columns = execSync(["tput", "cols"], { env: { TERM: 'dumb', ...process.env } });
269
+ const rows = execSync(["tput", "lines"], { env: { TERM: 'dumb', ...process.env } });
270
+
271
+ if (columns && rows) {
272
+ return { columns: Number.parseInt(columns.toString().trim(), 10), rows: Number.parseInt(rows.toString().trim(), 10) };
273
+ }
274
+ } catch {} `
275
+ }),
276
+ (0, _alloy_js_core_jsx_runtime.createComponent)(_powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
277
+ (0, _alloy_js_core_jsx_runtime.createComponent)(_alloy_js_typescript.FunctionDeclaration, {
278
+ name: "devTty",
279
+ children: _alloy_js_core.code`try {
280
+ const writeStream = new WriteStream(
281
+ openSync(
282
+ "/dev/tty",
283
+ fsConstants.O_NONBLOCK
284
+ )
285
+ ).getWindowSize();
286
+
287
+ return { columns: writeStream[0], rows: writeStream[1] };
288
+ } catch {} `
289
+ }),
290
+ (0, _alloy_js_core_jsx_runtime.createComponent)(_powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
291
+ (0, _alloy_js_core_jsx_runtime.createComponent)(_powerlines_plugin_alloy_typescript_components_tsdoc.TSDoc, {
292
+ heading: "A utility function that attempts to determine the size of the terminal (number of columns and rows) using various methods, and falls back to default values if it cannot be determined. This can be used to adjust output formatting based on the available terminal size.",
293
+ get children() {
294
+ return [
295
+ (0, _alloy_js_core_jsx_runtime.createComponent)(_powerlines_plugin_alloy_typescript_components_tsdoc.TSDocRemarks, { children: "The function first checks if the process is running in a TTY environment and if the stdout or stderr streams provide column and row information. If not, it attempts to use platform-specific methods (like reading from /proc/self/stat on Linux, using tput on Unix-like systems, or checking /dev/tty) to determine the terminal size. If all else fails, it returns default values." }),
296
+ (0, _alloy_js_core_jsx_runtime.createComponent)(_powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
297
+ (0, _alloy_js_core_jsx_runtime.createComponent)(_powerlines_plugin_alloy_typescript_components_tsdoc.TSDocReturns, { children: "An object containing the number of columns and rows of the terminal." })
298
+ ];
299
+ }
300
+ }),
301
+ (0, _alloy_js_core_jsx_runtime.createComponent)(_alloy_js_typescript.FunctionDeclaration, {
302
+ "export": true,
303
+ name: "getTerminalSize",
304
+ returnType: "{ columns: number; rows: number; }",
305
+ get children() {
306
+ return [
307
+ (0, _alloy_js_core_jsx_runtime.createComponent)(_alloy_js_typescript.IfStatement, {
308
+ condition: _alloy_js_core.code`process.stdout?.columns && process.stdout?.rows`,
309
+ children: _alloy_js_core.code`return { columns: process.stdout.columns, rows: process.stdout.rows }; `
310
+ }),
311
+ (0, _alloy_js_core_jsx_runtime.createComponent)(_alloy_js_typescript.IfStatement, {
312
+ condition: _alloy_js_core.code`process.stderr?.columns && process.stderr?.rows`,
313
+ children: _alloy_js_core.code`return { columns: process.stderr.columns, rows: process.stderr.rows };`
314
+ }),
315
+ (0, _alloy_js_core_jsx_runtime.createComponent)(_powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
316
+ (0, _alloy_js_core_jsx_runtime.createComponent)(_alloy_js_typescript.IfStatement, {
317
+ condition: _alloy_js_core.code`isWindows`,
318
+ children: _alloy_js_core.code`return tput() ?? {
319
+ columns: DEFAULT_TERMINAL_COLUMNS,
320
+ rows: DEFAULT_TERMINAL_ROWS,
321
+ }; `
322
+ }),
323
+ (0, _alloy_js_core_jsx_runtime.createComponent)(_alloy_js_typescript.IfStatement, {
324
+ condition: _alloy_js_core.code`isMacOS`,
325
+ children: _alloy_js_core.code`return devTty() ?? tput() ?? {
326
+ columns: DEFAULT_TERMINAL_COLUMNS,
327
+ rows: DEFAULT_TERMINAL_ROWS,
328
+ }; `
329
+ }),
330
+ (0, _alloy_js_core_jsx_runtime.createComponent)(_powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
331
+ (0, _alloy_js_core_jsx_runtime.createComponent)(_alloy_js_typescript.VarDeclaration, {
332
+ "let": true,
333
+ name: "result",
334
+ initializer: _alloy_js_core.code`devTty() ?? tput(); `
335
+ }),
336
+ (0, _alloy_js_core_jsx_runtime.createComponent)(_alloy_js_typescript.IfStatement, {
337
+ condition: _alloy_js_core.code`!result && isForegroundProcess()`,
338
+ children: _alloy_js_core.code`try {
339
+ const size = execSync(["resize", "-u"]).match(/\\d+/g);
340
+ if (size.length === 2) {
341
+ result = { columns: Number.parseInt(size[0], 10), rows: Number.parseInt(size[1], 10) };
342
+ }
343
+ } catch {} `
344
+ }),
345
+ (0, _alloy_js_core_jsx_runtime.createComponent)(_powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
346
+ _alloy_js_core.code`return result ?? {
347
+ columns: DEFAULT_TERMINAL_COLUMNS,
348
+ rows: DEFAULT_TERMINAL_ROWS,
349
+ }; `
350
+ ];
351
+ }
352
+ })
353
+ ];
354
+ }
355
+ /**
213
356
  * Generates utilities for detecting terminal color support.
214
357
  */
215
358
  function EnvSupportUtilities() {
@@ -1562,6 +1705,10 @@ function UtilsBuiltin(props) {
1562
1705
  "isAbsolute"
1563
1706
  ],
1564
1707
  "node:fs": [
1708
+ {
1709
+ name: "constants",
1710
+ alias: "fsConstants"
1711
+ },
1565
1712
  "openSync",
1566
1713
  "closeSync",
1567
1714
  "read",
@@ -1570,6 +1717,7 @@ function UtilsBuiltin(props) {
1570
1717
  "realpathSync"
1571
1718
  ],
1572
1719
  "node:fs/promises": ["stat"],
1720
+ "node:tty": ["WriteStream"],
1573
1721
  "node:util": ["promisify"],
1574
1722
  "node:url": ["fileURLToPath", "pathToFileURL"],
1575
1723
  "node:module": ["builtinModules"]
@@ -1587,9 +1735,12 @@ function UtilsBuiltin(props) {
1587
1735
  "isCI",
1588
1736
  "isTest",
1589
1737
  "isWindows",
1738
+ "isLinux",
1739
+ "isMacOS",
1590
1740
  "isDevelopment",
1591
1741
  "isDebug"
1592
1742
  ],
1743
+ exec: ["execSync"],
1593
1744
  state: ["hasFlag"]
1594
1745
  });
1595
1746
  },
@@ -1615,6 +1766,8 @@ function UtilsBuiltin(props) {
1615
1766
  children: _alloy_js_core.code`return new Promise((resolve) => setTimeout(resolve, durationMs)); `
1616
1767
  }),
1617
1768
  (0, _alloy_js_core_jsx_runtime.createComponent)(_powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
1769
+ (0, _alloy_js_core_jsx_runtime.createComponent)(TerminalSizeDeclaration, {}),
1770
+ (0, _alloy_js_core_jsx_runtime.createComponent)(_powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
1618
1771
  (0, _alloy_js_core_jsx_runtime.createComponent)(EnvSupportUtilities, {}),
1619
1772
  (0, _alloy_js_core_jsx_runtime.createComponent)(_powerlines_plugin_alloy_core_components_spacing.Spacing, {}),
1620
1773
  (0, _alloy_js_core_jsx_runtime.createComponent)(HyperlinkSupportUtilities, {}),
@@ -1642,5 +1795,6 @@ exports.EnvSupportUtilities = EnvSupportUtilities;
1642
1795
  exports.FindSuggestionsDeclaration = FindSuggestionsDeclaration;
1643
1796
  exports.HyperlinkSupportUtilities = HyperlinkSupportUtilities;
1644
1797
  exports.ResolveModuleFunctionDeclaration = ResolveModuleFunctionDeclaration;
1798
+ exports.TerminalSizeDeclaration = TerminalSizeDeclaration;
1645
1799
  exports.UtilsBuiltin = UtilsBuiltin;
1646
1800
  //# sourceMappingURL=utils-builtin.cjs.map