Linux/Unix 桌面趣事:终端上的圣诞树
给你的Linux或Unix控制台创造一棵圣诞树玩玩吧。在此之前,需要先安装一个Perl模块,命名为Acme::POE::Tree。这是一棵很喜庆的圣诞树,我已经在Linux、OSX和类Unix系统上验证过了。
安装 Acme::POE::Tree
安装perl模块最简单的办法就是使用CPAN(Perl综合典藏网(Comprehensive Perl Archive Network))。打开终端,把下面的指令敲进去便可安装Acme::POE::Tree。
<span class="com">### 以root身份运行 ###</span>
<span class="pln">perl </span><span class="pun">-</span><span class="pln">MCPAN </span><span class="pun">-</span><span class="pln">e </span><span class="str">'install Acme::POE::Tree'</span>
示例输出:
<span class="typ">Installing</span><span class="pun">/</span><span class="pln">home</span><span class="pun">/</span><span class="pln">vivek</span><span class="pun">/</span><span class="pln">perl5</span><span class="pun">/</span><span class="kwd">man</span><span class="pun">/</span><span class="pln">man3</span><span class="pun">/</span><span class="pln">POE</span><span class="pun">::</span><span class="pln">NFA</span><span class="pun">.</span><span class="lit">3pm</span>
<span class="typ">Installing</span><span class="pun">/</span><span class="pln">home</span><span class="pun">/</span><span class="pln">vivek</span><span class="pun">/</span><span class="pln">perl5</span><span class="pun">/</span><span class="kwd">man</span><span class="pun">/</span><span class="pln">man3</span><span class="pun">/</span><span class="pln">POE</span><span class="pun">::</span><span class="typ">Kernel</span><span class="pun">.</span><span class="lit">3pm</span>
<span class="typ">Installing</span><span class="pun">/</span><span class="pln">home</span><span class="pun">/</span><span class="pln">vivek</span><span class="pun">/</span><span class="pln">perl5</span><span class="pun">/</span><span class="kwd">man</span><span class="pun">/</span><span class="pln">man3</span><span class="pun">/</span><span class="pln">POE</span><span class="pun">::</span><span class="typ">Loop</span><span class="pun">.</span><span class="lit">3pm</span>
<span class="typ">Installing</span><span class="pun">/</span><span class="pln">home</span><span class="pun">/</span><span class="pln">vivek</span><span class="pun">/</span><span class="pln">perl5</span><span class="pun">/</span><span class="kwd">man</span><span class="pun">/</span><span class="pln">man3</span><span class="pun">/</span><span class="pln">POE</span><span class="pun">::</span><span class="typ">Resource</span><span class="pun">.</span><span class="lit">3pm</span>
<span class="typ">Installing</span><span class="pun">/</span><span class="pln">home</span><span class="pun">/</span><span class="pln">vivek</span><span class="pun">/</span><span class="pln">perl5</span><span class="pun">/</span><span class="kwd">man</span><span class="pun">/</span><span class="pln">man3</span><span class="pun">/</span><span class="pln">POE</span><span class="pun">::</span><span class="typ">Filter</span><span class="pun">::</span><span class="typ">Map</span><span class="pun">.</span><span class="lit">3pm</span>
<span class="typ">Installing</span><span class="pun">/</span><span class="pln">home</span><span class="pun">/</span><span class="pln">vivek</span><span class="pun">/</span><span class="pln">perl5</span><span class="pun">/</span><span class="kwd">man</span><span class="pun">/</span><span class="pln">man3</span><span class="pun">/</span><span class="pln">POE</span><span class="pun">::</span><span class="typ">Resource</span><span class="pun">::</span><span class="typ">SIDs</span><span class="pun">.</span><span class="lit">3pm</span>
<span class="typ">Installing</span><span class="pun">/</span><span class="pln">home</span><span class="pun">/</span><span class="pln">vivek</span><span class="pun">/</span><span class="pln">perl5</span><span class="pun">/</span><span class="kwd">man</span><span class="pun">/</span><span class="pln">man3</span><span class="pun">/</span><span class="pln">POE</span><span class="pun">::</span><span class="typ">Loop</span><span class="pun">::</span><span class="pln">IO_Poll</span><span class="pun">.</span><span class="lit">3pm</span>
<span class="typ">Installing</span><span class="pun">/</span><span class="pln">home</span><span class="pun">/</span><span class="pln">vivek</span><span class="pun">/</span><span class="pln">perl5</span><span class="pun">/</span><span class="kwd">man</span><span class="pun">/</span><span class="pln">man3</span><span class="pun">/</span><span class="pln">POE</span><span class="pun">::</span><span class="typ">Pipe</span><span class="pun">::</span><span class="typ">TwoWay</span><span class="pun">.</span><span class="lit">3pm</span>
<span class="typ">Appending</span><span class="pln"> installation </span><span class="kwd">info</span><span class="pln"> to </span><span class="pun">/</span><span class="pln">home</span><span class="pun">/</span><span class="pln">vivek</span><span class="pun">/</span><span class="pln">perl5</span><span class="pun">/</span><span class="pln">lib</span><span class="pun">/</span><span class="pln">perl5</span><span class="pun">/</span><span class="pln">x86_64</span><span class="pun">-</span><span class="pln">linux</span><span class="pun">-</span><span class="pln">gnu</span><span class="pun">-</span><span class="pln">thread</span><span class="pun">-</span><span class="pln">multi</span><span class="pun">/</span><span class="pln">perllocal</span><span class="pun">.</span><span class="pln">pod</span>
<span class="pln">RCAPUTO</span><span class="pun">/</span><span class="pln">POE</span><span class="pun">-</span><span class="lit">1.367</span><span class="pun">.</span><span class="kwd">tar</span><span class="pun">.</span><span class="pln">gz</span>
<span class="pun">/</span><span class="pln">usr</span><span class="pun">/</span><span class="pln">bin</span><span class="pun">/</span><span class="kwd">make</span><span class="pln"> install </span><span class="pun">--</span><span class="pln"> OK</span>
<span class="pln">RCAPUTO</span><span class="pun">/</span><span class="typ">Acme</span><span class="pun">-</span><span class="pln">POE</span><span class="pun">-</span><span class="typ">Tree</span><span class="pun">-</span><span class="lit">1.022</span><span class="pun">.</span><span class="kwd">tar</span><span class="pun">.</span><span class="pln">gz</span>
<span class="typ">Has</span><span class="pln"> already been unwrapped into directory </span><span class="pun">/</span><span class="pln">home</span><span class="pun">/</span><span class="pln">vivek</span><span class="pun">/.</span><span class="pln">cpan</span><span class="pun">/</span><span class="pln">build</span><span class="pun">/</span><span class="typ">Acme</span><span class="pun">-</span><span class="pln">POE</span><span class="pun">-</span><span class="typ">Tree</span><span class="pun">-</span><span class="lit">1.022</span><span class="pun">-</span><span class="pln">uhlZUz</span>
<span class="pln">RCAPUTO</span><span class="pun">/</span><span class="typ">Acme</span><span class="pun">-</span><span class="pln">POE</span><span class="pun">-</span><span class="typ">Tree</span><span class="pun">-</span><span class="lit">1.022</span><span class="pun">.</span><span class="kwd">tar</span><span class="pun">.</span><span class="pln">gz</span>
<span class="typ">Has</span><span class="pln"> already been prepared</span>
<span class="typ">Running</span><span class="kwd">make</span><span class="kwd">for</span><span class="pln"> R</span><span class="pun">/</span><span class="pln">RC</span><span class="pun">/</span><span class="pln">RCAPUTO</span><span class="pun">/</span><span class="typ">Acme</span><span class="pun">-</span><span class="pln">POE</span><span class="pun">-</span><span class="typ">Tree</span><span class="pun">-</span><span class="lit">1.022</span><span class="pun">.</span><span class="kwd">tar</span><span class="pun">.</span><span class="pln">gz</span>
<span class="kwd">cp</span><span class="pln"> lib</span><span class="pun">/</span><span class="typ">Acme</span><span class="pun">/</span><span class="pln">POE</span><span class="pun">/</span><span class="typ">Tree</span><span class="pun">.</span><span class="pln">pm blib</span><span class="pun">/</span><span class="pln">lib</span><span class="pun">/</span><span class="typ">Acme</span><span class="pun">/</span><span class="pln">POE</span><span class="pun">/</span><span class="typ">Tree</span><span class="pun">.</span><span class="pln">pm</span>
<span class="typ">Manifying</span><span class="lit">1</span><span class="pln"> pod document</span>
<span class="pln">RCAPUTO</span><span class="pun">/</span><span class="typ">Acme</span><span class="pun">-</span><span class="pln">POE</span><span class="pun">-</span><span class="typ">Tree</span><span class="pun">-</span><span class="lit">1.022</span><span class="pun">.</span><span class="kwd">tar</span><span class="pun">.</span><span class="pln">gz</span>
<span class="pun">/</span><span class="pln">usr</span><span class="pun">/</span><span class="pln">bin</span><span class="pun">/</span><span class="kwd">make</span><span class="pun">--</span><span class="pln"> OK</span>
<span class="typ">Running</span><span class="kwd">make</span><span class="kwd">test</span>
<span class="pln">PERL_DL_NONLAZY</span><span class="pun">=</span><span class="lit">1</span><span class="str">"/usr/bin/perl"</span><span class="str">"-MExtUtils::Command::MM"</span><span class="str">"-MTest::Harness"</span><span class="str">"-e"</span><span class="str">"undef *Test::Harness::Switches; test_harness(0, 'blib/lib', 'blib/arch')"</span><span class="pln"> t</span><span class="com">/*.t</span>
<span class="com">t/01_basic.t .. ok</span>
<span class="com">All tests successful.</span>
<span class="com">Files=1, Tests=2, 6 wallclock secs ( 0.09 usr 0.03 sys + 0.53 cusr 0.06 csys = 0.71 CPU)</span>
<span class="com">Result: PASS</span>
<span class="com">RCAPUTO/Acme-POE-Tree-1.022.tar.gz</span>
<span class="com">Tests succeeded but one dependency not OK (Curses)</span>
<span class="com">RCAPUTO/Acme-POE-Tree-1.022.tar.gz</span>
<span class="com">[dependencies] -- NA</span>
在Shell中显示圣诞树
只需要在终端上运行以下命令:
<span class="pln">perl </span><span class="pun">-</span><span class="typ">MAcme</span><span class="pun">::</span><span class="pln">POE</span><span class="pun">::</span><span class="typ">Tree</span><span class="pun">-</span><span class="pln">e </span><span class="str">'Acme::POE::Tree->new()->run()'</span>
示例输出
Gif 01: An animated christmas tree in Perl
Gif 01: 一棵用Perl写的喜庆圣诞树
树的定制
以下是我的脚本文件tree.pl的内容:
<span class="com">#</span><span class="pun">!</span><span class="str">/usr/</span><span class="pln">bin</span><span class="pun">/</span><span class="pln">perl</span>
<span class="kwd">use</span><span class="typ">Acme</span><span class="pun">::</span><span class="pln">POE</span><span class="pun">::</span><span class="typ">Tree</span><span class="pun">;</span>
<span class="kwd">my</span><span class="pln"> $tree </span><span class="pun">=</span><span class="typ">Acme</span><span class="pun">::</span><span class="pln">POE</span><span class="pun">::</span><span class="typ">Tree</span><span class="pun">-></span><span class="kwd">new</span><span class="pun">(</span>
<span class="pun">{</span>
<span class="pln">star_delay </span><span class="pun">=></span><span class="lit">1.5</span><span class="pun">,</span><span class="com">#</span><span class="pln"> shimmer star every </span><span class="lit">1.5</span><span class="pln"> sec</span>
<span class="pln">light_delay </span><span class="pun">=></span><span class="lit">2</span><span class="pun">,</span><span class="com">#</span><span class="pln"> twinkle lights every </span><span class="lit">2</span><span class="pln"> sec</span>
<span class="pln">run_for </span><span class="pun">=></span><span class="lit">10</span><span class="pun">,</span><span class="com">#</span><span class="pln"> automatically </span><span class="kwd">exit</span><span class="pln"> after </span><span class="lit">10</span><span class="pln"> sec</span>
<span class="pun">}</span>
<span class="pun">);</span>
<span class="pln">$tree</span><span class="pun">-></span><span class="pln">run</span><span class="pun">();</span>
这样就可以通过修改stardelay、runfor和light_delay参数的值来自定义你的树了。一棵好玩的终端圣诞树就此诞生。
作者:Vivek Gite 译者:soooogreen 校对:wxy
相关推荐
犇骉 2011-01-24
一个逗逗 2020-09-22
86530396 2020-06-12
patiencezzz 2020-05-16
死鱼喜欢猫 2020-05-12
书虫媛 2020-05-03
ffantastic 2020-03-17
JasonYeung 2020-03-08
SIMONDOMAIN 2020-02-25
服务器端攻城师 2020-02-24
SIMONDOMAIN 2020-02-03
zycglboy 2020-01-13
Jieen 2020-01-08
treasurelifelhf 2013-07-24
jadeball 2019-12-29
暗夜之城 2019-12-27
Hwaphon 2019-11-25
liuxingyuling 2019-11-18