Geant4 11.1.1
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4VUIshell Class Referenceabstract

#include <G4VUIshell.hh>

+ Inheritance diagram for G4VUIshell:

Public Member Functions

 G4VUIshell (const G4String &prompt="> ")
 
virtual ~G4VUIshell ()
 
void SetNColumn (G4int ncol)
 
void SetPrompt (const G4String &prompt)
 
void SetCurrentDirectory (const G4String &ccd)
 
virtual void SetLsColor (TermColorIndex, TermColorIndex)
 
virtual void ShowCurrentDirectory () const
 
virtual void ListCommand (const G4String &input, const G4String &candidate="") const
 
virtual G4String GetCommandLineString (const char *msg=0)=0
 
virtual void ResetTerminal ()
 

Protected Member Functions

virtual void MakePrompt (const char *msg=0)
 
G4UIcommandTreeGetCommandTree (const G4String &dir) const
 
G4String GetAbsCommandDirPath (const G4String &apath) const
 
G4String GetCommandPathTail (const G4String &apath) const
 

Protected Attributes

G4String promptSetting
 
G4String promptString
 
G4int nColumn
 
G4bool lsColorFlag
 
TermColorIndex directoryColor
 
TermColorIndex commandColor
 
G4String currentCommandDir
 

Detailed Description

Definition at line 58 of file G4VUIshell.hh.

Constructor & Destructor Documentation

◆ G4VUIshell()

G4VUIshell::G4VUIshell ( const G4String prompt = "> ")

Definition at line 45 of file G4VUIshell.cc.

46 : promptSetting(prompt), promptString(""), nColumn(80),
49///////////////////////////////////////////////////////////////////
50{
51}
@ BLACK
Definition: G4VUIshell.hh:53
TermColorIndex directoryColor
Definition: G4VUIshell.hh:68
G4int nColumn
Definition: G4VUIshell.hh:63
G4String currentCommandDir
Definition: G4VUIshell.hh:72
TermColorIndex commandColor
Definition: G4VUIshell.hh:69
G4String promptString
Definition: G4VUIshell.hh:61
G4bool lsColorFlag
Definition: G4VUIshell.hh:67
G4String promptSetting
Definition: G4VUIshell.hh:60
#define FALSE
Definition: globals.hh:38

◆ ~G4VUIshell()

G4VUIshell::~G4VUIshell ( )
virtual

Definition at line 54 of file G4VUIshell.cc.

56{
57}

Member Function Documentation

◆ GetAbsCommandDirPath()

G4String G4VUIshell::GetAbsCommandDirPath ( const G4String apath) const
protected

Definition at line 145 of file G4VUIshell.cc.

147{
148 if(apath.empty()) return apath; // null string
149
150 // if "apath" does not start with "/",
151 // then it is treared as relative path
152 G4String bpath= apath;
153 if(apath[(std::size_t)0] != '/') bpath= currentCommandDir + apath;
154
155 // parsing...
156 G4String absPath= "/";
157 for(std::size_t indx=1; indx<=bpath.length()-1; ) {
158 std::size_t jslash= bpath.find("/", indx); // search index begin with "/"
159 if(indx == jslash) { // skip first '///'
160 ++indx;
161 continue;
162 }
163 if(jslash != G4String::npos) {
164 if(bpath.substr(indx,jslash-indx) == ".."){ // directory up
165 if(absPath == "/") {
166 indx = jslash+1;
167 continue;
168 }
169 if(absPath.length() >= 2) {
170 absPath.erase(absPath.length()-1); // remove last "/"
171 auto jpre= absPath.rfind('/');
172 if(jpre != G4String::npos) absPath.erase(jpre+1);
173 }
174 } else if(bpath.substr(indx,jslash-indx) == "."){ // nothing to do
175 } else { // add
176 if( !(jslash==indx && bpath[(G4int)indx]=='/') ) // truncate "////"
177 absPath+= bpath.substr(indx, jslash-indx+1);
178 // better to be check directory existence. (it costs!)
179 }
180 indx= jslash+1;
181 } else { // directory ONLY (ignore non-"/" terminated string)
182 break;
183 }
184 }
185
186 return absPath;
187}
int G4int
Definition: G4Types.hh:85

Referenced by G4UItcsh::CompleteCommand(), and G4UItcsh::ListMatchedCommand().

◆ GetCommandLineString()

virtual G4String G4VUIshell::GetCommandLineString ( const char *  msg = 0)
pure virtual

Implemented in G4UIcsh, and G4UItcsh.

◆ GetCommandPathTail()

G4String G4VUIshell::GetCommandPathTail ( const G4String apath) const
protected

Definition at line 191 of file G4VUIshell.cc.

