Geant4 11.2.2
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4UItcsh Class Reference

#include <G4UItcsh.hh>

+ Inheritance diagram for G4UItcsh:

Public Member Functions

 G4UItcsh (const G4String &prompt="%s> ", G4int maxhist=100)
 
 ~G4UItcsh () override
 
void SetLsColor (TermColorIndex dirColor, TermColorIndex cmdColor) override
 
G4String GetCommandLineString (const char *msg=nullptr) override
 
void ResetTerminal () override
 
- Public Member Functions inherited from G4VUIshell
 G4VUIshell (const G4String &prompt="> ")
 
virtual ~G4VUIshell ()
 
void SetNColumn (G4int ncol)
 
void SetPrompt (const G4String &prompt)
 
void SetCurrentDirectory (const G4String &ccd)
 
virtual void ShowCurrentDirectory () const
 
virtual void ListCommand (const G4String &input, const G4String &candidate="") const
 

Protected Member Functions

void MakePrompt (const char *msg=nullptr) override
 
G4bool IsCursorLast () const
 
void InitializeCommandLine ()
 
G4String ReadLine ()
 
void InsertCharacter (char cc)
 
void BackspaceCharacter ()
 
void DeleteCharacter ()
 
void ClearLine ()
 
void ClearAfterCursor ()
 
void ClearScreen ()
 
void ForwardCursor ()
 
void BackwardCursor ()
 
void MoveCursorTop ()
 
void MoveCursorEnd ()
 
void NextCommand ()
 
void PreviousCommand ()
 
void ListMatchedCommand ()
 
void CompleteCommand ()
 
G4String GetFirstMatchedString (const G4String &str1, const G4String &str2) const
 
void StoreHistory (G4String aCommand)
 
G4String RestoreHistory (G4int index)
 
void SetTermToInputMode ()
 
void RestoreTerm ()
 
- Protected Member Functions inherited from G4VUIshell
G4UIcommandTreeGetCommandTree (const G4String &dir) const
 
G4String GetAbsCommandDirPath (const G4String &apath) const
 
G4String GetCommandPathTail (const G4String &apath) const
 

Protected Attributes

G4String commandLine
 
G4int cursorPosition
 
G4String commandLineBuf
 
std::vector< G4StringcommandHistory
 
G4int maxHistory
 
G4int currentHistoryNo
 
G4int relativeHistoryIndex
 
termios tios
 
G4String clearString
 
- Protected Attributes inherited from G4VUIshell
G4String promptSetting
 
G4String promptString
 
G4int nColumn
 
G4bool lsColorFlag
 
TermColorIndex directoryColor
 
TermColorIndex commandColor
 
G4String currentCommandDir
 

Detailed Description

Definition at line 72 of file G4UItcsh.hh.

Constructor & Destructor Documentation

◆ G4UItcsh()

G4UItcsh::G4UItcsh ( const G4String & prompt = "%s> ",
G4int maxhist = 100 )

Definition at line 67 of file G4UItcsh.cc.

68 : G4VUIshell(prompt),
69 commandLine(""),
71 commandHistory(maxhist),
72 maxHistory(maxhist),
75/////////////////////////////////////////////////////////
76{
77 // get current terminal mode
78 tcgetattr(0, &tios);
79
80 // read a shell history file
81 const char* path = std::getenv("HOME");
82 if (path == nullptr) return;
83
84 G4String homedir = path;
85 G4String fname = homedir + historyFileName;
86
87 std::ifstream histfile;
88 enum
89 {
90 BUFSIZE = 1024
91 };
92 char linebuf[BUFSIZE];
93
94 histfile.open(fname, std::ios::in);
95 while (histfile.good()) {
96 if (histfile.eof()) break;
97
98 histfile.getline(linebuf, BUFSIZE);
99 G4String aline = G4StrUtil::strip_copy(linebuf);
100 if (! aline.empty()) StoreHistory(linebuf);
101 }
102 histfile.close();
103}
G4int cursorPosition
Definition G4UItcsh.hh:146
G4int currentHistoryNo
Definition G4UItcsh.hh:151
termios tios
Definition G4UItcsh.hh:154
G4String commandLine
Definition G4UItcsh.hh:145
std::vector< G4String > commandHistory
Definition G4UItcsh.hh:149
G4int maxHistory
Definition G4UItcsh.hh:150
void StoreHistory(G4String aCommand)
Definition G4UItcsh.cc:728
G4int relativeHistoryIndex
Definition G4UItcsh.hh:152
G4VUIshell(const G4String &prompt="> ")
Definition G4VUIshell.cc:44

