Geant4  9.6.p02
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
G4UItcsh.hh
Go to the documentation of this file.
1 //
2 // ********************************************************************
3 // * License and Disclaimer *
4 // * *
5 // * The Geant4 software is copyright of the Copyright Holders of *
6 // * the Geant4 Collaboration. It is provided under the terms and *
7 // * conditions of the Geant4 Software License, included in the file *
8 // * LICENSE and available at http://cern.ch/geant4/license . These *
9 // * include a list of copyright holders. *
10 // * *
11 // * Neither the authors of this software system, nor their employing *
12 // * institutes,nor the agencies providing financial support for this *
13 // * work make any representation or warranty, express or implied, *
14 // * regarding this software system or assume any liability for its *
15 // * use. Please see the license in the file LICENSE and URL above *
16 // * for the full disclaimer and the limitation of liability. *
17 // * *
18 // * This code implementation is the result of the scientific and *
19 // * technical work of the GEANT4 collaboration. *
20 // * By using, copying, modifying or distributing the software (or *
21 // * any work based on the software) you agree to acknowledge its *
22 // * use in resulting scientific publications, and indicate your *
23 // * acceptance of all terms of the Geant4 Software license. *
24 // ********************************************************************
25 //
26 //
27 // $Id$
28 //
29 
30 #ifndef G4UItcsh_h
31 #define G4UItcsh_h 1
32 
33 #ifndef WIN32
34 
35 #include <termios.h>
36 #include <vector>
37 #include "G4VUIshell.hh"
38 #include "G4UIcommand.hh"
39 #include "G4UIcommandTree.hh"
40 
41 // ====================================================================
42 // Description:
43 // This class gives tcsh-like shell.
44 //
45 // If your terminal supports color code, colored strings are available
46 // in ListCommand(). For activating color support,
47 // e.g.
48 // tcsh-> SetLsColor(GREEN, CYAN); // (dir, command) color
49 //
50 // [key binding]
51 // ^A ... move cursor to the top
52 // ^B ... backward cursor ([LEFT])
53 // ^D ... delete/exit/show matched list
54 // ^E ... move cursor to the end
55 // ^F ... forward cursor ([RIGHT])
56 // ^K ... clear after the cursor
57 // ^L ... clear screen (not implemented)
58 // ^N ... next command ([DOWN])
59 // ^P ... previous command ([UP])
60 // TAB... command completion
61 // DEL... backspace
62 // BS ... backspace
63 //
64 // [prompt string substitution]
65 // %s ... current application status
66 // %/ ... current working directory
67 // %h ... history# (different from G4 history#)
68 //
69 // ====================================================================
70 
71 class G4UItcsh : public G4VUIshell {
72 protected:
73  virtual void MakePrompt(const char* msg=0);
74 
75  G4String commandLine; // command line string;
76  G4int cursorPosition; // cursor position
77  G4String commandLineBuf; // temp. command line;
78  G4bool IsCursorLast() const;
79  // Is cursor position at the last of command line ?
80 
81  void InitializeCommandLine();
83  void InsertCharacter(char cc); // insert character
84  void BackspaceCharacter(); // backspace character
85  void DeleteCharacter(); // delete character
86  void ClearLine(); // clear command line
87  void ClearAfterCursor(); // clear after the cursor
88  void ClearScreen(); // clear screen
89 
90  void ForwardCursor(); // move cursor forward
91  void BackwardCursor(); // move cursor backward
92  void MoveCursorTop(); // move cursor to the top
93  void MoveCursorEnd(); // move cursor to the end
94 
95  void NextCommand(); // next command
96  void PreviousCommand(); // previous command
97 
98  void ListMatchedCommand(); // list matched commands
99  void CompleteCommand(); // complete command
100 
101  // utilities...
103  const G4String& str2) const;
104 
105  // history functionality (history# is managed in itself)
106  std::vector<G4String> commandHistory;
107  G4int maxHistory; // max# of histories stored
109  G4int relativeHistoryIndex; // local index relative to current history#
110 
111  void StoreHistory(G4String aCommand);
112  G4String RestoreHistory(G4int index); // index is global history#
113 
114 
115  // (re)set termios
116  termios tios; // terminal mode (prestatus)
117  G4String clearString; // "clear code (^L)"
118  void SetTermToInputMode();
119  void RestoreTerm();
120 
121 public:
122  G4UItcsh(const G4String& prompt="%s> ", G4int maxhist=100);
123  ~G4UItcsh();
124 
125  void SetLsColor(TermColorIndex dirColor, TermColorIndex cmdColor);
126  virtual G4String GetCommandLineString(const char* msg=0);
127 
128  virtual void ResetTerminal();
129 };
130 
131 // ====================================================================
132 // inline functions
133 // ====================================================================
135 {
136  if(cursorPosition == G4int(commandLine.length()+1)) return TRUE;
137  else return FALSE;
138 }
139 
140 inline void G4UItcsh::SetLsColor(TermColorIndex dirColor,
141  TermColorIndex cmdColor)
142 {
143  lsColorFlag= TRUE;
144  directoryColor= dirColor;
145  commandColor= cmdColor;
146 }
147 
148 #endif
149 #endif
150