38static const G4String strESC(1,
'\033');
39static const G4String TermColorString[8] ={
40 strESC+
"[30m", strESC+
"[31m", strESC+
"[32m", strESC+
"[33m",
41 strESC+
"[34m", strESC+
"[35m", strESC+
"[36m", strESC+
"[37m"
46 : promptSetting(prompt), promptString(
""), nColumn(80),
48 currentCommandDir(
"/")
127 if(absPath.length()==0)
return NULL;
128 if(absPath[
G4int(absPath.length()-1)] !=
'/')
return NULL;
129 if(absPath==
"/")
return cmdTree;
131 for(std::size_t indx=1; indx<absPath.length()-1; ) {
132 std::size_t jslash= absPath.find(
"/", indx);
133 if(jslash != G4String::npos) {
135 cmdTree= cmdTree-> GetTree(
G4String(absPath.substr(0,jslash+1)));
140 if(cmdTree == NULL)
return NULL;
148 if(apath.empty())
return apath;
153 if(apath[(std::size_t)0] !=
'/') bpath= currentCommandDir + apath;
157 for(std::size_t indx=1; indx<=bpath.length()-1; ) {
158 std::size_t jslash= bpath.find(
"/", indx);
163 if(jslash != G4String::npos) {
164 if(bpath.substr(indx,jslash-indx) ==
".."){
169 if(absPath.length() >= 2) {
170 absPath.erase(absPath.length()-1);
171 auto jpre= absPath.rfind(
'/');
172 if(jpre != G4String::npos) absPath.erase(jpre+1);
174 }
else if(bpath.substr(indx,jslash-indx) ==
"."){
176 if( !(jslash==indx && bpath[(
G4int)indx]==
'/') )
177 absPath+= bpath.substr(indx, jslash-indx+1);
194 if(apath.empty())
return apath;
200 if(apath[lstr-1]==
'/') Qsla=
TRUE;
204 for(
G4int i=lstr-1; i>=0; --i) {
205 if(Qsla && apath[i]!=
'/') Qsla=
FALSE;
206 if(apath[i]==
'/' && !Qsla) {
212 if(indx==-1)
return apath;
214 if(indx==0 && lstr==1) {
220 newPath= newPath.substr(indx+1,lstr-indx-1);
241 if(! input.empty()) {
243 for(
G4int i=len-1; i>=0; --i) {
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);
258 if(GetCommandTree(tmpstr) != NULL) {
267 G4cout <<
"<" << input <<
">: No such directory" <<
G4endl;
275 G4int Ndir= atree-> GetTreeEntry();
276 G4int Ncmd= atree-> GetCommandEntry();
277 if(Ndir==0 && Ncmd==0)
return;
280 for(
G4int idir=1; idir<=Ndir; idir++) {
281 if(idir==1 && lsColorFlag) stream+= TermColorString[directoryColor];
282 G4String fpdir= atree-> GetTree(idir)-> GetPathName();
284 if(candidate.empty()) {
285 if(vcmd==
"" || fpdir==inputpath) {
286 stream+= GetCommandPathTail(fpdir); stream+=
" ";
290 if( fpdir.find(candidate, 0) == 0) {
291 stream+= GetCommandPathTail(fpdir); stream+=
" ";
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();
302 if(candidate.empty()) {
303 if(vcmd==
"" || fpcmd==inputpath) {
304 stream+= GetCommandPathTail(fpcmd); stream+=
"* ";
308 if( fpcmd.find(candidate, 0) == 0) {
309 stream+= GetCommandPathTail(fpcmd); stream+=
"* ";
315 if(!isMatch && candidate.empty())
317 <<
">: No such directory or command" << std::flush;
321 arrayString.
Show(nColumn);
G4GLOB_DLL std::ostream G4cout
const G4ApplicationState & GetCurrentState() const
static G4StateManager * GetStateManager()
static G4UImanager * GetUIpointer()
virtual void ResetTerminal()
virtual void MakePrompt(const char *msg=0)
virtual void ListCommand(const G4String &input, const G4String &candidate="") const
G4UIcommandTree * GetCommandTree(const G4String &dir) const
G4String currentCommandDir
G4VUIshell(const G4String &prompt="> ")
G4String GetCommandPathTail(const G4String &apath) const
G4String GetAbsCommandDirPath(const G4String &apath) const
G4String strip_copy(G4String str, char ch=' ')
Return copy of string with leading and trailing characters removed.