[Tutor] Is there a function for refreshing what's in the console?

Derrick 'dman' Hudson dman@dman.ddts.net
Sat, 8 Jun 2002 10:27:55 -0500


--5mCyUwZo2JvN/JJP
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

On Sat, Jun 08, 2002 at 05:40:45PM +1000, Dimitrije Nikic wrote:
| Is there a function for refreshing what's in the console? (Eg.
| delete everything printed previously in the window)

Yes and no.  There are a couple of ways you can do this, one doesn't
really work, one is not wholly cross-platform.  The problem is knowing
what the user's console looks like (eg how big it is, etc) and how to
tell it to clear.

The way that doesn't really work is to assume you know how many lines
it will contain and do something like this :
    print "\n"*24
That works for a VT-100 and work-alikes that only have 24 lines on the
screen.  When I work in gnome-terminal, it too has 24 lines (but it
allows that to be changed arbitrarily).  If I work in my linux console
I have about 64 lines on screen.  That's why it doesn't really work.
If some user gets a bigger screen, that won't push the text all the
way off it.

The way that works is to use the ncurses library.  Of course,
Microsoft didn't feel the need to provide a curses implementation on
their platform, so it doesn't work on Windows unless you require the
use of cygwin (to emulate UNIX :-)).  ncurses is a great library
because it abstracts away the details of each and every terminal ever
made and handles the interaction with the terminal for you.  You
simply tell it what you want it to do.  I've never done any curses
programming before, but I've heard that it isn't the easiest thing to
learn.

HTH,
-D

--=20

Whoever gives heed to instruction prospers,
and blessed is he who trusts in the Lord.
        Proverbs 16:20
=20
GnuPG key : http://dman.ddts.net/~dman/public_key.gpg


--5mCyUwZo2JvN/JJP
Content-Type: application/pgp-signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.6 (GNU/Linux)
Comment: For info see http://www.gnupg.org

iEYEARECAAYFAj0CInoACgkQO8l8XBKTpRTT9QCgtQv/CE96NQAqdzHe/wq9cNx+
DiQAn3lbF7QD9p1uI0DGqjsQx9x5wFMs
=muc/
-----END PGP SIGNATURE-----

--5mCyUwZo2JvN/JJP--