00001 // 00002 // ******************************************************************** 00003 // * License and Disclaimer * 00004 // * * 00005 // * The Geant4 software is copyright of the Copyright Holders of * 00006 // * the Geant4 Collaboration. It is provided under the terms and * 00007 // * conditions of the Geant4 Software License, included in the file * 00008 // * LICENSE and available at http://cern.ch/geant4/license . These * 00009 // * include a list of copyright holders. * 00010 // * * 00011 // * Neither the authors of this software system, nor their employing * 00012 // * institutes,nor the agencies providing financial support for this * 00013 // * work make any representation or warranty, express or implied, * 00014 // * regarding this software system or assume any liability for its * 00015 // * use. Please see the license in the file LICENSE and URL above * 00016 // * for the full disclaimer and the limitation of liability. * 00017 // * * 00018 // * This code implementation is the result of the scientific and * 00019 // * technical work of the GEANT4 collaboration. * 00020 // * By using, copying, modifying or distributing the software (or * 00021 // * any work based on the software) you agree to acknowledge its * 00022 // * use in resulting scientific publications, and indicate your * 00023 // * acceptance of all terms of the Geant4 Software license. * 00024 // ******************************************************************** 00025 // 00026 // 00027 // $Id: G4VUIshell.hh,v 1.6 2006/06/29 19:09:41 gunter Exp $ 00028 // GEANT4 tag $Name: geant4-08-01-patch-01 $ 00029 // 00030 00031 #ifndef G4VUIshell_h 00032 #define G4VUIshell_h 1 00033 00034 #include "globals.hh" 00035 00036 // 00037 // Description: 00038 // This class is the abstract base class for various UI shells. 00039 // 00040 // GetCommadLine() (virtual) returns a command string input from 00041 // a commad line. 00042 // 00043 // Two pre-inplemented shell commands(still virtual) are also included, 00044 // (somewhat differnt flavor from ones provided by G4VBasicShell) 00045 // ShowCurrentDirectory() ... show current directory 00046 // ListCommand() ... list commands 00047 // 00048 // [prompt string substitution] (default) 00049 // %s ... current application status 00050 // %/ ... current working directory 00051 // 00052 00053 // terminal color index 00054 enum TermColorIndex{ BLACK=0, RED, GREEN, YELLOW, 00055 BLUE, PURPLE, CYAN, WHITE}; 00056 00057 class G4UIcommandTree; 00058 00059 class G4VUIshell { 00060 protected: 00061 G4String promptSetting; // including %-directive 00062 G4String promptString; 00063 virtual void MakePrompt(const char* msg=0); // make prompt string 00064 G4int nColumn; // column size of terminal (default=80) 00065 00066 // color code support (effective if your terminal supports color code.) 00067 // default setting is off. 00068 G4bool lsColorFlag; // color flag for list command 00069 TermColorIndex directoryColor; 00070 TermColorIndex commandColor; 00071 00072 // for treating G4 command tree... 00073 G4String currentCommandDir; // current command directory (absolute path) 00074 // get tree node 00075 G4UIcommandTree* GetCommandTree(const G4String& dir) const; 00076 // absolute path name (ignore command) 00077 G4String GetAbsCommandDirPath(const G4String& apath) const; 00078 // tail of path ( xxx/xxx/zzz -> zzz, trancated //// -> /) 00079 G4String GetCommandPathTail(const G4String& apath) const; 00080 00081 public: 00082 G4VUIshell(const G4String& prompt="> "); 00083 virtual ~G4VUIshell(); 00084 00085 void SetNColumn(G4int ncol); 00086 void SetPrompt(const G4String& prompt); 00087 void SetCurrentDirectory(const G4String& ccd); 00088 00089 // shell commands 00090 virtual void ShowCurrentDirectory() const; 00091 virtual void ListCommand(const G4String& input, 00092 const G4String& candidate="") const; 00093 // "candidate" is specified with full path. 00094 00095 // get command string from a command line 00096 virtual G4String GetCommandLine(const char* msg=0)= 0; 00097 }; 00098 00099 00100 // inlines... 00101 inline void G4VUIshell::SetNColumn(G4int ncol) 00102 { 00103 nColumn= ncol; 00104 } 00105 00106 inline void G4VUIshell::SetPrompt(const G4String& prompt) 00107 { 00108 promptSetting= prompt; 00109 } 00110 00111 inline void G4VUIshell::SetCurrentDirectory(const G4String& dir) 00112 { 00113 currentCommandDir= dir; 00114 } 00115 00116 inline void G4VUIshell::ShowCurrentDirectory() const 00117 { 00118 G4cout << currentCommandDir << G4endl; 00119 } 00120 00121 #endif