c-3lab / dim

📦 dim: Manage the open data in your project like a package manager.
MIT License
126 stars 21 forks source link

Input characters may be garbled when running the installation interactively. #70

Open ta-Hirose opened 2 years ago

ta-Hirose commented 2 years ago

When running the installation interactively, the following input has been confirmed to be garbled

If only garbled characters are entered, no garbling occurs.

ta-Hirose commented 2 years ago

The cause may be the process of reading from Cliffy's standard output.

The buffer size for reading a character is 8 bytes, and when reading a character that exceeds this size, it seems that the character is split in the middle of one character.

https://github.com/c4spar/deno-cliffy/blob/cd8d73cc7407e6126976f567060b8715fa2a0a7b/prompt/_generic_prompt.ts#L294-L305

const buffer = new Uint8Array(8);
~~~~
const nread: number | null = await Deno.stdin.read(buffer);

Proposals:

As a countermeasure, we propose to clone Deno-cliffy and use its modified version.

We have the following two suggestions for modification.

  1. Keep buffer size large enough.

    There is no standard for how much increase is sufficient, so this is only a palliative measure

  2. Modify code to work even when split in the middle of a character.

    The conversion process to keycode using parse implemented in keycode/key_code.ts of deno-cliffy exists in between. The degree of difficulty of modification is considered to be quite high.