/[scripts]/trunk/dwm-status.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 /trunk/dwm-status.pl

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

revision 135 by dpavlin, Wed Mar 31 06:55:19 2010 UTC revision 136 by dpavlin, Wed Jun 30 15:21:02 2010 UTC
# Line 17  my $disk_blk_size = 512; Line 17  my $disk_blk_size = 512;
17    
18  my $debug = shift @ARGV;  my $debug = shift @ARGV;
19  my $awesome = 0;  my $awesome = 0;
 my $dzen = 1;  
20    
21  $|=1;  $|=1;
22    
# Line 68  find_proc_acpi('battery', sub { Line 67  find_proc_acpi('battery', sub {
67          }          }
68  });  });
69    
 my $unit_colors = {  
         'b' => '#ff0000',  
         'k' => '#ffff00',  
         'M' => '#00ff00',  
         'G' => '#0000ff',  
 };  
   
70  sub unit {  sub unit {
71          my ($v,$align) = @_;          my $v = shift;
         $align ||= '';  
72    
73          warn "unit( $v )\n" if ($debug);          warn "unit( $v )\n" if ($debug);
74    
# Line 89  sub unit { Line 80  sub unit {
80                  $v /= 1024;                  $v /= 1024;
81          }          }
82    
         my $unit = $units[$o];  
   
         my $out = '';  
         $out .= '^fg(' . $unit_colors->{$unit} . ')';  
   
83          if ( $v >= 1 ) {          if ( $v >= 1 ) {
84                  $out .= sprintf("%${align}5d",$v);                  return sprintf("%d%s", $v, $units[$o]);
85          } elsif ( $v == 0 ) {          } elsif ( $v == 0 ) {
86                  $out = ' ' x 5;                  return '';
87          } else {          } else {
88                  $out .= sprintf("%${align}5.1f", $v);                  return sprintf("%.1f%s", $v, $units[$o]);
89          }          }
   
         $unit = '^fg(#444444)' . $unit if $dzen;  
         $out =~ s/\s(\s*)$/$unit$1/ unless $out =~ m/\s{5}/;  
         $out .= '^fg(#ffffff)' if $dzen;  
   
         return $out;  
90  }  }
91    
92  my ( $lrx, $ltx ) = ( 0, 0 );  my ( $lrx, $ltx ) = ( 0, 0 );
# Line 126  while ( 1 ) { Line 106  while ( 1 ) {
106                          my $full = read_file( $sysfs_path );                          my $full = read_file( $sysfs_path );
107                          $sysfs_path =~ s/_full/_now/;                          $sysfs_path =~ s/_full/_now/;
108                          my $now = read_file( $sysfs_path );                          my $now = read_file( $sysfs_path );
109                          $bat = sprintf("%2d%%", $now * 100 / $full );                          $bat = sprintf("%2d%% | ", $now * 100 / $full );
110    
111                  } elsif ( $proc_acpi_battery ) {                  } elsif ( $proc_acpi_battery ) {
112    
# Line 146  while ( 1 ) { Line 126  while ( 1 ) {
126                                  my $mm = int( ( $time - $hh ) * 60 );                                  my $mm = int( ( $time - $hh ) * 60 );
127                                  my $ss = ( $time * 3600 ) % 60;                                  my $ss = ( $time * 3600 ) % 60;
128    
129                                  $bat = sprintf("%s %2d%% %02d:%02d:%02d %3.1fW!",                                  $bat = sprintf("%s %2d%% %02d:%02d:%02d %3.1fW!| ",
130                                          substr($state->{'charging state'},0,1),                                          substr($state->{'charging state'},0,1),
131                                          $pcnt * 100, $hh, $mm, $ss,                                          $pcnt * 100, $hh, $mm, $ss,
132                                          $state->{'present rate'} / 1000                                          $state->{'present rate'} / 1000
133                                  );                                  );
134                          }                          }
135                  }                  }
136            } else {
137                    $bat =~ s/!(\|\s)$/ $1/;
138          }          }
139          $i++;          $i++;
140    
# Line 205  while ( 1 ) { Line 187  while ( 1 ) {
187          my $d_write = ( $d_w - $ld_w ) / $dt;          my $d_write = ( $d_w - $ld_w ) / $dt;
188          ( $ld_r, $ld_w ) = ( $d_r, $d_w );          ( $ld_r, $ld_w ) = ( $d_r, $d_w );
189    
190          my $out = join( $dzen ? ' ^fg(#333333)|^fg(#ffffff) ' : ' | ',          my $out = sprintf("%s |%5s D %-5s|%5s > %-5s| %s%s | %s",
191                  $load,                  $load,
192                  unit( $d_read ) . ' D ' . unit( $d_write, '-' ),                  unit( $d_read ), unit( $d_write ),
193                  unit( $net_rx ) . ' > ' . unit( $net_tx, '-' ),                  unit( $net_rx ), unit( $net_tx ),
194                  $bat, $temp,                  $bat, $temp,
195                  $s,                  $s,
196          );          );
197    
   
198          print "$out\n";          print "$out\n";
199          if ( $awesome ) {          if ( $awesome ) {
200                  open(my $fh, '|-', 'awesome-client') || die "can't pipe to awesome-client: $!";                  open(my $fh, '|-', 'awesome-client') || die "can't pipe to awesome-client: $!";

Legend:
Removed from v.135  
changed lines
  Added in v.136

  ViewVC Help
Powered by ViewVC 1.1.26