#!/usr/bin/perl use Curses; use IO::Select; # Subs sub send_line { my $sl=shift; $top->addstr($sl."\n"); $top->refresh; } sub handle_keyboard { my $ch=$bottom->getch(); if($ch<0) { $leavenow++; return; } my $c=ord $ch; if($ch>255) { ; } elsif($c<32 || $c==127) { if($c==127) { $line=~s/.$//; $bottom->erase; $bottom->addstr(0,0,$line); } elsif($c==10 || $c==13) { send_line($line); $line=''; $bottom->erase; } } else { $line.=$ch; $bottom->addch($ch); } my $len=length($line); $bottom->move(int($len/80),($len % 80)); $bottom->refresh(); } # MAIN my $sel=IO::Select->new(); $sel->add(\*STDIN); $root=new Curses; cbreak(); noecho(); start_color(); init_pair(1,COLOR_WHITE,COLOR_BLACK); init_pair(2,COLOR_BLACK,COLOR_WHITE); $root->erase; $top=$root->subwin(20,80,0,0); $top->scrollok(1); $top->leaveok(1); $top->attron(COLOR_PAIR(1)); $top->refresh; $top->addstr(0,0,"Startup"); $top->refresh; $status=$root->subwin(1,80,20,0); $status->leaveok(1); $status->attron(COLOR_PAIR(2)); $status->addstr(0,0," " x 80); $status->refresh; $bottom=$root->subwin(3,80,21,0); $bottom->leaveok(0); $bottom->attron(COLOR_PAIR(1)); $bottom->keypad(1); $bottom->move(0,0); $bottom->refresh; my $leavenow=0; my @ready; my $line=''; while(@ready=$sel->can_read) { my $fh; # $top->addstr("test"); $top->refresh; foreach $fh (@ready) { if($fh == \*STDIN) { # Keyboard. # $top->addstr("key! "); $top->refresh; handle_keyboard; } } # $top->addstr($leavenow); $top->refresh; # last if($leavenow); } endwin; exit 0;