prompts icon indicating copy to clipboard operation
prompts copied to clipboard

Text prompt hint

Open Js-Brecht opened this issue 6 years ago • 6 comments
trafficstars

This PR adds the feature to display a hint to the user when giving them a text type prompt.

It will display the hint below the prompt, so some of the logic surrounding displaying errors had to be changed to support displaying a hint as well.

Additionally, cursor.restore is not supported on some terminals, so I changed the logic some to support displaying a message below the prompt, then resetting the cursor where it needs to go. This method reduces some of the flicker, too (it was really bad in some terminals), because it is not erasing all of the text then redrawing it every time. There is still some flicker, and it could probably be fine tuned some more, but I wasn't interested in going deeper than that.

The way it is now makes more sense, too, if you include an initial value. Your cursor will be at the beginning of the initial value, instead of at the end, so it is apparent that you are going to type over the default.

Js-Brecht avatar Nov 05 '19 21:11 Js-Brecht

Thank you @Js-Brecht. I'm very curious about ways to avoid flicker and provide better rendering. I would love to use whatever you learned in the next major release of prompts!

terkelg avatar Nov 06 '19 01:11 terkelg

I think that extends a little past the scope of this PR, but I do have some thoughts on that particular problem. I will open a new issue for discussion on a possible solution, then when I have some time, I will see about preparing a POC PR.

Js-Brecht avatar Nov 06 '19 17:11 Js-Brecht

See #233

Js-Brecht avatar Nov 06 '19 18:11 Js-Brecht

Made some changes that will help with output wrapping scenarios.

One thing I noticed is that cursor.restore restores the X position, but not the Y (at least in my terminal). So it seemed like a good idea to keep.

This still won't support all scenarios, however. If ever a line feed causes the output to extend past the bottom of the terminal, an extra line count is included that will be unaccounted for, so the output will be off. If cursor.restore works for restoring the Y position on your terminal, then it will work as expected. If not... not a lot to do about it right now, unless something is added that can track the cursor's current Y position. Need to know if it is on the last row, and if a line feed is going to occur, then the extra line can be accounted for.

I think it's possible to use \033[6n to get the cursor row... it may not be portable, though 🤷‍♂.

I need to test this with other terminals, too, just to make sure there's not any quirks that need to be accounted for. For now, I need to move on to other projects (that I'm actually getting paid for 😆). Later tonight I'll come back to this if I can.

Js-Brecht avatar Nov 06 '19 20:11 Js-Brecht

Figured out that cursor.restore was causing the problem with the "off by one" line count after printing on, or issuing a line feed on the last line of the terminal. Without it, I am able to correctly calculate the position of the input after every redraw. Placing the cursor accurately allows moving the cursor forward/backward on the input line.

This current state of this PR allows you to display a hint (instead of just an error) below the input, and it accounts for long, wrapping inputs, prompts, errors, messages. It also doesn't erase entire lines; instead it will write over the top of them, and then clear to the end of the line if the output hasn't reached the edge of the screen. Helps with flickering, but doesn't eliminate it.

This also handles quirks with the line clearing process, where the last character would get erased if you issued a clear line when your output was the width of the terminal.

Js-Brecht avatar Nov 09 '19 09:11 Js-Brecht

I don't get hints for text prompts sadly.

ctjlewis avatar Nov 04 '22 07:11 ctjlewis