Linux/Unix 桌面趣事:终端上的圣诞树

给你的Linux或Unix控制台创造一棵圣诞树玩玩吧。在此之前,需要先安装一个Perl模块,命名为Acme::POE::Tree。这是一棵很喜庆的圣诞树,我已经在Linux、OSX和类Unix系统上验证过了。

Linux/Unix 桌面趣事:终端上的圣诞树

 

安装 Acme::POE::Tree

安装perl模块最简单的办法就是使用CPAN(Perl综合典藏网(Comprehensive Perl Archive Network))。打开终端,把下面的指令敲进去便可安装Acme::POE::Tree。

  1. <span class="com">### 以root身份运行 ###</span>
  2. <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>

示例输出:

  1. <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>
  2. <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>
  3. <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>
  4. <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>
  5. <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>
  6. <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>
  7. <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>
  8. <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>
  9. <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>
  10. <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>
  11. <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>
  12. <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>
  13. <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>
  14. <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>
  15. <span class="typ">Has</span><span class="pln"> already been prepared</span>
  16. <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>
  17. <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>
  18. <span class="typ">Manifying</span><span class="lit">1</span><span class="pln"> pod document</span>
  19. <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>
  20. <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>
  21. <span class="typ">Running</span><span class="kwd">make</span><span class="kwd">test</span>
  22. <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>
  23. <span class="com">t/01_basic.t .. ok</span>
  24. <span class="com">All tests successful.</span>
  25. <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>
  26. <span class="com">Result: PASS</span>
  27. <span class="com">RCAPUTO/Acme-POE-Tree-1.022.tar.gz</span>
  28. <span class="com">Tests succeeded but one dependency not OK (Curses)</span>
  29. <span class="com">RCAPUTO/Acme-POE-Tree-1.022.tar.gz</span>
  30. <span class="com">[dependencies] -- NA</span>

 

在Shell中显示圣诞树

只需要在终端上运行以下命令:

  1. <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>

示例输出

Linux/Unix 桌面趣事:终端上的圣诞树

Gif 01: An animated christmas tree in Perl

Gif 01: 一棵用Perl写的喜庆圣诞树

 

树的定制

以下是我的脚本文件tree.pl的内容:

  1. <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>
  2. <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>
  3. <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>
  4. <span class="pun">{</span>
  5. <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>
  6. <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>
  7. <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>
  8. <span class="pun">}</span>
  9. <span class="pun">);</span>
  10. <span class="pln">$tree</span><span class="pun">-></span><span class="pln">run</span><span class="pun">();</span>

这样就可以通过修改stardelay、runfor和light_delay参数的值来自定义你的树了。一棵好玩的终端圣诞树就此诞生。


via: http://www.cyberciti.biz/open-source/command-line-hacks/linux-unix-desktop-fun-christmas-tree-for-your-terminal/

作者:Vivek Gite 译者:soooogreen 校对:wxy

本文由 LCTT 原创编译,Linux中国 荣誉推出

相关推荐