1 |
package x11; |
2 |
|
3 |
use warnings; |
4 |
use strict; |
5 |
|
6 |
use log; |
7 |
use File::Slurp; |
8 |
|
9 |
my @cols; |
10 |
|
11 |
my $last_col = ''; |
12 |
open(my $rgb, '<', '/etc/X11/rgb.txt'); |
13 |
while(<$rgb>) { |
14 |
chomp; |
15 |
my $col = $1 if m{(\S+)\s*$}; |
16 |
next unless $col =~ m{Light}; |
17 |
push @cols, $col if $last_col ne $col; |
18 |
$last_col = $col; |
19 |
} |
20 |
close($rgb); |
21 |
|
22 |
sub xterm { |
23 |
my ( $name, $cmd ) = @_; |
24 |
|
25 |
$name =~ s{\s+}{-}g; |
26 |
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"; |
63 |
exec $exec; |
64 |
} |
65 |
|
66 |
1; |