◆ ~G4UItcsh()

G4UItcsh::~G4UItcsh ( )
override

Definition at line 106 of file G4UItcsh.cc.

108{
109 // store a shell history
110 const char* path = std::getenv("HOME");
111 if (path == nullptr) return;
112
113 G4String homedir = path;
114 G4String fname = homedir + historyFileName;
115
116 std::ofstream histfile;
117 histfile.open(fname, std::ios::out);
118
119 G4int n0hist = 1;
121
122 for (G4int i = n0hist; i <= currentHistoryNo; i++) {
123 histfile << RestoreHistory(i) << G4endl;
124 }
125
126 histfile.close();
127}
int G4int
Definition G4Types.hh:85
#define G4endl
Definition G4ios.hh:67
G4String RestoreHistory(G4int index)
Definition G4UItcsh.cc:739

Member Function Documentation

◆ BackspaceCharacter()

void G4UItcsh::BackspaceCharacter ( )
protected

Definition at line 224 of file G4UItcsh.cc.

226{
227 if (cursorPosition == 1) return;
228
229 // display...
230 if (IsCursorLast()) {
231 G4cout << AsciiBS << ' ' << AsciiBS << std::flush;
232 }
233 else {
234 G4cout << AsciiBS;
235 std::size_t i;
236 for (i = cursorPosition - 2; i < commandLine.length() - 1; ++i) {
237 G4cout << commandLine[G4int(i + 1)];
238 }
239 G4cout << ' ';
240 for (i = cursorPosition - 2; i < commandLine.length(); ++i) {
241 G4cout << AsciiBS;
242 }
243 G4cout << std::flush;
244 }
245
246 // command line string...
247 commandLine.erase(cursorPosition - 2, 1);
248
250}
G4GLOB_DLL std::ostream G4cout
G4bool IsCursorLast() const
Definition G4UItcsh.hh:161

Referenced by ReadLine().

◆ BackwardCursor()

void G4UItcsh::BackwardCursor ( )
protected

Definition at line 334 of file G4UItcsh.cc.

336{
337 if (cursorPosition == 1) return;
338
340 G4cout << AsciiBS << std::flush;
341}

Referenced by ReadLine().

◆ ClearAfterCursor()

void G4UItcsh::ClearAfterCursor ( )
protected

Definition at line 293 of file G4UItcsh.cc.

295{
296 if (IsCursorLast()) return;
297
298 // display...
299 for (std::size_t i = cursorPosition; i <= commandLine.length(); ++i)
300 G4cout << ' ';
301 for (auto j = (G4int)commandLine.length(); j >= cursorPosition; --j)
302 G4cout << AsciiBS;
303 G4cout << std::flush;
304
305 // command line string...
306 commandLine.erase(cursorPosition - 1, commandLine.length() - cursorPosition + 1);
307}

Referenced by ReadLine().

◆ ClearLine()

void G4UItcsh::ClearLine ( )
protected

Definition at line 274 of file G4UItcsh.cc.

276{
277 // display...
278 std::size_t i;
279 for (i = cursorPosition; i >= 2; i--)
280 G4cout << AsciiBS;
281 for (i = 1; i <= commandLine.length(); ++i)
282 G4cout << ' ';
283 for (i = 1; i <= commandLine.length(); ++i)
284 G4cout << AsciiBS;
285 G4cout << std::flush;
286
287 // command line string...
288 commandLine.erase();
289 cursorPosition = 1;
290}

Referenced by NextCommand(), and PreviousCommand().

◆ ClearScreen()

void G4UItcsh::ClearScreen ( )
protected

Definition at line 310 of file G4UItcsh.cc.

312{
313 if (! clearString.empty()) {
315
316 G4cout << promptString << commandLine << std::flush;
317 // reset cursur position
318 for (auto i = G4int(commandLine.length() + 1); i >= cursorPosition + 1; --i)
319 G4cout << AsciiBS << std::flush;
320 }
321}
G4String clearString
Definition G4UItcsh.hh:155
G4String promptString

◆ CompleteCommand()

