Problem with Curses

Discussion in 'Perl Misc' started by Babacio, Aug 16, 2005.

  1. Babacio

    Babacio Guest

    Hi,

    Sorry if the question looks stupid to some of you...

    Here is a piece of code:
    ####################################
    use Curses;

    initscr();
    # here I should use curses
    endwin();

    print "Hello!\n";
    print "What do you say? ";
    $x=<STDIN>;
    print "You said $x\n";
    #####################################

    The functions initscr() and endwin() are to be use before and after
    doing stuff with curses...

    When I run it (on Mac OS X / darwin), I have the following problem :
    the text of the three prints does not appear until the end of the
    program, so I enter the value of $x with nothing printed, and
    after that the three line appear.

    This is due to some pertubation Curses makes in the terminal.

    This second piece of code sort of give a solution to this problem:

    ####################################
    use Curses;
    use IO::Handle;

    initscr();
    # here I should use curses
    endwin();

    STDOUT->autoflush(1); # or $|=1

    print "Hello!\n";
    print "What do you say? ";
    $x=<STDIN>;
    print "\nYou said $x\n";
    #####################################

    Forcing STDOUT to flush contiuously, the behaviour is (seems to be)
    what is expected.

    But it is obvious that this in not the right way to solve the
    problem. The vale of $| should remain 0.

    Any idea?
     
    Babacio, Aug 16, 2005
    #1
    1. Advertising

  2. Babacio

    Babacio Guest

    Babacio.

    > Hi,
    >
    > Sorry if the question looks stupid to some of you...
    >
    > Here is a piece of code:
    > ####################################
    > use Curses;
    >
    > initscr();
    > # here I should use curses
    > endwin();
    >
    > print "Hello!\n";
    > print "What do you say? ";
    > $x=<STDIN>;
    > print "You said $x\n";
    > #####################################
    >
    > The functions initscr() and endwin() are to be use before and after
    > doing stuff with curses...
    >
    > When I run it (on Mac OS X / darwin), I have the following problem :
    > the text of the three prints does not appear until the end of the
    > program, so I enter the value of $x with nothing printed, and
    > after that the three line appear.
    >
    > (...)


    Even if you don't have a solution, could you at least tell me if the
    behaviour is the same on other systems (Linux, FreeBSD) ?

    Thanks.
     
    Babacio, Aug 17, 2005
    #2
    1. Advertising

  3. Babacio

    Ian Wilson Guest

    Babacio wrote:
    > Babacio.
    >
    >
    >>Hi,
    >>
    >>Sorry if the question looks stupid to some of you...
    >>
    >>Here is a piece of code:
    >>####################################
    >>use Curses;
    >>
    >>initscr();
    >># here I should use curses
    >>endwin();
    >>
    >>print "Hello!\n";
    >>print "What do you say? ";
    >>$x=<STDIN>;
    >>print "You said $x\n";
    >>#####################################
    >>
    >>The functions initscr() and endwin() are to be use before and after
    >>doing stuff with curses...
    >>
    >>When I run it (on Mac OS X / darwin), I have the following problem :
    >>the text of the three prints does not appear until the end of the
    >>program, so I enter the value of $x with nothing printed, and
    >>after that the three line appear.
    >>
    >>(...)

    >
    >
    > Even if you don't have a solution, could you at least tell me if the
    > behaviour is the same on other systems (Linux, FreeBSD) ?


    $ uname
    Linux
    $ ./curses.pl
    Can't locate curses.pm in @INC

    Maybe you should say where you got Curses.pm and which version you are
    using?
     
    Ian Wilson, Aug 17, 2005
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. AK
    Replies:
    0
    Views:
    262
  2. AK
    Replies:
    0
    Views:
    260
  3. Ian Ward

    Problem with curses and UTF-8

    Ian Ward, Feb 7, 2006, in forum: Python
    Replies:
    30
    Views:
    1,825
    Ian Ward
    Feb 10, 2006
  4. Jean-Paul Calderone
    Replies:
    2
    Views:
    440
    Joel Hedlund
    Feb 9, 2006
  5. Simon Morgan

    curses problem reading cursor keys

    Simon Morgan, Oct 7, 2006, in forum: Python
    Replies:
    3
    Views:
    691
    Thomas Dickey
    Oct 11, 2006
Loading...

Share This Page