Search code examples
javascriptcommand-promptdeno

How to get Deno prompt() to go over 255 characters


If you run a prompt("Paste JSON into here") in Deno, you can put a maximum of 255 characters.

Is there a method to make it unlimited, or at least get a better reasonable limit without taking on a dependency or looping.

I tried taking on chunks of json through looping prompt() calls, but that would require hitting enter() and adding more complexity to users of program.


Solution

  • It is a bug in Deno for Windows https://github.com/denoland/deno/issues/19010

    Until it is fixed, as a workaround you could use Ubuntu on WSL or use the following snippet from @Lenni009 (Who reported the bug)

    import { readLines } from "https://deno.land/[email protected]/io/mod.ts";
    
    async function prompt(promptText) {
        const text = new TextEncoder().encode(`${promptText} `);
        Deno.writeAllSync(Deno.stdout, text);
        const { value: input } = await readLines(Deno.stdin).next();
        return input;
    }