void G4UItcsh::CompleteCommand ( )
protected

Definition at line 445 of file G4UItcsh.cc.

447{
448 // inputting string
449 G4String input = G4StrUtil::lstrip_copy(commandLine);
450
451 // target token is last token
452 auto jhead = input.rfind(' ');
453 if (jhead != G4String::npos) {
454 input.erase(0, jhead);
455 G4StrUtil::lstrip(input);
456 }
457
458 // tail string
459 std::size_t thead = input.find_last_of('/');
460 G4String strtail = input;
461 if (thead != G4String::npos) strtail = input.substr(thead + 1, input.size() - thead - 1);
462
463 // command tree of "user specified directory"
465 G4String vcmd;
466
467 auto len = (G4int)input.length();
468 if (! input.empty()) {
469 G4int indx = -1;
470 for (G4int i = len - 1; i >= 0; --i) {
471 if (input[i] == '/') {
472 indx = i;
473 break;
474 }
475 }
476 // get abs. path
477 if (indx != -1) vpath = GetAbsCommandDirPath(input.substr(0, indx + 1));
478 if (indx != 0 || len != 1) vcmd = input.substr(indx + 1, len - indx - 1); // care for "/"
479 }
480
481 G4UIcommandTree* atree = GetCommandTree(vpath); // get command tree
482 if (atree == nullptr) return;
483
484 // list matched directories/commands
485 G4String stream, strtmp;
486 G4String inputpath = vpath + vcmd;
487 G4int nMatch = 0;
488
489 G4int Ndir = atree->GetTreeEntry();
490 G4int Ncmd = atree->GetCommandEntry();
491
492 // directory ...
493 for (G4int idir = 1; idir <= Ndir; idir++) {
494 G4String fpdir = atree->GetTree(idir)->GetPathName();
495 // matching test
496 if (fpdir.find(inputpath, 0) == 0) {
497 if (nMatch == 0) {
498 stream = GetCommandPathTail(fpdir);
499 }
500 else {
501 strtmp = GetCommandPathTail(fpdir);
502 stream = GetFirstMatchedString(stream, strtmp);
503 }
504 nMatch++;
505 }
506 }
507
508 // command ...
509 for (G4int icmd = 1; icmd <= Ncmd; icmd++) {
510 G4String fpcmd = atree->GetPathName() + atree->GetCommand(icmd)->GetCommandName();
511 // matching test
512 if (fpcmd.find(inputpath, 0) == 0) {
513 if (nMatch == 0) {
514 stream = GetCommandPathTail(fpcmd) + " ";
515 }
516 else {
517 strtmp = GetCommandPathTail(fpcmd) + " ";
518 stream = GetFirstMatchedString(stream, strtmp);
519 }
520 nMatch++;
521 }
522 }
523
524 // display...
525 input = commandLine;
526 // target token is last token
527 jhead = input.rfind(' ');
528 if (jhead == G4String::npos)
529 jhead = 0;
530 else
531 jhead++;
532
533 std::size_t jt = jhead;
534
535 G4String dspstr;
536 std::size_t i;
537 for (i = jt; i <= input.length() - 1; ++i)
538 dspstr += AsciiBS;
539 for (i = jt; i <= input.length() - 1; ++i)
540 dspstr += ' ';
541 for (i = jt; i <= input.length() - 1; ++i)
542 dspstr += AsciiBS;
543
544 dspstr += (vpath + stream);
545 if (nMatch == 0) dspstr += strtail;
546 G4cout << dspstr << std::flush;
547
548 // command line string
549 input.erase(jt);
550 input += (vpath + stream);
551 if (nMatch == 0) input += strtail;
552
553 commandLine = input;
554 cursorPosition = G4int(commandLine.length() + 1);
555}
G4int GetCommandEntry() const
G4UIcommand * GetCommand(G4int i)
const G4String & GetPathName() const
G4int GetTreeEntry() const
G4UIcommandTree * GetTree(G4int i)
const G4String & GetCommandName() const
G4String GetFirstMatchedString(const G4String &str1, const G4String &str2) const
Definition G4UItcsh.cc:703
G4UIcommandTree * GetCommandTree(const G4String &dir) const
G4String currentCommandDir
G4String GetCommandPathTail(const G4String &apath) const
G4String GetAbsCommandDirPath(const G4String &apath) const

Referenced by ReadLine().

