sindresorhus / ansi-escapes

ANSI escape codes for manipulating the terminal
MIT License
494 stars 44 forks source link

Get x, y from the result of cursorGetPosition #22

Open lebaphi opened 4 years ago

lebaphi commented 4 years ago

I get the result from cursorGetPosition is: ^[[12;1R. So how can to parse or convert this to x, y then I can use other API likes cursorMove?

sindresorhus commented 4 years ago

https://stackoverflow.com/questions/8343250/how-can-i-get-position-of-cursor-in-terminal

We should indeed document this better.

devingfx commented 3 years ago

And so? Do you have a nodejs working exemple? Because knowing how to get the position using bash is a bit useless here...

I tried to listen process.stdin while outputing ansi.cursorGetPosition on process.stdout but without success... :/

carljohnson93 commented 3 years ago

Yeah have the same question as @lebaphi. How do I use this with provided API? In my case I need to fully redraw what's on the terminal "screen" but without removing history, so I came up with idea to remember initial cursor position and set it before process.stdout.writeing all the logs

Qix- commented 3 years ago

To be completely fair and honest, I've never personally gotten this escape code to work.

Supposedly, you're supposed to read from stdin after issuing this code. This, however, has never worked for me. I've not seen a program actually use this before and I've always kind of assumed it's a dead escape code lost to the sands of time, lol.

If you want my domain-expert opinion, don't use this escape code. Find a better way to do it.

carljohnson93 commented 3 years ago

aight, thanks. Know some library for my needs? I mean "redrawing" what's in terminal without clearing history

Qix- commented 3 years ago

@carljohnesan Check out blessed, though it's quite high level. Maybe that's what you're looking for.

jamonholmgren commented 1 year ago

This seemed to work for me decently well.

https://github.com/bubkoo/get-cursor-position/blob/master/index.js