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 G4UItcsh_h 00031 #define G4UItcsh_h 1 00032 00033 #ifndef WIN32 00034 00035 #include <termios.h> 00036 #include <vector> 00037 #include "G4VUIshell.hh" 00038 #include "G4UIcommand.hh" 00039 #include "G4UIcommandTree.hh" 00040 00041 // ==================================================================== 00042 // Description: 00043 // This class gives tcsh-like shell. 00044 // 00045 // If your terminal supports color code, colored strings are available 00046 // in ListCommand(). For activating color support, 00047 // e.g. 00048 // tcsh-> SetLsColor(GREEN, CYAN); // (dir, command) color 00049 // 00050 // [key binding] 00051 // ^A ... move cursor to the top 00052 // ^B ... backward cursor ([LEFT]) 00053 // ^D ... delete/exit/show matched list 00054 // ^E ... move cursor to the end 00055 // ^F ... forward cursor ([RIGHT]) 00056 // ^K ... clear after the cursor 00057 // ^L ... clear screen (not implemented) 00058 // ^N ... next command ([DOWN]) 00059 // ^P ... previous command ([UP]) 00060 // TAB... command completion 00061 // DEL... backspace 00062 // BS ... backspace 00063 // 00064 // [prompt string substitution] 00065 // %s ... current application status 00066 // %/ ... current working directory 00067 // %h ... history# (different from G4 history#) 00068 // 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 GetCommandLineString(const char* msg=0); 00127 00128 virtual void ResetTerminal(); 00129 }; 00130 00131 // ==================================================================== 00132 // inline functions 00133 // ==================================================================== 00134 inline G4bool G4UItcsh::IsCursorLast() const 00135 { 00136 if(cursorPosition == G4int(commandLine.length()+1)) return TRUE; 00137 else return FALSE; 00138 } 00139 00140 inline void G4UItcsh::SetLsColor(TermColorIndex dirColor, 00141 TermColorIndex cmdColor) 00142 { 00143 lsColorFlag= TRUE; 00144 directoryColor= dirColor; 00145 commandColor= cmdColor; 00146 } 00147 00148 #endif 00149 #endif 00150