line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
##################################################################### |
2
|
|
|
|
|
|
|
# This program is not guaranteed to work at all, and by using this # |
3
|
|
|
|
|
|
|
# program you release the author of any and all liability. # |
4
|
|
|
|
|
|
|
# # |
5
|
|
|
|
|
|
|
# You may use this code as long as you are in compliance with the # |
6
|
|
|
|
|
|
|
# license (see the LICENSE file) and this notice, disclaimer and # |
7
|
|
|
|
|
|
|
# comment box remain intact and unchanged. # |
8
|
|
|
|
|
|
|
# # |
9
|
|
|
|
|
|
|
# Package: Term::RouterCLI # |
10
|
|
|
|
|
|
|
# Class: Prompt # |
11
|
|
|
|
|
|
|
# Description: Methods for building a Router (Stanford) style CLI # |
12
|
|
|
|
|
|
|
# # |
13
|
|
|
|
|
|
|
# Written by: Bret Jordan (jordan at open1x littledot org) # |
14
|
|
|
|
|
|
|
# Created: 2011-02-21 # |
15
|
|
|
|
|
|
|
##################################################################### |
16
|
|
|
|
|
|
|
# |
17
|
|
|
|
|
|
|
# |
18
|
|
|
|
|
|
|
# |
19
|
|
|
|
|
|
|
# |
20
|
|
|
|
|
|
|
package Term::RouterCLI::Prompt; |
21
|
|
|
|
|
|
|
|
22
|
4
|
|
|
4
|
|
55
|
use 5.8.8; |
|
4
|
|
|
|
|
19
|
|
|
4
|
|
|
|
|
191
|
|
23
|
4
|
|
|
4
|
|
22
|
use strict; |
|
4
|
|
|
|
|
7
|
|
|
4
|
|
|
|
|
132
|
|
24
|
4
|
|
|
4
|
|
26
|
use warnings; |
|
4
|
|
|
|
|
6
|
|
|
4
|
|
|
|
|
140
|
|
25
|
4
|
|
|
4
|
|
31
|
use Log::Log4perl; |
|
4
|
|
|
|
|
14
|
|
|
4
|
|
|
|
|
39
|
|
26
|
|
|
|
|
|
|
|
27
|
4
|
|
|
4
|
|
239
|
use parent qw(Exporter); |
|
4
|
|
|
|
|
7
|
|
|
4
|
|
|
|
|
25
|
|
28
|
|
|
|
|
|
|
our @EXPORT = qw(); |
29
|
|
|
|
|
|
|
our @EXPORT_OK = qw( SetPrompt GetPrompt SetPromptLevel GetPromptLevel ClearPromptOrnaments ChangeActivePrompt); |
30
|
|
|
|
|
|
|
our %EXPORT_TAGS = ( 'all' => [ @EXPORT_OK ] ); |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
our $VERSION = '1.00'; |
33
|
|
|
|
|
|
|
$VERSION = eval $VERSION; |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
# ---------------------------------------- |
38
|
|
|
|
|
|
|
# Public Methods |
39
|
|
|
|
|
|
|
# ---------------------------------------- |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
sub SetPrompt |
42
|
|
|
|
|
|
|
{ |
43
|
|
|
|
|
|
|
# This method is for setting the current prompt value. It is based on the hostname |
44
|
|
|
|
|
|
|
# and the prompt level. |
45
|
|
|
|
|
|
|
# Required: |
46
|
|
|
|
|
|
|
# string (prompt name/hostname value) |
47
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
48
|
0
|
|
|
|
|
|
my $parameter = shift; |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
# If the hostname is not found in the configuration file, lets set a default |
51
|
0
|
0
|
|
|
|
|
if (defined $parameter) { $self->{'_sCurrentPrompt'} = "$parameter" . "$self->{'_sCurrentPromptLevel'}"; } |
|
0
|
|
|
|
|
|
|
52
|
0
|
|
|
|
|
|
else { $self->{'_sCurrentPrompt'} = "Router" . "$self->{'_sCurrentPromptLevel'}"; } |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
sub GetPrompt |
56
|
|
|
|
|
|
|
{ |
57
|
|
|
|
|
|
|
# This method will return the current prompt value |
58
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
59
|
0
|
|
|
|
|
|
return $self->{'_sCurrentPrompt'}; |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
sub SetPromptLevel |
63
|
|
|
|
|
|
|
{ |
64
|
|
|
|
|
|
|
# This method will set the prompt level indicator such as "> ", "# ", "(config) " etc |
65
|
|
|
|
|
|
|
# Required: |
66
|
|
|
|
|
|
|
# string (prompt level indicator) |
67
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
68
|
0
|
|
|
|
|
|
my $parameter = shift; |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
# If this method is called from a command tree option, then it will have the data structure hashref |
71
|
|
|
|
|
|
|
# as the first argument. So we need to check for that just to be safe. |
72
|
0
|
0
|
|
|
|
|
if (ref($parameter) eq 'HASH') { $parameter = $parameter->{'aCommandArguments'}->[0]; } |
|
0
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
|
74
|
0
|
0
|
|
|
|
|
unless (defined $parameter) { $parameter = "> "; } |
|
0
|
|
|
|
|
|
|
75
|
0
|
|
|
|
|
|
$self->{'_sCurrentPromptLevel'} = $parameter; |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
sub GetPromptLevel |
79
|
|
|
|
|
|
|
{ |
80
|
|
|
|
|
|
|
# This method will return the current problem level indicator |
81
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
82
|
0
|
|
|
|
|
|
return $self->{'_sCurrentPromptLevel'}; |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
sub ClearPromptOrnaments |
86
|
|
|
|
|
|
|
{ |
87
|
|
|
|
|
|
|
# This method will turn off the prompt ornamentation aka underlining |
88
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
89
|
0
|
|
|
|
|
|
$self->{'_oTerm'}->Attribs->ornaments(0); |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
sub ChangeActivePrompt |
93
|
|
|
|
|
|
|
{ |
94
|
|
|
|
|
|
|
# This method will change the active prompt that is currently being displayed. Normally the prompt will |
95
|
|
|
|
|
|
|
# change after each command is . But for things like password prompts and other diaplogs, we |
96
|
|
|
|
|
|
|
# need to do it on the fly. |
97
|
|
|
|
|
|
|
# Required: |
98
|
|
|
|
|
|
|
# string (new prompt value) |
99
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
100
|
0
|
|
|
|
|
|
my $parameter = shift; |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
# This line was needed for post tab completion so that it would display the prompt |
103
|
0
|
|
|
|
|
|
$self->{'_oTerm'}->rl_redisplay(); |
104
|
0
|
|
|
|
|
|
$self->{'_oTerm'}->rl_set_prompt($parameter); |
105
|
|
|
|
|
|
|
# This is needed so that when we redisplay, we do not show the current line buffer |
106
|
0
|
|
|
|
|
|
$self->{'_oTerm'}->Attribs->{'line_buffer'} = ""; |
107
|
0
|
|
|
|
|
|
$self->{'_oTerm'}->rl_on_new_line(); |
108
|
0
|
|
|
|
|
|
$self->{'_oTerm'}->rl_redisplay(); |
109
|
|
|
|
|
|
|
} |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
return 1; |