2019-12-18 13:26:59 +01:00
|
|
|
#include <iostream>
|
2020-01-08 19:19:26 +01:00
|
|
|
#include "Terminal.hpp"
|
2019-12-12 11:59:07 +01:00
|
|
|
|
|
|
|
std::string Terminal::getString() {
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
2019-12-18 13:26:59 +01:00
|
|
|
void Terminal::init(){
|
|
|
|
s = s + cursor;
|
|
|
|
}
|
|
|
|
|
2019-12-12 11:59:07 +01:00
|
|
|
void Terminal::setString(char c) {
|
2019-12-18 13:26:59 +01:00
|
|
|
// s.erase(s.end() - 1);
|
|
|
|
// s = s + c + cursor;
|
|
|
|
int i = s.find(cursor);
|
|
|
|
std::cout << i << std::endl;
|
|
|
|
std::cout<< s.length() -1 <<std::endl;
|
|
|
|
if(i < s.length() -1 ){
|
|
|
|
s= s + s[s.length() - 1];
|
|
|
|
int l = s.length() - 1;
|
|
|
|
for(; l > i + 1; l--){
|
|
|
|
s[l] = s[l-1];
|
|
|
|
}
|
|
|
|
s[i+1] = c;
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
s = s + cursor;
|
|
|
|
s[s.length()-2] = c;
|
2019-12-19 12:22:39 +01:00
|
|
|
|
2019-12-18 13:26:59 +01:00
|
|
|
|
|
|
|
}
|
2019-12-12 11:59:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void Terminal::subString(){
|
2019-12-18 13:26:59 +01:00
|
|
|
// if(s.length() > 1)
|
|
|
|
// s.erase(s.end() - 1);
|
|
|
|
// s.erase(s.end() - 1);
|
|
|
|
// s = s + cursor;
|
2019-12-19 12:22:39 +01:00
|
|
|
if(s.length() > 1) {
|
|
|
|
int i = s.find(cursor);
|
|
|
|
s.erase(i - 1, 1);
|
|
|
|
}
|
2019-12-12 11:59:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void Terminal::shiftpressed() {
|
|
|
|
status = 1;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void Terminal::shiftup() {
|
|
|
|
status = 0;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
int Terminal::getstatus() {
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
2019-12-18 13:26:59 +01:00
|
|
|
void Terminal::moveleft(){
|
|
|
|
int i = s.find(cursor);
|
|
|
|
if(i > 0){
|
|
|
|
char c = s[i-1];
|
|
|
|
s[i-1] = cursor;
|
|
|
|
s[i] = c;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Terminal::moveright() {
|
|
|
|
int i = s.find(cursor);
|
|
|
|
if(i < (s.length() - 1)){
|
|
|
|
char c = s[i+1];
|
|
|
|
s[i+1] = cursor;
|
|
|
|
s[i] = c;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Terminal::movedown() {
|
2019-12-20 16:13:24 +01:00
|
|
|
// std::string news="";
|
|
|
|
// int i = s.find(cursor);
|
|
|
|
// s.erase(i, 1);
|
|
|
|
//
|
|
|
|
// std::vector<std::vector<char>> vec(100,std::vector<char>(21,0));
|
|
|
|
// for(int n = 0; n < 100; n++){
|
|
|
|
// if(n*21 < s.length()) {
|
|
|
|
// for (int m = 0; m < 21; m++) {
|
|
|
|
// int sum = n * 21 + m;
|
|
|
|
// if (s[sum] != '\n') {
|
|
|
|
// vec[n][m] = s[sum];
|
|
|
|
// std::cout<<"vec before" + vec[n][m]<<std::endl;
|
|
|
|
// }
|
|
|
|
// else {
|
|
|
|
// vec[n][m] = s[sum];
|
|
|
|
// break;
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// else {
|
|
|
|
// break;
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// int cursorrow = i / 21;
|
|
|
|
// int cursorcolumn =i % 21;
|
|
|
|
// std::cout<<"before" + std::to_string(cursorrow) + ' '+ std::to_string(cursorcolumn)<<std::endl;
|
|
|
|
// if(vec[cursorrow+1].size() >= cursorcolumn){
|
|
|
|
// cursorrow++;
|
|
|
|
// }
|
|
|
|
// else if(vec[cursorrow+1].size() >=1){
|
|
|
|
// cursorrow++;
|
|
|
|
// cursorcolumn = vec[cursorrow].size()-1;
|
|
|
|
// }
|
|
|
|
// std::cout<<"after" + std::to_string(cursorrow) + ' '+ std::to_string(cursorcolumn)<<std::endl;
|
|
|
|
//
|
|
|
|
// for(int n = 0; n < 100; n++){
|
|
|
|
// for(int m=0;m<21;m++){
|
|
|
|
// if((n==cursorrow) && (m==cursorcolumn)){
|
|
|
|
// news = news + cursor;
|
|
|
|
// }
|
|
|
|
// else if(vec[n][m] != '\n'){
|
|
|
|
// std::cout<<"vec after" + vec[n][m]<<std::endl;
|
|
|
|
// news = news + vec[n][m];
|
|
|
|
// }
|
|
|
|
// else{
|
|
|
|
// news = news + vec[n][m];
|
|
|
|
// break;
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// std::cout<< news<<std::endl;
|
|
|
|
|
|
|
|
|
|
|
|
int count =0;
|
|
|
|
for(int i = 0; i < s.length(); i++) {
|
|
|
|
if (s[i] == '\n') {
|
|
|
|
count = 0;
|
|
|
|
}
|
2019-12-20 17:04:21 +01:00
|
|
|
else {
|
|
|
|
if(s[i]!=cursor)
|
|
|
|
count++;
|
2019-12-20 16:13:24 +01:00
|
|
|
}
|
2019-12-20 17:04:21 +01:00
|
|
|
if(count == 22){
|
2019-12-20 16:13:24 +01:00
|
|
|
s = s + s[s.length() - 1];
|
|
|
|
int x = s.length() - 1;
|
|
|
|
for(; x > i; x--){
|
|
|
|
s[x] = s[x-1];
|
|
|
|
}
|
|
|
|
s[x] = '\n';
|
2019-12-20 17:04:21 +01:00
|
|
|
count = 0;
|
2019-12-20 16:13:24 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
std::cout<<"plus enter:" + s <<std::endl;
|
|
|
|
int cursorposition = s.find(cursor);
|
|
|
|
int aftercursorenter1 = s.find('\n',cursorposition);
|
|
|
|
int beforcursorenter = cursorposition - 1;
|
2020-01-06 15:35:22 +01:00
|
|
|
while (beforcursorenter >= 0){
|
2019-12-20 16:13:24 +01:00
|
|
|
if (s[beforcursorenter] != '\n') {
|
|
|
|
beforcursorenter--;
|
|
|
|
} else {
|
|
|
|
break;
|
|
|
|
}
|
2020-01-06 15:35:22 +01:00
|
|
|
}
|
2019-12-20 16:13:24 +01:00
|
|
|
std::cout<<"cursorpositon:" + std::to_string(cursorposition)<<std::endl;
|
|
|
|
std::cout<<"aftercursorenter1:" + std::to_string(aftercursorenter1)<<std::endl;
|
|
|
|
std::cout<<"beforecursorenter:" + std::to_string(beforcursorenter)<<std::endl;
|
|
|
|
if(aftercursorenter1 != s.npos) {
|
|
|
|
int aftercursorenter2 = s.find('\n', aftercursorenter1 + 1);
|
|
|
|
std::cout<<"aftercursorenter2:" + std::to_string(aftercursorenter2)<<std::endl;
|
|
|
|
if(aftercursorenter2 != s.npos){
|
|
|
|
std::cout<<"enter the loop & aftercursorenter2 !=s.npos" <<std::endl;
|
|
|
|
if((aftercursorenter2 - aftercursorenter1) >= (cursorposition - beforcursorenter)) {
|
|
|
|
for(int newcursorposition = cursorposition;newcursorposition < (aftercursorenter1 + cursorposition -beforcursorenter -1);newcursorposition++){
|
|
|
|
s[newcursorposition] = s[newcursorposition + 1];
|
|
|
|
}
|
|
|
|
s[aftercursorenter1 + cursorposition - beforcursorenter -1] = cursor;
|
2019-12-19 12:22:39 +01:00
|
|
|
}
|
2019-12-20 16:13:24 +01:00
|
|
|
else{
|
|
|
|
for(int newcursorposition = cursorposition;newcursorposition < (aftercursorenter2); newcursorposition++){
|
|
|
|
s[newcursorposition] = s[newcursorposition + 1];
|
|
|
|
}
|
|
|
|
s[aftercursorenter2] = cursor;
|
2019-12-19 12:22:39 +01:00
|
|
|
}
|
2019-12-20 16:13:24 +01:00
|
|
|
|
2019-12-19 12:22:39 +01:00
|
|
|
}
|
2019-12-20 16:13:24 +01:00
|
|
|
else{
|
|
|
|
std::cout<<"enter the loop & aftercursorenter2 ==s.npos" <<std::endl;
|
|
|
|
std::cout<<"elsecursorpositon:" + std::to_string(cursorposition)<<std::endl;
|
|
|
|
std::cout<<"elseaftercursorenter1:" + std::to_string(aftercursorenter1)<<std::endl;
|
|
|
|
std::cout<<"elsebeforecursorenter:" + std::to_string(beforcursorenter)<<std::endl;
|
|
|
|
if((s.length()- 1 - aftercursorenter1) >= (cursorposition - beforcursorenter)) {
|
|
|
|
std::cout<<"enter the loop if" <<std::endl;
|
2020-01-06 15:35:22 +01:00
|
|
|
for(int newcursorposition=cursorposition; newcursorposition < (aftercursorenter1 + cursorposition -beforcursorenter -1); newcursorposition++){
|
2019-12-20 16:13:24 +01:00
|
|
|
s[newcursorposition] = s[newcursorposition + 1];
|
|
|
|
std::cout<<"forcursorpositon:" + std::to_string(cursorposition)<<std::endl;
|
|
|
|
}
|
2020-01-06 15:35:22 +01:00
|
|
|
s[aftercursorenter1 + cursorposition - beforcursorenter -1] = cursor;
|
2019-12-20 16:13:24 +01:00
|
|
|
std::cout<<"new cursorposition" + std::to_string(aftercursorenter1 + cursorposition - beforcursorenter -1) <<std::endl;
|
|
|
|
std::cout<<"delect enter:" + s <<std::endl;
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
std::cout<<"enter the loop else" <<std::endl;
|
|
|
|
for(int newcursorposition = cursorposition;newcursorposition < (s.length() -1); newcursorposition++){
|
|
|
|
s[newcursorposition] = s[newcursorposition + 1];
|
|
|
|
}
|
|
|
|
std::cout<<"new cursorposition" + std::to_string(s.length() - 1) <<std::endl;
|
|
|
|
s[s.length() - 1] = cursor;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-12-19 12:22:39 +01:00
|
|
|
}
|
2019-12-20 16:13:24 +01:00
|
|
|
std::cout<<"after down:" + s <<std::endl;
|
2019-12-19 12:22:39 +01:00
|
|
|
|
2019-12-20 16:13:24 +01:00
|
|
|
count = 0;
|
|
|
|
for(int i = 0; i < s.length(); i++) {
|
2020-01-06 15:35:22 +01:00
|
|
|
if(s[i] != cursor) {
|
|
|
|
count++;
|
|
|
|
}
|
2019-12-20 17:04:21 +01:00
|
|
|
if((count ==22)){
|
2019-12-20 16:13:24 +01:00
|
|
|
for(int n=i; n < s.length();n++){
|
|
|
|
s[n] = s[n+1];
|
|
|
|
}
|
|
|
|
s = s.substr(0,s.length()-1);
|
2020-01-06 15:35:22 +01:00
|
|
|
|
2019-12-20 17:04:21 +01:00
|
|
|
count =1;
|
2019-12-20 16:13:24 +01:00
|
|
|
}
|
2019-12-19 12:22:39 +01:00
|
|
|
}
|
2019-12-20 16:13:24 +01:00
|
|
|
std::cout<<"delect enter:" + s <<std::endl;
|
|
|
|
|
|
|
|
|
2019-12-18 13:26:59 +01:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2020-01-06 15:35:22 +01:00
|
|
|
void Terminal::moveup() {
|
|
|
|
int count =0;
|
|
|
|
for(int i = 0; i < s.length(); i++) {
|
|
|
|
if (s[i] == '\n') {
|
|
|
|
count = 0;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if(s[i]!=cursor)
|
|
|
|
count++;
|
|
|
|
}
|
|
|
|
if(count == 22){
|
|
|
|
s = s + s[s.length() - 1];
|
|
|
|
int x = s.length() - 1;
|
|
|
|
for(; x > i; x--){
|
|
|
|
s[x] = s[x-1];
|
|
|
|
}
|
|
|
|
s[x] = '\n';
|
|
|
|
count = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
std::cout<<"plus enter:" + s <<std::endl;
|
|
|
|
int cursorposition = s.find(cursor);
|
|
|
|
int beforecursorenter1 = cursorposition - 1;
|
|
|
|
while (beforecursorenter1 >= 0){
|
|
|
|
if (s[beforecursorenter1] != '\n') {
|
|
|
|
beforecursorenter1--;
|
|
|
|
} else {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
std::cout<<"cursorpositon:" + std::to_string(cursorposition)<<std::endl;
|
|
|
|
std::cout<<"beforecursorenter1:" + std::to_string(beforecursorenter1)<<std::endl;
|
|
|
|
if(beforecursorenter1 != -1) {
|
|
|
|
int beforecursorenter2 = beforecursorenter1 - 1;
|
|
|
|
while (beforecursorenter2 >= 0){
|
|
|
|
if (s[beforecursorenter2] != '\n') {
|
|
|
|
beforecursorenter2--;
|
|
|
|
} else {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
std::cout<<"beforecursorenter2:" + std::to_string(beforecursorenter2)<<std::endl;
|
|
|
|
if(beforecursorenter2 != -1){
|
|
|
|
std::cout<<"enter the loop & beforecursorenter2 !=-1" <<std::endl;
|
|
|
|
if((beforecursorenter1 - beforecursorenter2) >= (cursorposition - beforecursorenter1)) {
|
|
|
|
for(int newcursorposition = cursorposition;newcursorposition > (beforecursorenter2 + cursorposition - beforecursorenter1 );newcursorposition--){
|
|
|
|
s[newcursorposition] = s[newcursorposition - 1];
|
|
|
|
}
|
|
|
|
s[beforecursorenter2 + cursorposition - beforecursorenter1] = cursor;
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
for(int newcursorposition = cursorposition;newcursorposition > (beforecursorenter1); newcursorposition--){
|
|
|
|
s[newcursorposition] = s[newcursorposition -1];
|
|
|
|
}
|
|
|
|
s[beforecursorenter1] = cursor;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
std::cout<<"enter the loop & aftercursorenter2 ==s.npos" <<std::endl;
|
|
|
|
std::cout<<"elsecursorpositon:" + std::to_string(cursorposition)<<std::endl;
|
|
|
|
std::cout<<"elsebeforecursorenter1:" + std::to_string(beforecursorenter1)<<std::endl;
|
|
|
|
std::cout<<"elsebeforecursorenter2:" + std::to_string(beforecursorenter2)<<std::endl;
|
|
|
|
if((beforecursorenter1 + 1) >= (cursorposition - beforecursorenter1)) {
|
|
|
|
std::cout<<"enter the loop if" <<std::endl;
|
|
|
|
for(int newcursorposition=cursorposition; newcursorposition > (cursorposition -beforecursorenter1 -1); newcursorposition--){
|
|
|
|
s[newcursorposition] = s[newcursorposition - 1];
|
|
|
|
std::cout<<"forcursorpositon:" + std::to_string(cursorposition)<<std::endl;
|
|
|
|
}
|
|
|
|
s[cursorposition -beforecursorenter1 -1] = cursor;
|
|
|
|
std::cout<<"new cursorposition" + std::to_string(cursorposition -beforecursorenter1 -1) <<std::endl;
|
|
|
|
std::cout<<"delect enter:" + s <<std::endl;
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
std::cout<<"enter the loop else" <<std::endl;
|
|
|
|
for(int newcursorposition = cursorposition;newcursorposition > (beforecursorenter1); newcursorposition--){
|
|
|
|
s[newcursorposition] = s[newcursorposition - 1];
|
|
|
|
}
|
|
|
|
std::cout<<"new cursorposition" + std::to_string(beforecursorenter1) <<std::endl;
|
|
|
|
s[beforecursorenter1] = cursor;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
std::cout<<"after up:" + s <<std::endl;
|
|
|
|
|
|
|
|
count = 0;
|
|
|
|
for(int i = 0; i < s.length(); i++) {
|
|
|
|
if(s[i] != cursor) {
|
|
|
|
count++;
|
|
|
|
}
|
|
|
|
if((count ==22)){
|
|
|
|
for(int n=i; n < s.length();n++){
|
|
|
|
s[n] = s[n+1];
|
|
|
|
}
|
|
|
|
s = s.substr(0,s.length()-1);
|
|
|
|
|
|
|
|
count =1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
std::cout<<"delect enter:" + s <<std::endl;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|