42static const char AsciiCtrA =
'\001';
43static const char AsciiCtrB =
'\002';
44static const char AsciiCtrC =
'\003';
45static const char AsciiCtrD =
'\004';
46static const char AsciiCtrE =
'\005';
47static const char AsciiCtrF =
'\006';
48static const char AsciiCtrK =
'\013';
49static const char AsciiCtrL =
'\014';
50static const char AsciiCtrN =
'\016';
51static const char AsciiCtrP =
'\020';
52static const char AsciiCtrQ =
'\021';
53static const char AsciiCtrS =
'\023';
54static const char AsciiCtrZ =
'\032';
55static const char AsciiTAB =
'\011';
56static const char AsciiBS =
'\010';
57static const char AsciiDEL =
'\177';
58static const char AsciiESC =
'\033';
60static const int AsciiPrintableMin = 32;
63static const G4String historyFileName=
"/.g4_hist";
68 commandLine(
""), cursorPosition(1),
69 commandHistory(maxhist), maxHistory(maxhist),
70 currentHistoryNo(1), relativeHistoryIndex(0)
77 const char* path = getenv(
"HOME");
78 if( path == NULL )
return;
81 G4String fname= homedir + historyFileName;
83 std::ifstream histfile;
84 enum { BUFSIZE= 1024 };
char linebuf[BUFSIZE];
86 histfile.open(fname, std::ios::in);
87 while (histfile.good()) {
88 if(histfile.eof())
break;
90 histfile.getline(linebuf, BUFSIZE);
103 const char* path = getenv(
"HOME");
104 if( path == NULL )
return;
107 G4String fname= homedir + historyFileName;
109 std::ofstream histfile;
110 histfile.open(fname, std::ios::out);
156 std::ostringstream os;
199 if( ! (cc >= AsciiPrintableMin && isprint(cc)) )
return;
227 G4cout << AsciiBS <<
' ' << AsciiBS << std::flush;
311 G4cout << AsciiBS << std::flush;
332 G4cout << AsciiBS << std::flush;
407 if(jhead !=
G4int(G4String::npos)) {
417 if( !input.empty() ) {
418 G4int len= input.length();
420 for(
G4int i=len-1; i>=0; i--) {
421 if(input[(
size_t)i]==
'/') {
428 if(!(indx==0 && len==1)) vcmd= input(indx+1,len-indx-1);
446 if(jhead !=
G4int(G4String::npos)) {
452 size_t thead = input.find_last_of(
'/');
454 if (thead != G4String::npos) strtail = input(thead+1, input.size()-thead-1);
460 G4int len= input.length();
463 for(
G4int i=len-1; i>=0; i--) {
471 if(!(indx==0 && len==1)) vcmd= input(indx+1,len-indx-1);
475 if(atree == NULL)
return;
482 int Ndir= atree-> GetTreeEntry();
483 int Ncmd= atree-> GetCommandEntry();
486 for(
G4int idir=1; idir<=Ndir; idir++) {
487 G4String fpdir= atree-> GetTree(idir)-> GetPathName();
489 if( fpdir.
index(inputpath, 0) == 0) {
501 for(
G4int icmd=1; icmd<=Ncmd; icmd++){
502 G4String fpcmd= atree-> GetPathName() +
503 atree-> GetCommand(icmd) -> GetCommandName();
505 if( fpcmd.
index(inputpath, 0) ==0) {
519 jhead= input.
last(
' ');
520 if(jhead ==
G4int(G4String::npos)) jhead=0;
527 for(i=jt; i<=
G4int(input.length())-1; i++) dspstr+=
G4String(AsciiBS);
528 for(i=jt; i<=
G4int(input.length())-1; i++) dspstr+=
G4String(
' ');
529 for(i=jt; i<=
G4int(input.length())-1; i++) dspstr+=
G4String(AsciiBS);
531 dspstr+= (vpath + stream);
532 if (nMatch == 0) dspstr+= strtail;
533 G4cout << dspstr << std::flush;
537 input+= (vpath + stream);
538 if (nMatch==0) input+= strtail;
611 if( cc == AsciiESC) {
613 if (cc ==
'[' || cc ==
'O') {
642 }
while( cc !=
'\n');
660 while( (newCommand.length() > 0) &&
661 ( newCommand[newCommand.length()-1] ==
'_') ) {
662 newCommand.
remove(newCommand.length()-1);
667 newCommand.
append(newLine);
672 for (
size_t i=0; i<newCommand.length(); i++) {
673 if(newCommand[i] !=
' ') {
678 if( !newCommand.empty() && isMeaningfull)
StoreHistory(newCommand);
692 int nlen1= str1.length();
693 int nlen2= str2.length();
695 int nmin = nlen1<nlen2 ? nlen1 : nlen2;
698 for(
size_t i=0;
G4int(i)<nmin; i++){
699 if(str1[i]==str2[i]) {
700 strMatched+= str1[i];
742 termios tiosbuf=
tios;
744 tiosbuf.c_iflag &= ~(BRKINT | ISTRIP);
745 tiosbuf.c_iflag |= (IGNBRK | IGNPAR);
746 tiosbuf.c_lflag &= ~(ICANON | IEXTEN | ECHO);
747 tiosbuf.c_cc[VMIN] = 1;
748 tiosbuf.c_cc[VTIME] = 0;
750 tcsetattr(0, TCSAFLUSH, &tiosbuf);
758 tcsetattr(0, TCSAFLUSH, &
tios);
G4DLLIMPORT std::ostream G4cout
G4ApplicationState GetCurrentState() const
static G4StateManager * GetStateManager()
G4String & remove(str_size)
G4String & append(const G4String &)
str_size index(const char *, G4int pos=0) const
G4String strip(G4int strip_Type=trailing, char c=' ')
void InsertCharacter(char cc)
virtual void ResetTerminal()
virtual void MakePrompt(const char *msg=0)
G4String GetFirstMatchedString(const G4String &str1, const G4String &str2) const
G4String RestoreHistory(G4int index)
void SetTermToInputMode()
void ListMatchedCommand()
G4bool IsCursorLast() const
void InitializeCommandLine()
G4UItcsh(const G4String &prompt="%s> ", G4int maxhist=100)
virtual G4String GetCommandLineString(const char *msg=0)
std::vector< G4String > commandHistory
void StoreHistory(G4String aCommand)
void BackspaceCharacter()
G4int relativeHistoryIndex
virtual void ListCommand(const G4String &input, const G4String &candidate="") const
G4UIcommandTree * GetCommandTree(const G4String &dir) const
G4String currentCommandDir
G4String GetCommandPathTail(const G4String &apath) const
G4String GetAbsCommandDirPath(const G4String &apath) const