ansi-escapes icon indicating copy to clipboard operation
ansi-escapes copied to clipboard

Get x, y from the result of cursorGetPosition

Open lebaphi opened this issue 4 years ago • 7 comments

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?

lebaphi avatar Aug 28 '20 12:08 lebaphi

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

We should indeed document this better.

sindresorhus avatar Sep 03 '20 14:09 sindresorhus

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... :/

devingfx avatar Feb 12 '21 15:02 devingfx

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

carljohnson93 avatar Mar 06 '21 02:03 carljohnson93

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.

Qix- avatar Mar 06 '21 06:03 Qix-

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

carljohnson93 avatar Mar 06 '21 06:03 carljohnson93

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

Qix- avatar Mar 06 '21 08:03 Qix-

This seemed to work for me decently well.

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

jamonholmgren avatar Oct 12 '23 06:10 jamonholmgren