◆ DeleteCharacter()

void G4UItcsh::DeleteCharacter ( )
protected

Definition at line 253 of file G4UItcsh.cc.

255{
256 if (IsCursorLast()) return;
257
258 // display...
259 std::size_t i;
260 for (i = cursorPosition - 1; i < commandLine.length() - 1; ++i) {
261 G4cout << commandLine[G4int(i + 1)];
262 }
263 G4cout << ' ';
264 for (i = cursorPosition - 1; i < commandLine.length(); ++i) {
265 G4cout << AsciiBS;
266 }
267 G4cout << std::flush;
268
269 // command lin string...
270 commandLine.erase(cursorPosition - 1, 1);
271}

Referenced by ReadLine().

◆ ForwardCursor()

void G4UItcsh::ForwardCursor ( )
protected

Definition at line 324 of file G4UItcsh.cc.

326{
327 if (IsCursorLast()) return;
328
329 G4cout << commandLine[cursorPosition - 1] << std::flush;
331}

Referenced by ReadLine().

◆ GetCommandLineString()

G4String G4UItcsh::GetCommandLineString ( const char * msg = nullptr)
overridevirtual

Implements G4VUIshell.

Definition at line 664 of file G4UItcsh.cc.

666{
668
669 MakePrompt(msg); // update
671
672 G4cout << promptString << std::flush;
673
674 G4String newCommand = ReadLine(); // read line...
675 // multi-line
676 while ((newCommand.length() > 0) && (newCommand[G4int(newCommand.length() - 1)] == '_')) {
677 newCommand.erase(newCommand.length() - 1);
678 G4cout << G4endl;
679 promptString = "? ";
680 G4cout << promptString << std::flush;
681 G4String newLine = ReadLine();
682 newCommand.append(newLine);
683 }
684
685 // update history...
686 G4bool isMeaningfull = false; // check NULL command
687 for (G4int i = 0; i < (G4int)newCommand.length(); ++i) {
688 if (newCommand[i] != ' ') {
689 isMeaningfull = true;
690 break;
691 }
692 }
693 if (! newCommand.empty() && isMeaningfull) StoreHistory(newCommand);
694
695 // reset terminal
696 RestoreTerm();
697
698 G4cout << G4endl;
699 return newCommand;
700}
bool G4bool
Definition G4Types.hh:86
void RestoreTerm()
Definition G4UItcsh.cc:769
G4String ReadLine()
Definition G4UItcsh.cc:561
void SetTermToInputMode()
Definition G4UItcsh.cc:754
void MakePrompt(const char *msg=nullptr) override
Definition G4UItcsh.cc:130

◆ GetFirstMatchedString()

G4String G4UItcsh::GetFirstMatchedString ( const G4String & str1,
const G4String & str2 ) const
protected

Definition at line 703 of file G4UItcsh.cc.

705{
706 std::size_t nlen1 = str1.length();
707 std::size_t nlen2 = str2.length();
708
709 std::size_t nmin = nlen1 < nlen2 ? nlen1 : nlen2;
710
711 G4String strMatched;
712 for (G4int i = 0; i < (G4int)nmin; ++i) {
713 if (str1[i] == str2[i]) {
714 strMatched += str1[i];
715 }
716 else {
717 break;
718 }
719 }
720
721 return strMatched;
722}

Referenced by CompleteCommand().

◆ InitializeCommandLine()

void G4UItcsh::InitializeCommandLine ( )
protected

Definition at line 191 of file G4UItcsh.cc.

193{
194 commandLine = "";
195 cursorPosition = 1;
196}

Referenced by ReadLine().

◆ InsertCharacter()

void G4UItcsh::InsertCharacter ( char cc)
protected

Definition at line 199 of file G4UItcsh.cc.

201{
202 if (cc < AsciiPrintableMin || (isprint(cc) == 0)) return;
203
204 // display...
205 G4cout << cc;
206 std::size_t i;
207 for (i = cursorPosition - 1; i < commandLine.length(); ++i)
208 G4cout << commandLine[(G4int)i];
209 for (i = cursorPosition - 1; i < commandLine.length(); ++i)
210 G4cout << AsciiBS;
211 G4cout << std::flush;
212
213 // command line string...
214 if (IsCursorLast()) { // add
215 commandLine += cc;
216 }
217 else { // insert
218 commandLine.insert(cursorPosition - 1, G4String(1, cc));
219 }
221}

