diff --git a/CHANGELOG.md b/CHANGELOG.md index 161668a..5bf98f5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +## 0.16.2 + +- Fix for Node.js; use `readline` instead of prompt. +- + ## 0.16.1 - Fix for Node.js not treating subarrays of buffers as expected diff --git a/deno.json b/deno.json index 2ebe3b5..53ba6e7 100644 --- a/deno.json +++ b/deno.json @@ -1,6 +1,6 @@ { "name": "@cross/kv", - "version": "0.16.1", + "version": "0.16.2", "exports": { ".": "./mod.ts", "./cli": "./src/cli/mod.ts" diff --git a/src/cli/common.ts b/src/cli/common.ts index 2ec8c8c..d655504 100644 --- a/src/cli/common.ts +++ b/src/cli/common.ts @@ -34,9 +34,6 @@ export function hasParameter(p: string[], n: number): boolean { return true; } } -export function userInput(t: string): string { - return prompt(t) || ""; -} export function toHexString(bytes: number): string { // Ensure the input is a valid number if (typeof bytes !== "number" || isNaN(bytes)) { diff --git a/src/cli/loop.ts b/src/cli/loop.ts index 13086aa..2cd5c7d 100644 --- a/src/cli/loop.ts +++ b/src/cli/loop.ts @@ -1,4 +1,6 @@ import { Colors } from "@cross/utils"; +import { CurrentRuntime, Runtime } from "@cross/runtime"; +import { createInterface } from "node:readline"; import type { KVCliHandler, KVDBContainer } from "./common.ts"; @@ -16,7 +18,23 @@ export async function main() { let exit = false; while (!exit) { // Collect user input - const command = await prompt(Colors.blue(">")); + let command; + if (CurrentRuntime === Runtime.Node) { + const rl = createInterface({ + // @ts-ignore Cross-runtime + input: process.stdin, + // @ts-ignore Cross-runtime + output: process.stdout, + }); + command = await new Promise((resolve) => { + rl.question(Colors.blue("> "), (cmd: unknown) => { + rl.close(); + resolve(cmd); + }); + }); + } else { + command = await prompt(Colors.blue(">")); + } if (command === null) { continue; }