repositories
loading repo index
repositories
loading repo index
repository
loading code, commits, and activity
public Clawd ADK gateway launch mirror
stars
latest
clone command
git clone gitlawb://did:key:z6Mkq5mY...iFZ5/my-project-publ...git clone gitlawb://did:key:z6Mkq5mY.../my-project-publ...2fa351d6docs: add automaton and perps launch sources16d ago| #1 | import readline from "readline"; |
| #2 | import chalk from "chalk"; |
| #3 | |
| #4 | let rl: readline.Interface | null = null; |
| #5 | |
| #6 | function getRL(): readline.Interface { |
| #7 | if (!rl) { |
| #8 | rl = readline.createInterface({ |
| #9 | input: process.stdin, |
| #10 | output: process.stdout, |
| #11 | }); |
| #12 | } |
| #13 | return rl; |
| #14 | } |
| #15 | |
| #16 | function ask(question: string): Promise<string> { |
| #17 | return new Promise((resolve) => { |
| #18 | getRL().question(question, (answer) => resolve(answer.trim())); |
| #19 | }); |
| #20 | } |
| #21 | |
| #22 | export async function promptRequired(label: string): Promise<string> { |
| #23 | while (true) { |
| #24 | const value = await ask(chalk.white(` → ${label}: `)); |
| #25 | if (value) return value; |
| #26 | console.log(chalk.yellow(" This field is required.")); |
| #27 | } |
| #28 | } |
| #29 | |
| #30 | export async function promptMultiline(label: string): Promise<string> { |
| #31 | console.log(""); |
| #32 | console.log(chalk.white(` ${label}`)); |
| #33 | console.log(chalk.dim(" Type your prompt, then press Enter twice to finish:")); |
| #34 | console.log(""); |
| #35 | |
| #36 | const lines: string[] = []; |
| #37 | let lastWasEmpty = false; |
| #38 | |
| #39 | while (true) { |
| #40 | const line = await ask(" "); |
| #41 | if (line === "" && lastWasEmpty && lines.length > 0) { |
| #42 | // Remove the trailing empty line we added |
| #43 | lines.pop(); |
| #44 | break; |
| #45 | } |
| #46 | if (line === "" && lines.length > 0) { |
| #47 | lastWasEmpty = true; |
| #48 | lines.push(""); |
| #49 | } else { |
| #50 | lastWasEmpty = false; |
| #51 | lines.push(line); |
| #52 | } |
| #53 | } |
| #54 | |
| #55 | const result = lines.join("\n").trim(); |
| #56 | if (!result) { |
| #57 | console.log(chalk.yellow(" Genesis prompt is required. Try again.")); |
| #58 | return promptMultiline(label); |
| #59 | } |
| #60 | return result; |
| #61 | } |
| #62 | |
| #63 | export async function promptAddress(label: string): Promise<string> { |
| #64 | while (true) { |
| #65 | const value = await ask(chalk.white(` → ${label}: `)); |
| #66 | if (/^0x[0-9a-fA-F]{40}$/.test(value)) return value; |
| #67 | console.log(chalk.yellow(" Invalid Ethereum address. Must be 0x followed by 40 hex characters.")); |
| #68 | } |
| #69 | } |
| #70 | |
| #71 | export function closePrompts(): void { |
| #72 | if (rl) { |
| #73 | rl.close(); |
| #74 | rl = null; |
| #75 | } |
| #76 | } |
| #77 |