/[iselect]/iselect.pl
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /iselect.pl

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1 by dpavlin, Thu Oct 25 11:22:18 2007 UTC revision 2 by dpavlin, Thu Oct 25 11:43:48 2007 UTC
# Line 28  while(<$ps>) { Line 28  while(<$ps>) {
28  }  }
29  close($ps);  close($ps);
30    
31    my $scr;
32    
33  my @lines = split(/\n/, $data);  # leave sane terminal if script dies
34    $SIG{__DIE__} = sub {
35        eval { system('stty sane'); };
36    };
37    
38  my $scr = new Term::Screen || die "can't init Term::Screen";  
39  $scr->clrscr()->noecho();  my @lines = split(/\n/, $data);
40    
41  my $o = 0;      # offset in original text  my $o = 0;      # offset in original text
42  my $pos = 0;  my $pos = 0;
43    
44    # default: select first line
45    my $sel_pos = 0;
46    my $status_text = '';
47    my $error_text = '';
48    
49    
50  # find which lines are selectable in input file  # find which lines are selectable in input file
51  my $selectable_line;  my $selectable_line;
52    
# Line 50  for my $l (0 .. $#lines) { Line 60  for my $l (0 .. $#lines) {
60          warn "$l: $foo $lines[$l]\n";          warn "$l: $foo $lines[$l]\n";
61  }  }
62    
63    # select first selectable line
64    
65    if ( $selectable_line ) {
66            $sel_pos = (sort keys %$selectable_line)[0];
67            warn "selected first selectable line $pos";
68    }
69    
70  sub full_line {  sub full_line {
71          my $t = shift;          my $t = shift;
72          my $l = length($t);          my $l = length($t);
# Line 76  sub redraw { Line 93  sub redraw {
93          }          }
94  }  }
95    
 # default: select first line  
 my $sel_pos = 0;  
 my $status_text = '';  
 my $error_text = '';  
 $pos = 0;  
   
96  sub status {  sub status {
97          my $pcnt = int(($pos || 0) * 100 / ($#lines || 1));          my $pcnt = int(($pos || 0) * 100 / ($#lines || 1));
98          my $pos_txt = sprintf('%d, %d%% ',$pos,$pcnt);          my $pos_txt = sprintf('%d, %d%% ',$pos,$pcnt);
# Line 95  sub status { Line 106  sub status {
106  }  }
107    
108  sub selected {  sub selected {
109          my $d = shift || return;          my $d = shift || 0;
110    
111          if ( $selectable_line->{ $pos } ) {          if ( $selectable_line->{ $pos } ) {
112                  $scr->at($pos-$o,0)->bold()->puts( chunk($lines[$pos]) )->normal();                  $scr->at($pos-$o,0)->bold()->puts( chunk($lines[$pos]) )->normal();
# Line 120  sub selected { Line 131  sub selected {
131          status;          status;
132  }  }
133    
134    $scr = new Term::Screen || die "can't init Term::Screen";
135    $scr->clrscr()->noecho();
136  $status_text = "let's see does it work?";  $status_text = "let's see does it work?";
137  redraw;  redraw;
138  selected;  selected;
139    
140  while(my $key = $scr->getch()) {  while(my $key = $scr->getch()) {
141    
142          $status_text = "key: $key pos: $pos sel_pos: $sel_pos";          $status_text = sprintf("pos: %-3d sel_pos: %-3d", $pos, $sel_pos );
143            if ( length($key) > 1 ) {
144                    $status_text .= " key: $key";
145            } else {
146                    $status_text .= sprintf("key: %s [%03d][%02x]", $key, ord($key), ord($key) );
147            }
148    
149          $error_text = "";          $error_text = "";
150    
151          if ($key eq 'ku') {          if ($key eq 'ku') {

Legend:
Removed from v.1  
changed lines
  Added in v.2

  ViewVC Help
Powered by ViewVC 1.1.26