bart2287
bart2287

Reputation: 99

Is there an ANSI control sequence which moves the cursor to the end of line?

I know of \33[nC which moves the cursor n columns forward; the problem is, I don't know how many characters the particular line consists of.

Upvotes: 4

Views: 6523

Answers (5)

Jason Granzow
Jason Granzow

Reputation: 21

You can use the ANSI command \33[1000C This will send the cursor 1,000 columns to the right. If there aren't 1,000 colums it just hits the end of the line and stays there. It doesn't wrap around. It's a bit of a brute force method but it works well and easy enough for what I've been doing.

Upvotes: 2

Multifix
Multifix

Reputation: 130

If there was a line end then you could save it with \033[s. And then, after you've done manipulating the line, restore the position with \033[u.

Upvotes: 1

bart2287
bart2287

Reputation: 99

In case anyone has a similar problem, I have managed to work around the necessity of explicitly knowing n in \33[nC by obtaining its value in my program and using string interpolation to put the value of the variable n into a string containing the aforementioned escape sequence.

This isn't a universal solution, however, as there might be cases where n cannot be determined so easily.

Upvotes: 0

Thomas Dickey
Thomas Dickey

Reputation: 54475

There is nothing explicit, however screens are "small", and you could use any of the cursor-movement commands to move to an arbitrarily far destination and the terminal will limit the movement by the screen's size.

For instance, the cursor-forward (in terminfo, cuf) control uses a repeat-count, and horizontal position absolute (in terminfo, hpa) control uses a column value. Either of these should work for you:

tput cuf 999
tput hpa 999

(assuming that your screen has fewer than a thousand columns). There are others which may be implemented in your terminal (emulator...), but those are fairly common.

By the way, for hardcoding, cuf is the same as the example in the question. That's columns, not lines which are moved. To move the cursor by lines, you would use cud (escape> [nB).

Upvotes: 5

erip
erip

Reputation: 16935

No, there is no such ANSI control sequence.

Upvotes: 3

Related Questions