用户注册



邮箱:

密码:

用户登录


邮箱:

密码:
记住登录一个月忘记密码?

发表随想


还能输入:200字
云代码 - perl代码库

perl 屏幕管理

2012-10-14 作者: 神马举报

[perl]代码库

#-----------------------------
#% rep ps aux
#% rep netstat
#% rep -2.5 lpq
#-----------------------------
# download the following standalone program
#!/usr/bin/perl -w
# rep - screen repeat command
use strict;
use Curses;

my $timeout = 10;
if ( @ARGV && $ARGV[0] =~ /^- ( \d+\.?\d* ) $/ )
{
	$timeout = $1;
	shift;
}

die "usage: $0 [ -timeout ] cmd args\n" unless @ARGV;

initscr();
# start screen
noecho();
cbreak();
nodelay ( 1 );
# so getch() is non-blocking

$SIG {INT} = sub { done ( "Ouch!" ) };
sub done { endwin(); print "@_\n"; exit; }

while ( 1 )
{
	while ( ( my $key = getch() ) ne ERR )
	{
# maybe multiple keys
		done ( "See ya" ) if $key eq 'q'
	}
my @data = ` ( @ARGV ) 2>&1`;
# gather output+errors
	for ( my $i = 0; $i < $LINES; $i++ )
	{
		addstr ( $i, 0, $data[$i] || ' ' x $COLS );
	}

	standout();
	addstr ( $LINES-1, $COLS - 24, scalar localtime );
	standend();

	move ( 0,0 );
	refresh();
# flush new output to display

	my ( $in, $out ) = ( '', '' );
	vec ( $in,fileno ( STDIN ),1 ) = 1;
# look for key on stdin
	select ( $out = $in,undef,undef,$timeout );
# wait up to this long
}

#-----------------------------
keypad ( 1 );
# enable keypad mode
$key = getch();
if ( $key eq 'k'     ||      # vi mode
        $key eq "\cP"   ||      # emacs mode
        $key eq KEY_UP )         # arrow mode
{
# do something
}
#-----------------------------
#		       Template Entry Demonstration
#
#   Address Data Example                                     Record # ___
#
#   Name: [________________________________________________]
#   Addr: [________________________________________________]
#   City: [__________________]          State: [__]       Zip: [\\\\\]
#
#   Phone: (\\\) \\\-\\\\                            Password: [^^^^^^^^]
#
#   Enter all information available.
#   Edit fields with left/right arrow keys or "delete".
#   Switch fields with "Tab" or up/down arrow keys.
#   Indicate completion by pressing "Return".
#   Refresh screen with "Control-L".
#   Abort this demo here with "Control-X".
#-----------------------------


网友评论    (发表评论)


发表评论:

评论须知:

  • 1、评论每次加2分,每天上限为30;
  • 2、请文明用语,共同创建干净的技术交流环境;
  • 3、若被发现提交非法信息,评论将会被删除,并且给予扣分处理,严重者给予封号处理;
  • 4、请勿发布广告信息或其他无关评论,否则将会删除评论并扣分,严重者给予封号处理。


扫码下载

加载中,请稍后...

输入口令后可复制整站源码

加载中,请稍后...