source: trunk/geant4/interfaces/basic/include/G4UItcsh.hh @ 483

Last change on this file since 483 was 483, checked in by garnier, 17 years ago

r569@mac-90108: laurentgarnier | 2007-06-05 15:53:34 +0200
version contre geant4.8.2.p01

File size: 5.1 KB
Line 
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: G4UItcsh.hh,v 1.7 2006/06/29 19:09:37 gunter Exp $
28// GEANT4 tag $Name: geant4-08-01-patch-01 $
29//
30
31#ifndef G4UItcsh_h
32#define G4UItcsh_h 1
33
34#ifndef WIN32
35
36#include <termios.h>
37#include <vector>
38#include "G4VUIshell.hh"
39#include "G4UIcommand.hh"
40#include "G4UIcommandTree.hh"
41
42//
43//   Description:
44//   This class gives tcsh-like shell.
45//   
46//   If your terminal supports color code, colored strings are available
47//   in ListCommand(). For activating color support,
48//   e.g.
49//     tcsh-> SetLsColor(GREEN, CYAN); // (dir, command) color
50//   
51//   [key binding]
52//   ^A ... move cursor to the top
53//   ^B ... backward cursor ([LEFT])
54//   ^D ... delete/exit/show matched list
55//   ^E ... move cursor to the end
56//   ^F ... forward cursor ([RIGHT])
57//   ^K ... clear after the cursor
58//   ^L ... clear screen (not implemented)
59//   ^N ... next command ([DOWN])
60//   ^P ... previous command ([UP])
61//   TAB... command completion
62//   DEL... backspace
63//   BS ... backspace
64//
65//   [prompt string substitution]
66//   %s ... current application status
67//   %/ ... current working directory
68//   %h ... history# (different from G4 history#)
69//
70
71class G4UItcsh : public G4VUIshell {
72protected:
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();
82  G4String ReadLine();
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...
102  G4String GetFirstMatchedString(const G4String& str1, 
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
108  G4int currentHistoryNo;      // global
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
121public:
122  G4UItcsh(const G4String& prompt="%s> ", G4int maxhist=100);
123  ~G4UItcsh();
124 
125  void SetLsColor(TermColorIndex dirColor, TermColorIndex cmdColor);
126  virtual G4String GetCommandLine(const char* msg=0);
127};
128
129inline G4bool G4UItcsh::IsCursorLast() const
130{
131  if(cursorPosition == G4int(commandLine.length()+1)) return TRUE;
132  else return FALSE;
133}
134
135inline void G4UItcsh::SetLsColor(TermColorIndex dirColor, 
136                                 TermColorIndex cmdColor)
137{
138  lsColorFlag= TRUE;
139  directoryColor= dirColor;
140  commandColor= cmdColor;
141}
142
143#endif
144#endif
145
Note: See TracBrowser for help on using the repository browser.