Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:59:16

0001 //
0002 // ********************************************************************
0003 // * License and Disclaimer                                           *
0004 // *                                                                  *
0005 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
0006 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
0007 // * conditions of the Geant4 Software License,  included in the file *
0008 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
0009 // * include a list of copyright holders.                             *
0010 // *                                                                  *
0011 // * Neither the authors of this software system, nor their employing *
0012 // * institutes,nor the agencies providing financial support for this *
0013 // * work  make  any representation or  warranty, express or implied, *
0014 // * regarding  this  software system or assume any liability for its *
0015 // * use.  Please see the license in the file  LICENSE  and URL above *
0016 // * for the full disclaimer and the limitation of liability.         *
0017 // *                                                                  *
0018 // * This  code  implementation is the result of  the  scientific and *
0019 // * technical work of the GEANT4 collaboration.                      *
0020 // * By using,  copying,  modifying or  distributing the software (or *
0021 // * any work based  on the software)  you  agree  to acknowledge its *
0022 // * use  in  resulting  scientific  publications,  and indicate your *
0023 // * acceptance of all terms of the Geant4 Software license.          *
0024 // ********************************************************************
0025 //
0026 //
0027 //
0028 
0029 #ifndef G4UItcsh_h
0030 #define G4UItcsh_h 1
0031 
0032 #if ! (defined(WIN32) || defined(__MINGW32__))
0033 
0034 #  include "G4UIcommand.hh"
0035 #  include "G4UIcommandTree.hh"
0036 #  include "G4VUIshell.hh"
0037 
0038 #  include <termios.h>
0039 
0040 #  include <vector>
0041 
0042 // ====================================================================
0043 //   Description:
0044 //   This class gives tcsh-like shell.
0045 //
0046 //   If your terminal supports color code, colored strings are available
0047 //   in ListCommand(). For activating color support,
0048 //   e.g.
0049 //     tcsh-> SetLsColor(GREEN, CYAN); // (dir, command) color
0050 //
0051 //   [key binding]
0052 //   ^A ... move cursor to the top
0053 //   ^B ... backward cursor ([LEFT])
0054 //   ^D ... delete/exit/show matched list
0055 //   ^E ... move cursor to the end
0056 //   ^F ... forward cursor ([RIGHT])
0057 //   ^K ... clear after the cursor
0058 //   ^L ... clear screen (not implemented)
0059 //   ^N ... next command ([DOWN])
0060 //   ^P ... previous command ([UP])
0061 //   TAB... command completion
0062 //   DEL... backspace
0063 //   BS ... backspace
0064 //
0065 //   [prompt string substitution]
0066 //   %s ... current application status
0067 //   %/ ... current working directory
0068 //   %h ... history# (different from G4 history#)
0069 //
0070 // ====================================================================
0071 
0072 class G4UItcsh : public G4VUIshell
0073 {
0074  public:
0075   G4UItcsh(const G4String& prompt = "%s> ", G4int maxhist = 100);
0076   ~G4UItcsh() override;
0077 
0078   void SetLsColor(TermColorIndex dirColor, TermColorIndex cmdColor) override;
0079   G4String GetCommandLineString(const char* msg = nullptr) override;
0080 
0081   void ResetTerminal() override;
0082 
0083  protected:
0084   void MakePrompt(const char* msg = nullptr) override;
0085 
0086   // Is cursor position at the last of command line ?
0087   G4bool IsCursorLast() const;
0088 
0089   void InitializeCommandLine();
0090   G4String ReadLine();
0091 
0092   // insert character
0093   void InsertCharacter(char cc);
0094 
0095   // backspace character
0096   void BackspaceCharacter();
0097 
0098   // delete character
0099   void DeleteCharacter();
0100 
0101   // clear command line
0102   void ClearLine();
0103 
0104   // clear after the cursor
0105   void ClearAfterCursor();
0106 
0107   // clear screen
0108   void ClearScreen();
0109 
0110   // move cursor forward
0111   void ForwardCursor();
0112 
0113   // move cursor backward
0114   void BackwardCursor();
0115 
0116   // move cursor to the top
0117   void MoveCursorTop();
0118 
0119   // move cursor to the end
0120   void MoveCursorEnd();
0121 
0122   // next command
0123   void NextCommand();
0124 
0125   // previous command
0126   void PreviousCommand();
0127 
0128   // list matched commands
0129   void ListMatchedCommand();
0130 
0131   // complete command
0132   void CompleteCommand();
0133 
0134   // utilities...
0135   G4String GetFirstMatchedString(const G4String& str1, const G4String& str2) const;
0136 
0137   void StoreHistory(G4String aCommand);
0138 
0139   // index is global history#
0140   G4String RestoreHistory(G4int index);
0141 
0142   void SetTermToInputMode();
0143   void RestoreTerm();
0144 
0145   G4String commandLine;  // command line string;
0146   G4int cursorPosition;  // cursor position
0147   G4String commandLineBuf;  // temp. command line;
0148   // history functionality  (history# is managed in itself)
0149   std::vector<G4String> commandHistory;
0150   G4int maxHistory;  // max# of histories stored
0151   G4int currentHistoryNo;  // global
0152   G4int relativeHistoryIndex;  // local index relative to current history#
0153   // (re)set termios
0154   termios tios;  // terminal mode (prestatus)
0155   G4String clearString;  // "clear code (^L)"
0156 };
0157 
0158 // ====================================================================
0159 //   inline functions
0160 // ====================================================================
0161 inline G4bool G4UItcsh::IsCursorLast() const
0162 {
0163   return cursorPosition == G4int(commandLine.length() + 1);
0164 }
0165 
0166 inline void G4UItcsh::SetLsColor(TermColorIndex dirColor, TermColorIndex cmdColor)
0167 {
0168   lsColorFlag = true;
0169   directoryColor = dirColor;
0170   commandColor = cmdColor;
0171 }
0172 
0173 #endif
0174 #endif