forked from vit-project/vit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
env.pl
112 lines (107 loc) · 3.24 KB
/
env.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# Copyright 2012 - 2013, Steve Rader
# Copyright 2013 - 2016, Scott Kostyshak
sub init_shell_env {
if ( $ENV{'TERM'} =~ /^(xterm|screen)/ ) {
my $TERM_newval = "$1-256color";
&audit("setting ENV TERM=$TERM_newval");
$ENV{'TERM'} = "$TERM_newval";
}
if ( $titlebar ) {
&audit("ENV set titlebar");
open(TTY, ">>/dev/tty");
print TTY "\e]0;$version\cg\n";
close(TTY);
}
}
#------------------------------------------------------------------
sub init_task_env {
my @reports;
my $id_column = 0;
my ($header_color,$task_header_color,$vit_header_color);
&audit("EXEC $task show 2>&1");
open(IN,"$task show 2>&1 |");
while(<IN>) {
chop;
if ( $_ =~ /color\.header\s+(.*)/ ) {
$task_header_color = $1;
next;
}
if ( $_ =~ /color\.vit\.header\s+(.*)/ ) {
$vit_header_color = $1;
next;
}
if ( $_ =~ /color\.vit\.selection\s+(.*)/ ) {
my $str = $1;
$str =~ s/\x1b.*?m//g;
$str =~ s/^\s+//;
$str =~ s/\s+$//;
&extract_color($str,'vit selection');
$selection_attrs = $parsed_attrs[1];
init_pair($COLOR_SELECTION,$parsed_colors_fg[1],$parsed_colors_bg[1]);
next;
}
if ( $_ =~ /default.command\s+(.*)/ ) {
$default_command = $1;
$default_command =~ s/\x1b.*?m//g;
$default_command =~ s/^\s+//g;
$default_command =~ s/\s+$//g;
next;
}
if ( $_ =~ /report\.(.*?)\.columns/ ) {
push(@reports, $1);
next;
}
if ( $_ =~ /The color .* is not recognized/ ) {
endwin();
print "$_\r\n";
exit(1);
}
}
close(IN);
if ( defined $vit_header_color ) {
$header_color = $vit_header_color;
} elsif ( defined $task_header_color ) {
$header_color = $task_header_color;
} else {
init_pair($COLOR_HEADER,-1,-1); # not reached
}
if ( defined $header_color ) {
&extract_color($header_color,'header');
$header_color =~ s/\x1b.*?m//g;
$header_color =~ s/^\s+//;
$header_color =~ s/\s+$//;
$header_attrs = $parsed_attrs[1];
init_pair($COLOR_HEADER,$parsed_colors_fg[1],$parsed_colors_bg[1]);
}
if ( $cli_args ne '' ) {
chop $cli_args;
$default_command = $cli_args;
}
&audit("EXEC $task rc._forcecolor=on rc.verbose=on $default_command 2>&1");
open(IN,"$task rc._forcecolor=on rc.verbose=on $default_command 2>&1 |");
while(<IN>) {
chop;
if ( $_ =~ /ID/ || ($default_command eq 'summary' && $_ =~ /Project/) ) {
&parse_line(0,$_);
@report_header_colors_fg = @parsed_colors_fg;
@report_header_colors_bg = @parsed_colors_bg;
@report_header_attrs = @parsed_attrs;
if ( $parsed_colors_fg[0] eq '999999' ) { $parsed_colors_fg[0] = -1; }
if ( $parsed_colors_bg[0] eq '999999' ) { $parsed_colors_bg[0] = -1; }
init_pair($COLOR_REPORT_HEADER,$parsed_colors_fg[0],$parsed_colors_bg[0]);
$id_column = 1;
}
}
close(IN);
if ( ! $id_column && $default_command ne 'summary' ) {
endwin();
print "Fatal error: default.command (\"$default_command\") must print an \"ID\" column\n";
exit(1);
}
&audit("ENV default command is \"$default_command\"");
$current_command = $default_command;
push(@reports,$default_command);
push(@reports,'summary');
@report_types = sort(@reports);
}
return 1;