c - Returning the terminal cursor to start-of-line with wrapping enabled -


I am writing a filter (in a fixed pipe for terminal output) which is sometimes used to "overwrite" a line It is necessary that it has just happened, it works by stdin to reach character-up-to-character until one \ n , and then to implement special behavior. My problem is to know how to get back in the beginning of the line.

The first thing that I thought was the \ r or the ANSI sequence \ 033 [1G . However, if the line is wrapped on a terminal for a very long time (and so it is due to scrolling), it will only take the cursor back to the existing physical line.

My second thought was that the length of the line (the number of characters passing through the previous \ n ), and then sometimes echo out \ b though , It goes wrong if the line has a control letter or escape sequence (and possibly Unicode?).

To search for all the special sequences is small and an easy way to use it to adjust the number of my characters is to achieve this?

Even if there is a "magic sequence" that can be easily erased when written on the console Last Written Line, you will still get the sequence (though hidden on the console) on the line and output. Think what would happen if a person wrote out the output to the file, or sent the pipes to other filters? Do they know how to handle such inputs? And tell me that you deny the possibility of writing directly from the console directly elsewhere. Soon or later, anybody wants to redirect the output - maybe you too!

The correct way to do this is to buffer each row in memory because it is processed, and then decide whether to output it or not. There really is no way to it.


Comments

Popular posts from this blog

c++ - Linux and clipboard -

Visual Studio 2005: How to speed up builds when a VSMDI is open? -

booting ubuntu from usb using virtualbox -