| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Term::Tmux::StatusBar; |
|
2
|
|
|
|
|
|
|
$Term::Tmux::StatusBar::VERSION = '0.0.1.0'; |
|
3
|
1
|
|
|
1
|
|
68746
|
use strict; |
|
|
1
|
|
|
|
|
4
|
|
|
|
1
|
|
|
|
|
30
|
|
|
4
|
1
|
|
|
1
|
|
7
|
use warnings; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
27
|
|
|
5
|
1
|
|
|
1
|
|
6
|
use base 'Term::Tmux'; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
441
|
|
|
6
|
1
|
|
|
1
|
|
8
|
use Exporter qw(import); |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
1395
|
|
|
7
|
|
|
|
|
|
|
our @EXPORT = qw( main window_status_current_format_left parse |
|
8
|
|
|
|
|
|
|
window_status_current_format_right status_left status_right ); |
|
9
|
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
my $delimiter = ';'; |
|
11
|
|
|
|
|
|
|
my $sub_delimiter = ','; |
|
12
|
|
|
|
|
|
|
my $default_left_sep = ''; |
|
13
|
|
|
|
|
|
|
my $default_right_sep = ''; |
|
14
|
|
|
|
|
|
|
my $default_format = ' %s '; |
|
15
|
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub change_format_sep { |
|
17
|
0
|
|
|
0
|
0
|
0
|
my $i = shift; |
|
18
|
0
|
0
|
0
|
|
|
0
|
if ( defined $i and $i =~ /%s/ ) { |
|
19
|
0
|
|
|
|
|
0
|
$_[0] = $i; |
|
20
|
|
|
|
|
|
|
} |
|
21
|
|
|
|
|
|
|
else { |
|
22
|
0
|
|
|
|
|
0
|
$_[1] = $i; |
|
23
|
|
|
|
|
|
|
} |
|
24
|
0
|
|
|
|
|
0
|
return @_; |
|
25
|
|
|
|
|
|
|
} |
|
26
|
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
sub get_tokens { |
|
28
|
1
|
|
|
1
|
0
|
4
|
my @tokens = parse( $sub_delimiter, $_[0] ); |
|
29
|
1
|
|
|
|
|
6
|
$tokens[3] = sprintf $_[1], $tokens[2]; |
|
30
|
1
|
|
|
|
|
4
|
return @tokens; |
|
31
|
|
|
|
|
|
|
} |
|
32
|
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
sub window_status_current_format_left { |
|
34
|
0
|
|
|
0
|
0
|
0
|
my $out = ''; |
|
35
|
0
|
|
|
|
|
0
|
my $sep = $default_left_sep; |
|
36
|
0
|
|
|
|
|
0
|
my $format = $default_format; |
|
37
|
0
|
|
|
|
|
0
|
my $fg = ''; |
|
38
|
0
|
|
|
|
|
0
|
my $bg = ''; |
|
39
|
0
|
|
|
|
|
0
|
my $text = ''; |
|
40
|
0
|
|
|
|
|
0
|
my $old_text = ''; |
|
41
|
0
|
|
|
|
|
0
|
foreach (@_) { |
|
42
|
0
|
0
|
|
|
|
0
|
unless (/$sub_delimiter/) { |
|
43
|
0
|
|
|
|
|
0
|
( $format, $sep ) = change_format_sep( $_, $format, $sep ); |
|
44
|
0
|
|
|
|
|
0
|
next; |
|
45
|
|
|
|
|
|
|
} |
|
46
|
0
|
|
|
|
|
0
|
( $fg, $bg, $old_text, $text ) = get_tokens( $_, $format ); |
|
47
|
0
|
|
|
|
|
0
|
$out .= "#[reverse,fg=$bg]$sep#[noreverse,fg=$fg,bg=$bg]$text"; |
|
48
|
|
|
|
|
|
|
} |
|
49
|
0
|
|
|
|
|
0
|
$out .= "#[fg=$bg,bg=default]$sep"; |
|
50
|
0
|
|
|
|
|
0
|
return $out; |
|
51
|
|
|
|
|
|
|
} |
|
52
|
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
sub status_left { |
|
54
|
1
|
|
|
1
|
0
|
1113
|
my $last_bg = ''; |
|
55
|
1
|
|
|
|
|
22
|
my $out = ''; |
|
56
|
1
|
|
|
|
|
3
|
my $sep = $default_left_sep; |
|
57
|
1
|
|
|
|
|
3
|
my $format = $default_format; |
|
58
|
1
|
|
|
|
|
2
|
my $fg = ''; |
|
59
|
1
|
|
|
|
|
2
|
my $bg = ''; |
|
60
|
1
|
|
|
|
|
2
|
my $text = ''; |
|
61
|
1
|
|
|
|
|
2
|
my $old_text = ''; |
|
62
|
1
|
|
|
|
|
3
|
foreach (@_) { |
|
63
|
1
|
50
|
|
|
|
16
|
unless (/$sub_delimiter/) { |
|
64
|
0
|
|
|
|
|
0
|
( $format, $sep ) = change_format_sep( $_, $format, $sep ); |
|
65
|
0
|
|
|
|
|
0
|
next; |
|
66
|
|
|
|
|
|
|
} |
|
67
|
1
|
|
|
|
|
4
|
( $fg, $bg, $old_text, $text ) = get_tokens( $_, $format ); |
|
68
|
1
|
50
|
|
|
|
4
|
if ( $last_bg eq '' ) { |
|
69
|
1
|
|
|
|
|
5
|
$out .= "#[fg=$fg,bg=$bg]$text"; |
|
70
|
|
|
|
|
|
|
} |
|
71
|
|
|
|
|
|
|
else { |
|
72
|
0
|
|
|
|
|
0
|
$out .= "#[fg=$last_bg,bg=$bg]$sep#[fg=$fg]$text"; |
|
73
|
|
|
|
|
|
|
} |
|
74
|
1
|
|
|
|
|
3
|
$last_bg = $bg; |
|
75
|
|
|
|
|
|
|
} |
|
76
|
1
|
|
|
|
|
3
|
$out .= "#[fg=$bg,bg=default]$sep"; |
|
77
|
1
|
|
|
|
|
4
|
return $out; |
|
78
|
|
|
|
|
|
|
} |
|
79
|
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
sub right { |
|
81
|
0
|
|
|
0
|
0
|
0
|
my $out = ''; |
|
82
|
0
|
|
|
|
|
0
|
my $sep = $default_right_sep; |
|
83
|
0
|
|
|
|
|
0
|
my $format = $default_format; |
|
84
|
0
|
|
|
|
|
0
|
my $fg = ''; |
|
85
|
0
|
|
|
|
|
0
|
my $bg = ''; |
|
86
|
0
|
|
|
|
|
0
|
my $text = ''; |
|
87
|
0
|
|
|
|
|
0
|
my $old_text = ''; |
|
88
|
0
|
|
|
|
|
0
|
foreach (@_) { |
|
89
|
0
|
0
|
|
|
|
0
|
unless (/$sub_delimiter/) { |
|
90
|
0
|
|
|
|
|
0
|
( $format, $sep ) = change_format_sep( $_, $format, $sep ); |
|
91
|
0
|
|
|
|
|
0
|
next; |
|
92
|
|
|
|
|
|
|
} |
|
93
|
0
|
|
|
|
|
0
|
( $fg, $bg, $old_text, $text ) = get_tokens( $_, $format ); |
|
94
|
0
|
|
|
|
|
0
|
$out .= "#[fg=$bg]$sep#[fg=$fg]#[bg=$bg]$text"; |
|
95
|
|
|
|
|
|
|
# $out .= "#{?#{==:$old_text,},,#[fg=$bg]$sep#[fg=$fg]#[bg=$bg]$text}"; |
|
96
|
|
|
|
|
|
|
} |
|
97
|
0
|
|
|
|
|
0
|
return ( $out, $sep ); |
|
98
|
|
|
|
|
|
|
} |
|
99
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
sub window_status_current_format_right { |
|
101
|
0
|
|
|
0
|
0
|
0
|
my ( $out, $sep ) = right(@_); |
|
102
|
0
|
|
|
|
|
0
|
$out .= "#[fg=default]$sep"; |
|
103
|
0
|
|
|
|
|
0
|
return $out; |
|
104
|
|
|
|
|
|
|
} |
|
105
|
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
sub status_right { |
|
107
|
0
|
|
|
0
|
0
|
0
|
my ( $out, $sep ) = right(@_); |
|
108
|
0
|
|
|
|
|
0
|
return $out; |
|
109
|
|
|
|
|
|
|
} |
|
110
|
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
sub parse { |
|
112
|
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
# 0: normal |
|
114
|
|
|
|
|
|
|
# 1: # |
|
115
|
|
|
|
|
|
|
# 2: #[ |
|
116
|
|
|
|
|
|
|
# 3: #[...# |
|
117
|
|
|
|
|
|
|
# 4: #[...#[ |
|
118
|
|
|
|
|
|
|
# ... |
|
119
|
3
|
|
|
3
|
0
|
385
|
my $status = 0; |
|
120
|
3
|
|
|
|
|
6
|
my @tokens = (); |
|
121
|
3
|
|
|
|
|
7
|
my $token = ''; |
|
122
|
3
|
|
|
|
|
11
|
my %braces = ( |
|
123
|
|
|
|
|
|
|
'[' => ']', |
|
124
|
|
|
|
|
|
|
'(' => ')', |
|
125
|
|
|
|
|
|
|
'{' => '}', |
|
126
|
|
|
|
|
|
|
); |
|
127
|
3
|
|
|
|
|
5
|
my $last_brace = ''; |
|
128
|
3
|
|
|
|
|
6
|
my @braces = (); |
|
129
|
3
|
|
|
|
|
5
|
my @status = (); |
|
130
|
3
|
|
|
|
|
56
|
foreach ( split( '', $_[1] ) ) { |
|
131
|
235
|
100
|
100
|
|
|
529
|
if ( $status == 0 and $_ eq $_[0] ) { |
|
132
|
7
|
|
|
|
|
11
|
push @tokens, $token; |
|
133
|
7
|
|
|
|
|
10
|
$token = ''; |
|
134
|
|
|
|
|
|
|
} |
|
135
|
|
|
|
|
|
|
else { |
|
136
|
228
|
|
|
|
|
301
|
$token .= $_; |
|
137
|
|
|
|
|
|
|
} |
|
138
|
235
|
100
|
|
|
|
353
|
if ( $status % 2 == 0 ) { |
|
139
|
220
|
100
|
100
|
|
|
628
|
if ( $_ eq '#' ) { |
|
|
|
100
|
|
|
|
|
|
|
140
|
15
|
|
|
|
|
23
|
$status += 1; |
|
141
|
|
|
|
|
|
|
} |
|
142
|
|
|
|
|
|
|
elsif ( $last_brace ne '' and $_ eq $braces{$last_brace} ) { |
|
143
|
8
|
|
|
|
|
14
|
$status -= 2; |
|
144
|
8
|
|
|
|
|
12
|
$last_brace = pop @braces; |
|
145
|
|
|
|
|
|
|
} |
|
146
|
|
|
|
|
|
|
} |
|
147
|
|
|
|
|
|
|
else { |
|
148
|
15
|
100
|
|
|
|
53
|
if ( $_ =~ /\[|\{|\(/ ) { |
|
149
|
8
|
|
|
|
|
12
|
$status += 1; |
|
150
|
8
|
|
|
|
|
12
|
$last_brace = $_; |
|
151
|
8
|
|
|
|
|
14
|
push @braces, $_; |
|
152
|
|
|
|
|
|
|
} |
|
153
|
|
|
|
|
|
|
else { |
|
154
|
7
|
|
|
|
|
11
|
$status -= 1; |
|
155
|
|
|
|
|
|
|
} |
|
156
|
|
|
|
|
|
|
} |
|
157
|
235
|
|
|
|
|
364
|
push @status, $status, |
|
158
|
|
|
|
|
|
|
} |
|
159
|
3
|
|
|
|
|
18
|
push @tokens, $token; |
|
160
|
|
|
|
|
|
|
# print @status; |
|
161
|
|
|
|
|
|
|
# print("\n" . join("\n", @tokens,) . "\n"); |
|
162
|
3
|
|
|
|
|
22
|
return @tokens; |
|
163
|
|
|
|
|
|
|
} |
|
164
|
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
sub do_interpolation { |
|
166
|
0
|
|
|
0
|
0
|
|
$_[0] =~ s/#\{status-left:(.*)\}/status_left(parse($delimiter, $1))/ge; |
|
|
0
|
|
|
|
|
|
|
|
167
|
0
|
|
|
|
|
|
$_[0] =~ s/#\{status-right:(.*)\}/status_right(parse($delimiter, $1))/ge; |
|
|
0
|
|
|
|
|
|
|
|
168
|
0
|
|
|
|
|
|
$_[0] =~ |
|
169
|
0
|
|
|
|
|
|
s/#\{window-status-current-format-left:(.*)\}/window_status_current_format_left(parse($delimiter, $1))/ge; |
|
170
|
0
|
|
|
|
|
|
$_[0] =~ |
|
171
|
0
|
|
|
|
|
|
s/#\{window-status-current-format-right:(.*)\}/window_status_current_format_right(parse($delimiter, $1))/ge; |
|
172
|
0
|
|
|
|
|
|
return $_[0]; |
|
173
|
|
|
|
|
|
|
} |
|
174
|
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
sub main { |
|
176
|
0
|
|
|
0
|
0
|
|
my @array = |
|
177
|
|
|
|
|
|
|
( 'status-left', 'status-right', 'window-status-current-format', ); |
|
178
|
0
|
|
|
|
|
|
foreach my $option (@array) { |
|
179
|
0
|
|
|
|
|
|
my $value = `tmux show-option -gqv '$option'`; |
|
180
|
0
|
0
|
|
|
|
|
if ( $value ne '' ) { |
|
181
|
0
|
|
|
|
|
|
$value = do_interpolation($value); |
|
182
|
0
|
|
|
|
|
|
`tmux set-option -gq '$option' '$value'`; |
|
183
|
|
|
|
|
|
|
} |
|
184
|
|
|
|
|
|
|
} |
|
185
|
|
|
|
|
|
|
} |
|
186
|
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
1; |
|
188
|
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
__END__ |