Connecting Tech Pros Worldwide Help | Site Map

printf() with control character

  #1  
Old May 15th, 2006, 10:55 AM
Sebastian Araya
Guest
 
Posts: n/a
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.

  #2  
Old May 15th, 2006, 01:05 PM
Tim Van Wassenhove
Guest
 
Posts: n/a

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>
  #3  
Old May 16th, 2006, 11:45 AM
numisys
Guest
 
Posts: n/a

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

  #4  
Old May 16th, 2006, 12:05 PM
Rik
Guest
 
Posts: n/a

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


  #5  
Old May 16th, 2006, 12:25 PM
numisys
Guest
 
Posts: n/a

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

  #6  
Old May 16th, 2006, 12:35 PM
numisys
Guest
 
Posts: n/a

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 Threads
Thread Thread Starter Forum Replies Last Post
printf and cout laikon answers 10 March 28th, 2008 11:15 AM
Histogram of character frequencies rajash@thisisnotmyrealemail.com answers 35 December 11th, 2007 10:45 AM
character sets jraul answers 9 June 25th, 2007 02:55 PM
Need help with problem Scott answers 18 March 30th, 2007 05:35 PM