NumeRe v1.1.4
NumeRe: Framework für Numerische Rechnungen
actions.cpp
Go to the documentation of this file.
1// Copyright Timothy Miller, 1999
2
3#include "gterm.hpp"
4#include <wx/log.h>
5
6#define GTERM_PC
7// For efficiency, this grabs all printing characters from buffer, up to
8// the end of the line or end of buffer
9
10// Forward declaration
11std::string toLowerCase(const std::string&);
12
22{
23 // Convert the current view cursor position into
24 // the corresponding logical position
26
27 // Ensure that the cursor is valid
28 if (!cursor)
29 cursor = tm.getCurrentLogicalPos();
30
31 // Insert the text at the cursor's position
33
34 // Advance the cursor
35 cursor.pos += sInput_Data.length();
36
37 // Clear the input buffer
38 sInput_Data.clear();
39
40 // Get the new view cursor position from the logical cursor
41 termCursor = tm.toViewCursor(cursor);
42
43 // If the view cursor is not valid, get the
44 // view cursor of the last position
45 if (!termCursor)
47
49}
50
51
60{
61 // Get the output data
62 std::string sInput = sInput_Data;
63
64#ifdef DO_LOG
65 wxLogDebug("%s", sInput.c_str());
66#endif
67
68 // As long as the output data has a length
69 do
70 {
71 // Print the output until the first control character
72 tm.printOutput(sInput.substr(0, sInput.find_first_of("\n\r\t")));
73
74 // Store the position of the first control character
75 size_t nPos = sInput.find_first_of("\n\r\t");
76
77 // If the position is valid
78 if (nPos != std::string::npos)
79 {
80 // Evalute the control character
81 switch (sInput[nPos])
82 {
83 case '\n':
84 tm.newLine();
85 break;
86 case '\t':
87 tm.tab();
88 break;
89 case '\r':
90 tm.eraseLine();
91 break;
92 }
93
94 // Erase everything in front of and including
95 // the control character
96 sInput.erase(0, nPos + 1);
97 }
98 else
99 {
100 sInput.clear();
101 }
102
103 }
104 while (sInput.length());
105
106 // Set the view cursor to the last position
107 // and clear the input data
109 sInput_Data.clear();
110}
111
112
121{
122 // Reset the cursor position after using the up down keys
123 if (mode & RESETCURSOR)
124 {
127 }
128
129 // Reset the cursor position for the tab key
130 if (!(mode & RESETTAB) || nTabStartPos == -1)
131 return;
132 nTabStartPos = -1;
133
134 sAutoCompList.clear();
135 sAutoCompWordStart.clear();
136}
137
138
149{
150 std::string sNameSpace;
151
152 // Get the position of the current autocompletion start
153 int nNameSpacePos = nTabStartPos - 1;
154
155 // Find the start of the current procedure syntax
156 while (nNameSpacePos && ((tm.GetColorAdjusted(termCursor.y, nNameSpacePos - 1) >> 4) & 0xf) == NumeReSyntax::SYNTAX_PROCEDURE && tm.GetCharAdjusted(termCursor.y, nNameSpacePos - 1) != '$')
157 nNameSpacePos--;
158
159 // Get the text between the start and the current autocompletion start
160 sNameSpace = toLowerCase(tm.GetTextRange(termCursor.y, nNameSpacePos, nTabStartPos));
161
162 // If the obtained namespace contains the (possible) procedure
163 // name, then erase this part, because we only want to have the
164 // current namespace
165 if (sNameSpace.find(sAutoCompWordStart) != std::string::npos)
166 sNameSpace.erase(sNameSpace.rfind(sAutoCompWordStart));
167
168 // return the evaluted namespace
169 return sNameSpace;
170}
171
172
180{
182}
183
184
192{
193 tm.newLine();
194
195 if (termCursor.y < (size_t)scroll_bot)
196 {
198 }
199}
200
201
209{
211
213}
214
215
225{
226 // Determine, whether this is the first tab key press (in this case
227 // the tab start position is equal to -1)
228 if (nTabStartPos == -1)
229 {
231
232 // Get the word start from the terminal
234
235 // There are different autocompletion lists for procedures and every other syntax element
237 {
238 std::string sNameSpace = getProcNameSpace();
240 }
243 else
245
246 // Reset the autocompletion, if no completion was found or the word start is too short
247 if (!sAutoCompList.length() || !sAutoCompWordStart.length())
248 {
250 return;
251 }
252 }
253 else
254 {
255 // This is not the first time the tab key was pressed
256 // If the autocompletion list is empty, recreate it here
257 if (!sAutoCompList.length())
258 {
260 {
261 std::string sNameSpace = getProcNameSpace();
263 }
266 else
268 }
269 }
270
271 // clear the word start and move the cursor back to the word start
272 // (word start cleared to avoid character case issues)
275
276 // Get the next autocompletion proposal, store it as input and remove it from the list
277 sInput_Data = sAutoCompList.substr(0, sAutoCompList.find('?'));
278 data_len = sInput_Data.length();
279 sAutoCompList.erase(0, sAutoCompList.find(' ') + 1);
280
281 // Process the input
282 normal_input();
283}
284
285
293{
294 // Convert the current view cursor to a logical cursor
296
297 // Ensure that the position is editable and perform the backspace
298 if (termCursor.x > 0 && tm.IsEditable(termCursor.y, termCursor.x - 1))
299 {
300 tm.backspace(cursor);
301 }
302 else
303 return false;
304
305 // move the cursor to the left
306 cursor--;
307
308 // Convert it to a new view cursor
309 termCursor = tm.toViewCursor(cursor);
310
311 // If the view cursor is not valid, use the current input position
312 if (!termCursor)
314
315 // Update the GUI and return
317
319 return true;
320}
321
322
330{
331 // Convert the current view cursor to a logical cursor
333
334 // Move the cursor to the right
335 cursor++;
336
337 // Ensure that the position to the right is editable and perform the backspace
338 if (termCursor.x > 0 && tm.IsEditable(termCursor.y, termCursor.x + 1))
339 {
340 tm.backspace(cursor);
341 }
342 else
343 return false;
344
345 // The view cursor stays at its position so
346 // only update the GUI and return
348
350 return true;
351}
352
353
361{
363 return false;
364
367
368 // Reverse the starting point (if selected left of
369 // the current cursor)
370 while (tm.IsEditableLogical(curStart) && tm.isSelectedLogical(curStart) && curStart.pos)
371 curStart--;
372
373 curStart++;
374
375 // Advance the ending point (if selected right of
376 // the current cursor)
377 while (tm.IsEditableLogical(curEnd) && tm.isSelectedLogical(curEnd) && curEnd < tm.getCurrentLogicalPos())
378 curEnd++;
379
380 tm.clearRange(tm.toViewCursor(curStart), tm.toViewCursor(curEnd));
381
382 termCursor = tm.toViewCursor(curStart);
384
386 return true;
387}
388
389
397{
398 Bell();
399}
400
401
410{
411 bg_color = 0;
412 fg_color = 7;
413 scroll_top = 0;
414 scroll_bot = height - 1;
415
418
419 clear_area(0, 0, width - 1, height - 1);
420 move_cursor(0, 0);
421
422 tm.Reset();
423}
424
425
433{
435
436 if (!cursor--)
437 return false;
438
439 if (!tm.IsEditableLogical(cursor))
440 return false;
441
442 termCursor = tm.toViewCursor(cursor);
443
445
446 return true;
447}
448
449
457{
459
460 cursor++;
461
462 if (!tm.IsEditableLogical(cursor))
463 return false;
464
465 termCursor = tm.toViewCursor(cursor);
466
468
469 return true;
470}
471
472
481{
482 // Store the cursor position
483 if (nCursorUpDownStartPos == -1)
485
487 {
488 // Get the last history entry
489 std::string sHistory = tm.GetInputHistory(true);
490
491 // Get the current user input line
492 std::string currentLine = tm.getCurrentInputLine();
493
494 while (sHistory.length())
495 {
496 wxLogDebug(std::to_string(nCursorUpDownStartPos).c_str());
497 if (sHistory != currentLine && sHistory.substr(0, nCursorUpDownStartPos) == currentLine.substr(0, nCursorUpDownStartPos))
498 {
500 sInput_Data = sHistory;
501 data_len = sHistory.length();
502 normal_input();
503 return true;
504 }
505 sHistory = tm.GetInputHistory(true);
506 }
507 return false;
508 }
509
510 // Move the cursor up
511 int n, y;
512
513 n = param[0];
514
515 if (n < 1)
516 n = 1;
517
518 y = termCursor.y - n;
519
520 if (y < 0)
521 y = 0;
522
524 return true;
525}
526
527
536{
537 // Store the cursor position
538 if (nCursorUpDownStartPos == -1)
540
542 {
543 // Get the last history entry
544 std::string sHistory = tm.GetInputHistory(false);
545
546 // Get the current user input line
547 std::string currentLine = tm.getCurrentInputLine();
548
549 while (sHistory.length())
550 {
551 if (sHistory != currentLine && sHistory.substr(0, nCursorUpDownStartPos) == currentLine.substr(0, nCursorUpDownStartPos))
552 {
554 sInput_Data = sHistory;
555 data_len = sHistory.length();
556 normal_input();
557 return true;
558 }
559 sHistory = tm.GetInputHistory(false);
560 }
561
562 // Reset to original input if no other result was found
563 if ((int)currentLine.length() > nCursorUpDownStartPos)
564 {
566 sInput_Data = currentLine.substr(0, nCursorUpDownStartPos);
568 normal_input();
569 return true;
570 }
571
572 return false;
573 }
574
575 // Move the cursor down
576 int n, y;
577
578 n = param[0];
579
580 if (n < 1)
581 n = 1;
582
583 y = termCursor.y + n;
584
585 if (y >= height)
586 y = height - 1;
587
589 return true;
590}
591
592
600{
602
603 // If already at the beginning of a word, go one
604 // position to the left
605 if (!isalnum(tm.GetCharLogical(cursor - 1)))
606 cursor--;
607
608 // Always go to the first non-whitespace character
609 while (!isalnum(tm.GetCharLogical(cursor)) && tm.IsEditableLogical(cursor))
610 cursor--;
611
612 // Search now the first whitespace character to the
613 // left
614 while (isalnum(tm.GetCharLogical(cursor)) && tm.IsEditableLogical(cursor))
615 cursor--;
616
617 // Go back to the first word character
618 cursor++;
619
620 if (!tm.IsEditableLogical(cursor))
621 return false;
622
623 termCursor = tm.toViewCursor(cursor);
625
626 return true;
627}
628
629
638{
640
641 // Search for the next whitespace character to the
642 // right
643 while (isalnum(tm.GetCharLogical(cursor)) && tm.IsEditableLogical(cursor))
644 cursor++;
645
646 // Go to the first word character
647 while (!isalnum(tm.GetCharLogical(cursor)) && tm.IsEditableLogical(cursor))
648 cursor++;
649
650 if (!tm.IsEditableLogical(cursor))
651 return false;
652
653 termCursor = tm.toViewCursor(cursor);
655
656 return true;
657}
658
659
668{
669 int n = termCursor.x;
670
671 // Search the last not editable character from the right
672 while (tm.IsEditable(termCursor.y, n - 1))
673 n--;
674
675 // Don't do anything, if the cursor is already there
676 if (n == (int)termCursor.x)
677 return front();
678
679 // Move the cursor
681 return true;
682}
683
684
693{
694 size_t n = termCursor.x;
695
696 // Search the first not editable character from the left
697 while (tm.IsEditable(termCursor.y, n + 1))
698 n++;
699
700 // Don't do anything, if the cursor is already there
701 if (n == termCursor.x)
702 return back();
703
704 // Move the cursor
706 return true;
707}
708
709
718{
720
721 // Search the last not editable character from the right
722 while (tm.IsEditableLogical(cursor))
723 cursor--;
724
725 // Move the cursor to the first editable position
726 cursor++;
727
728 // Create a corresponding view cursor
729 ViewCursor vCursor = tm.toViewCursor(cursor);
730
731 // Ensure that the cursor is different
732 if (vCursor == termCursor)
733 return false;
734
735 // Move the cursor
736 move_cursor(vCursor.x, vCursor.y);
737 return true;
738}
739
740
749{
751
752 // Search the last not editable character from the right
753 while (tm.IsEditableLogical(cursor))
754 cursor++;
755
756 // Move the cursor to the last editable position
757 cursor--;
758
759 // Create a corresponding view cursor
760 ViewCursor vCursor = tm.toViewCursor(cursor);
761
762 // Ensure that the cursor is different
763 if (vCursor == termCursor)
764 return false;
765
766 // Move the cursor
767 move_cursor(vCursor.x, vCursor.y);
768 return true;
769}
770
771
780{
781 tm.eraseLine();
782}
783
784
793{
794 // Go to the very last position first
795 back();
796
798 return;
799
800 // Convert the current view cursor into a logical cursor
802 cursor.pos--;
803
804 // While the current character is editable, erase it
805 while (tm.IsEditableLogical(cursor))
806 {
807 cursor.pos++;
808 tm.backspace(cursor);
809 cursor.pos -= 2;
810 }
811
812 // Get the new view cursor
813 termCursor = tm.toViewCursor(cursor);
814 termCursor.x++;
815
816 // If the view cursor is not valid, use the current input location
817 if (!termCursor)
819
821}
822
823
824
825
std::string toLowerCase(const std::string &)
Converts uppercase to lowercase letters.
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
int scroll_bot
Definition: gterm.hpp:77
ViewCursor termCursor
Definition: gterm.hpp:85
int nTabStartPos
Definition: gterm.hpp:111
virtual void Bell()
Definition: gterm.hpp:199
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
std::string sInput_Data
Definition: gterm.hpp:97
void update_changes()
Definition: utils.cpp:37
int scroll_top
Definition: gterm.hpp:77
bool cursor_down()
Either moves the cursor down or performs a history jump.
Definition: actions.cpp:535
void resetAutoComp(int mode)
Reset the current autocompletion list and the corresponding variables.
Definition: actions.cpp:120
void normal_input()
Definition: actions.cpp:21
bool cursor_left()
Moves the cursor to the left.
Definition: actions.cpp:432
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
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
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
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 erase_usercontent_line()
Erases alle user-written contents from the current line.
Definition: actions.cpp:792
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
NumeReSyntax _syntax
Definition: gterm.hpp:99
std::string sAutoCompList
Definition: gterm.hpp:114
@ SYNTAX_PROCEDURE
Definition: syntax.hpp:99
std::string getAutoCompList(std::string sFirstChars, bool useSmartSense=false)
This function returns the autocompletion list for the editor.
Definition: syntax.cpp:670
std::string getProcAutoCompList(std::string sFirstChars, std::string sBaseNameSpace, std::string sSelectedNameSpace)
This function will return the autocompletion list for the procedures based upon the provided procedur...
Definition: syntax.cpp:878
bool clearRange(const ViewCursor &cursor1, const ViewCursor &cursor2)
Clears the range between two view cursors.
void printOutput(const std::string &sLine)
This is the read-only print function.
Definition: TextManager.cpp:76
unsigned short GetColorAdjusted(int y, int x) const
size_t tab()
Insert a tab character at the current position.
void insertInput(const std::string &sLine, size_t logicalpos=std::string::npos)
This is the user input function.
void newLine()
Adds a new line to the current managed text.
void backspace(const LogicalCursor &logCursor)
Performs a backspace operation.
ViewCursor toViewCursor(const LogicalCursor &logCursor) const
Convert a logical cursor to a view cursor.
char GetCharAdjusted(int y, int x) const
bool IsEditableLogical(const LogicalCursor &logCursor) const
Determines, whether the character at the logical position is editable text.
char GetCharLogical(const LogicalCursor &cursor) const
Returns the character at the logical position.
std::string GetInputHistory(bool vcursorup=true)
Get the next history line.
void eraseLine()
Erase the current line.
ViewCursor getCurrentViewPos() const
Returns the current cursor position as view cursor.
bool IsEditable(int y, int x) const
Determines, whether the character at (x,y) is editable text.
std::string GetTextRange(int y, int x0, int x1) const
Extracts the text between the positions.
void ResetVirtualCursorLine()
Definition: TextManager.h:536
bool isSelected(const ViewCursor &viewCursor) const
Determines, whether the pointed character is selected.
std::string GetWordStartAt(int y, int x) const
Returns the word start at the passed position.
LogicalCursor toLogicalCursor(const ViewCursor &viewCursor) const
Convert a view cursor into a logical cursor.
LogicalCursor getCurrentLogicalPos() const
Returns the current cursor position as logical cursor.
std::string getCurrentInputLine() const
Returns the contents of the input line.
bool isSelectedLogical(const LogicalCursor &cursor) const
Determines, whether the pointed character is selected.
Cursor, which is used in the TextManager to identify the actual line and position in the m_text varia...
Definition: TextManager.h:38
Cursor, which is used in the terminal. The TextManager is able to convert this cursor into a LogicalC...
Definition: TextManager.h:124
size_t y
Definition: TextManager.h:126
size_t x
Definition: TextManager.h:125