App-FQStat

 view release on metacpan or  search on metacpan

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

  }
  ::GetTermSize();
  $line = substr($line, 0, $::Termsize[0]) if $::Termsize[0] < length($line);
  printline($line);
  print RESET if $::MenuMode;
}

# draws the column header line
sub draw_header_line {
  warnenter if ::DEBUG > 1;
  my @highlight = @_;
  my %highlight = map {($_ => 1)} @highlight;

  # Header Line
  locate(2,1);
  my ($line, $width);

  my $high = get_color("header_highlight");
  my $norm = get_color("header_normal");

  my $summary_mode = $::SummaryMode;
  my $summary_clustering = App::FQStat::Config::get("summary_clustering");

  print $norm;
  if (not $summary_mode) {
    if (exists $highlight{1}) { $line = $high.'Stat'.$norm }
    else { $line = 'Stat' }
  }

  $width = 4;
  my $colno = 1;
  my $columns_list = $summary_mode ? \@::SummaryColumns : \@::Columns;
  my $columns_hash = $summary_mode ? \%::SummaryColumns : \%::Columns;
  foreach my $col (@$columns_list) {
    my $c = $columns_hash->{$col};
    $colno++;
    next if $summary_mode and $c->{key} eq 'name' and not $summary_clustering;
    $line .= (' 'x($::Termsize[0]-$width-1)).'>', last if $width+2+$c->{width} > $::Termsize[0];
    $width += 1+$c->{width};
    $line .= ' ' unless $colno == 2 and $summary_mode;
    if (exists $highlight{$colno}) { $line .= $high.sprintf("\%-".$c->{width}."s", $c->{name}).$norm }
    else                           { $line .= sprintf("\%-".$c->{width}."s", $c->{name}) }
  }
  printline($line);
  print RESET;
}


my $last_update;
sub update_display {
  warnenter if ::DEBUG;
  my $force = shift;
  $last_update ||= time();
  my $time = time();

  if ($force or $time-$last_update > $::Interval) {
    $last_update = $time;
    $::ProgressIndicator++;
    $::ProgressIndicator = 0
      if $::ProgressIndicator >= scalar(@{::PROGRESS_INDICATORS()});
    App::FQStat::Scanner::run_qstat($force);
  }

  cls();
  ::GetTermSize();

  draw_title_line(); # first line
  draw_header_line(); # second line
  my $summary_mode = $::SummaryMode;

  if ($summary_mode) {
    draw_summary();
  } else {
    draw_job_display(); # list of jobs
  }

  if ($::MenuMode) {
    App::FQStat::Menu::draw_menu();
  }

  locate(1,1);
}

# Draws the job summary
sub draw_summary {
  warnenter if ::DEBUG;

  # before there's any jobs, warn the user that the
  # queue isn't actually empty.
  if (not $::Initialized) {
    draw_initializing_sign();
    locate(1,1);
    return;
  }

  App::FQStat::Scanner::calculate_summary()
    if not defined $::Summary or @$::Summary == 0;

  my $summary = $::Summary;
  my $summary_clustering = App::FQStat::Config::get("summary_clustering");

  my $maxno_lines = space_for_jobs();

  my %status_color = (
    nrun  => get_color("status_running"),
    nerr  => get_color("status_error"),
    nhold => get_color("status_hold"),
    nwait => get_color("status_queued"),
  );

  locate(3,1);
  my $summary_color = get_color("summary");

  my $no = 0;

  foreach my $summaryLine (@$summary) {
    $no++;
    last if $no >= $maxno_lines;

    clline();
    print $summary_color;



( run in 2.137 seconds using v1.01-cache-2.11-cpan-39bf76dae61 )