# NB: $mapleheader is a global variable
sub interact {
  my $type = shift;
  my $content = shift;
  if ($type == -1) { # initialisation
    print "Enter your Maple commands, finish with Ctrl-D.\n";
    $mapleheader = 1;
    return;
  }
  if ($type == -2) { # end
    close CIN;
    return;
  }
  if ($type == 0) { # was STDIN
    print CIN;
    return;
  }
  if ($type == 1) { # was STDOUT
    do { $mapleheader = 0; return; } if /Type \? for help/;
    return if $mapleheader;
    s/^> .*\n//mg;
    s/^\s+//mg;
  #  return if /^> /;
    return unless $_;
    return if /bytes used/;
    print STDOUT "Maple: $_";
    return;
  }
  if ($type == 2) { # was STDERR
    print STDOUT "Maple[err]: $_";
    return;
  }
}
1;
