3 |
use warnings; |
use warnings; |
4 |
use strict; |
use strict; |
5 |
|
|
6 |
|
use log; |
7 |
|
use File::Slurp; |
8 |
|
|
9 |
my @cols; |
my @cols; |
10 |
|
|
11 |
my $last_col = ''; |
my $last_col = ''; |
12 |
open(my $rgb, '<', '/etc/X11/rgb.txt'); |
open(my $rgb, '<', '/etc/X11/rgb.txt'); |
13 |
while(<$rgb>) { |
while(<$rgb>) { |
14 |
chomp; |
chomp; |
15 |
my (undef,$col) = split(/\s\s+/,$_,2); |
my $col = $1 if m{(\S+)\s*$}; |
16 |
next unless $col =~ m{Light}; |
next unless $col =~ m{Light}; |
17 |
push @cols, $col if $last_col ne $col; |
push @cols, $col if $last_col ne $col; |
18 |
$last_col = $col; |
$last_col = $col; |
22 |
sub xterm { |
sub xterm { |
23 |
my ( $name, $cmd ) = @_; |
my ( $name, $cmd ) = @_; |
24 |
|
|
25 |
my $fg = $cols[ unpack('C*', $name) % $#cols ]; |
$name =~ s{\s+}{-}g; |
26 |
my $exec = "xterm -fg $fg -T '$name' -n '$name' -e '$cmd || $server::base_dir/bin/beep.sh'"; |
my $screenrc = "/tmp/$name.screenrc"; |
27 |
|
|
28 |
|
my ($autodetach,$detach) = $ENV{DISPLAY} ? ('off','') : ( 'on', 'detach' ); |
29 |
|
|
30 |
|
write_file $screenrc, qq| |
31 |
|
|
32 |
|
autodetach $autodetach |
33 |
|
altscreen off |
34 |
|
defscrollback 10000 |
35 |
|
startup_message off |
36 |
|
|
37 |
|
sessionname $name |
38 |
|
|
39 |
|
screen -t $name $cmd |
40 |
|
logfile $log::dir/$name.log |
41 |
|
log on |
42 |
|
|
43 |
|
$detach |
44 |
|
|
45 |
|
|; |
46 |
|
|
47 |
|
my $screen = "screen -R $name -c $screenrc"; |
48 |
|
my $exec; |
49 |
|
|
50 |
|
if ( $ENV{DISPLAY} ) { |
51 |
|
my $hash; |
52 |
|
$hash += ord($_) foreach ( split //, $name ); |
53 |
|
my $fg = $cols[ $hash % $#cols ]; |
54 |
|
$exec = "xterm -fg $fg -T '$name' -n '$name' -e '$screen'"; |
55 |
|
warn "XXXX $exec"; |
56 |
|
} else { |
57 |
|
warn "system $screen"; |
58 |
|
system $screen; |
59 |
|
return; |
60 |
|
} |
61 |
|
|
62 |
warn "exec $exec"; |
warn "exec $exec"; |
63 |
exec $exec; |
exec $exec; |
64 |
} |
} |