move down

This commit is contained in:
yukun 2020-01-06 15:35:22 +01:00
parent cfe0e7fad2
commit 6257befb79
2 changed files with 122 additions and 114 deletions

View File

@ -110,12 +110,12 @@ int main() {
vkvm::callEvent(vkvm::EventType::RenderText); vkvm::callEvent(vkvm::EventType::RenderText);
} }
// if(vkvm::KeyCode::Arrow_Up == keycode){ if(vkvm::KeyCode::Arrow_Up == keycode){
// terminal.moveup(); terminal.moveup();
// std::cout << terminal.getString() << std::endl; std::cout << terminal.getString() << std::endl;
// vkvm::setText(terminal.getString()); vkvm::setText(terminal.getString());
// vkvm::callEvent(vkvm::EventType::RenderText); vkvm::callEvent(vkvm::EventType::RenderText);
// } }

View File

@ -158,13 +158,13 @@ void Terminal::movedown() {
int cursorposition = s.find(cursor); int cursorposition = s.find(cursor);
int aftercursorenter1 = s.find('\n',cursorposition); int aftercursorenter1 = s.find('\n',cursorposition);
int beforcursorenter = cursorposition - 1; int beforcursorenter = cursorposition - 1;
do { while (beforcursorenter >= 0){
if (s[beforcursorenter] != '\n') { if (s[beforcursorenter] != '\n') {
beforcursorenter--; beforcursorenter--;
} else { } else {
break; break;
} }
} while (beforcursorenter >= 0); }
std::cout<<"cursorpositon:" + std::to_string(cursorposition)<<std::endl; std::cout<<"cursorpositon:" + std::to_string(cursorposition)<<std::endl;
std::cout<<"aftercursorenter1:" + std::to_string(aftercursorenter1)<<std::endl; std::cout<<"aftercursorenter1:" + std::to_string(aftercursorenter1)<<std::endl;
std::cout<<"beforecursorenter:" + std::to_string(beforcursorenter)<<std::endl; std::cout<<"beforecursorenter:" + std::to_string(beforcursorenter)<<std::endl;
@ -194,11 +194,11 @@ void Terminal::movedown() {
std::cout<<"elsebeforecursorenter:" + std::to_string(beforcursorenter)<<std::endl; std::cout<<"elsebeforecursorenter:" + std::to_string(beforcursorenter)<<std::endl;
if((s.length()- 1 - aftercursorenter1) >= (cursorposition - beforcursorenter)) { if((s.length()- 1 - aftercursorenter1) >= (cursorposition - beforcursorenter)) {
std::cout<<"enter the loop if" <<std::endl; std::cout<<"enter the loop if" <<std::endl;
for(int newcursorposition=cursorposition; newcursorposition < (aftercursorenter1 + cursorposition -beforcursorenter); newcursorposition++){ for(int newcursorposition=cursorposition; newcursorposition < (aftercursorenter1 + cursorposition -beforcursorenter -1); newcursorposition++){
s[newcursorposition] = s[newcursorposition + 1]; s[newcursorposition] = s[newcursorposition + 1];
std::cout<<"forcursorpositon:" + std::to_string(cursorposition)<<std::endl; std::cout<<"forcursorpositon:" + std::to_string(cursorposition)<<std::endl;
} }
s[aftercursorenter1 + cursorposition - beforcursorenter ] = cursor; s[aftercursorenter1 + cursorposition - beforcursorenter -1] = cursor;
std::cout<<"new cursorposition" + std::to_string(aftercursorenter1 + cursorposition - beforcursorenter -1) <<std::endl; std::cout<<"new cursorposition" + std::to_string(aftercursorenter1 + cursorposition - beforcursorenter -1) <<std::endl;
std::cout<<"delect enter:" + s <<std::endl; std::cout<<"delect enter:" + s <<std::endl;
} }
@ -217,12 +217,15 @@ void Terminal::movedown() {
count = 0; count = 0;
for(int i = 0; i < s.length(); i++) { for(int i = 0; i < s.length(); i++) {
if(s[i] != cursor) {
count++; count++;
}
if((count ==22)){ if((count ==22)){
for(int n=i; n < s.length();n++){ for(int n=i; n < s.length();n++){
s[n] = s[n+1]; s[n] = s[n+1];
} }
s = s.substr(0,s.length()-1); s = s.substr(0,s.length()-1);
count =1; count =1;
} }
} }
@ -232,106 +235,111 @@ void Terminal::movedown() {
} }
//void Terminal::moveup() { void Terminal::moveup() {
// int count =0; int count =0;
// for(int i = 0; i < s.length(); i++) { for(int i = 0; i < s.length(); i++) {
// if (s[i] == '\n') { if (s[i] == '\n') {
// count = 0; count = 0;
// } }
// else {if(s[i]!=cursor) else {
// count++; if(s[i]!=cursor)
// } count++;
// if(count == 21){ }
// s = s + s[s.length() - 1]; if(count == 22){
// int x = s.length() - 1; s = s + s[s.length() - 1];
// for(; x > i; x--){ int x = s.length() - 1;
// s[x] = s[x-1]; for(; x > i; x--){
// } s[x] = s[x-1];
// s[x] = '\n'; }
// } s[x] = '\n';
// } count = 0;
// std::cout<<"plus enter:" + s <<std::endl; }
// int cursorposition = s.find(cursor); }
// int aftercursorenter1 = s.find('\n',cursorposition); std::cout<<"plus enter:" + s <<std::endl;
// int beforecursorenter1 = cursorposition - 1; int cursorposition = s.find(cursor);
// int beforecursorenter1 = cursorposition - 1;
// do { while (beforecursorenter1 >= 0){
// if (s[beforecursorenter1] != '\n') { if (s[beforecursorenter1] != '\n') {
// beforecursorenter1--; beforecursorenter1--;
// } else { } else {
// break; break;
// } }
// } while (beforecursorenter1 >= 0); }
// std::cout<<"cursorpositon:" + std::to_string(cursorposition)<<std::endl;
// std::cout<<"aftercursorenter1:" + std::to_string(aftercursorenter1)<<std::endl; std::cout<<"cursorpositon:" + std::to_string(cursorposition)<<std::endl;
// std::cout<<"beforecursorenter:" + std::to_string(beforecursorenter1)<<std::endl; std::cout<<"beforecursorenter1:" + std::to_string(beforecursorenter1)<<std::endl;
// if(beforecursorenter1 != s.npos) { if(beforecursorenter1 != -1) {
// int beforecursorenter2 =beforecursorenter1 -1; int beforecursorenter2 = beforecursorenter1 - 1;
// do { while (beforecursorenter2 >= 0){
// if (s[beforecursorenter2] != '\n') { if (s[beforecursorenter2] != '\n') {
// beforecursorenter2--; beforecursorenter2--;
// } else { } else {
// break; break;
// } }
// } while (beforecursorenter2 >= 0); }
//
//
// std::cout<<"aftercursorenter2:" + std::to_string(aftercursorenter2)<<std::endl; std::cout<<"beforecursorenter2:" + std::to_string(beforecursorenter2)<<std::endl;
// if(aftercursorenter2 != s.npos){ if(beforecursorenter2 != -1){
// std::cout<<"enter the loop & aftercursorenter2 !=s.npos" <<std::endl; std::cout<<"enter the loop & beforecursorenter2 !=-1" <<std::endl;
// if((aftercursorenter2 - aftercursorenter1) >= (cursorposition - beforcursorenter)) { if((beforecursorenter1 - beforecursorenter2) >= (cursorposition - beforecursorenter1)) {
// for(int newcursorposition = cursorposition;newcursorposition < (aftercursorenter1 + cursorposition -beforcursorenter -1);newcursorposition++){ for(int newcursorposition = cursorposition;newcursorposition > (beforecursorenter2 + cursorposition - beforecursorenter1 );newcursorposition--){
// s[newcursorposition] = s[newcursorposition + 1]; s[newcursorposition] = s[newcursorposition - 1];
// } }
// s[aftercursorenter1 + cursorposition - beforcursorenter -1] = cursor; s[beforecursorenter2 + cursorposition - beforecursorenter1] = cursor;
// } }
// else{ else{
// for(int newcursorposition = cursorposition;newcursorposition < (aftercursorenter2); newcursorposition++){ for(int newcursorposition = cursorposition;newcursorposition > (beforecursorenter1); newcursorposition--){
// s[newcursorposition] = s[newcursorposition + 1]; s[newcursorposition] = s[newcursorposition -1];
// } }
// s[aftercursorenter2] = cursor; s[beforecursorenter1] = cursor;
// } }
//
// } }
// else{ else{
// std::cout<<"enter the loop & aftercursorenter2 ==s.npos" <<std::endl; std::cout<<"enter the loop & aftercursorenter2 ==s.npos" <<std::endl;
// std::cout<<"elsecursorpositon:" + std::to_string(cursorposition)<<std::endl; std::cout<<"elsecursorpositon:" + std::to_string(cursorposition)<<std::endl;
// std::cout<<"elseaftercursorenter1:" + std::to_string(aftercursorenter1)<<std::endl; std::cout<<"elsebeforecursorenter1:" + std::to_string(beforecursorenter1)<<std::endl;
// std::cout<<"elsebeforecursorenter:" + std::to_string(beforcursorenter)<<std::endl; std::cout<<"elsebeforecursorenter2:" + std::to_string(beforecursorenter2)<<std::endl;
// if((s.length()- 1 - aftercursorenter1) >= (cursorposition - beforcursorenter)) { if((beforecursorenter1 + 1) >= (cursorposition - beforecursorenter1)) {
// std::cout<<"enter the loop if" <<std::endl; std::cout<<"enter the loop if" <<std::endl;
// for(int newcursorposition=cursorposition; newcursorposition < (aftercursorenter1 + cursorposition -beforcursorenter); newcursorposition++){ for(int newcursorposition=cursorposition; newcursorposition > (cursorposition -beforecursorenter1 -1); newcursorposition--){
// s[newcursorposition] = s[newcursorposition + 1]; s[newcursorposition] = s[newcursorposition - 1];
// std::cout<<"forcursorpositon:" + std::to_string(cursorposition)<<std::endl; std::cout<<"forcursorpositon:" + std::to_string(cursorposition)<<std::endl;
// } }
// s[aftercursorenter1 + cursorposition - beforcursorenter ] = cursor; s[cursorposition -beforecursorenter1 -1] = cursor;
// std::cout<<"new cursorposition" + std::to_string(aftercursorenter1 + cursorposition - beforcursorenter -1) <<std::endl; std::cout<<"new cursorposition" + std::to_string(cursorposition -beforecursorenter1 -1) <<std::endl;
// std::cout<<"delect enter:" + s <<std::endl; std::cout<<"delect enter:" + s <<std::endl;
// } }
// else{ else{
// std::cout<<"enter the loop else" <<std::endl; std::cout<<"enter the loop else" <<std::endl;
// for(int newcursorposition = cursorposition;newcursorposition < (s.length() -1); newcursorposition++){ for(int newcursorposition = cursorposition;newcursorposition > (beforecursorenter1); newcursorposition--){
// s[newcursorposition] = s[newcursorposition + 1]; s[newcursorposition] = s[newcursorposition - 1];
// } }
// std::cout<<"new cursorposition" + std::to_string(s.length() - 1) <<std::endl; std::cout<<"new cursorposition" + std::to_string(beforecursorenter1) <<std::endl;
// s[s.length() - 1] = cursor; s[beforecursorenter1] = cursor;
// } }
// } }
//
// } }
// std::cout<<"after down:" + s <<std::endl; std::cout<<"after up:" + s <<std::endl;
//
// count = 0; count = 0;
// for(int i = 0; i < s.length(); i++) { for(int i = 0; i < s.length(); i++) {
// count++; if(s[i] != cursor) {
// if((count ==21) && (s[i]=='\n')){ count++;
// for(int n=i; n < s.length();n++){ }
// s[n] = s[n+1]; if((count ==22)){
// } for(int n=i; n < s.length();n++){
// s = s.substr(0,s.length()-1); s[n] = s[n+1];
// } }
// } s = s.substr(0,s.length()-1);
// std::cout<<"delect enter:" + s <<std::endl;
// count =1;
// }
//} }
std::cout<<"delect enter:" + s <<std::endl;
}