Connecting Tech Pros Worldwide Help | Site Map

printf() with control character

Sebastian Araya
Guest
 
Posts: n/a
#1: May 15 '06
Hello,

I'm trying to write a rotational symbol in a CLI process, to report
activity to the user console, using printf( "%s\b", symbol ); but I see
the control character (\b) is been printed out instead of backspacing.

Is there any work around ?

Thanks in advance,

Sebastián.

Tim Van Wassenhove
Guest
 
Posts: n/a
#2: May 15 '06

re: printf() with control character


On 2006-05-15, Sebastian Araya <numisys@gmail.com> wrote:[color=blue]
> Hello,
>
> I'm trying to write a rotational symbol in a CLI process, to report
> activity to the user console, using printf( "%s\b", symbol ); but I see
> the control character (\b) is been printed out instead of backspacing.
>
> Is there any work around ?[/color]

Tried "%s\\b" or '%s\\b' already?

--
Met vriendelijke groeten,
Tim Van Wassenhove <http://timvw.madoka.be>
numisys
Guest
 
Posts: n/a
#3: May 16 '06

re: printf() with control character


Hello,

and thanks for your answer.

Yes, I tried it, but it didn't work... perhaps I need to use NCurses
(http://www.zend.com/pecl/tutorials/ncurses.php) ??

Best,

Sebastian

Rik
Guest
 
Posts: n/a
#4: May 16 '06

re: printf() with control character


Tim Van Wassenhove wrote:[color=blue]
> On 2006-05-15, Sebastian Araya <numisys@gmail.com> wrote:[color=green]
>> Hello,
>>
>> I'm trying to write a rotational symbol in a CLI process, to report
>> activity to the user console, using printf( "%s\b", symbol ); but I
>> see the control character (\b) is been printed out instead of
>> backspacing.
>>
>> Is there any work around ?[/color][/color]

What about:
printf( "%s%c", symbol,8);

%c:
c - the argument is treated as an integer, and presented as the character
with that ASCII value

Then again, I know nothing about CLI.

Grtz,
--
Rik Wasmus


numisys
Guest
 
Posts: n/a
#5: May 16 '06

re: printf() with control character


Hello,

I figured out with ANSI terminal control codes; here is a little
example:

<?

$sym = "|/-\\";

while( True )
for( $i = 0; $i!= 4; $i++ )
{
printf( "%s\x1b[D", substr( $sym, $i, 1 ) );
sleep(.25);
}

?>

I tested in a Gentoo 2006.0 using a SSH terminal under Windows
(PuTTy).

Best,

Sebastian

numisys
Guest
 
Posts: n/a
#6: May 16 '06

re: printf() with control character


Hello Tim,

thanks again for your answer.

I think that, in PHP-CLI (console) environment, the screen is treated
as a common file, and every character output is send in a raw mode...
like if you use PHP under web development (where every output byte is
send through the net).

So, seeing Stefan Walk ProgressBar
(http://pear.php.net/package/Console_ProgressBar) I realized that using
ANSI terminal chars' control, you change the console behavior, so it
apparently deletes a char and writes a new one.

Best,

Sebastian

Closed Thread


Similar PHP bytes