/[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 5 by dpavlin, Thu Oct 25 13:04:52 2007 UTC revision 6 by dpavlin, Thu Oct 25 13:24:02 2007 UTC
# Line 30  while(<$ps>) { Line 30  while(<$ps>) {
30  }  }
31  close($ps);  close($ps);
32    
33    $data .= "\n--EOF--";
34    
35  my $scr;  my $scr;
36    
37  # leave sane terminal if script dies  # leave sane terminal if script dies
# Line 40  $SIG{__DIE__} = sub { Line 42  $SIG{__DIE__} = sub {
42    
43  my @lines = split(/\n/, $data);  my @lines = split(/\n/, $data);
44    
45  my $o = 0;      # offset in original text  my $top_screen_line = 0;        # offset in original text
46  my $pos = 0;  my $pos = 0;
47    
48  # default: select first line  # default: select first line
# Line 89  sub redraw_line { Line 91  sub redraw_line {
91    
92  sub redraw {  sub redraw {
93          for my $l (0 .. $scr->rows - 3) {          for my $l (0 .. $scr->rows - 3) {
94                  my $line = $lines[ $l + $o ];                  my $line = $lines[ $l + $top_screen_line ];
                 next if (length($line) < 2);  
95                  redraw_line( $l, $line );                  redraw_line( $l, $line );
96                  last if ($l == $#lines);                  last if ($l == $#lines);
97          }          }
# Line 111  sub status { Line 112  sub status {
112  sub selected {  sub selected {
113          my $d = shift || 0;          my $d = shift || 0;
114    
115          my $screen_line = $pos - $o;          my $screen_line = $pos - $top_screen_line;
116    
117          redraw_line( $screen_line, $lines[$pos] );          redraw_line( $screen_line, $lines[$pos] );
118    
# Line 119  sub selected { Line 120  sub selected {
120    
121          if ( $d < 0 && $screen_line == 0 ) {          if ( $d < 0 && $screen_line == 0 ) {
122                  if ( $pos > 0 ) {                  if ( $pos > 0 ) {
123                          $o--;                          $top_screen_line--;
124                          $pos--;                          $pos--;
125                  } else {                  } else {
126                          $error_text = "Already at Begin.";                          $error_text = "Already at Begin.";
# Line 127  sub selected { Line 128  sub selected {
128                  redraw;                  redraw;
129          } elsif ( $d > 0 && $screen_line == $last_screen_line ) {          } elsif ( $d > 0 && $screen_line == $last_screen_line ) {
130                  if ( $pos <= $#lines ) {                  if ( $pos <= $#lines ) {
131                          $o++;                          $top_screen_line++;
132                          $pos++;                          $pos++;
133                  } else {                  } else {
134                          $error_text = "Already at End.";                          $error_text = "Already at End.";
# Line 139  sub selected { Line 140  sub selected {
140    
141          my $line = $lines[$pos];          my $line = $lines[$pos];
142          if ( defined $selectable_line->{ $pos } ) {          if ( defined $selectable_line->{ $pos } ) {
143                  $scr->at($pos - $o,0)->reverse->bold()->puts( full_line( chunk($line) ) )->normal();                  $scr->at($pos - $top_screen_line,0)->reverse->bold()->puts( full_line( chunk($line) ) )->normal();
144                  $sel_pos = $pos;                  $sel_pos = $pos;
145          } else {          } else {
146                  $scr->at($pos - $o,0)->reverse->puts( full_line( chunk($line) ) );                  $scr->at($pos - $top_screen_line,0)->reverse->puts( full_line( chunk($line) ) );
147                  $sel_pos = -1;                  $sel_pos = -1;
148          }          }
149          status;          status;
# Line 157  while(my $key = $scr->getch()) { Line 158  while(my $key = $scr->getch()) {
158    
159          $error_text = "";          $error_text = "";
160    
161            my $lines_on_screen = $scr->rows - 3;
162    
163          if ($key eq 'ku') {          if ($key eq 'ku') {
164                  selected( -1 );                  selected( -1 );
165          } elsif ($key eq 'kd') {          } elsif ($key eq 'kd') {
166                  selected( +1 );                  selected( +1 );
167            } elsif ($key eq 'pgup' ) {
168                    # first line on screen?
169                    if ( $pos == $top_screen_line ) {
170                            $top_screen_line -= $lines_on_screen;
171                            $top_screen_line = 0;
172                            $pos = $top_screen_line;
173                            redraw;
174                            selected( $pos );
175                    } else {
176                            selected( -( $pos - $top_screen_line ) );
177                    }
178            } elsif ($key eq 'pgdn' ) {
179                    # last line on screen?
180                    if ( $pos - $top_screen_line == $lines_on_screen ) {
181                            $top_screen_line += $lines_on_screen;
182                            $top_screen_line = $#lines - $lines_on_screen if $top_screen_line > $#lines - $lines_on_screen;
183                            $pos = $top_screen_line;
184                            redraw;
185                            selected( $pos );
186                    } else {
187                            selected( $top_screen_line + $scr->rows - $pos - 3 );
188                    }
189          }          }
190    
191          $status_text = sprintf("pos: %-3d sel_pos: %-3d top offset: %-3d", $pos, $sel_pos, $o );          $status_text = sprintf("pos: %-3d sel_pos: %-3d top_screen_line: %-3d", $pos, $sel_pos, $top_screen_line );
192          if ( length($key) > 1 ) {          if ( length($key) > 1 ) {
193                  $status_text .= " key: $key";                  $status_text .= " key: $key";
194          } else {          } else {

Legend:
Removed from v.5  
changed lines
  Added in v.6

  ViewVC Help
Powered by ViewVC 1.1.26