⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ch15_19.htm

📁 By Tom Christiansen and Nathan Torkington ISBN 1-56592-243-3 First Edition, published August 1998
💻 HTM
字号:
<HTML><HEAD><TITLE>Recipe 15.18. Program: Small termcap program (Perl Cookbook)</TITLE><METANAME="DC.title"CONTENT="Perl Cookbook"><METANAME="DC.creator"CONTENT="Tom Christiansen &amp; Nathan Torkington"><METANAME="DC.publisher"CONTENT="O'Reilly &amp; Associates, Inc."><METANAME="DC.date"CONTENT="1999-07-02T01:43:32Z"><METANAME="DC.type"CONTENT="Text.Monograph"><METANAME="DC.format"CONTENT="text/html"SCHEME="MIME"><METANAME="DC.source"CONTENT="1-56592-243-3"SCHEME="ISBN"><METANAME="DC.language"CONTENT="en-US"><METANAME="generator"CONTENT="Jade 1.1/O'Reilly DocBook 3.0 to HTML 4.0"><LINKREV="made"HREF="mailto:online-books@oreilly.com"TITLE="Online Books Comments"><LINKREL="up"HREF="ch15_01.htm"TITLE="15. User Interfaces"><LINKREL="prev"HREF="ch15_18.htm"TITLE="15.17. Removing the DOS Shell Window with Windows Perl/Tk"><LINKREL="next"HREF="ch15_20.htm"TITLE="15.19. Program: tkshufflepod"></HEAD><BODYBGCOLOR="#FFFFFF"><img alt="Book Home" border="0" src="gifs/smbanner.gif" usemap="#banner-map" /><map name="banner-map"><area shape="rect" coords="1,-2,616,66" href="index.htm" alt="Perl Cookbook"><area shape="rect" coords="629,-11,726,25" href="jobjects/fsearch.htm" alt="Search this book" /></map><div class="navbar"><p><TABLEWIDTH="684"BORDER="0"CELLSPACING="0"CELLPADDING="0"><TR><TDALIGN="LEFT"VALIGN="TOP"WIDTH="228"><ACLASS="sect1"HREF="ch15_18.htm"TITLE="15.17. Removing the DOS Shell Window with Windows Perl/Tk"><IMGSRC="../gifs/txtpreva.gif"ALT="Previous: 15.17. Removing the DOS Shell Window with Windows Perl/Tk"BORDER="0"></A></TD><TDALIGN="CENTER"VALIGN="TOP"WIDTH="228"><B><FONTFACE="ARIEL,HELVETICA,HELV,SANSERIF"SIZE="-1"><ACLASS="chapter"REL="up"HREF="ch15_01.htm"TITLE="15. User Interfaces"></A></FONT></B></TD><TDALIGN="RIGHT"VALIGN="TOP"WIDTH="228"><ACLASS="sect1"HREF="ch15_20.htm"TITLE="15.19. Program: tkshufflepod"><IMGSRC="../gifs/txtnexta.gif"ALT="Next: 15.19. Program: tkshufflepod"BORDER="0"></A></TD></TR></TABLE></DIV><DIVCLASS="sect1"><H2CLASS="sect1"><ACLASS="title"NAME="ch15-chap15_program_0">15.18. Program: Small termcap program</A></H2><DIVCLASS="sect2"><H3CLASS="sect2"><ACLASS="title"NAME="ch15-pgfId-2003">Description</A></H3><PCLASS="para"><ACLASS="indexterm"NAME="ch15-idx-1000005206-0"></A><ACLASS="indexterm"NAME="ch15-idx-1000005206-1"></A>This program clears your screen and scribbles all over it until you interrupt it. It shows how to use Term::Cap to clear the screen, move the cursor, and write anywhere on the screen. It also uses <ACLASS="xref"HREF="ch16_07.htm"TITLE="Preprocessing Input">Recipe 16.6</A>.</P><PCLASS="para">The program text is shown in <ACLASS="xref"HREF="ch15_19.htm#ch15-24645"TITLE="tcapdemo">Example 15.9</A>.</P><DIVCLASS="example"><H4CLASS="example"><ACLASS="title"NAME="ch15-24645">Example 15.9: tcapdemo</A></H4><PRECLASS="programlisting">#!/usr/bin/perl -w# <ACLASS="indexterm"NAME="ch15-idx-1000005014-0"></A>tcapdemo - show off direct cursor placementuse POSIX;use Term::Cap;    init();                     # Initialize Term::Cap.zip();                      # Bounce lines around the screen.finish();                   # Clean up afterward.exit();# Two convenience functions.  clear_screen is obvious, and# clear_end clears to the end of the screen.sub clear_screen { $tcap-&gt;Tputs('cl', 1, *STDOUT) } sub clear_end    { $tcap-&gt;Tputs('cd', 1, *STDOUT) } # Move the cursor to a particular location.sub gotoxy {    my($x, $y) = @_;    $tcap-&gt;Tgoto('cm', $x, $y, *STDOUT);} # Get the terminal speed through the POSIX module and use that# to initialize Term::Cap.sub init {     $| = 1;    $delay = (shift() || 0) * 0.005;    my $termios = POSIX::Termios-&gt;new();    $termios-&gt;getattr;    my $ospeed = $termios-&gt;getospeed;    $tcap = Term::Cap-&gt;Tgetent ({ TERM =&gt; undef, OSPEED =&gt; $ospeed });    $tcap-&gt;Trequire(qw(cl cm cd));}# Bounce lines around the screen until the user interrupts with# Ctrl-C.sub zip {     clear_screen();    ($maxrow, $maxcol) = ($tcap-&gt;{_li} - 1, $tcap-&gt;{_co} - 1);    @chars = qw(* - / | \ _ );    sub circle { push(@chars, shift @chars); }    $interrupted = 0;    $SIG{INT} = sub { ++$interrupted };    $col = $row = 0;    ($row_sign, $col_sign) = (1,1);    do {        gotoxy($col, $row);        print $chars[0];        select(undef, undef, undef, $delay);        $row += $row_sign;        $col += $col_sign;        if    ($row == $maxrow) { $row_sign = -1; circle; }         elsif ($row == 0 )      { $row_sign = +1; circle; }        if    ($col == $maxcol) { $col_sign = -1; circle; }         elsif ($col == 0 )      { $col_sign = +1; circle; }        } until $interrupted;}# Clean up the screen.sub finish {     gotoxy(0, $maxrow);    clear_end();}<ACLASS="indexterm"NAME="ch15-idx-1000005208-0"></A><ACLASS="indexterm"NAME="ch15-idx-1000005208-1"></A></PRE></DIV><PCLASS="para">This is what it looks like in mid-run:</P><PRECLASS="programlisting">*     _                       /     |                       \     - *   _ \                     - /   | /                     | \   - *  * _   \                   -   / |   /                   |   \ -   *   *     \                 -     |     /                 |     -     *  _ *     \               -     | /     /               |     - \     * _   *     \             -     |   /     /             |     -   \     **     *     \           -     |     /     /           |     -     \     * *     *     \         -     |       /     /         |     -       \     *  *     *     \       -     |         /     /       |     -         \     *   *     *     \     -     |           /     /     |     -           \     *    *     *     \   -     |             /     /   |     -             \     *     *     *     \ -     |               /     / |     -               \           *     -     \     |                 /     /     -                 \           *   - *   - \   |                   /   | /   -                   \           * -   * -   \ |                     / |   / -                     \ _         -     -     \                       |     /                       _</PRE></DIV><DIVCLASS="sect2"><H3CLASS="sect2"><ACLASS="title"NAME="ch15-pgfId-1000005759">See Also</A></H3><PCLASS="para"><ICLASS="filename">termcap </I>(5) (if you have it); the documentation for the standard Term::Cap module</P></DIV></DIV><DIVCLASS="htmlnav"><P></P><HRALIGN="LEFT"WIDTH="684"TITLE="footer"><TABLEWIDTH="684"BORDER="0"CELLSPACING="0"CELLPADDING="0"><TR><TDALIGN="LEFT"VALIGN="TOP"WIDTH="228"><ACLASS="sect1"HREF="ch15_18.htm"TITLE="15.17. Removing the DOS Shell Window with Windows Perl/Tk"><IMGSRC="../gifs/txtpreva.gif"ALT="Previous: 15.17. Removing the DOS Shell Window with Windows Perl/Tk"BORDER="0"></A></TD><TDALIGN="CENTER"VALIGN="TOP"WIDTH="228"><ACLASS="book"HREF="index.htm"TITLE="Perl Cookbook"><IMGSRC="../gifs/txthome.gif"ALT="Perl Cookbook"BORDER="0"></A></TD><TDALIGN="RIGHT"VALIGN="TOP"WIDTH="228"><ACLASS="sect1"HREF="ch15_20.htm"TITLE="15.19. Program: tkshufflepod"><IMGSRC="../gifs/txtnexta.gif"ALT="Next: 15.19. Program: tkshufflepod"BORDER="0"></A></TD></TR><TR><TDALIGN="LEFT"VALIGN="TOP"WIDTH="228">15.17. Removing the DOS Shell Window with Windows Perl/Tk</TD><TDALIGN="CENTER"VALIGN="TOP"WIDTH="228"><ACLASS="index"HREF="index/index.htm"TITLE="Book Index"><IMGSRC="../gifs/index.gif"ALT="Book Index"BORDER="0"></A></TD><TDALIGN="RIGHT"VALIGN="TOP"WIDTH="228">15.19. Program: tkshufflepod</TD></TR></TABLE><HRALIGN="LEFT"WIDTH="684"TITLE="footer"><FONTSIZE="-1"></DIV<!-- LIBRARY NAV BAR --> <img src="../gifs/smnavbar.gif" usemap="#library-map" border="0" alt="Library Navigation Links"><p> <a href="copyrght.htm">Copyright &copy; 2002</a> O'Reilly &amp; Associates. All rights reserved.</font> </p> <map name="library-map"> <area shape="rect" coords="1,0,85,94" href="../index.htm"><area shape="rect" coords="86,1,178,103" href="../lwp/index.htm"><area shape="rect" coords="180,0,265,103" href="../lperl/index.htm"><area shape="rect" coords="267,0,353,105" href="../perlnut/index.htm"><area shape="rect" coords="354,1,446,115" href="../prog/index.htm"><area shape="rect" coords="448,0,526,132" href="../tk/index.htm"><area shape="rect" coords="528,1,615,119" href="../cookbook/index.htm"><area shape="rect" coords="617,0,690,135" href="../pxml/index.htm"></map> </BODY></HTML>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -