App-FQStat

 view release on metacpan or  search on metacpan

lib/App/FQStat/Actions.pm  view on Meta::CPAN

  warnenter if ::DEBUG;
  my $lines = shift || 1;
  lock($::DisplayOffset);
  $::DisplayOffset += $lines;
  my $limit = @{$::Records} - $::Termsize[1]+4;
  $::DisplayOffset = $limit if $::DisplayOffset > $limit;
  $::DisplayOffset = 0 if $::DisplayOffset < 0;
}


sub update_user_name {
  warnenter if ::DEBUG;
  my $input = poll_user("User name: ");
  lock($::User);
  if (not defined $input or $input =~ /^\s*$/) {
    $::User = undef;
  }
  else {
    $::User = $input;
  }
  update_display(1);
}

sub set_user_interval {
  warnenter if ::DEBUG;
  my $input = poll_user("Desired update interval: ");
  if (defined $input and  $input =~ /^\s*[+-]?(?=\d|\.\d)\d*(?:\.\d*)?(?:[Ee][+-]?\d+)?\s*$/) {
    $::UserInterval = $input+0;
    lock($::Interval);
    $::Interval = $::UserInterval;
  }
  update_display(1);
}

sub select_sort_field {
  warnenter if ::DEBUG;
  my @cols = ('status', @::Columns);

  # determine start sort field
  my $sort = 0;
  my $colno = 0;
  if (defined $::SortField) {
    foreach my $col (@cols) {
      if ($col eq $::SortField) {
        $sort = $colno;
        last;
      }
      $colno++;
    }
  }

  # key mappings
  my %ckeys = (
    'D' => sub { $sort--; $sort = @cols-1 if $sort < 0; }, # left
    'C' => sub { $sort++; $sort = 0 if $sort >= @cols;  }, # right
  );

  # print instructions
  locate(1,1);
  clline();
  print get_color("selected_cursor");
  print "Select Sort Field:";
  print RESET;
  print " (left/right to select, s/Enter to confirm, n for none, q to cancel)\n";

  while (1) {
    App::FQStat::Drawing::draw_header_line($sort+1);
    my $input = get_input_key();
    if (defined $input) {
      if ($input eq 's' or $input =~ /\n/ or $input =~ /\r/) { # select
        $::SortField = $cols[$sort];
        App::FQStat::Scanner::sort_current($::Records);
        return 1; # redraw
      }
      elsif ($input eq 'n') {
        $::SortField = undef;
        return 1; # redraw
      }
      elsif ($input eq 'q') {
        return 1;
      }
      elsif ($input eq '[') {
        my $key = get_input_key(0.01);
        if (defined $key and exists $ckeys{$key}) {
          $ckeys{$key}->($key);
        }
      }
    } # end if defined input
  } # end while
}

sub toggle_reverse_sort {
  warnenter if ::DEBUG;
  ::debug "Reversing sort order";
  lock($::RecordsReversed);
  if ($::RecordsReversed == 1) { $::RecordsReversed = 0 }
  else { $::RecordsReversed = 1 }
  App::FQStat::Scanner::reverse_records($::Records);
  return 1; # redraw
}


sub kill_jobs {
  warnenter if ::DEBUG;
  # print instructions
  locate(1,1);
  clline();
  print get_color("user_instructions");
  print "Kill jobs: Select with Space, span with 's', hit 'k' to kill or 'q' to cancel.";
  print RESET;
  print "\n";

  my ($selected, $key) = select_multiple_jobs( ['q', 'k'] );

  if ($key eq 'q' or @$selected == 0) {
    # cancel
    return 1; # redraw
  }
  elsif ($key eq 'k') {
    my $confirm = poll_user("Really kill? Type 'yes' to kill: ");
    if ($confirm =~ /^\s*yes\s*$/i) {



( run in 2.243 seconds using v1.01-cache-2.11-cpan-cdf2f3d4e48 )