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;
82 std::ifstream histfile;
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;
107 std::ofstream histfile;
108 histfile.open(
fname, std::ios::out);
154 std::ostringstream os;
404 auto jhead= input.rfind(
' ');
405 if(jhead != G4String::npos) {
406 input.erase(0, jhead);
414 if( !input.empty() ) {
415 G4int len= input.length();
417 for(
G4int i=len-1; i>=0; i--) {
418 if(input[(
size_t)i]==
'/') {
425 if(!(indx==0 && len==1)) vcmd= input.substr(indx+1,len-indx-1);
443 auto jhead= input.rfind(
' ');
444 if(jhead != G4String::npos) {
445 input.erase(0, jhead);
450 size_t thead = input.find_last_of(
'/');
452 if (thead != G4String::npos) strtail = input.substr(thead+1, input.size()-thead-1);
458 G4int len= input.length();
461 for(
G4int i=len-1; i>=0; i--) {
469 if(!(indx==0 && len==1)) vcmd= input.substr(indx+1,len-indx-1);
473 if(atree == NULL)
return;
480 int Ndir= atree-> GetTreeEntry();
481 int Ncmd= atree-> GetCommandEntry();
484 for(
G4int idir=1; idir<=Ndir; idir++) {
485 G4String fpdir= atree-> GetTree(idir)-> GetPathName();
487 if( fpdir.find(inputpath, 0) == 0) {
499 for(
G4int icmd=1; icmd<=Ncmd; icmd++){
500 G4String fpcmd= atree-> GetPathName() +
501 atree-> GetCommand(icmd) -> GetCommandName();
503 if( fpcmd.find(inputpath, 0) ==0) {
517 jhead= input.rfind(
' ');
518 if(jhead == G4String::npos) jhead=0;
525 for(i=jt; i<=
G4int(input.length())-1; i++) dspstr+=
AsciiBS;
526 for(i=jt; i<=
G4int(input.length())-1; i++) dspstr+=
' ';
527 for(i=jt; i<=
G4int(input.length())-1; i++) dspstr+=
AsciiBS;
529 dspstr+= (vpath + stream);
530 if (nMatch == 0) dspstr+= strtail;
531 G4cout << dspstr << std::flush;
535 input+= (vpath + stream);
536 if (nMatch==0) input+= strtail;
611 if (cc ==
'[' || cc ==
'O') {
640 }
while( cc !=
'\n');
658 while( (newCommand.length() > 0) &&
659 ( newCommand[newCommand.length()-1] ==
'_') ) {
660 newCommand.erase(newCommand.length()-1);
665 newCommand.append(newLine);
670 for (
size_t i=0; i<newCommand.length(); i++) {
671 if(newCommand[i] !=
' ') {
676 if( !newCommand.empty() && isMeaningfull)
StoreHistory(newCommand);
690 int nlen1= str1.length();
691 int nlen2= str2.length();
693 int nmin = nlen1<nlen2 ? nlen1 : nlen2;
696 for(
size_t i=0;
G4int(i)<nmin; i++){
697 if(str1[i]==str2[i]) {
698 strMatched+= str1[i];
740 termios tiosbuf=
tios;
742 tiosbuf.c_iflag &= ~(BRKINT | ISTRIP);
743 tiosbuf.c_iflag |= (IGNBRK | IGNPAR);
744 tiosbuf.c_lflag &= ~(ICANON | IEXTEN | ECHO);
745 tiosbuf.c_cc[VMIN] = 1;
746 tiosbuf.c_cc[VTIME] = 0;
748 tcsetattr(0, TCSAFLUSH, &tiosbuf);
756 tcsetattr(0, TCSAFLUSH, &
tios);
static const char AsciiCtrN
static const char AsciiCtrS
static const char AsciiCtrL
static const char AsciiCtrE
static const char AsciiTAB
static const char AsciiBS
static const char AsciiCtrD
static const char AsciiCtrK
static const G4String historyFileName
static const char AsciiCtrP
static const char AsciiCtrA
static const char AsciiDEL
static const char AsciiCtrZ
static const char AsciiCtrB
static const char AsciiCtrC
static const char AsciiCtrQ
static const int AsciiPrintableMin
static const char AsciiCtrF
static const char AsciiESC
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 c=' ')
Return copy of string with leading and trailing characters removed.
void lstrip(G4String &str, char c=' ')
Remove leading characters from string.
G4String lstrip_copy(G4String str, char c=' ')
Return copy of string with leading characters removed.