Geant4-11
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//
28
29#ifndef G4UItcsh_h
30#define G4UItcsh_h 1
31
32#ifndef WIN32
33
34#include <termios.h>
35#include <vector>
36#include "G4VUIshell.hh"
37#include "G4UIcommand.hh"
38#include "G4UIcommandTree.hh"
39
40// ====================================================================
41// Description:
42// This class gives tcsh-like shell.
43//
44// If your terminal supports color code, colored strings are available
45// in ListCommand(). For activating color support,
46// e.g.
47// tcsh-> SetLsColor(GREEN, CYAN); // (dir, command) color
48//
49// [key binding]
50// ^A ... move cursor to the top
51// ^B ... backward cursor ([LEFT])
52// ^D ... delete/exit/show matched list
53// ^E ... move cursor to the end
54// ^F ... forward cursor ([RIGHT])
55// ^K ... clear after the cursor
56// ^L ... clear screen (not implemented)
57// ^N ... next command ([DOWN])
58// ^P ... previous command ([UP])
59// TAB... command completion
60// DEL... backspace
61// BS ... backspace
62//
63// [prompt string substitution]
64// %s ... current application status
65// %/ ... current working directory
66// %h ... history# (different from G4 history#)
67//
68// ====================================================================
69
70class G4UItcsh : public G4VUIshell {
71protected:
72 virtual void MakePrompt(const char* msg=0);
73
74 G4String commandLine; // command line string;
75 G4int cursorPosition; // cursor position
76 G4String commandLineBuf; // temp. command line;
77 G4bool IsCursorLast() const;
78 // Is cursor position at the last of command line ?
79
82 void InsertCharacter(char cc); // insert character
83 void BackspaceCharacter(); // backspace character
84 void DeleteCharacter(); // delete character
85 void ClearLine(); // clear command line
86 void ClearAfterCursor(); // clear after the cursor
87 void ClearScreen(); // clear screen
88
89 void ForwardCursor(); // move cursor forward
90 void BackwardCursor(); // move cursor backward
91 void MoveCursorTop(); // move cursor to the top
92 void MoveCursorEnd(); // move cursor to the end
93
94 void NextCommand(); // next command
95 void PreviousCommand(); // previous command
96
97 void ListMatchedCommand(); // list matched commands
98 void CompleteCommand(); // complete command
99
100 // utilities...
102 const G4String& str2) const;
103
104 // history functionality (history# is managed in itself)
105 std::vector<G4String> commandHistory;
106 G4int maxHistory; // max# of histories stored
108 G4int relativeHistoryIndex; // local index relative to current history#
109
110 void StoreHistory(G4String aCommand);
111 G4String RestoreHistory(G4int index); // index is global history#
112
113
114 // (re)set termios
115 termios tios; // terminal mode (prestatus)
116 G4String clearString; // "clear code (^L)"
117 void SetTermToInputMode();
118 void RestoreTerm();
119
120public:
121 G4UItcsh(const G4String& prompt="%s> ", G4int maxhist=100);
122 ~G4UItcsh();
123
124 void SetLsColor(TermColorIndex dirColor, TermColorIndex cmdColor);
125 virtual G4String GetCommandLineString(const char* msg=0);
126
127 virtual void ResetTerminal();
128};
129
130// ====================================================================
131// inline functions
132// ====================================================================
134{
135 if(cursorPosition == G4int(commandLine.length()+1)) return TRUE;
136 else return FALSE;
137}
138
140 TermColorIndex cmdColor)
141{
143 directoryColor= dirColor;
144 commandColor= cmdColor;
145}
146
147#endif
148#endif
149
bool G4bool
Definition: G4Types.hh:86
int G4int
Definition: G4Types.hh:85
TermColorIndex
Definition: G4VUIshell.hh:53
#define TRUE
Definition: Globals.hh:27
#define FALSE
Definition: Globals.hh:23
void MoveCursorTop()
Definition: G4UItcsh.cc:334
void InsertCharacter(char cc)
Definition: G4UItcsh.cc:194
virtual void ResetTerminal()
Definition: G4UItcsh.cc:175
void PreviousCommand()
Definition: G4UItcsh.cc:356
virtual void MakePrompt(const char *msg=0)
Definition: G4UItcsh.cc:121
G4String GetFirstMatchedString(const G4String &str1, const G4String &str2) const
Definition: G4UItcsh.cc:686
void CompleteCommand()
Definition: G4UItcsh.cc:436
void NextCommand()
Definition: G4UItcsh.cc:376
G4String RestoreHistory(G4int index)
Definition: G4UItcsh.cc:722
void RestoreTerm()
Definition: G4UItcsh.cc:753
void ForwardCursor()
Definition: G4UItcsh.cc:314
G4String ReadLine()
Definition: G4UItcsh.cc:546
G4int cursorPosition
Definition: G4UItcsh.hh:75
void MoveCursorEnd()
Definition: G4UItcsh.cc:345
G4int currentHistoryNo
Definition: G4UItcsh.hh:107
void DeleteCharacter()
Definition: G4UItcsh.cc:246
termios tios
Definition: G4UItcsh.hh:115
void SetTermToInputMode()
Definition: G4UItcsh.cc:737
void ListMatchedCommand()
Definition: G4UItcsh.cc:396
G4String clearString
Definition: G4UItcsh.hh:116
G4bool IsCursorLast() const
Definition: G4UItcsh.hh:133
G4String commandLine
Definition: G4UItcsh.hh:74
void InitializeCommandLine()
Definition: G4UItcsh.cc:186
G4String commandLineBuf
Definition: G4UItcsh.hh:76
G4UItcsh(const G4String &prompt="%s> ", G4int maxhist=100)
Definition: G4UItcsh.cc:65
virtual G4String GetCommandLineString(const char *msg=0)
Definition: G4UItcsh.cc:646
std::vector< G4String > commandHistory
Definition: G4UItcsh.hh:105
G4int maxHistory
Definition: G4UItcsh.hh:106
void SetLsColor(TermColorIndex dirColor, TermColorIndex cmdColor)
Definition: G4UItcsh.hh:139
void ClearLine()
Definition: G4UItcsh.cc:267
void BackwardCursor()
Definition: G4UItcsh.cc:324
void ClearAfterCursor()
Definition: G4UItcsh.cc:283
void ClearScreen()
Definition: G4UItcsh.cc:300
void StoreHistory(G4String aCommand)
Definition: G4UItcsh.cc:711
void BackspaceCharacter()
Definition: G4UItcsh.cc:218
G4int relativeHistoryIndex
Definition: G4UItcsh.hh:108
~G4UItcsh()
Definition: G4UItcsh.cc:97
TermColorIndex directoryColor
Definition: G4VUIshell.hh:68
TermColorIndex commandColor
Definition: G4VUIshell.hh:69
G4bool lsColorFlag
Definition: G4VUIshell.hh:67