41static const char AsciiCtrA =
'\001';
42static const char AsciiCtrB =
'\002';
43static const char AsciiCtrC =
'\003';
44static const char AsciiCtrD =
'\004';
45static const char AsciiCtrE =
'\005';
46static const char AsciiCtrF =
'\006';
47static const char AsciiCtrK =
'\013';
48static const char AsciiCtrL =
'\014';
49static const char AsciiCtrN =
'\016';
50static const char AsciiCtrP =
'\020';
51static const char AsciiCtrQ =
'\021';
52static const char AsciiCtrS =
'\023';
53static const char AsciiCtrZ =
'\032';
54static const char AsciiTAB =
'\011';
55static const char AsciiBS =
'\010';
56static const char AsciiDEL =
'\177';
57static const char AsciiESC =
'\033';
59static const int AsciiPrintableMin = 32;
62static const G4String historyFileName=
"/.g4_hist";
67 commandLine(
""), cursorPosition(1),
68 commandHistory(maxhist), maxHistory(maxhist),
69 currentHistoryNo(1), relativeHistoryIndex(0)
76 const char* path = std::getenv(
"HOME");
77 if( path == NULL )
return;
80 G4String fname= homedir + historyFileName;
82 std::ifstream histfile;
83 enum { BUFSIZE= 1024 };
char linebuf[BUFSIZE];
85 histfile.open(fname, std::ios::in);
86 while (histfile.good()) {
87 if(histfile.eof())
break;
89 histfile.getline(linebuf, BUFSIZE);
101 const char* path = std::getenv(
"HOME");
102 if( path == NULL )
return;
105 G4String fname= homedir + historyFileName;
107 std::ofstream histfile;
108 histfile.open(fname, std::ios::out);
154 std::ostringstream os;
197 if( ! (cc >= AsciiPrintableMin && isprint(cc)) )
return;
225 G4cout << AsciiBS <<
' ' << AsciiBS << std::flush;
308 G4cout << AsciiBS << std::flush;
329 G4cout << AsciiBS << std::flush;
403 auto jhead= input.rfind(
' ');
404 if(jhead != G4String::npos) {
405 input.erase(0, jhead);
413 if( !input.empty() ) {
416 for(
G4int i=len-1; i>=0; --i) {
424 if(!(indx==0 && len==1)) vcmd= input.substr(indx+1,len-indx-1);
442 auto jhead= input.rfind(
' ');
443 if(jhead != G4String::npos) {
444 input.erase(0, jhead);
449 std::size_t thead = input.find_last_of(
'/');
451 if (thead != G4String::npos) strtail = input.substr(thead+1, input.size()-thead-1);
460 for(
G4int i=len-1; i>=0; --i) {
468 if(!(indx==0 && len==1)) vcmd= input.substr(indx+1,len-indx-1);
472 if(atree == NULL)
return;
479 G4int Ndir= atree-> GetTreeEntry();
480 G4int Ncmd= atree-> GetCommandEntry();
483 for(
G4int idir=1; idir<=Ndir; idir++) {
484 G4String fpdir= atree-> GetTree(idir)-> GetPathName();
486 if( fpdir.find(inputpath, 0) == 0) {
498 for(
G4int icmd=1; icmd<=Ncmd; icmd++){
499 G4String fpcmd= atree-> GetPathName() +
500 atree-> GetCommand(icmd) -> GetCommandName();
502 if( fpcmd.find(inputpath, 0) ==0) {
516 jhead= input.rfind(
' ');
517 if(jhead == G4String::npos) jhead=0;
520 std::size_t jt = jhead;
524 for(i=jt; i<=input.length()-1; ++i) dspstr+= AsciiBS;
525 for(i=jt; i<=input.length()-1; ++i) dspstr+=
' ';
526 for(i=jt; i<=input.length()-1; ++i) dspstr+= AsciiBS;
528 dspstr+= (vpath + stream);
529 if (nMatch == 0) dspstr+= strtail;
530 G4cout << dspstr << std::flush;
534 input+= (vpath + stream);
535 if (nMatch==0) input+= strtail;
608 if( cc == AsciiESC) {
610 if (cc ==
'[' || cc ==
'O') {
639 }
while( cc !=
'\n');
657 while( (newCommand.length() > 0) &&
658 ( newCommand[
G4int(newCommand.length()-1)] ==
'_') ) {
659 newCommand.erase(newCommand.length()-1);
664 newCommand.append(newLine);
669 for (
G4int i=0; i<(
G4int)newCommand.length(); ++i) {
670 if(newCommand[i] !=
' ') {
675 if( !newCommand.empty() && isMeaningfull)
StoreHistory(newCommand);
689 std::size_t nlen1= str1.length();
690 std::size_t nlen2= str2.length();
692 std::size_t nmin = nlen1<nlen2 ? nlen1 : nlen2;
696 if(str1[i]==str2[i]) {
697 strMatched+= str1[i];
739 termios tiosbuf=
tios;
741 tiosbuf.c_iflag &= ~(BRKINT | ISTRIP);
742 tiosbuf.c_iflag |= (IGNBRK | IGNPAR);
743 tiosbuf.c_lflag &= ~(ICANON | IEXTEN | ECHO);
744 tiosbuf.c_cc[VMIN] = 1;
745 tiosbuf.c_cc[VTIME] = 0;
747 tcsetattr(0, TCSAFLUSH, &tiosbuf);
755 tcsetattr(0, TCSAFLUSH, &
tios);
G4GLOB_DLL std::ostream G4cout
const G4ApplicationState & GetCurrentState() const
static G4StateManager * GetStateManager()
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
G4String strip_copy(G4String str, char ch=' ')
Return copy of string with leading and trailing characters removed.
void lstrip(G4String &str, char ch=' ')
Remove leading characters from string.
G4String lstrip_copy(G4String str, char ch=' ')
Return copy of string with leading characters removed.