NumeRe v1.1.4
NumeRe: Framework für Numerische Rechnungen
gterm.hpp
Go to the documentation of this file.
1
2// Copyright Timothy Miller, 1999
3
4#ifndef INCLUDED_GTERM_H
5#define INCLUDED_GTERM_H
6
7#ifdef __GNUG__
8#pragma interface
9#endif
10
11#include <string.h>
12#include <cstring>
13#include <stdlib.h>
14#include <stdio.h>
15
16#include <vector>
17#include <queue>
18#include <deque>
19#include <string>
20//#include "../common/FixedSizeQueue.h"
21#include "TextManager.h"
22
23#include "../../kernel/syntax.hpp"
24#include "../../kernel/core/ui/calltipprovider.hpp"
25
26#define MAXWIDTH 320
27#define MAXHEIGHT 500
28
29#define GTERM_PC
30
31
32class GenericTerminal;
33typedef void (GenericTerminal::*StateFunc)();
34
35
42{
43 public:
44 // mode flags
45 enum
46 {
47 BOLD=0x1,
48 BLINK=0x2,
54 NEWLINE=0x80,
55 INSERT=0x100,
59 TEXTONLY=0x1000,
60 LOCALECHO=0x2000,
62#ifdef GTERM_PC
63// ,PC=0x10000
64 PC=0x8000,
65#endif // GTERM_PC
66 SELECTED=0x8000 // flag to indicate a char is selected
68
69 enum
70 {
72 RESETCURSOR=0x2
73 };
74
75 private:
76 // terminal info
78
79 // The text buffer and renderer
81
83
84 // terminal state
88
89 // utility functions
90 void clear_area(int start_x, int start_y, int end_x, int end_y);
91 int calc_color(int fg, int bg, int flags);
92 void move_cursor(int x, int y);
93 void handle_calltip(int x, int y);
94
95 // action parameters
96 int nparam, param[30];
97 std::string sInput_Data;
100
101 // terminal actions
102 protected:
104 // move cursor by clicking
105 void move_cursor_editable_area(int x, int y);
106 void update_changes();
107 void normal_input();
108 void normal_output();
109
110 // autocomp params
114 std::string sAutoCompList;
115 void resetAutoComp(int mode);
116 std::string getProcNameSpace();
118
119 // non-printing characters
120 void cr(), lf(), ff(), bell(), tab();
121 bool bs(), del();
122 bool delSelected();
123
124 // escape sequence actions
125 void reset();
126
127 bool cursor_left();
128 bool cursor_down();
129 bool cursor_right();
130 bool cursor_up();
131 bool ctrl_left();
132 bool ctrl_right();
133 bool home();
134 bool end();
135 bool front();
136 bool back();
137
138 void erase_line();
140
141 public:
142 GenericTerminal(int w, int h);
143 virtual ~GenericTerminal();
144
147
148 // function to control terminal
149 virtual void ProcessInput(int len, const std::string& sData);
150 virtual void ProcessOutput(int len, const std::string& sData);
151 virtual void ResizeTerminal(int _width, int _height);
152 int Width() const
153 {
154 return width;
155 }
156 int Height() const
157 {
158 return height;
159 }
160 virtual void Update();
161 virtual void Reset();
162
163 bool Scroll(int numLines, bool scrollUp);
164 int GetScrollHeight();
165 int GetScrollPosition();
167
168 void SetTerminalHistory(int size);
169
170 bool IsScrolledUp();
171 int GetMode() const
172 {
173 return mode_flags;
174 }
175 void SetMode(int mode)
176 {
177 mode_flags = mode;
178 }
179 void set_mode_flag(int flag);
180 void clear_mode_flag(int flag);
181
182 // manditory child-supplied functions
183 virtual void DrawText(int fg_color, int bg_color, int flags,
184 int x, int y, const std::string& sText) = 0;
185 virtual void DrawCursor(int fg_color, int bg_color, int flags,
186 int x, int y, unsigned char c) = 0;
187
188 virtual void Calltip(int x, int y, NumeRe::CallTip& _cTip) {}
189 virtual void CalltipCancel() {}
190
191 // optional child-supplied functions
192 virtual void ClearChars(int bg_color, int x, int y, int w, int h) { }
193 virtual void SendBack(int len, char *data) { }
194 virtual void SendBack(char *data)
195 {
196 SendBack(strlen(data), data);
197 }
198 virtual void ModeChange(int state) { }
199 virtual void Bell() { }
200
201 virtual int IsSelected(int x, int y);
202 virtual void Select(int x, int y, int select);
203 virtual unsigned char GetChar(int x, int y);
204 std::string get_selected_text();
205};
206
207#endif
An implementation of a generic terminal, which has to be specialized in the child classes.
Definition: gterm.hpp:42
bool cursor_up()
Either moves the cursor up or performs a history jump.
Definition: actions.cpp:480
bool del()
Perform a delete key operation.
Definition: actions.cpp:329
void clear_mode_flag(int flag)
Clears a mode flag (mainly used to make the cursor visible again).
Definition: utils.cpp:336
void erase_line()
Erases the current line in the internal buffer.
Definition: actions.cpp:779
TextManager * GetTM()
Get a pointer to the internal text buffer.
Definition: gterm.cpp:261
int calc_color(int fg, int bg, int flags)
Returns the encoded color bitlist.
Definition: utils.cpp:22
virtual ~GenericTerminal()
Empty destructor.
Definition: gterm.cpp:177
bool Scroll(int numLines, bool scrollUp)
Definition: gterm.cpp:278
virtual void Reset()
Simple wrapper around reset().
Definition: gterm.cpp:83
int scroll_bot
Definition: gterm.hpp:77
virtual void ProcessInput(int len, const std::string &sData)
Definition: gterm.cpp:36
int GetScrollHeight()
Definition: gterm.cpp:312
virtual void ClearChars(int bg_color, int x, int y, int w, int h)
Definition: gterm.hpp:192
void set_mode_flag(int flag)
Sets a mode flag (only used to make the cursor invisble).
Definition: utils.cpp:320
ViewCursor termCursor
Definition: gterm.hpp:85
int nTabStartPos
Definition: gterm.hpp:111
std::string get_selected_text()
Gets the selected text (if any).
Definition: gterm.cpp:248
virtual void Bell()
Definition: gterm.hpp:199
virtual unsigned char GetChar(int x, int y)
Gets the character at the selected location.
Definition: gterm.cpp:233
virtual void Update()
Simple wrapper around update_changes()
Definition: gterm.cpp:19
virtual void CalltipCancel()
Definition: gterm.hpp:189
bool cursor_right()
Moves the cursor to the right.
Definition: actions.cpp:456
void tab()
Evaluate the tab key (do not insert a tab character but try to autocomplete the current input).
Definition: actions.cpp:224
void move_cursor(int x, int y)
Definition: utils.cpp:134
virtual void ModeChange(int state)
Definition: gterm.hpp:198
std::string sInput_Data
Definition: gterm.hpp:97
virtual void ProcessOutput(int len, const std::string &sData)
Processes output returned from the kernel and hands it over to the internal buffer.
Definition: gterm.cpp:63
void update_changes()
Definition: utils.cpp:37
int Width() const
Definition: gterm.hpp:152
int scroll_top
Definition: gterm.hpp:77
bool cursor_down()
Either moves the cursor down or performs a history jump.
Definition: actions.cpp:535
int doing_update
Definition: gterm.hpp:103
void resetAutoComp(int mode)
Reset the current autocompletion list and the corresponding variables.
Definition: actions.cpp:120
NumeRe::CallTipProvider * getProvider()
Definition: gterm.hpp:146
void normal_input()
Definition: actions.cpp:21
virtual void DrawCursor(int fg_color, int bg_color, int flags, int x, int y, unsigned char c)=0
virtual void Select(int x, int y, int select)
Definition: gterm.cpp:215
void SetMode(int mode)
Definition: gterm.hpp:175
GenericTerminal(int w, int h)
Constructor.
Definition: gterm.cpp:154
virtual void Calltip(int x, int y, NumeRe::CallTip &_cTip)
Definition: gterm.hpp:188
bool cursor_left()
Moves the cursor to the left.
Definition: actions.cpp:432
enum GenericTerminal::@2 MODES
virtual void ResizeTerminal(int _width, int _height)
Definition: gterm.cpp:101
bool m_useSmartSense
Definition: gterm.hpp:117
bool end()
Moves the cursor to the rightmost position in the current line.
Definition: actions.cpp:692
TextManager tm
Definition: gterm.hpp:80
bool back()
Moves the cursor to the rightmost position in the whole input.
Definition: actions.cpp:748
NumeRe::CallTipProvider m_tipProvider
Definition: gterm.hpp:82
std::string getProcNameSpace()
This member function evalutes the procedure signature and returns its namespace. Will only be called ...
Definition: actions.cpp:148
bool home()
Moves the cursor to the leftmost position in the current line.
Definition: actions.cpp:667
void SetTerminalHistory(int size)
Set the terminal buffer size (not the length of the input history). The length of the history (i....
Definition: gterm.cpp:348
int GetScrollPosition()
Returns the current scroll position.
Definition: gterm.cpp:331
NumeReSyntax * getSyntax()
Definition: gterm.hpp:145
virtual void SendBack(int len, char *data)
Definition: gterm.hpp:193
bool delSelected()
Delete a selected block.
Definition: actions.cpp:360
bool ctrl_left()
Moves the cursor one word to the left.
Definition: actions.cpp:599
int Height() const
Definition: gterm.hpp:156
void cr()
Insert a carriage return.
Definition: actions.cpp:179
void handle_calltip(int x, int y)
Check, whether a calltip is needed and select the corresponding text from the CallTipProvider.
Definition: utils.cpp:193
void clear_area(int start_x, int start_y, int end_x, int end_y)
Definition: utils.cpp:117
std::string sAutoCompWordStart
Definition: gterm.hpp:113
void bell()
Perform a bell sound (not used).
Definition: actions.cpp:396
int nCursorUpDownStartPos
Definition: gterm.hpp:112
bool bs()
Perform a backspace operation.
Definition: actions.cpp:292
bool front()
Moves the cursor to the leftmost position in the whole input.
Definition: actions.cpp:717
void reset()
Resets the terminal, so that it starts with an empty buffer.
Definition: actions.cpp:409
int param[30]
Definition: gterm.hpp:96
void move_cursor_editable_area(int x, int y)
Moves the cursor to a location, if this location is editable.
Definition: utils.cpp:305
void erase_usercontent_line()
Erases alle user-written contents from the current line.
Definition: actions.cpp:792
virtual void SendBack(char *data)
Definition: gterm.hpp:194
virtual int IsSelected(int x, int y)
Definition: gterm.cpp:194
bool IsScrolledUp()
Determine, whether the terminal is scrolled up.
Definition: gterm.cpp:298
void ff()
Insert a form feed (not used).
Definition: actions.cpp:208
void normal_output()
This member function is for printing the kernel's output to the console.
Definition: actions.cpp:59
bool ctrl_right()
Moves the cursor one word to the right.
Definition: actions.cpp:637
void lf()
Insert a line feed.
Definition: actions.cpp:191
virtual void DrawText(int fg_color, int bg_color, int flags, int x, int y, const std::string &sText)=0
int mode_flags
Definition: gterm.hpp:87
NumeReSyntax _syntax
Definition: gterm.hpp:99
int GetMode() const
Definition: gterm.hpp:171
std::string sAutoCompList
Definition: gterm.hpp:114
This class uses a global Language instance to obtain the language string associated with a distinct c...
This class contains all needed keywords to highlight their occurences correspondingly....
Definition: syntax.hpp:55
This class manages the actual text by storing it in an internal buffer. During an update the TextMana...
Definition: TextManager.h:486
void(GenericTerminal::* StateFunc)()
Definition: gterm.hpp:33
This structure contains the data for a single calltip, which might be shown in the editor or the term...
Cursor, which is used in the terminal. The TextManager is able to convert this cursor into a LogicalC...
Definition: TextManager.h:124