printf() with control character

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Sebastian  Araya

    printf() with control character

    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

    #2
    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 >

    Comment

    • numisys

      #3
      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

      Comment

      • Rik

        #4
        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


        Comment

        • numisys

          #5
          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

          Comment

          • numisys

            #6
            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

            Comment

            Working...