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);
102 const char* path = std::getenv(
"HOME");
103 if( path == NULL )
return;
106 G4String fname= homedir + historyFileName;
108 std::ofstream histfile;
109 histfile.open(fname, std::ios::out);
155 std::ostringstream os;
198 if( ! (cc >= AsciiPrintableMin && isprint(cc)) )
return;
226 G4cout << AsciiBS <<
' ' << AsciiBS << std::flush;
310 G4cout << AsciiBS << std::flush;
331 G4cout << AsciiBS << std::flush;
406 if(jhead !=
G4int(G4String::npos)) {
416 if( !input.empty() ) {
417 G4int len= input.length();
419 for(
G4int i=len-1; i>=0; i--) {
420 if(input[(
size_t)i]==
'/') {
427 if(!(indx==0 && len==1)) vcmd= input(indx+1,len-indx-1);
445 if(jhead !=
G4int(G4String::npos)) {
451 size_t thead = input.find_last_of(
'/');
453 if (thead != G4String::npos) strtail = input(thead+1, input.size()-thead-1);
459 G4int len= input.length();
462 for(
G4int i=len-1; i>=0; i--) {
470 if(!(indx==0 && len==1)) vcmd= input(indx+1,len-indx-1);
474 if(atree == NULL)
return;
481 int Ndir= atree-> GetTreeEntry();
482 int Ncmd= atree-> GetCommandEntry();
485 for(
G4int idir=1; idir<=Ndir; idir++) {
486 G4String fpdir= atree-> GetTree(idir)-> GetPathName();
488 if( fpdir.
index(inputpath, 0) == 0) {
500 for(
G4int icmd=1; icmd<=Ncmd; icmd++){
501 G4String fpcmd= atree-> GetPathName() +
502 atree-> GetCommand(icmd) -> GetCommandName();
504 if( fpcmd.
index(inputpath, 0) ==0) {
518 jhead= input.
last(
' ');
519 if(jhead ==
G4int(G4String::npos)) jhead=0;
526 for(i=jt; i<=
G4int(input.length())-1; i++) dspstr+=
G4String(AsciiBS);
527 for(i=jt; i<=
G4int(input.length())-1; i++) dspstr+=
G4String(
' ');
528 for(i=jt; i<=
G4int(input.length())-1; i++) dspstr+=
G4String(AsciiBS);
530 dspstr+= (vpath + stream);
531 if (nMatch == 0) dspstr+= strtail;
532 G4cout << dspstr << std::flush;
536 input+= (vpath + stream);
537 if (nMatch==0) input+= strtail;
610 if( cc == AsciiESC) {
612 if (cc ==
'[' || cc ==
'O') {
641 }
while( cc !=
'\n');
659 while( (newCommand.length() > 0) &&
660 ( newCommand[newCommand.length()-1] ==
'_') ) {
661 newCommand.
remove(newCommand.length()-1);
666 newCommand.
append(newLine);
671 for (
size_t i=0; i<newCommand.length(); i++) {
672 if(newCommand[i] !=
' ') {
677 if( !newCommand.empty() && isMeaningfull)
StoreHistory(newCommand);
691 int nlen1= str1.length();
692 int nlen2= str2.length();
694 int nmin = nlen1<nlen2 ? nlen1 : nlen2;
697 for(
size_t i=0;
G4int(i)<nmin; i++){
698 if(str1[i]==str2[i]) {
699 strMatched+= str1[i];
741 termios tiosbuf=
tios;
743 tiosbuf.c_iflag &= ~(BRKINT | ISTRIP);
744 tiosbuf.c_iflag |= (IGNBRK | IGNPAR);
745 tiosbuf.c_lflag &= ~(ICANON | IEXTEN | ECHO);
746 tiosbuf.c_cc[VMIN] = 1;
747 tiosbuf.c_cc[VTIME] = 0;
749 tcsetattr(0, TCSAFLUSH, &tiosbuf);
757 tcsetattr(0, TCSAFLUSH, &
tios);
G4GLOB_DLL std::ostream G4cout
const G4ApplicationState & GetCurrentState() const
static G4StateManager * GetStateManager()
G4String & remove(str_size)
G4String & append(const G4String &)
str_size index(const char *, G4int pos=0) const
std::size_t last(char) 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