58 static void SignalHandler(
G4int)
65 G4cout <<
"aborting Run ...";
73 "G4UIterminal::SignalHandler()",
"UI0001",
FatalException,
"KeyboardInterrput with Ctrl-C");
77 signal(SIGINT, SignalHandler);
99 if (aShell !=
nullptr)
108 signal(SIGINT, SignalHandler);
140 ExecuteCommand(newCommand);
141 newCommand = GetCommand();
152 G4String newCommand = GetCommand(msg);
154 ExecuteCommand(newCommand);
155 newCommand = GetCommand(msg);
160void G4UIterminal::ExecuteCommand(
const G4String& aCommand)
163 if (aCommand.length() < 2)
return;
167 G4int paramIndex = returnVal % 100;
170 G4int commandStatus = returnVal - paramIndex;
177 switch (commandStatus) {
182 if (aCommand.find(
"@@") != G4String::npos) {
187 G4cerr <<
"illegal application state -- command refused" <<
G4endl;
200 G4cerr <<
"Parameter is out of candidate list (index " << paramIndex <<
")" <<
G4endl;
205 G4cerr <<
"Parameter is wrong type and/or is not omittable (index " << paramIndex <<
")"
210 G4cerr <<
"command refused (" << commandStatus <<
")" <<
G4endl;
215G4String G4UIterminal::GetCommand(
const char* msg)
221 G4String nC = G4StrUtil::lstrip_copy(newCommand);
223 if (nC.length() == 0) {
224 newCommand = nullString;
226 else if (nC[0] ==
'#') {
228 newCommand = nullString;
230 else if (nC ==
"ls" || nC.substr(0, 3) ==
"ls ") {
232 newCommand = nullString;
234 else if (nC ==
"lc" || nC.substr(0, 3) ==
"lc ") {
236 newCommand = nullString;
238 else if (nC ==
"pwd") {
240 newCommand = nullString;
242 else if (nC ==
"cwd") {
244 newCommand = nullString;
246 else if (nC ==
"cd" || nC.substr(0, 3) ==
"cd ") {
249 newCommand = nullString;
251 else if (nC ==
"help" || nC.substr(0, 5) ==
"help ") {
253 newCommand = nullString;
255 else if (nC[0] ==
'?') {
257 newCommand = nullString;
259 else if (nC ==
"hist" || nC ==
"history") {
261 for (
G4int i = 0; i < nh; i++) {
264 newCommand = nullString;
266 else if (nC[0] ==
'!') {
267 G4String ss = nC.substr(1, nC.length() - 1);
270 std::istringstream is(tt);
273 if (vl >= 0 && vl < nh) {
278 G4cerr <<
"history " << vl <<
" is not found." <<
G4endl;
279 newCommand = nullString;
282 else if (nC ==
"exit") {
285 G4cout <<
"Please abort it using \"/run/abort\" command first" <<
G4endl;
286 G4cout <<
" and use \"continue\" command until the application" <<
G4endl;
291 newCommand = nullString;
294 else if (nC ==
"cont" || nC ==
"continue") {
296 newCommand = nullString;
298 else if (nC.empty()) {
299 newCommand = nullString;
311 std::cout << debugString << std::flush;
319 std::cout << coutString << std::flush;
327 std::cerr << cerrString << std::flush;
336 if (!
G4cin.good()) {
338 G4cin.ignore(30,
'\n');
345void G4UIterminal::ExitHelp() const
349 G4cin.getline(temp, 100);
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
@ fParameterOutOfCandidates
@ fIllegalApplicationState
G4GLOB_DLL std::ostream G4cerr
G4GLOB_DLL std::ostream G4cout
const G4ApplicationState & GetCurrentState() const
static G4StateManager * GetStateManager()
G4UIparameter * GetParameter(G4int i) const
void SetCoutDestination(G4UIsession *const value)
G4int ApplyCommand(const char *aCommand)
G4int GetNumberOfHistory() const
G4String GetPreviousCommand(G4int i) const
G4String SolveAlias(const char *aCmd)
static G4UImanager * GetUIpointer()
void SetSession(G4UIsession *const value)
const G4String & GetParameterCandidates() const
G4UIsession * SessionStart() override
void SetPrompt(const G4String &prompt)
void PauseSessionStart(const G4String &msg) override
G4int ReceiveG4debug(const G4String &debugString) override
G4UIterminal(G4VUIshell *aShell=nullptr, G4bool qsig=true)
G4int ReceiveG4cout(const G4String &coutString) override
G4int ReceiveG4cerr(const G4String &cerrString) override
G4UIcommand * FindCommand(const char *commandName) const
G4String ModifyToFullPathCommand(const char *aCommandLine) const
void ShowCurrent(const G4String &) const
void TerminalHelp(const G4String &)
void ListDirectory(const G4String &) const
G4String GetCurrentWorkingDirectory() const
void ChangeDirectoryCommand(const G4String &)
virtual void ResetTerminal()
virtual void ListCommand(const G4String &input, const G4String &candidate="") const
virtual void ShowCurrentDirectory() const
void SetCurrentDirectory(const G4String &ccd)
virtual G4String GetCommandLineString(const char *msg=nullptr)=0
void SetPrompt(const G4String &prompt)