193{ // xxx/xxx/zzz -> zzz, trancate /// -> /
194 if(apath.empty()) return apath;
195
196 G4int lstr= (G4int)apath.length();
197
198 // for trancating "/"
199 G4bool Qsla= FALSE;
200 if(apath[lstr-1]=='/') Qsla= TRUE;
201
202 // searching last '/' from tail
203 G4int indx= -1;
204 for(G4int i=lstr-1; i>=0; --i) {
205 if(Qsla && apath[i]!='/') Qsla= FALSE; // break "/" flag!!
206 if(apath[i]=='/' && !Qsla) {
207 indx= i;
208 break;
209 }
210 }
211
212 if(indx==-1) return apath; // not found
213
214 if(indx==0 && lstr==1) { // "/"
215 G4String nullStr;
216 return nullStr;
217 } else {
218 //G4String newPath= apath(indx+1,lstr-indx-1);
219 G4String newPath= apath;
220 newPath= newPath.substr(indx+1,lstr-indx-1);
221 return newPath;
222 }
223}
bool G4bool
Definition: G4Types.hh:86
#define TRUE
Definition: globals.hh:41

Referenced by G4UItcsh::CompleteCommand().

◆ GetCommandTree()

G4UIcommandTree * G4VUIshell::GetCommandTree ( const G4String dir) const
protected

Definition at line 117 of file G4VUIshell.cc.

119{
121
122 G4UIcommandTree* cmdTree= UI-> GetTree(); // root tree
123
125
126 // parsing absolute path ...
127 if(absPath.length()==0) return NULL;
128 if(absPath[G4int(absPath.length()-1)] != '/') return NULL; // error??
129 if(absPath=="/") return cmdTree;
130
131 for(std::size_t indx=1; indx<absPath.length()-1; ) {
132 std::size_t jslash= absPath.find("/", indx); // search index begin with "/"
133 if(jslash != G4String::npos) {
134 if(cmdTree != NULL)
135 cmdTree= cmdTree-> GetTree(G4String(absPath.substr(0,jslash+1)));
136 }
137 indx= jslash+1;
138 }
139
140 if(cmdTree == NULL) return NULL;
141 else return cmdTree;
142}
static G4UImanager * GetUIpointer()
Definition: G4UImanager.cc:77
G4String GetAbsCommandDirPath(const G4String &apath) const
Definition: G4VUIshell.cc:145
G4String strip_copy(G4String str, char ch=' ')
Return copy of string with leading and trailing characters removed.

Referenced by G4UItcsh::CompleteCommand().

◆ ListCommand()

void G4VUIshell::ListCommand ( const G4String input,
const G4String candidate = "" 
) const
virtual

Definition at line 229 of file G4VUIshell.cc.

232{
233 // specified directpry
234 G4String input = G4StrUtil::strip_copy(dir);
235
236 // command tree of "user specified directory"
238 G4String vcmd;
239
240 G4int len= (G4int)input.length();
241 if(! input.empty()) {
242 G4int indx= -1;
243 for(G4int i=len-1; i>=0; --i) { // search last '/'
244 if(input[i]=='/') {
245 indx= i;
246 break;
247 }
248 }
249 // get abs. path
250 if(indx != -1) vpath= GetAbsCommandDirPath(input.substr(0,indx+1));
251 if(!(indx==0 && len==1)) vcmd= input.substr(indx+1,len-indx-1); // care for "/"
252 }
253
254 // check "vcmd" is directory?
255 G4String inputpath= vpath+vcmd;
256 if(! vcmd.empty()){
257 G4String tmpstr= inputpath + "/";
258 if(GetCommandTree(tmpstr) != NULL) {
259 vpath= tmpstr;
260 vcmd= "";
261 }
262 }
263
264 // check "vpath" directory exists?
265 G4UIcommandTree* atree= GetCommandTree(vpath);
266 if(atree == NULL) {
267 G4cout << "<" << input << ">: No such directory" << G4endl;
268 return;
269 }
270
271 // list matched directories/commands
272 G4String stream;
273 G4bool isMatch= FALSE;
274
275 G4int Ndir= atree-> GetTreeEntry();
276 G4int Ncmd= atree-> GetCommandEntry();
277 if(Ndir==0 && Ncmd==0) return; // no contents
278
279 // directory ...
280 for(G4int idir=1; idir<=Ndir; idir++) {
281 if(idir==1 && lsColorFlag) stream+= TermColorString[directoryColor];
282 G4String fpdir= atree-> GetTree(idir)-> GetPathName();
283 // matching test
284 if(candidate.empty()) { // list all
285 if(vcmd=="" || fpdir==inputpath) {
286 stream+= GetCommandPathTail(fpdir); stream+= " ";
287 isMatch= TRUE;
288 }
289 } else { // list only matched with candidate
290 if( fpdir.find(candidate, 0) == 0) {
291 stream+= GetCommandPathTail(fpdir); stream+= " ";
292 }
293 }
294 }
295
296 // command ...
297 for(G4int icmd=1; icmd<=Ncmd; icmd++){
298 if(icmd==1 && lsColorFlag) stream+= TermColorString[commandColor];
299 G4String fpcmd= atree-> GetPathName() +
300 atree-> GetCommand(icmd) -> GetCommandName();
301 // matching test
302 if(candidate.empty()) { // list all
303 if(vcmd=="" || fpcmd==inputpath) {
304 stream+= GetCommandPathTail(fpcmd); stream+= "* ";
305 isMatch= TRUE;
306 }
307 } else { // list only matched with candidate
308 if( fpcmd.find(candidate, 0) == 0) {
309 stream+= GetCommandPathTail(fpcmd); stream+= "* ";
310 }
311 }
312 }
313
314 // waring : not matched
315 if(!isMatch && candidate.empty())
316 G4cout << "<" << input
317 << ">: No such directory or command" << std::flush;
318
319 // display
320 G4UIArrayString arrayString(stream);
321 arrayString.Show(nColumn);
322}
#define G4endl
Definition: G4ios.hh:57
G4GLOB_DLL std::ostream G4cout
G4UIcommandTree * GetCommandTree(const G4String &dir) const
Definition: G4VUIshell.cc:117
G4String GetCommandPathTail(const G4String &apath) const
Definition: G4VUIshell.cc:191

