31#if defined(G4UI_BUILD_QT_SESSION)
36#if defined(G4UI_BUILD_XM_SESSION)
40#if defined(G4UI_BUILD_WIN32_SESSION)
52#if defined(G4UI_BUILD_QT_SESSION)
53static const G4bool qt_build =
true;
55static const G4bool qt_build =
false;
58#if defined(G4UI_BUILD_XM_SESSION)
59static const G4bool xm_build =
true;
61static const G4bool xm_build =
false;
64#if defined(G4UI_BUILD_WIN32_SESSION)
65static const G4bool win32_build =
true;
67static const G4bool win32_build =
false;
71static const G4bool tcsh_build =
true;
73static const G4bool tcsh_build =
false;
76#define DISCARD_PARAMETER(p) (void)p
80 : selected(
kNone),
session(nullptr), shell(nullptr), isGUI(false), verbose(true)
83 G4cout <<
"Available UI session types: [ ";
84 if (qt_build)
G4cout <<
"Qt, ";
85 if (xm_build)
G4cout <<
"Xm, ";
86 if (win32_build)
G4cout <<
"Win32, ";
87 if (tcsh_build)
G4cout <<
"tcsh, ";
93 G4String stype = G4StrUtil::to_lower_copy(type);
94 if (! type.empty()) SelectSessionByArg(stype);
97 if (selected == kNone) SelectSessionByEnv();
100 if (selected == kNone) {
103 size_t islash = appinput.find_last_of(
"/\\");
104 if (islash == G4String::npos)
107 appname = appinput.substr(islash + 1, appinput.size() - islash - 1);
109 SelectSessionByFile(appname);
113 if (selected == kNone) SelectSessionByBestGuess();
118#if defined(G4UI_BUILD_QT_SESSION)
124#if defined(G4UI_BUILD_XM_SESSION)
130#if defined(G4UI_BUILD_WIN32_SESSION)
138#if ! (defined(WIN32) || defined(__MINGW32__))
157 "Specified session type is not build in your system,\n"
158 "or no session type is specified.\n"
159 "A fallback session type is used.");
175void G4UIExecutive::SelectSessionByArg(
const G4String& stype)
177 if (qt_build && stype ==
"qt")
179 else if (xm_build && stype ==
"xm")
181 else if (win32_build && stype ==
"win32")
183 else if (tcsh_build && stype ==
"tcsh")
185 else if (stype ==
"csh")
190void G4UIExecutive::SelectSessionByEnv()
192 if (qt_build && (std::getenv(
"G4UI_USE_QT") !=
nullptr))
194 else if (xm_build && (std::getenv(
"G4UI_USE_XM") !=
nullptr))
196 else if (win32_build && (std::getenv(
"G4UI_USE_WIN32") !=
nullptr))
198 else if (tcsh_build && (std::getenv(
"G4UI_USE_TCSH") !=
nullptr))
203void G4UIExecutive::SelectSessionByFile(
const G4String& appname)
205 const char* path = std::getenv(
"HOME");
206 if (path ==
nullptr)
return;
210 G4String fname = homedir +
"/.g4session";
212 G4String fname = homedir +
"\\.g4session";
215 std::ifstream fsession;
220 char linebuf[BUFSIZE];
222 fsession.open(fname, std::ios::in);
227 while (fsession.good()) {
228 if (fsession.eof())
break;
229 fsession.getline(linebuf, BUFSIZE);
230 G4String aline = G4StrUtil::strip_copy(linebuf);
231 if (aline[0] ==
'#')
continue;
232 if (aline.empty())
continue;
234 default_session = aline;
236 size_t idx = aline.find_first_of(
' ');
237 if (idx == G4String::npos)
break;
238 G4String aname = aline.substr(0, idx);
239 idx = aline.find_first_not_of(
' ', idx);
240 if (idx == G4String::npos)
break;
241 G4String sname = aline.substr(idx, aline.size() - idx);
242 sessionMap[aname] = sname;
249 auto it = sessionMap.find(appname);
250 if (it != sessionMap.end())
251 stype = sessionMap[appname];
253 stype = default_session;
254 G4StrUtil::to_lower(stype);
257 if (qt_build && stype ==
"qt")
259 else if (xm_build && stype ==
"xm")
261 else if (win32_build && stype ==
"win32")
263 else if (tcsh_build && stype ==
"tcsh")
265 else if (stype ==
"csh")
270void G4UIExecutive::SelectSessionByBestGuess()
274 else if (win32_build)
285 if (shell !=
nullptr) shell->
SetPrompt(prompt);
291 if (shell !=
nullptr) shell->
SetLsColor(dirColor, cmdColor);
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
#define TIMEMORY_INIT(...)
#define DISCARD_PARAMETER(p)
G4GLOB_DLL std::ostream G4cout
void SetPrompt(const G4String &prompt)
G4UIExecutive(G4int argc, char **argv, const G4String &type="")
void SetLsColor(TermColorIndex dirColor, TermColorIndex cmdColor)
virtual void SetLsColor(TermColorIndex, TermColorIndex)
void SetPrompt(const G4String &prompt)