read icon indicating copy to clipboard operation
read copied to clipboard

Weird formatting of colored prompt message

Open bilalq opened this issue 11 years ago • 1 comments

I cut a similar issue to the node-promptly module earlier: IndigoUnited/node-promptly#2

When the prompt contains colored/formatted text, the cursor is indented far to the right.

I skimmed through the code, and I think I see where the issue is: https://github.com/isaacs/read/blob/master/lib/read.js#L56

Formatted strings end up with ANSI color codes are part of the string. Looking up the length property on them returns a misleading result. Would you accept a patch to strip ANSI codes before reading the length of the prompt?

bilalq avatar Feb 24 '14 07:02 bilalq

You need to calculate the length of the prompt and pass it when calling setPrompt(), see #21 and https://github.com/joyent/node/issues/3860.

A modified version of read that allows for this is here:

https://github.com/freeformsystems/cli-input/blob/master/lib/read.js

tmpfs avatar Sep 12 '14 08:09 tmpfs