| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package X11::Terminal; |
|
2
|
|
|
|
|
|
|
|
|
3
|
4
|
|
|
4
|
|
3255
|
use Moose; |
|
|
4
|
|
|
|
|
463327
|
|
|
|
4
|
|
|
|
|
28
|
|
|
4
|
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
our $VERSION = 1.0.0; |
|
6
|
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
=head1 NAME |
|
8
|
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
X11::Terminal - Create customised X11 terminal windows |
|
10
|
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
12
|
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
This module provides a baseclass for launching terminal windows on your |
|
14
|
|
|
|
|
|
|
desktop. You would normally instantiate subclass rather than using this |
|
15
|
|
|
|
|
|
|
class directly. |
|
16
|
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
For example: |
|
18
|
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
use X11::Terminal::XTerm; |
|
20
|
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
# Create an xterm window, logged in to a remote server |
|
22
|
|
|
|
|
|
|
my $term = X11::Terminal::XTerm->new(host => "remotehost"); |
|
23
|
|
|
|
|
|
|
$term->launch(); |
|
24
|
|
|
|
|
|
|
=cut |
|
25
|
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
=head1 ATTRIBUTES |
|
27
|
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
Each of the following attributes provide an accessor method, but they |
|
29
|
|
|
|
|
|
|
can also be set in the constructor. |
|
30
|
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
The following attributes define the shell command to be run within the |
|
32
|
|
|
|
|
|
|
terminal window. |
|
33
|
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
=over |
|
35
|
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
=item host |
|
37
|
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
If set, the terminal window will ssh to that host. Otherwise, it will |
|
39
|
|
|
|
|
|
|
just run a bash shell. |
|
40
|
|
|
|
|
|
|
=cut |
|
41
|
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
has 'host' => ( |
|
43
|
|
|
|
|
|
|
is => 'rw', |
|
44
|
|
|
|
|
|
|
isa => 'Str', |
|
45
|
|
|
|
|
|
|
); |
|
46
|
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
=item xforward |
|
48
|
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
If set, the ssh command will enable X11 forwarding. Requires L</host>. |
|
50
|
|
|
|
|
|
|
=cut |
|
51
|
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
has 'xforward' => ( |
|
53
|
|
|
|
|
|
|
is => 'rw', |
|
54
|
|
|
|
|
|
|
isa => 'Bool', |
|
55
|
|
|
|
|
|
|
); |
|
56
|
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
=item agentforward |
|
58
|
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
If set, the ssh command will enable agent forwarding. Requires L</host>. |
|
60
|
|
|
|
|
|
|
=cut |
|
61
|
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
has 'agentforward' => ( |
|
63
|
|
|
|
|
|
|
is => 'rw', |
|
64
|
|
|
|
|
|
|
isa => 'Bool', |
|
65
|
|
|
|
|
|
|
); |
|
66
|
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
=back |
|
68
|
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
The following attributes are implemented in the various subclasses and |
|
70
|
|
|
|
|
|
|
depending on the subclass involved they may have no effect. For example, |
|
71
|
|
|
|
|
|
|
a C<GnomeTerminal> subclass can't set the font as gnome-terminals |
|
72
|
|
|
|
|
|
|
utilise a profile setting for that bahaviour. |
|
73
|
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
=over |
|
75
|
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
=item profile |
|
77
|
|
|
|
|
|
|
=cut |
|
78
|
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
has 'profile' => ( |
|
80
|
|
|
|
|
|
|
is => 'rw', |
|
81
|
|
|
|
|
|
|
isa => 'Str', |
|
82
|
|
|
|
|
|
|
); |
|
83
|
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
=item geometry |
|
85
|
|
|
|
|
|
|
=cut |
|
86
|
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
has 'geometry' => ( |
|
88
|
|
|
|
|
|
|
is => 'rw', |
|
89
|
|
|
|
|
|
|
isa => 'Str', |
|
90
|
|
|
|
|
|
|
); |
|
91
|
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
=item font |
|
93
|
|
|
|
|
|
|
=cut |
|
94
|
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
has 'font' => ( |
|
96
|
|
|
|
|
|
|
is => 'rw', |
|
97
|
|
|
|
|
|
|
isa => 'Str', |
|
98
|
|
|
|
|
|
|
); |
|
99
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
=item foreground |
|
101
|
|
|
|
|
|
|
=cut |
|
102
|
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
has 'foreground' => ( |
|
104
|
|
|
|
|
|
|
is => 'rw', |
|
105
|
|
|
|
|
|
|
isa => 'Str', |
|
106
|
|
|
|
|
|
|
); |
|
107
|
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
=item background |
|
109
|
|
|
|
|
|
|
=cut |
|
110
|
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
has 'background' => ( |
|
112
|
|
|
|
|
|
|
is => 'rw', |
|
113
|
|
|
|
|
|
|
isa => 'Str', |
|
114
|
|
|
|
|
|
|
); |
|
115
|
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
=item scrollback |
|
117
|
|
|
|
|
|
|
=cut |
|
118
|
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
has 'scrollback' => ( |
|
120
|
|
|
|
|
|
|
is => 'rw', |
|
121
|
|
|
|
|
|
|
isa => 'Int', |
|
122
|
|
|
|
|
|
|
); |
|
123
|
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
=back |
|
125
|
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
=head1 OTHER METHODS |
|
127
|
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
=over |
|
129
|
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
=item launch($debug); |
|
131
|
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
Calculates (and returns) the command that will launch your terminal program. |
|
133
|
|
|
|
|
|
|
The exact content of the command will depend on which subclass is calling |
|
134
|
|
|
|
|
|
|
the command, and the attributes that have been specified. |
|
135
|
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
It also runs that command in a child process - unless $debug is specified. |
|
137
|
|
|
|
|
|
|
=cut |
|
138
|
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
sub launch { |
|
140
|
78
|
|
|
78
|
1
|
51083
|
my ( $self, $debug ) = @_; |
|
141
|
|
|
|
|
|
|
|
|
142
|
78
|
|
|
|
|
182
|
my $shell = $self->shellCommand(); |
|
143
|
78
|
|
|
|
|
175
|
my $term = $self->terminalName(); |
|
144
|
78
|
|
|
|
|
190
|
my $args = $self->terminalArgs(); |
|
145
|
78
|
|
|
|
|
202
|
my $command = "$term $args -e '$shell'"; |
|
146
|
|
|
|
|
|
|
|
|
147
|
78
|
50
|
|
|
|
161
|
if ( !$debug ) { |
|
148
|
0
|
0
|
|
|
|
0
|
if ( fork() == 0 ) { |
|
149
|
0
|
|
|
|
|
0
|
exec($command); |
|
150
|
|
|
|
|
|
|
} |
|
151
|
|
|
|
|
|
|
} |
|
152
|
78
|
|
|
|
|
359
|
return $command; |
|
153
|
|
|
|
|
|
|
} |
|
154
|
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
=item shellCommand(); |
|
156
|
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
Returns the shell command that should be run within the terminal window. |
|
158
|
|
|
|
|
|
|
There should be no need to call this method directly. |
|
159
|
|
|
|
|
|
|
=cut |
|
160
|
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
sub shellCommand { |
|
162
|
78
|
|
|
78
|
1
|
128
|
my ($self) = @_; |
|
163
|
|
|
|
|
|
|
|
|
164
|
78
|
100
|
|
|
|
2020
|
if ( my $host = $self->host() ) { |
|
165
|
33
|
100
|
|
|
|
793
|
my $sshForward = $self->xforward() ? "-X" : ""; |
|
166
|
33
|
100
|
|
|
|
796
|
my $agentForward = $self->agentforward() ? "-A" : ""; |
|
167
|
33
|
|
|
|
|
110
|
return "ssh $sshForward $agentForward $host"; |
|
168
|
|
|
|
|
|
|
} |
|
169
|
45
|
|
|
|
|
88
|
return "bash"; |
|
170
|
|
|
|
|
|
|
} |
|
171
|
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
=item terminalName(); |
|
173
|
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
Returns the name of the program that will be run to provide the terminal |
|
175
|
|
|
|
|
|
|
window. There should be no need to call this method directly. |
|
176
|
|
|
|
|
|
|
=cut |
|
177
|
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
sub terminalName { |
|
179
|
58
|
|
|
58
|
1
|
5594
|
my ($self) = @_; |
|
180
|
|
|
|
|
|
|
|
|
181
|
58
|
|
|
|
|
323
|
my ($className) = ref($self) =~ m/([\w|-]+)$/; |
|
182
|
58
|
|
|
|
|
147
|
return lc($className); |
|
183
|
|
|
|
|
|
|
} |
|
184
|
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
=back |
|
186
|
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
=head1 COPYRIGHT |
|
188
|
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
Copyright 2010-2011 Evan Giles. |
|
190
|
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
This module is free software; you can redistribute it and/or modify it |
|
192
|
|
|
|
|
|
|
under the same terms as Perl itself. |
|
193
|
|
|
|
|
|
|
=cut |
|
194
|
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
1; # End of X11::Terminal |