move down

This commit is contained in:
yukun 2019-12-20 17:04:21 +01:00
parent 53f0d3d033
commit cfe0e7fad2
2 changed files with 116 additions and 103 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

@ -140,16 +140,18 @@ void Terminal::movedown() {
if (s[i] == '\n') { if (s[i] == '\n') {
count = 0; count = 0;
} }
else {if(s[i]!=cursor) else {
if(s[i]!=cursor)
count++; count++;
} }
if(count == 21){ if(count == 22){
s = s + s[s.length() - 1]; s = s + s[s.length() - 1];
int x = s.length() - 1; int x = s.length() - 1;
for(; x > i; x--){ for(; x > i; x--){
s[x] = s[x-1]; s[x] = s[x-1];
} }
s[x] = '\n'; s[x] = '\n';
count = 0;
} }
} }
std::cout<<"plus enter:" + s <<std::endl; std::cout<<"plus enter:" + s <<std::endl;
@ -216,11 +218,12 @@ void Terminal::movedown() {
count = 0; count = 0;
for(int i = 0; i < s.length(); i++) { for(int i = 0; i < s.length(); i++) {
count++; count++;
if((count ==21) && (s[i]=='\n')){ 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;
} }
} }
std::cout<<"delect enter:" + s <<std::endl; std::cout<<"delect enter:" + s <<std::endl;
@ -229,96 +232,106 @@ 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 {if(s[i]!=cursor)
count++; // count++;
} // }
if(count == 21){ // if(count == 21){
s = s + s[s.length() - 1]; // s = s + s[s.length() - 1];
int x = s.length() - 1; // int x = s.length() - 1;
for(; x > i; x--){ // for(; x > i; x--){
s[x] = s[x-1]; // s[x] = s[x-1];
} // }
s[x] = '\n'; // s[x] = '\n';
} // }
} // }
std::cout<<"plus enter:" + s <<std::endl; // std::cout<<"plus enter:" + s <<std::endl;
int cursorposition = s.find(cursor); // int cursorposition = s.find(cursor);
int aftercursorenter1 = s.find('\n',cursorposition); // int aftercursorenter1 = s.find('\n',cursorposition);
int beforecursorenter1 = cursorposition - 1; // int beforecursorenter1 = cursorposition - 1;
do { //
if (s[beforecursorenter1] != '\n') { // do {
beforecursorenter1--; // if (s[beforecursorenter1] != '\n') {
} else { // beforecursorenter1--;
break; // } else {
} // break;
} while (beforecursorenter1 >= 0); // }
std::cout<<"cursorpositon:" + std::to_string(cursorposition)<<std::endl; // } while (beforecursorenter1 >= 0);
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<<"aftercursorenter1:" + std::to_string(aftercursorenter1)<<std::endl;
if(beforecursorenter1 != s.npos) { // std::cout<<"beforecursorenter:" + std::to_string(beforecursorenter1)<<std::endl;
int beforercursorenter2 = s.find('\n', aftercursorenter1 + 1); // if(beforecursorenter1 != s.npos) {
std::cout<<"aftercursorenter2:" + std::to_string(aftercursorenter2)<<std::endl; // int beforecursorenter2 =beforecursorenter1 -1;
if(aftercursorenter2 != s.npos){ // do {
std::cout<<"enter the loop & aftercursorenter2 !=s.npos" <<std::endl; // if (s[beforecursorenter2] != '\n') {
if((aftercursorenter2 - aftercursorenter1) >= (cursorposition - beforcursorenter)) { // beforecursorenter2--;
for(int newcursorposition = cursorposition;newcursorposition < (aftercursorenter1 + cursorposition -beforcursorenter -1);newcursorposition++){ // } else {
s[newcursorposition] = s[newcursorposition + 1]; // break;
} // }
s[aftercursorenter1 + cursorposition - beforcursorenter -1] = cursor; // } while (beforecursorenter2 >= 0);
} //
else{ //
for(int newcursorposition = cursorposition;newcursorposition < (aftercursorenter2); newcursorposition++){ // std::cout<<"aftercursorenter2:" + std::to_string(aftercursorenter2)<<std::endl;
s[newcursorposition] = s[newcursorposition + 1]; // if(aftercursorenter2 != s.npos){
} // std::cout<<"enter the loop & aftercursorenter2 !=s.npos" <<std::endl;
s[aftercursorenter2] = cursor; // if((aftercursorenter2 - aftercursorenter1) >= (cursorposition - beforcursorenter)) {
} // for(int newcursorposition = cursorposition;newcursorposition < (aftercursorenter1 + cursorposition -beforcursorenter -1);newcursorposition++){
// s[newcursorposition] = s[newcursorposition + 1];
} // }
else{ // s[aftercursorenter1 + cursorposition - beforcursorenter -1] = cursor;
std::cout<<"enter the loop & aftercursorenter2 ==s.npos" <<std::endl; // }
std::cout<<"elsecursorpositon:" + std::to_string(cursorposition)<<std::endl; // else{
std::cout<<"elseaftercursorenter1:" + std::to_string(aftercursorenter1)<<std::endl; // for(int newcursorposition = cursorposition;newcursorposition < (aftercursorenter2); newcursorposition++){
std::cout<<"elsebeforecursorenter:" + std::to_string(beforcursorenter)<<std::endl; // s[newcursorposition] = s[newcursorposition + 1];
if((s.length()- 1 - aftercursorenter1) >= (cursorposition - beforcursorenter)) { // }
std::cout<<"enter the loop if" <<std::endl; // s[aftercursorenter2] = cursor;
for(int newcursorposition=cursorposition; newcursorposition < (aftercursorenter1 + cursorposition -beforcursorenter); newcursorposition++){ // }
s[newcursorposition] = s[newcursorposition + 1]; //
std::cout<<"forcursorpositon:" + std::to_string(cursorposition)<<std::endl; // }
} // else{
s[aftercursorenter1 + cursorposition - beforcursorenter ] = cursor; // std::cout<<"enter the loop & aftercursorenter2 ==s.npos" <<std::endl;
std::cout<<"new cursorposition" + std::to_string(aftercursorenter1 + cursorposition - beforcursorenter -1) <<std::endl; // std::cout<<"elsecursorpositon:" + std::to_string(cursorposition)<<std::endl;
std::cout<<"delect enter:" + s <<std::endl; // std::cout<<"elseaftercursorenter1:" + std::to_string(aftercursorenter1)<<std::endl;
} // std::cout<<"elsebeforecursorenter:" + std::to_string(beforcursorenter)<<std::endl;
else{ // if((s.length()- 1 - aftercursorenter1) >= (cursorposition - beforcursorenter)) {
std::cout<<"enter the loop else" <<std::endl; // std::cout<<"enter the loop if" <<std::endl;
for(int newcursorposition = cursorposition;newcursorposition < (s.length() -1); newcursorposition++){ // for(int newcursorposition=cursorposition; newcursorposition < (aftercursorenter1 + cursorposition -beforcursorenter); newcursorposition++){
s[newcursorposition] = s[newcursorposition + 1]; // s[newcursorposition] = s[newcursorposition + 1];
} // std::cout<<"forcursorpositon:" + std::to_string(cursorposition)<<std::endl;
std::cout<<"new cursorposition" + std::to_string(s.length() - 1) <<std::endl; // }
s[s.length() - 1] = cursor; // s[aftercursorenter1 + cursorposition - beforcursorenter ] = cursor;
} // std::cout<<"new cursorposition" + std::to_string(aftercursorenter1 + cursorposition - beforcursorenter -1) <<std::endl;
} // std::cout<<"delect enter:" + s <<std::endl;
// }
} // else{
std::cout<<"after down:" + s <<std::endl; // std::cout<<"enter the loop else" <<std::endl;
// for(int newcursorposition = cursorposition;newcursorposition < (s.length() -1); newcursorposition++){
count = 0; // s[newcursorposition] = s[newcursorposition + 1];
for(int i = 0; i < s.length(); i++) { // }
count++; // std::cout<<"new cursorposition" + std::to_string(s.length() - 1) <<std::endl;
if((count ==21) && (s[i]=='\n')){ // s[s.length() - 1] = cursor;
for(int n=i; n < s.length();n++){ // }
s[n] = s[n+1]; // }
} //
s = s.substr(0,s.length()-1); // }
} // std::cout<<"after down:" + s <<std::endl;
} //
std::cout<<"delect enter:" + s <<std::endl; // count = 0;
// for(int i = 0; i < s.length(); i++) {
// count++;
} // if((count ==21) && (s[i]=='\n')){
// for(int n=i; n < s.length();n++){
// s[n] = s[n+1];
// }
// s = s.substr(0,s.length()-1);
// }
// }
// std::cout<<"delect enter:" + s <<std::endl;
//
//
//}