import { z } from "zod"; import type { ShellNamespace } from "./desktop/shell"; declare const toggleSchema: z.ZodObject<{ default: z.ZodBoolean; kind: z.ZodLiteral<"toggle">; label: z.ZodString; }, z.core.$strict>; declare const choiceSchema: z.ZodObject<{ choices: z.ZodArray; default: z.ZodString; kind: z.ZodLiteral<"choice">; label: z.ZodString; }, z.core.$strict>; declare const numberSchema: z.ZodObject<{ default: z.ZodNumber; kind: z.ZodLiteral<"number">; label: z.ZodString; max: z.ZodOptional; min: z.ZodOptional; }, z.core.$strict>; declare const textSchema: z.ZodObject<{ default: z.ZodString; kind: z.ZodLiteral<"text">; label: z.ZodString; }, z.core.$strict>; declare const listSchema: z.ZodObject<{ default: z.ZodArray; kind: z.ZodLiteral<"list">; label: z.ZodString; }, z.core.$strict>; /** A switch. Its value is `true` or `false`. */ export type ToggleOption = z.infer; /** One of a list of words. */ export type ChoiceOption = Omit, "choices" | "default"> & { readonly choices: readonly C[]; readonly default: C; }; /** A number, within `min` and `max` when they are given. */ export type NumberOption = z.infer; /** A line of text. */ export type TextOption = z.infer; /** A list of lines of text. */ export type ListOption = Omit, "default"> & { readonly default: readonly string[]; }; /** One option a shell reads. */ export type Option = ToggleOption | ChoiceOption | NumberOption | TextOption | ListOption; /** Options under one key, as `clock: { format, seconds }`. */ export type GroupOption = { readonly kind: "group"; readonly options: T; }; /** A shell's declared options, by key: what `options.json` holds. */ export type Options = { readonly [key: string]: Option | GroupOption; }; /** What `defineOptions` takes: options, and plain objects of them as groups. */ export type OptionsInput = { readonly [key: string]: Option | OptionsInput; }; /** The declaration `defineOptions` makes of `T`. */ export type Declared = { readonly [K in keyof T]: T[K] extends Option ? T[K] : T[K] extends OptionsInput ? GroupOption> : never; }; /** The value each option in `T` has. */ export type OptionValues = { readonly [K in keyof T]: OptionValue; }; /** The value an option, or a group of them, has. */ export type OptionValue = E extends GroupOption ? OptionValues : E extends ToggleOption ? boolean : E extends ChoiceOption ? C : E extends NumberOption ? number : E extends TextOption ? string : E extends ListOption ? readonly string[] : never; /** The values a config gives, and why any it gave were dropped. */ export type ReadOptions = { readonly values: OptionValues; /** One line per value dropped: where it is, and what is wrong with it. */ readonly dropped: readonly string[]; }; /** `options.json`: a shell's declared options, by key. */ export declare const optionsSchema: z.ZodType; /** The option kinds, each with a label and a default. */ export declare const option: { choice: (label: string, choices: readonly C[], defaultChoice: C) => ChoiceOption; list: (label: string, defaultList: readonly string[]) => ListOption; number: (label: string, defaultNumber: number, limits?: { readonly min?: number; readonly max?: number; }) => NumberOption; text: (label: string, defaultText: string) => TextOption; toggle: (label: string, defaultValue: boolean) => ToggleOption; }; /** * A shell's options, for its `options` export. A plain object of options is a * group. Throws on a default its own choices or limits refuse. */ export declare const defineOptions: (input: T) => Declared; /** * The value of every option in `declared`: the config's where it gives a good * one, the default elsewhere. */ export declare const readOptions: (declared: T, given: Readonly> | undefined) => ReadOptions; /** * The value `given` sets for `option`, or its default where it sets none or * one `option` refuses. */ export declare const readOption: (option: O, given: unknown) => OptionValue; /** What is wrong with `value` for `option`, or `undefined` if nothing is. */ export declare const optionProblem: (option: Option, value: unknown) => string | undefined; /** What `watchShellOptions` needs of the desktop. */ export type ShellOptionsDesktop = { readonly shell: Pick; }; /** * Call `listener` with the values of `declared` now and each time the config * changes them. Returns a function that stops listening. * * A value the config gives that `declared` refuses is dropped, takes its * default and is passed to `report`, so the shell starts whatever the config * says. */ export declare const watchShellOptions: ({ shell }: ShellOptionsDesktop, declared: T, listener: (values: OptionValues) => void, report?: (dropped: string) => void) => (() => void); export {};