Main Page | Class Hierarchy | Class List | File List | Class Members | File Members

# G4UItcsh.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: G4UItcsh.hh,v 1.7 2006/06/29 19:09:37 gunter Exp $
    00028 // GEANT4 tag $Name: geant4-08-01-patch-01 $
    00029 //
    00030
    00031 #ifndef G4UItcsh_h
    00032 #define G4UItcsh_h 1
    00033
    00034 #ifndef WIN32
    00035
    00036 #include <termios.h>
    00037 #include <vector>
    00038 #include "G4VUIshell.hh"
    00039 #include "G4UIcommand.hh"
    00040 #include "G4UIcommandTree.hh"
    00041
    00042 //
    00043 //   Description:
    00044 //   This class gives tcsh-like shell.
    00045 //
    00046 //   If your terminal supports color code, colored strings are available
    00047 //   in ListCommand(). For activating color support,
    00048 //   e.g.
    00049 //     tcsh-> SetLsColor(GREEN, CYAN); // (dir, command) color
    00050 //
    00051 //   [key binding]
    00052 //   ^A ... move cursor to the top
    00053 //   ^B ... backward cursor ([LEFT])
    00054 //   ^D ... delete/exit/show matched list
    00055 //   ^E ... move cursor to the end
    00056 //   ^F ... forward cursor ([RIGHT])
    00057 //   ^K ... clear after the cursor
    00058 //   ^L ... clear screen (not implemented)
    00059 //   ^N ... next command ([DOWN])
    00060 //   ^P ... previous command ([UP])
    00061 //   TAB... command completion
    00062 //   DEL... backspace
    00063 //   BS ... backspace
    00064 //
    00065 //   [prompt string substitution]
    00066 //   %s ... current application status
    00067 //   %/ ... current working directory
    00068 //   %h ... history# (different from G4 history#)
    00069 //
    00070
    00071 class G4UItcsh : public G4VUIshell {
    00072 protected:
    00073   virtual void MakePrompt(const char* msg=0);
    00074
    00075   G4String commandLine;    // command line string;
    00076   G4int cursorPosition;    // cursor position
    00077   G4String commandLineBuf; // temp. command line;
    00078   G4bool IsCursorLast() const;
    00079                            // Is cursor position at the last of command line ?
    00080
    00081   void InitializeCommandLine();
    00082   G4String ReadLine();
    00083   void InsertCharacter(char cc); // insert character
    00084   void BackspaceCharacter();     // backspace character
    00085   void DeleteCharacter();        // delete character
    00086   void ClearLine();              // clear command line
    00087   void ClearAfterCursor();       // clear after the cursor
    00088   void ClearScreen();            // clear screen
    00089
    00090   void ForwardCursor();          // move cursor forward
    00091   void BackwardCursor();         // move cursor backward
    00092   void MoveCursorTop();          // move cursor to the top
    00093   void MoveCursorEnd();          // move cursor to the end
    00094
    00095   void NextCommand();            // next command
    00096   void PreviousCommand();        // previous command
    00097
    00098   void ListMatchedCommand();     // list matched commands
    00099   void CompleteCommand();        // complete command
    00100
    00101   // utilities...
    00102   G4String GetFirstMatchedString(const G4String& str1,
    00103                                  const G4String& str2) const;
    00104
    00105   // history functionality  (history# is managed in itself)
    00106   std::vector<G4String> commandHistory;
    00107   G4int maxHistory;            // max# of histories stored
    00108   G4int currentHistoryNo;      // global
    00109   G4int relativeHistoryIndex;  // local index relative to current history#
    00110
    00111   void StoreHistory(G4String aCommand);
    00112   G4String RestoreHistory(G4int index); // index is global history#
    00113
    00114
    00115   // (re)set termios
    00116   termios tios; // terminal mode (prestatus)
    00117   G4String clearString;  // "clear code (^L)"
    00118   void SetTermToInputMode();
    00119   void RestoreTerm();
    00120
    00121 public:
    00122   G4UItcsh(const G4String& prompt="%s> ", G4int maxhist=100);
    00123   ~G4UItcsh();
    00124
    00125   void SetLsColor(TermColorIndex dirColor, TermColorIndex cmdColor);
    00126   virtual G4String GetCommandLine(const char* msg=0);
    00127 };
    00128
    00129 inline G4bool G4UItcsh::IsCursorLast() const
    00130 {
    00131   if(cursorPosition == G4int(commandLine.length()+1)) return TRUE;
    00132   else return FALSE;
    00133 }
    00134
    00135 inline void G4UItcsh::SetLsColor(TermColorIndex dirColor,
    00136                                  TermColorIndex cmdColor)
    00137 {
    00138   lsColorFlag= TRUE;
    00139   directoryColor= dirColor;
    00140   commandColor= cmdColor;
    00141 }
    00142
    00143 #endif
    00144 #endif
    00145