Referenced by ReadLine().

◆ IsCursorLast()

G4bool G4UItcsh::IsCursorLast ( ) const
inlineprotected

Definition at line 161 of file G4UItcsh.hh.

162{
163 return cursorPosition == G4int(commandLine.length() + 1);
164}

Referenced by BackspaceCharacter(), ClearAfterCursor(), DeleteCharacter(), ForwardCursor(), InsertCharacter(), and ReadLine().

◆ ListMatchedCommand()

void G4UItcsh::ListMatchedCommand ( )
protected

Definition at line 405 of file G4UItcsh.cc.

407{
408 G4cout << G4endl;
409
410 // input string
411 G4String input = G4StrUtil::lstrip_copy(commandLine);
412 // target token is last token
413 auto jhead = input.rfind(' ');
414 if (jhead != G4String::npos) {
415 input.erase(0, jhead);
416 G4StrUtil::lstrip(input);
417 }
418
419 // command tree of "user specified directory"
421 G4String vcmd = "";
422
423 if (! input.empty()) {
424 auto len = (G4int)input.length();
425 G4int indx = -1;
426 for (G4int i = len - 1; i >= 0; --i) {
427 if (input[i] == '/') {
428 indx = (G4int)i;
429 break;
430 }
431 }
432 // get abs. path
433 if (indx != -1) vpath = GetAbsCommandDirPath(input.substr(0, indx + 1));
434 if (indx != 0 || len != 1) vcmd = input.substr(indx + 1, len - indx - 1); // care for "/"
435 }
436
437 // list matched dirs/commands
438 // G4cout << "@@@ vpath=" << vpath <<":vcmd=" << vcmd << G4endl;
439 ListCommand(vpath, vpath + vcmd);
440
441 G4cout << promptString << commandLine << std::flush;
442}
virtual void ListCommand(const G4String &input, const G4String &candidate="") const

Referenced by ReadLine().

◆ MakePrompt()

void G4UItcsh::MakePrompt ( const char * msg = nullptr)
overrideprotectedvirtual

Reimplemented from G4VUIshell.

Definition at line 130 of file G4UItcsh.cc.

132{
133 if (promptSetting.length() <= 1) {
135 return;
136 }
137
138 promptString = "";
139 G4int i;
140 for (i = 0; i < (G4int)promptSetting.length() - 1; ++i) {
141 if (promptSetting[i] == '%') {
142 switch (promptSetting[i + 1]) {
143 case 's': // current application status
144 {
145 G4String stateStr;
146 if (msg != nullptr) {
147 stateStr = msg;
148 }
149 else {
151 stateStr = statM->GetStateString(statM->GetCurrentState());
152 }
153 promptString.append(stateStr);
154 i++;
155 } break;
156 case '/': // current working directory
158 i++;
159 break;
160 case 'h': // history#
161 {
162 std::ostringstream os;
163 os << currentHistoryNo;
164 promptString.append(os.str());
165 i++;
166 } break;
167 default:
168 break;
169 }
170 }
171 else {
173 }
174 }
175
176 // append last chaacter
177 if (i == G4int(promptSetting.length() - 1)) promptString += promptSetting[i];
178}
const G4ApplicationState & GetCurrentState() const
G4String GetStateString(const G4ApplicationState &aState) const
static G4StateManager * GetStateManager()
G4String promptSetting

Referenced by GetCommandLineString().

◆ MoveCursorEnd()

void G4UItcsh::MoveCursorEnd ( )
protected

Definition at line 355 of file G4UItcsh.cc.

357{
358 for (G4int i = cursorPosition - 1; i < (G4int)commandLine.length(); ++i) {
359 G4cout << commandLine[i];
360 }
361 G4cout << std::flush;
362 cursorPosition = G4int(commandLine.length() + 1);
363}

Referenced by ReadLine().

◆ MoveCursorTop()

void G4UItcsh::MoveCursorTop ( )
protected

Definition at line 344 of file G4UItcsh.cc.

346{
347 for (G4int i = cursorPosition; i > 1; --i) {
348 G4cout << AsciiBS;
349 }
350 G4cout << std::flush;
351 cursorPosition = 1;
352}

Referenced by ReadLine().

◆ NextCommand()