Referenced by G4UItcsh::ListMatchedCommand().

◆ MakePrompt()

void G4VUIshell::MakePrompt ( const char *  msg = 0)
protectedvirtual

Reimplemented in G4UItcsh.

Definition at line 60 of file G4VUIshell.cc.

62{
63 if(promptSetting.length()<=1) {
65 return;
66 }
67
68 promptString="";
69 G4int i;
70 for(i=0; i<(G4int)promptSetting.length()-1; ++i){
71 if(promptSetting[i]=='%'){
72 switch (promptSetting[i+1]) {
73 case 's': // current application status
74 {
75 G4String stateStr;
76 if(msg)
77 { stateStr = msg; }
78 else
79 {
81 stateStr= statM-> GetStateString(statM->GetCurrentState());
82 }
83 promptString.append(stateStr);
84 i++;
85 }
86 break;
87 case '/': // current working directory
89 i++;
90 break;
91 default:
93 break;
94 }
95 } else {
97 }
98 }
99
100 // append last chaacter
101 if(i == G4int(promptSetting.length())-1)
103}
const G4ApplicationState & GetCurrentState() const
static G4StateManager * GetStateManager()

Referenced by G4UIcsh::GetCommandLineString().

◆ ResetTerminal()

void G4VUIshell::ResetTerminal ( )
virtual

Reimplemented in G4UItcsh.

Definition at line 107 of file G4VUIshell.cc.

109{
110
111}

◆ SetCurrentDirectory()

void G4VUIshell::SetCurrentDirectory ( const G4String ccd)
inline

Definition at line 114 of file G4VUIshell.hh.

115{
117}

◆ SetLsColor()

void G4VUIshell::SetLsColor ( TermColorIndex  ,
TermColorIndex   
)
inlinevirtual

Reimplemented in G4UItcsh.

Definition at line 119 of file G4VUIshell.hh.

120{
121}

◆ SetNColumn()

void G4VUIshell::SetNColumn ( G4int  ncol)
inline

Definition at line 104 of file G4VUIshell.hh.

105{
106 nColumn= ncol;
107}

◆ SetPrompt()

void G4VUIshell::SetPrompt ( const G4String prompt)
inline

Definition at line 109 of file G4VUIshell.hh.

110{
111 promptSetting= prompt;
112}

◆ ShowCurrentDirectory()

void G4VUIshell::ShowCurrentDirectory ( ) const
inlinevirtual

Definition at line 123 of file G4VUIshell.hh.

124{
126}

Member Data Documentation

◆ commandColor

TermColorIndex G4VUIshell::commandColor
protected

Definition at line 69 of file G4VUIshell.hh.

Referenced by G4UItcsh::SetLsColor().

◆ currentCommandDir

◆ directoryColor

TermColorIndex G4VUIshell::directoryColor
protected

Definition at line 68 of file G4VUIshell.hh.

Referenced by G4UItcsh::SetLsColor().

◆ lsColorFlag

G4bool G4VUIshell::lsColorFlag
protected

Definition at line 67 of file G4VUIshell.hh.

Referenced by G4UItcsh::SetLsColor().

◆ nColumn

G4int G4VUIshell::nColumn
protected

Definition at line 63 of file G4VUIshell.hh.

Referenced by SetNColumn().

◆ promptSetting

G4String G4VUIshell::promptSetting
protected

Definition at line 60 of file G4VUIshell.hh.

Referenced by G4UItcsh::MakePrompt(), MakePrompt(), and SetPrompt().

◆ promptString


The documentation for this class was generated from the following files: