FAQ
Author: comdog
Date: Sun Jun 22 23:50:14 2008
New Revision: 11440

Modified:
perlfaq/trunk/perlfaq7.pod
perlfaq/trunk/perlfaq8.pod

Log:
* perlfaq8: How do I clear the screen?
+ Expanded answer to cover Term::ANSIScreen and Win32::Console


Modified: perlfaq/trunk/perlfaq7.pod
==============================================================================
--- perlfaq/trunk/perlfaq7.pod (original)
+++ perlfaq/trunk/perlfaq7.pod Sun Jun 22 23:50:14 2008
@@ -238,6 +238,7 @@
=back

=head2 How do I create a class?
+X<class, creation> X<package>

(contributed by brian d foy)


Modified: perlfaq/trunk/perlfaq8.pod
==============================================================================
--- perlfaq/trunk/perlfaq8.pod (original)
+++ perlfaq/trunk/perlfaq8.pod Sun Jun 22 23:50:14 2008
@@ -169,23 +169,49 @@

=head2 How do I clear the screen?

-If you only have do so infrequently, use C<system>:
+(contributed by brian d foy)

- system("clear");
+To clear the screen, you just have to print the special sequence
+that tells the terminal to clear the screen. Once you have that
+sequence, output it when you want to clear the screen.

-If you have to do this a lot, save the clear string
-so you can print it 100 times without calling a program
-100 times:
+You can use the C<Term::ANSIScreen> module to get the special
+sequence. Import the C<cls> function (or the C<:screen> tag):

- $clear_string = `clear`;
- print $clear_string;
+ use Term::ANSIScreen qw(cls);
+ my $clear_screen = cls();
+
+ print $clear_screen;

-If you're planning on doing other screen manipulations, like cursor
-positions, etc, you might wish to use Term::Cap module:
+The C<Term::Cap> module can also get the special sequence if you want
+to deal with the low-level details of terminal control. The C<Tputs>
+method returns the string for the given capability:

use Term::Cap;
- $terminal = Term::Cap->Tgetent( {OSPEED => 9600} );
+
+ $terminal = Term::Cap->Tgetent( { OSPEED => 9600 } );
$clear_string = $terminal->Tputs('cl');
+
+ print $clear_screen;
+
+On Windows, you can use the C<Win32::Console> module. After creating
+an object for the output filehandle you want to affect, call the
+C<Cls> method:
+
+ Win32::Console;
+
+ $OUT = Win32::Console->new(STD_OUTPUT_HANDLE);
+ my $clear_string = $OUT->Cls;
+
+ print $clear_screen;
+
+If you have a command-line program that does the job, you can call
+it in backticks to capture whatever it outputs so you can use it
+later:
+
+ $clear_string = `clear`;
+
+ print $clear_string;

=head2 How do I get the screen size?

Search Discussions

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupcvs-perlfaq @
categoriesperl
postedJun 23, '08 at 6:50a
activeJun 23, '08 at 6:50a
posts1
users1
websitelearn.perl.org...

1 user in discussion

Comdog: 1 post

People

Translate

site design / logo © 2018 Grokbase