how to go back on previous line with printf

View: New views
3 Messages — Rating Filter:   Alert me  

how to go back on previous line with printf

by pauljoseph :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi,
Is there anyway we can move the cursor back to the previous line using printf? For example if I do

printf('test line 1.\n');

The \n will change to the next line. May I know what character I can use to go back to the "test line 1." and put the cursor back after the dot?

Thanks.

Re: how to go back on previous line with printf

by Jaroslav Hajek-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Mon, Sep 1, 2008 at 8:52 AM, pauljoseph <oka.kurniawan@...> wrote:

>
> Hi,
> Is there anyway we can move the cursor back to the previous line using
> printf? For example if I do
>
> printf('test line 1.\n');
>
> The \n will change to the next line. May I know what character I can use to
> go back to the "test line 1." and put the cursor back after the dot?
>

AFAIK this is not possible using standard console output. For
instance, the output may be redirected to a printer, and you simply
can't go back. If your terminal supports ANSI escape sequences (most
of them do), then you can use them to accomplish this.
If you are trying to do something like progress reporting, then it's
better to not print the linefeed \n until done.

cheers

> Thanks.
> --
> View this message in context: http://www.nabble.com/how-to-go-back-on-previous-line-with-printf-tp19249702p19249702.html
> Sent from the Octave - General mailing list archive at Nabble.com.
>
> _______________________________________________
> Help-octave mailing list
> Help-octave@...
> https://www-old.cae.wisc.edu/mailman/listinfo/help-octave
>



--
RNDr. Jaroslav Hajek
computing expert
Aeronautical Research and Test Institute (VZLU)
Prague, Czech Republic
url: www.highegg.matfyz.cz
_______________________________________________
Help-octave mailing list
Help-octave@...
https://www-old.cae.wisc.edu/mailman/listinfo/help-octave

Re: how to go back on previous line with printf

by Dave.Haddon :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Sun, 2008-08-31 at 23:52 -0700, pauljoseph wrote:

> Hi,
> Is there anyway we can move the cursor back to the previous line using
> printf? For example if I do
>
> printf('test line 1.\n');
>
> The \n will change to the next line. May I know what character I can use to
> go back to the "test line 1." and put the cursor back after the dot?
>
> Thanks.

If you use '\r' that will take you to the beginning of the line.


for i = 1:10
    printf("Line %d of 10 \r",i)
endfor

This will print the message on the same line in a standard Octave shell.
When testing it, I found that it doesn't work under the QtOctave
though...  QtOctave does make some changes though.

I hope this helps.

David
_______________________________________________
Help-octave mailing list
Help-octave@...
https://www-old.cae.wisc.edu/mailman/listinfo/help-octave