G4VUIshell.hh

Go to the documentation of this file.
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$
00028 //
00029 
00030 #ifndef G4VUIshell_h
00031 #define G4VUIshell_h 1
00032 
00033 #include "globals.hh"
00034 
00035 // ====================================================================
00036 //   Description: 
00037 //   This class is the abstract base class for various UI shells.
00038 //
00039 //   GetCommadLineString() (virtual) returns a command string input from
00040 //    a commad line.
00041 //
00042 //   Two pre-inplemented shell commands(still virtual) are also included, 
00043 //   (somewhat differnt flavor from ones provided by G4VBasicShell)
00044 //     ShowCurrentDirectory()   ... show current directory
00045 //     ListCommand()            ... list commands
00046 //
00047 //   [prompt string substitution] (default)
00048 //   %s ... current application status
00049 //   %/ ... current working directory
00050 //
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   virtual void SetLsColor(TermColorIndex, TermColorIndex);
00089 
00090   // shell commands
00091   virtual void ShowCurrentDirectory() const;
00092   virtual void ListCommand(const G4String& input, 
00093                            const G4String& candidate="") const;
00094   //  "candidate" is specified with full path.
00095 
00096   // get command string from a command line
00097   virtual G4String GetCommandLineString(const char* msg=0)= 0;
00098 
00099   virtual void ResetTerminal();
00100 };
00101 
00102 // ====================================================================
00103 //   inline functions
00104 // ====================================================================
00105 inline void G4VUIshell::SetNColumn(G4int ncol)
00106 {
00107   nColumn= ncol;
00108 }
00109 
00110 inline void G4VUIshell::SetPrompt(const G4String& prompt)
00111 {
00112   promptSetting= prompt;
00113 }
00114 
00115 inline void G4VUIshell::SetCurrentDirectory(const G4String& dir)
00116 {
00117   currentCommandDir= dir;
00118 }
00119 
00120 inline void G4VUIshell::SetLsColor(TermColorIndex, TermColorIndex)
00121 {
00122 }
00123 
00124 inline void G4VUIshell::ShowCurrentDirectory() const
00125 {
00126   G4cout << currentCommandDir << G4endl;
00127 }
00128 
00129 #endif

Generated on Mon May 27 17:50:23 2013 for Geant4 by  doxygen 1.4.7