#!/usr/bin/perl

# Written by Greg Kurtzer to provide a basic interface to configure
# network devices for cAos Linux.

BEGIN {
   push (@INC, "./lib/");
   push (@INC, "../lib/");
   push (@INC, "/usr/lib/sidekick/");
   push (@INC, "/usr/lib64/sidekick/");
}


use Term::ScreenColor;
use Getopt::Long;
use Sys::Hostname;
use Sidekick;
#use strict;

Getopt::Long::Configure ("bundling", "pass_through");

if ( $> != '0' ) {
   die "You need to run this as root!\n";
#   warn "You need to be root to make configuration changes!\n";
}


sub write_page {
   my ( $sel, @NULL) = @_;
   if ( ! $scr ) {
      $scr = new Term::ScreenColor;
      $scr->noecho();
   }
   $scr->clrscr();
   $scr->at(0,0);
   $scr->puts("cAos Linux: Blah");

   $line = 2;
   $count = 1;
   $scr->at($line,1);
   $scr->bold();
   $out=sprintf("  %-23.23s %-52.52s", "Option", "Description");
   $scr->puts($out);
   $scr->normal();
   $line++;
   $count++;

   if ( $sel == $line ) {
      &info_message($scr, "Message about opt 1");
      $scr->at($line,1);
      $scr->reverse();
   } else {
      $scr->at($line,1);
      $scr->normal();
   }
   $out=sprintf("  %-23.23s %-52.52s", "Opt 1", "description 1");
   $scr->puts($out);
   $line++;
   $count++;

   if ( $sel == $line ) {
      &info_message($scr, "Message about opt 2");
      $scr->at($line,1);
      $scr->reverse();
   } else {
      $scr->at($line,1);
      $scr->normal();
   }
   $out=sprintf("  %-23.23s %-52.52s", "Opt 2", "description 2");
   $scr->puts($out);
   $line++;
   $count++;


   $scr->normal();
   $scr->at($line+1,0);
   $scr->clreol();
   $scr->puts("Up/Down to navigate, Space/Enter to select, 'd' when done: ");
   return($count);
}


$select = 3;
while(1){
   $total = &write_page($select);
   $scr->flush_input();
   $key = $scr->getch();
   if ( $key =~ /kd/ or $key =~ /        / ) {
      if ( $total == $select ) {
         $select = 3;
      } else {
         $select++;
      }
   } elsif ( $key eq 'ku' ) {
      if ( $select == 3 ) {
         $select = $total;
      } else {
         $select--;
      }
   } elsif ( $key eq '
' or $key eq ' ' or $key eq 'kr' ) {
      # Do something useful here
   } elsif ( $key eq 'd' ) {
      $post = '1';
      last;
   } elsif ( $key eq 'q' or $key eq 'kl' or $key eq '' ) {
      last;
   } else {
   }
}

$scr->normal();
&info_message($scr, undef);
$scr=();

print "\n";

if ( $post ) {
   # Do soemthing else useful hery

}
