--- lib/PXElator/x11.pm 2009/08/06 22:15:09 171 +++ lib/PXElator/x11.pm 2009/08/16 21:10:42 226 @@ -3,13 +3,16 @@ use warnings; use strict; +use log; +use File::Slurp; + my @cols; my $last_col = ''; open(my $rgb, '<', '/etc/X11/rgb.txt'); while(<$rgb>) { chomp; - my (undef,$col) = split(/\s\s+/,$_,2); + my $col = $1 if m{(\S+)\s*$}; next unless $col =~ m{Light}; push @cols, $col if $last_col ne $col; $last_col = $col; @@ -19,8 +22,43 @@ sub xterm { my ( $name, $cmd ) = @_; - my $fg = $cols[ unpack('C*', $name) % $#cols ]; - my $exec = "xterm -fg $fg -T '$name' -n '$name' -e '$cmd || $server::base_dir/bin/beep.sh'"; + my $screenrc = "/tmp/$name.screenrc"; + $screenrc =~ s{\s+}{-}g; + + my ($autodetach,$detach) = $ENV{DISPLAY} ? ('off','') : ( 'on', 'detach' ); + + write_file $screenrc, qq| + +autodetach $autodetach +altscreen off +defscrollback 10000 +startup_message off + +sessionname $name + +screen -t $name $cmd +logfile $log::dir/$name.log +log on + +$detach + +|; + + my $screen = "screen -R $name -c $screenrc"; + my $exec; + + if ( $ENV{DISPLAY} ) { + my $hash; + $hash += ord($_) foreach ( split //, $name ); + my $fg = $cols[ $hash % $#cols ]; + $exec = "xterm -fg $fg -T '$name' -n '$name' -e '$screen'"; +warn "XXXX $exec"; + } else { + warn "system $screen"; + system $screen; + return; + } + warn "exec $exec"; exec $exec; }