void G4UItcsh::NextCommand ( )
protected

Definition at line 385 of file G4UItcsh.cc.

387{
389
390 if (relativeHistoryIndex >= -nhmax && relativeHistoryIndex <= -1) {
391 ClearLine();
393
394 if (relativeHistoryIndex == 0)
396 else
398
399 G4cout << commandLine << std::flush;
400 cursorPosition = G4int(commandLine.length() + 1);
401 }
402}
G4String commandLineBuf
Definition G4UItcsh.hh:147
void ClearLine()
Definition G4UItcsh.cc:274

Referenced by ReadLine().

◆ PreviousCommand()

void G4UItcsh::PreviousCommand ( )
protected

Definition at line 366 of file G4UItcsh.cc.

368{
370
371 // retain current input
373
374 if (relativeHistoryIndex >= -nhmax + 1 && relativeHistoryIndex <= 0) {
375 ClearLine();
378
379 G4cout << commandLine << std::flush;
380 cursorPosition = G4int(commandLine.length() + 1);
381 }
382}

Referenced by ReadLine().

◆ ReadLine()

G4String G4UItcsh::ReadLine ( )
protected

Definition at line 561 of file G4UItcsh.cc.

563{
565
566 char cc;
567 do { // input loop
568 G4cin.get(cc);
569
570 // treatment for special character
571 switch (cc) {
572 case AsciiCtrA: // ... move cursor to the top
574 break;
575 case AsciiCtrB: // ... backward cursor
577 break;
578 case AsciiCtrD: // ... delete/exit/show matched list
579 if (commandLine.length() != 0 && IsCursorLast())
581 else if (commandLine.empty()) {
582 return G4String("exit");
583 }
584 else
586 break;
587 case AsciiCtrE: // ... move cursor to the end
589 break;
590 case AsciiCtrF: // ... forward cursor
592 break;
593 case AsciiCtrK: // ... clear after the cursor
595 break;
596 case AsciiCtrL: // ... clear screen
597 // ClearScreen();
598 break;
599 case AsciiCtrN: // ... next command
600 NextCommand();
601 break;
602 case AsciiCtrP: // ... previous command
604 break;
605 case AsciiTAB: // ... command completion
606 if ((! commandLine.empty()) && IsCursorLast()) CompleteCommand();
607 break;
608 case AsciiDEL: // ... backspace
610 break;
611 case AsciiBS: // ... backspace
613 break;
614 case AsciiCtrC: // ... kill prompt
615 break;
616 case AsciiCtrQ: // ... restarts suspeded output
617 break;
618 case AsciiCtrS: // ... suspend output
619 break;
620 case AsciiCtrZ: // ... suspend
621 break;
622 default:
623 break;
624 }
625
626 // treatment for ESC. character
627 if (cc == AsciiESC) { // ESC
628 G4cin.get(cc);
629 if (cc == '[' || cc == 'O') { // care for another termcap, such as konsole
630 G4cin.get(cc);
631 switch (cc) {
632 case 'A': // [UP]
633 cc = 'P' - '@';
634 PreviousCommand(); // ... show previous commad
635 break;
636 case 'B': // [DOWN]
637 cc = 'N' - '@';
638 NextCommand(); // ... show next commad
639 break;
640 case 'C': // [RIGHT]
641 cc = 'F' - '@';
642 ForwardCursor(); // ... forward cursor
643 break;
644 case 'D': // [LEFT]
645 cc = 'B' - '@';
646 BackwardCursor(); // ... backward cursor
647 break;
648 default: // who knows !?
649 cc = 0;
650 break;
651 }
652 }
653 }
654
655 // insert character to command line and display
656 InsertCharacter(cc);
657
658 } while (cc != '\n');
659
660 return commandLine;
661}
#define G4cin
Definition G4ios.hh:66
void MoveCursorTop()
Definition G4UItcsh.cc:344
void InsertCharacter(char cc)
Definition G4UItcsh.cc:199
void PreviousCommand()
Definition G4UItcsh.cc:366
void CompleteCommand()
Definition G4UItcsh.cc:445
void NextCommand()
Definition G4UItcsh.cc:385
void ForwardCursor()
Definition G4UItcsh.cc:324
void MoveCursorEnd()
Definition G4UItcsh.cc:355
void DeleteCharacter()
Definition G4UItcsh.cc:253
void ListMatchedCommand()
Definition G4UItcsh.cc:405
void InitializeCommandLine()
Definition G4UItcsh.cc:191
void BackwardCursor()
Definition G4UItcsh.cc:334
void ClearAfterCursor()
Definition G4UItcsh.cc:293
void BackspaceCharacter()
Definition G4UItcsh.cc:224

