feat: delete fields tool
fix: field rename fix: list fields now scrolls
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import { cliPrompt } from "./prompts.ts";
|
||||
import type { TerminalBlock } from "./TerminalLayout.ts";
|
||||
|
||||
type prompt = [string, (v?: string) => boolean] | string;
|
||||
type prompt = [string, (v?: string) => boolean | undefined] | string;
|
||||
|
||||
export async function forceArgs(
|
||||
args: string[],
|
||||
|
@@ -13,6 +13,7 @@ const toolRegistry: [string, Promise<{ default: ITool }>][] = [
|
||||
["checkCode", import("../tools/checkCode.ts")],
|
||||
["fieldRename", import("../tools/fieldRename.ts")],
|
||||
["listFormFields", import("../tools/listFormFields.ts")],
|
||||
["deleteFields", import("../tools/deleteFields.ts")],
|
||||
];
|
||||
|
||||
export class PdfToolsCli {
|
||||
|
@@ -1,4 +1,5 @@
|
||||
import type { callback } from "../types.ts";
|
||||
import { log } from "util/logfile.ts";
|
||||
import { type CLICharEvent, InputManager } from "./InputManager.ts";
|
||||
import { cliLog } from "./prompts.ts";
|
||||
import { colorize } from "./style.ts";
|
||||
@@ -127,13 +128,16 @@ export async function selectMenuInteractive(
|
||||
|
||||
export async function multiSelectMenuInteractive(
|
||||
q: string,
|
||||
options: string[] | [string, callback][],
|
||||
config?: ISelectMenuConfig,
|
||||
options: (string | [string, callback])[],
|
||||
config?: ISelectMenuConfig & { allOption?: boolean },
|
||||
): Promise<string[] | null> {
|
||||
Deno.stdin.setRaw(true);
|
||||
let selected = 0;
|
||||
let selectedOptions: number[] = config?.initialSelections || [];
|
||||
|
||||
if (config?.allOption) {
|
||||
options.unshift("Select All");
|
||||
}
|
||||
const rawValues = options.map((i) => typeof i === "string" ? i : i[0]);
|
||||
|
||||
if (rawValues.length !== options.length) {
|
||||
@@ -145,6 +149,21 @@ export async function multiSelectMenuInteractive(
|
||||
terminalBlock.setRenderHeight(Deno.consoleSize().rows);
|
||||
}
|
||||
|
||||
const checkSelectAll = () => {
|
||||
if (selectedOptions.includes(0)) {
|
||||
log("yeet");
|
||||
selectedOptions = [];
|
||||
} else {
|
||||
log("neat");
|
||||
selectedOptions = Array.from(options).map((_, i) => i);
|
||||
}
|
||||
};
|
||||
|
||||
const validateSelectAll = () => {
|
||||
const allPresent = selectedOptions.length == options.length;
|
||||
if (!allPresent) selectedOptions = selectedOptions.filter((e) => e != 0);
|
||||
};
|
||||
|
||||
let range: [number, number] = [terminalBlock.lineCount, 1];
|
||||
function renderMenu() {
|
||||
const { rows } = Deno.consoleSize();
|
||||
@@ -193,11 +212,14 @@ export async function multiSelectMenuInteractive(
|
||||
const onSpace = (e: CLICharEvent) => {
|
||||
if (e.detail.char !== " ") return;
|
||||
e.stopImmediatePropagation();
|
||||
if (selectedOptions.includes(selected)) {
|
||||
if (config?.allOption && selected === 0) {
|
||||
checkSelectAll();
|
||||
} else if (selectedOptions.includes(selected)) {
|
||||
selectedOptions = selectedOptions.filter((i) => i !== selected);
|
||||
} else {
|
||||
selectedOptions.push(selected);
|
||||
}
|
||||
validateSelectAll();
|
||||
renderMenu();
|
||||
};
|
||||
|
||||
@@ -299,7 +321,7 @@ if (import.meta.main) {
|
||||
"ximenia",
|
||||
"yuzu",
|
||||
"zucchini",
|
||||
], { terminalBlock: block });
|
||||
], { terminalBlock: block, allOption: true });
|
||||
cliLog(val || "No value");
|
||||
|
||||
// Deno.stdout.writeSync(new TextEncoder().encode("\x07"));
|
||||
|
Reference in New Issue
Block a user