Need constant screen with periodic updates

Discussion in 'Perl Misc' started by Kris Dugan, Jun 7, 2004.

  1. Kris Dugan

    Kris Dugan Guest

    I am using a Unix/Solaris 8/9 environment.

    I want to make a tool that will constantly read a structure of
    information and display that information (or "paint it") to the
    screen. Rather than having the information scroll by, I want
    a way in which the screen would be "repainted". Sample Screen:

    -------------------------------------------------
    | foo: 6 bar: 12 |
    | this: 18 that: 20 |
    |etc. |
    -------------------------------------------------

    If the values change, I want the screen to be repainted, as opposed
    to using "printf" to print it to a screen or logfile.

    I am aware that C has the "cursor" libraries, which will do what
    I am looking for. Upon first examination, this looked somewhat
    complicated. Are there any other modules/libraries that would
    accomplish this kind of task (in any other languages) that would
    be simple to use?

    I am not doing anything with X windows, so this would just be text
    to the screen.
     
    Kris Dugan, Jun 7, 2004
    #1
    1. Advertising

  2. Kris Dugan

    Ben Morrow Guest

    Quoth Kris Dugan <>:
    > I am using a Unix/Solaris 8/9 environment.
    >
    > I want to make a tool that will constantly read a structure of
    > information and display that information (or "paint it") to the
    > screen. Rather than having the information scroll by, I want
    > a way in which the screen would be "repainted". Sample Screen:
    >
    > -------------------------------------------------
    > | foo: 6 bar: 12 |
    > | this: 18 that: 20 |
    > |etc. |
    > -------------------------------------------------
    >
    > If the values change, I want the screen to be repainted, as opposed
    > to using "printf" to print it to a screen or logfile.
    >
    > I am aware that C has the "cursor" libraries, which will do what
    > I am looking for. Upon first examination, this looked somewhat
    > complicated. Are there any other modules/libraries that would
    > accomplish this kind of task (in any other languages) that would
    > be simple to use?


    In Perl you can use Term::ANSIScreen to achieve this (very easily).

    Ben

    --
    Although few may originate a policy, we are all able to judge it.
    - Pericles of Athens, c.430 B.C.
     
    Ben Morrow, Jun 7, 2004
    #2
    1. Advertising

  3. >>>>> "Kris" == Kris Dugan <> writes:

    Kris> I want to make a tool that will constantly read a structure of
    Kris> information and display that information (or "paint it") to the
    Kris> screen. Rather than having the information scroll by, I want
    Kris> a way in which the screen would be "repainted".

    Sounds like a perfect job for Curses.pm. Look in to it.

    --
    Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
    <> <URL:http://www.stonehenge.com/merlyn/>
    Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
    See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!
     
    Randal L. Schwartz, Jun 8, 2004
    #3
  4. Kris Dugan wrote:

    > I am using a Unix/Solaris 8/9 environment.
    >
    > I want to make a tool that will constantly read a structure of
    > information and display that information (or "paint it") to the
    > screen. Rather than having the information scroll by, I want
    > a way in which the screen would be "repainted". Sample Screen:


    Easiest Perl way:

    system('clear');
    print "new info ..."


    gtoomey
     
    Gregory Toomey, Jun 8, 2004
    #4
  5. Kris Dugan

    Ben Morrow Guest

    Quoth Gregory Toomey <>:
    > Kris Dugan wrote:
    >
    > > I am using a Unix/Solaris 8/9 environment.
    > >
    > > I want to make a tool that will constantly read a structure of
    > > information and display that information (or "paint it") to the
    > > screen. Rather than having the information scroll by, I want
    > > a way in which the screen would be "repainted". Sample Screen:

    >
    > Easiest Perl way:
    >
    > system('clear');
    > print "new info ..."


    Come now, using external programs for something that simple is nearly
    always wrong.

    use Term::ANSIScreen qw/:screen :cursor/;

    locate 1, 1;
    cls;
    print "...";

    For some reason I have found that both cls and clline only work for me
    if I locate to the start of the region to be cleared first... I am
    presuming this is a bug in eiher Term::ANSIScreen or the linux console
    driver :).

    Ben

    --
    The cosmos, at best, is like a rubbish heap scattered at random.
    - Heraclitus
     
    Ben Morrow, Jun 8, 2004
    #5
  6. Kris Dugan

    Joe Smith Guest

    Purl Gurl wrote:

    > I am a bit confused by your response.
    >
    > You indicate Toomey should not use an external program.


    Correct. Using an external executable program that runs as
    a different process is inefficient.

    > Then you indicate to use an external program, a module.


    No, a module is not an external program. It is additional
    source code for the perl compiler. The end result is a
    pure-perl solution, which is better in many cases than
    a solution relying on external executable binaries.

    -Joe
     
    Joe Smith, Jun 8, 2004
    #6
  7. Kris Dugan

    Joe Smith Guest

    Re: ANSI Screen escape sequences

    Ben Morrow wrote:

    > use Term::ANSIScreen qw/:screen :cursor/;
    >
    > locate 1, 1;
    > cls;
    > print "...";
    >
    > For some reason I have found that both cls and clline only work for me
    > if I locate to the start of the region to be cleared first.


    That's a bug in your terminal emulator; it is not responding to escape
    sequences as per the ANSI specs.

    cldown = "\x33[0J" = clear from location to end of screen
    clup = "\x33[1J" = clear from beginning of screen to location
    cls = "\x33[2J" = clear the entire screen

    > presuming this is a bug in the linux console driver :) .


    Works fine with xterm, gnome-terminal, and the Linux 2.4.20 console.
    -Joe
     
    Joe Smith, Jun 8, 2004
    #7
  8. Also sprach Purl Gurl:

    > I know of many circumstances where running an external
    > program is significantly more efficient than pure
    > Perl based solutions. Before writing any Perl program,
    > I ask myself,
    >
    > "Can I do this better system direct?"
    >
    > Perl allows all kinds of execution of external programs.
    > Certainly there is a reason, yes?


    For me it's mostly a means of last resort. It's just so that many
    programs exist and some do things not covered by Perl modules. It stands
    to reason that those are the binaries that can be used without having a
    bad conscience.

    > A module is an external program. This could be debated
    > based on the nature of a given module. Nonetheless,
    > many modules are complex coding which perform tasks
    > independently of your main Perl program. Stein's
    > bloatware is a good example of a module being a
    > true external program. Modules which perform calls
    > to Win API functions, those modules are external
    > programs performing specific tasks, independent of
    > your calling Perl program.
    >
    > What true difference is there between system() calls
    > and get() calls as with the LWP module? Does not
    > LWP make use of your system, independent of Perl?


    There are two kinds of system calls. Actually, there is only one kind.
    You find system calls in the section 2 of the manpages. Thus, read(2),
    open(2), ioctl(2) and many more are system calls. They need special
    treatment as they do not run in userspace (interrupts are involved). See
    for instance <http://unix.ittoolbox.com/documents/document.asp?i=2509>.

    And then there is Perl's system() built-in, often and sloppily referred
    to as system call as well. Under the hood it usually involves many real
    system calls (the first one being fork(2), then execve(2) and finally
    all system calls made by the thusly called program).

    > We could debate forever "what" qualifies an external
    > program. Nonetheless, there is a well known feature
    > about Perl modules which does directly point to a
    > module being an external program. This feature is
    > feeding a module arguments, in a fashion no different
    > than command line arguments.


    But technically it's very different. A module usually runs in the same
    process as the Perl interpreter. An external program has to be spawned
    off using fork. That's by a magnitude more expensive for the operating
    system.

    Tassilo
    --
    $_=q#",}])!JAPH!qq(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
    pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#;
    $_=reverse,s+(?<=sub).+q#q!'"qq.\t$&."'!#+sexisexiixesixeseg;y~\n~~dddd;eval
     
    Tassilo v. Parseval, Jun 8, 2004
    #8
  9. Purl Gurl wrote:

    > What true difference is there between system() calls
    > and get() calls as with the LWP module?


    Are you serious? You really don't know the difference between launching a
    child process and calling a function in a shared library? Please tell me
    you're trolling - you can't possibly be *that* clueless.

    sherm--

    --
    Cocoa programming in Perl: http://camelbones.sourceforge.net
    Hire me! My resume: http://www.dot-app.org
     
    Sherm Pendley, Jun 8, 2004
    #9
  10. Kris Dugan

    Ben Morrow Guest

    Re: ANSI Screen escape sequences

    Quoth Joe Smith <>:
    > Ben Morrow wrote:
    >
    > > use Term::ANSIScreen qw/:screen :cursor/;
    > >
    > > locate 1, 1;
    > > cls;
    > > print "...";
    > >
    > > For some reason I have found that both cls and clline only work for me
    > > if I locate to the start of the region to be cleared first.

    >
    > That's a bug in your terminal emulator; it is not responding to escape
    > sequences as per the ANSI specs.
    >
    > cldown = "\x33[0J" = clear from location to end of screen
    > clup = "\x33[1J" = clear from beginning of screen to location
    > cls = "\x33[2J" = clear the entire screen


    I suspected as much. I didn't *really* think it likely that there would
    be a bug in a module as simple as Term::ANSIScreen :).

    > > presuming this is a bug in the linux console driver :) .

    >
    > Works fine with xterm, gnome-terminal, and the Linux 2.4.20 console.


    Linux 2.6.3 console, in UTF-8 mode. I suspect the latter may be the
    problem...

    Ben

    --
    Heracles: Vulture! Here's a titbit for you / A few dried molecules of the gall
    From the liver of a friend of yours. / Excuse the arrow but I have no spoon.
    (Ted Hughes, [ Heracles shoots Vulture with arrow. Vulture bursts into ]
    /Alcestis/) [ flame, and falls out of sight. ]
     
    Ben Morrow, Jun 8, 2004
    #10
  11. Re: ANSI Screen escape sequences

    In comp.lang.perl.misc Ben Morrow <> wrote:

    > Quoth Joe Smith <>:
    >> Ben Morrow wrote:
    >>
    >> > use Term::ANSIScreen qw/:screen :cursor/;
    >> >
    >> > locate 1, 1;
    >> > cls;
    >> > print "...";
    >> >
    >> > For some reason I have found that both cls and clline only work for me
    >> > if I locate to the start of the region to be cleared first.

    >>
    >> That's a bug in your terminal emulator; it is not responding to escape
    >> sequences as per the ANSI specs.
    >>
    >> cldown = "\x33[0J" = clear from location to end of screen
    >> clup = "\x33[1J" = clear from beginning of screen to location
    >> cls = "\x33[2J" = clear the entire screen


    > I suspected as much. I didn't *really* think it likely that there would
    > be a bug in a module as simple as Term::ANSIScreen :).


    >> > presuming this is a bug in the linux console driver :) .

    >>
    >> Works fine with xterm, gnome-terminal, and the Linux 2.4.20 console.


    > Linux 2.6.3 console, in UTF-8 mode. I suspect the latter may be the
    > problem...


    ....or the perl script (the defect you're describing is a well-known defect
    of the so-called "ansi.sys" - perhaps someone made the perl script follow it).

    --
    Thomas E. Dickey
    http://invisible-island.net
    ftp://invisible-island.net
     
    Thomas Dickey, Jun 8, 2004
    #11
  12. Kris Dugan

    Joe Smith Guest

    Purl Gurl wrote:

    > I shall put the whammy on you.
    >
    > Perl core is an external program. It is external to your
    > hand written Perl script / program, yes?


    A library is not the same as an external program.

    Libraries get merged into your program's virtual address space
    and run there, with the same process ID is your main program.

    External programs have their own virtual address space,
    involve process creation and deletion, and run with a
    process ID different from your main program.

    -Joe
     
    Joe Smith, Jun 9, 2004
    #12
    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. Replies:
    2
    Views:
    625
    OutputLogic
    May 22, 2009
  2. Comcast

    Newbie ?: Force a periodic postback??

    Comcast, Aug 7, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    512
    Natty Gur
    Aug 7, 2003
  3. Kris Dugan

    Need constant screen with periodic updates

    Kris Dugan, Jun 7, 2004, in forum: C Programming
    Replies:
    8
    Views:
    353
    Thomas Dickey
    Jun 8, 2004
  4. robert
    Replies:
    1
    Views:
    103
    Martin Honnen
    Aug 23, 2003
  5. Gene Wirchenko

    Forcing Screen Updates

    Gene Wirchenko, Nov 25, 2011, in forum: Javascript
    Replies:
    4
    Views:
    571
    Dr J R Stockton
    Nov 26, 2011
Loading...

Share This Page