Referenced by GetCommandLineString().

◆ ResetTerminal()

void G4UItcsh::ResetTerminal ( )
overridevirtual

Reimplemented from G4VUIshell.

Definition at line 181 of file G4UItcsh.cc.

183{
184 RestoreTerm();
185}

◆ RestoreHistory()

G4String G4UItcsh::RestoreHistory ( G4int index)
protected

Definition at line 739 of file G4UItcsh.cc.

741{
742 if (histNo >= currentHistoryNo) return "";
743
744 G4int index = histNo % maxHistory;
745 if (index == 0) index = maxHistory;
746
747 return commandHistory[index - 1]; // 0-offset
748}

Referenced by NextCommand(), PreviousCommand(), and ~G4UItcsh().

◆ RestoreTerm()

void G4UItcsh::RestoreTerm ( )
protected

Definition at line 769 of file G4UItcsh.cc.

771{
772 tcsetattr(0, TCSAFLUSH, &tios);
773}

Referenced by GetCommandLineString(), and ResetTerminal().

◆ SetLsColor()

void G4UItcsh::SetLsColor ( TermColorIndex dirColor,
TermColorIndex cmdColor )
inlineoverridevirtual

Reimplemented from G4VUIshell.

Definition at line 166 of file G4UItcsh.hh.

167{
168 lsColorFlag = true;
169 directoryColor = dirColor;
170 commandColor = cmdColor;
171}
TermColorIndex directoryColor
TermColorIndex commandColor
G4bool lsColorFlag

◆ SetTermToInputMode()

void G4UItcsh::SetTermToInputMode ( )
protected

Definition at line 754 of file G4UItcsh.cc.

756{
757 termios tiosbuf = tios;
758
759 tiosbuf.c_iflag &= ~(BRKINT | ISTRIP);
760 tiosbuf.c_iflag |= (IGNBRK | IGNPAR);
761 tiosbuf.c_lflag &= ~(ICANON | IEXTEN | ECHO);
762 tiosbuf.c_cc[VMIN] = 1;
763 tiosbuf.c_cc[VTIME] = 0;
764
765 tcsetattr(0, TCSAFLUSH, &tiosbuf);
766}

Referenced by GetCommandLineString().

◆ StoreHistory()

void G4UItcsh::StoreHistory ( G4String aCommand)
protected

Definition at line 728 of file G4UItcsh.cc.

730{
732 if (i == 0) i = maxHistory;
733
734 commandHistory[i - 1] = aCommand; // 0-offset
736}

Referenced by G4UItcsh(), and GetCommandLineString().

Member Data Documentation

◆ clearString

G4String G4UItcsh::clearString
protected

Definition at line 155 of file G4UItcsh.hh.

Referenced by ClearScreen().

◆ commandHistory

std::vector<G4String> G4UItcsh::commandHistory
protected

Definition at line 149 of file G4UItcsh.hh.

Referenced by RestoreHistory(), and StoreHistory().

◆ commandLine

◆ commandLineBuf

G4String G4UItcsh::commandLineBuf
protected

Definition at line 147 of file G4UItcsh.hh.

Referenced by NextCommand(), and PreviousCommand().

◆ currentHistoryNo

G4int G4UItcsh::currentHistoryNo
protected

◆ cursorPosition

◆ maxHistory

G4int G4UItcsh::maxHistory
protected

Definition at line 150 of file G4UItcsh.hh.

Referenced by NextCommand(), PreviousCommand(), RestoreHistory(), StoreHistory(), and ~G4UItcsh().

◆ relativeHistoryIndex

G4int G4UItcsh::relativeHistoryIndex
protected

Definition at line 152 of file G4UItcsh.hh.

Referenced by GetCommandLineString(), NextCommand(), and PreviousCommand().

◆ tios

termios G4UItcsh::tios
protected

Definition at line 154 of file G4UItcsh.hh.

Referenced by G4UItcsh(), RestoreTerm(), and SetTermToInputMode().


The documentation for this class was generated from the following files: