Skip to content

Instantly share code, notes, and snippets.

@rafikhan
Last active May 2, 2023 23:32
Show Gist options
  • Save rafikhan/f3f9e7a77b71c6a1150ff6e8f0f50353 to your computer and use it in GitHub Desktop.
Save rafikhan/f3f9e7a77b71c6a1150ff6e8f0f50353 to your computer and use it in GitHub Desktop.
A quick and dirty copy/paste of most of the internal typings for KBar. This comes directly from the KBar source code.
export interface IKBarManifest {
version: number;
createdDate: string;
toolbar: IToolbar;
isBaked: boolean;
notes: string;
scripts: IManifestDependency[];
presets: IManifestDependency[];
shell: IManifestDependency[];
}
export interface IManifestDependency {
source: string;
}
export interface IToolbar {
id: string;
name: string;
buttons: AllowedRootButtons[];
}
export enum IconType {
Text,
FontAwesome,
Custom,
}
export interface IIcon {
type: IconType;
path: string;
color: string;
}
export type IRootButton = {
id: string;
type: ButtonType;
name: string;
description: string;
icon: IIcon;
modifiers: IModifiers;
};
export type IModifierButton = {
id: string;
type: ButtonType;
name: string;
description: string;
icon: IIcon;
};
export enum ButtonType {
SetExpression = 0,
InvokeScript = 1,
InvokeScriptlet = 2,
ApplyEffect = 3,
ApplyPreset = 4,
InvokeMenuItem = 5,
OpenExtension = 6,
RunShellCommand = 7,
Spacer = 8,
}
export enum ButtonModifier {
Ctrl = 'ctrl',
Alt = 'alt',
Shift = 'shift',
CtrlAlt = 'ctrlalt',
CtrlShift = 'ctrlshift',
AltShift = 'altshift',
CtrlAltShift = 'ctrlaltshift',
}
export interface IModifiers {
[key: string]: AllowedModifierButtons | null;
[ButtonModifier.Ctrl]: AllowedModifierButtons | null;
[ButtonModifier.Alt]: AllowedModifierButtons | null;
[ButtonModifier.Shift]: AllowedModifierButtons | null;
[ButtonModifier.CtrlAlt]: AllowedModifierButtons | null;
[ButtonModifier.CtrlShift]: AllowedModifierButtons | null;
[ButtonModifier.AltShift]: AllowedModifierButtons | null;
[ButtonModifier.CtrlAltShift]: AllowedModifierButtons | null;
}
interface ButtonBase {
id: string;
type: ButtonType;
}
interface SpacerData extends ButtonBase {
type: ButtonType.Spacer;
}
interface ActionButtonBase extends ButtonBase {
name: string;
description: string;
icon: IIcon;
}
interface InvokeMenuItemData extends ActionButtonBase {
type: ButtonType.InvokeMenuItem;
menuCommand: string;
}
interface SetExpressionData extends ActionButtonBase {
type: ButtonType.SetExpression;
expression: string;
}
interface InvokeScriptData extends ActionButtonBase {
type: ButtonType.InvokeScript;
filePath: string;
command: string;
argument: string;
}
interface RunShellCommandData extends ActionButtonBase {
type: ButtonType.RunShellCommand;
command: string;
argument: string;
isScriptFile: boolean;
}
interface InvokeScriptletData extends ActionButtonBase {
type: ButtonType.InvokeScriptlet;
script: string;
command: string;
argument: string;
}
interface ApplyEffectData extends ActionButtonBase {
type: ButtonType.ApplyEffect;
matchName: string;
displayName: string;
}
interface OpenExtensionData extends ActionButtonBase {
type: ButtonType.OpenExtension;
extensionId: string;
argument: string;
}
interface ApplyPresetData extends ActionButtonBase {
type: ButtonType.ApplyPreset;
presetPath: string;
}
export type ButtonTypeDataMap = {
[ButtonType.SetExpression]: SetExpressionData;
[ButtonType.InvokeScript]: InvokeScriptData;
[ButtonType.InvokeScriptlet]: InvokeScriptletData;
[ButtonType.ApplyEffect]: ApplyEffectData;
[ButtonType.ApplyPreset]: ApplyPresetData;
[ButtonType.InvokeMenuItem]: InvokeMenuItemData;
[ButtonType.OpenExtension]: OpenExtensionData;
[ButtonType.RunShellCommand]: RunShellCommandData;
[ButtonType.Spacer]: SpacerData;
};
type AllButtonDataTypes = ButtonTypeDataMap[keyof ButtonTypeDataMap];
export type ButtonData<T extends AllButtonDataTypes> = ButtonTypeDataMap[T['type']];
type ActionButtonDataTypes = Exclude<AllButtonDataTypes, SpacerData>;
export type AllowedRootButtons = AsRoot<AllButtonDataTypes>;
export type AllowedModifierButtons = AsModifier<ActionButtonDataTypes>;
export type ActionButtons = AsButton<ActionButtonDataTypes>;
export type AllButtons = AsButton<AllButtonDataTypes>;
export type IButton = IRootButton | IModifierButton;
export type AsRoot<T> = T & IRootButton;
export type AsModifier<T> = T & IModifierButton;
export type AsButton<T> = AsRoot<T> | AsModifier<T>;
export type AllowedRootButtons = AsRoot<AllButtonDataTypes>;
export type AllowedModifierButtons = AsModifier<ActionButtonDataTypes>;
export type ActionButtons = AsButton<ActionButtonDataTypes>;
export type AllButtons = AsButton<AllButtonDataTypes>;
export type ISpacerButton = AsRoot<SpacerData>;
export type IInvokeMenuButton = AsButton<InvokeMenuItemData>;
export type ISetExpressionButton = AsButton<SetExpressionData>;
export type IInvokeScriptButton = AsButton<InvokeScriptData>;
export type IRunShellCommandButton = AsButton<RunShellCommandData>;
export type IInvokeScriptletButton = AsButton<InvokeScriptletData>;
export type IApplyEffectButton = AsButton<ApplyEffectData>;
export type IOpenExtensionButton = AsButton<OpenExtensionData>;
export type IApplyPresetButton = AsButton<ApplyPresetData>;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment