+ cease(1, @_);
+}
+
+# determine the colour of the line
+sub setattr
+{
+ if ($has_colors) {
+ foreach my $ref (@colors) {
+ if ($_[0] =~ m{$$ref[0]}) {
+ $top->attrset($$ref[1]);
+ last;
+ }
+ }
+ }
+}
+
+# measure the no of screen lines a line will take
+sub measure
+{
+ my $line = shift;
+ return 0 unless $line;
+
+ my $l = length $line;
+ my $lines = int ($l / COLS());
+ $lines++ if $l / COLS() > $lines;
+ return $lines;
+}
+
+# display the top screen
+sub show_screen
+{
+ if ($spos == @shistory - 1) {
+
+ # if we really are scrolling thru at the end of the history
+ my $line = $shistory[$spos];
+ $top->addstr("\n") if $spos > 0;
+ setattr($line);
+ $top->addstr($line);
+ $top->attrset(COLOR_PAIR(0)) if $has_colors;
+ $spos = @shistory;
+
+ } else {
+
+ # anywhere else
+ my ($i, $l);
+ my $p = $spos-1;
+ for ($i = 0; $i < $pagel && $p >= 0; ) {
+ $l = measure($shistory[$p]);
+ $i += $l;
+ $p-- if $i < $pagel;
+ }
+ $p = 0 if $p < 0;
+
+ $top->move(0, 0);
+ $top->attrset(COLOR_PAIR(0)) if $has_colors;
+ $top->clrtobot();
+ for ($i = 0; $i < $pagel && $p < @shistory; $p++) {
+ my $line = $shistory[$p];
+ my $lines = measure($line);
+ last if $i + $lines > $pagel;
+ setattr($line);
+ $top->addstr($i, 0, $line);
+ $top->attrset(COLOR_PAIR(0)) if $has_colors;
+ $i += $lines;
+ }
+ $spos = $p;
+ $spos = @shistory if $spos > @shistory;
+ }
+ my $shl = @shistory;
+ my $add = "-$spos-$shl";
+ $scr->addstr(LINES()-4, 0, '-' x (COLS() - (length($call) + length($add))));
+ $scr->attrset($mycallcolor) if $has_colors;
+ $scr->addstr("$call");
+ $scr->attrset(COLOR_PAIR(0)) if $has_colors;
+ $scr->addstr($add);
+ $scr->refresh();
+# $top->refresh();
+}
+
+# add a line to the end of the top screen
+sub addtotop
+{
+ while (@_) {
+ my $inbuf = shift;
+ push @shistory, $inbuf;
+ shift @shistory if @shistory > $maxshist;
+ }
+ show_screen();