mirror of
https://github.com/Termix-SSH/Termix.git
synced 2026-10-28 22:25:24 +00:00
feat: move snippets, keybinding actions and macros out of core into plugins
This commit is contained in:
1 parent
d9bba10612
commit
e0c30a4e6f
262 files changed
+9091
-10744
No files matched your search
@@ -1,10 +1,7 @@
|
||||
import {
|
||||
getErrorMessage,
|
||||
extractSnippetInputs,
|
||||
type SnippetInput,
|
||||
} from "./helpers.js";
|
||||
import { getErrorMessage, type SnippetInput } from "./helpers.js";
|
||||
import { useState, useEffect, useCallback, useMemo, useRef } from "react";
|
||||
import {
|
||||
invokeAction,
|
||||
useTranslation,
|
||||
useHosts,
|
||||
type PluginHostRecord,
|
||||
@@ -792,8 +789,16 @@ function RunCommandTab({ api, fleetId }: { api: FleetsApi; fleetId: number }) {
|
||||
const [running, setRunning] = useState(false);
|
||||
const [results, setResults] = useState<FleetHostResult[] | null>(null);
|
||||
|
||||
// The snippets plugin owns $INPUT_n parsing; without it the command
|
||||
// runs as typed.
|
||||
useEffect(() => {
|
||||
setInputs(extractSnippetInputs(command));
|
||||
let cancelled = false;
|
||||
void invokeAction("snippets.extractInputs", command).then((found) => {
|
||||
if (!cancelled) setInputs(Array.isArray(found) ? found : []);
|
||||
});
|
||||
return () => {
|
||||
cancelled = true;
|
||||
};
|
||||
}, [command]);
|
||||
|
||||
async function handleRun() {
|
||||
|
||||
@@ -21,24 +21,3 @@ export interface SnippetInput {
|
||||
key: string;
|
||||
label: string;
|
||||
}
|
||||
|
||||
const INPUT_PATTERN =
|
||||
/\$\{INPUT_(\d+)(?::([^}$]+))?\}|\$INPUT_(\d+)(?![a-zA-Z0-9_])/g;
|
||||
|
||||
/**
|
||||
* Finds the $INPUT_n placeholders in a command, for the fleet run box's
|
||||
* input fields. Mirrors src/ui/lib/snippet-variables.ts extractSnippetInputs.
|
||||
*/
|
||||
export function extractSnippetInputs(content: string): SnippetInput[] {
|
||||
const seen = new Map<string, SnippetInput>();
|
||||
let match: RegExpExecArray | null;
|
||||
INPUT_PATTERN.lastIndex = 0;
|
||||
while ((match = INPUT_PATTERN.exec(content)) !== null) {
|
||||
const digits = match[1] ?? match[3];
|
||||
const key = `INPUT_${digits}`;
|
||||
if (!seen.has(key)) {
|
||||
seen.set(key, { key, label: match[2]?.trim() || `Input ${digits}` });
|
||||
}
|
||||
}
|
||||
return Array.from(seen.values());
|
||||
}
|
||||
Reference in new issue
Block a user