-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclikit.ts
76 lines (61 loc) · 1.54 KB
/
clikit.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import prompts from "https://esm.sh/[email protected]";
import nfzf from "https://esm.sh/[email protected]";
import { rgb24 } from "https://deno.land/[email protected]/fmt/colors.ts";
import { FzfOptions } from "./types.ts";
export async function text(message: string) {
const opt: prompts.PromptObject = {
type: "text",
name: "value",
message: message,
};
return runPrompt(opt);
}
export async function confirm(messge: string) {
const opt: prompts.PromptObject = {
type: "confirm",
name: "value",
message: messge,
initial: true,
};
return runPrompt(opt);
}
export async function toggle(messge: string) {
const opt: prompts.PromptObject = {
type: "toggle",
name: "value",
message: messge,
initial: true,
active: "yes",
inactive: "no",
};
return Boolean(await runPrompt(opt));
}
async function runPrompt(
opt: prompts.PromptObject,
) {
const result = await prompts(opt);
return result.value;
}
export async function fuzzy(list: Array<string>) {
const opts: FzfOptions = {
list: list,
mode: "fuzzy" || "normal",
prefill: "",
prelinehook: () => "",
postlinehook: () => "",
};
const result = await nfzf(opts);
const { selected, query } = result;
if (!selected) {
console.log("No matches for:", query);
} else {
return list[selected.index];
}
}
function colorcodeToHex(code: string) {
const raw = "0x" + code.substr(1);
return Number(raw);
}
export function colorLog(text: string, colorCode: string) {
console.log(rgb24(text, colorcodeToHex(colorCode)));
}