diff --git a/main/main.cpp b/main/main.cpp index f581430..016d5f9 100644 --- a/main/main.cpp +++ b/main/main.cpp @@ -103,12 +103,19 @@ int main() { vkvm::callEvent(vkvm::EventType::RenderText); } -// if(vkvm::KeyCode::Arrow_Down == keycode){ -// terminal.movedown(); -// std::cout << terminal.getString() << std::endl; -// vkvm::setText(terminal.getString()); -// vkvm::callEvent(vkvm::EventType::RenderText); -// } + if(vkvm::KeyCode::Arrow_Down == keycode){ + terminal.movedown(); + std::cout << terminal.getString() << std::endl; + vkvm::setText(terminal.getString()); + vkvm::callEvent(vkvm::EventType::RenderText); + } + + if(vkvm::KeyCode::Arrow_Up == keycode){ + terminal.moveup(); + std::cout << terminal.getString() << std::endl; + vkvm::setText(terminal.getString()); + vkvm::callEvent(vkvm::EventType::RenderText); + } diff --git a/src/Terminal.cpp b/src/Terminal.cpp index d71055f..7149c3d 100644 --- a/src/Terminal.cpp +++ b/src/Terminal.cpp @@ -80,62 +80,245 @@ void Terminal::moveright() { } void Terminal::movedown() { - std::string news=""; - int i = s.find(cursor); - s.erase(i, 1); +// std::string news=""; +// int i = s.find(cursor); +// s.erase(i, 1); +// +// std::vector> vec(100,std::vector(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]<= 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)<> vec(100,std::vector(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]< i; x--){ + s[x] = s[x-1]; + } + s[x] = '\n'; + } + } + std::cout<<"plus enter:" + s <= 0); + std::cout<<"cursorpositon:" + std::to_string(cursorposition)<= (cursorposition - beforcursorenter)) { + for(int newcursorposition = cursorposition;newcursorposition < (aftercursorenter1 + cursorposition -beforcursorenter -1);newcursorposition++){ + s[newcursorposition] = s[newcursorposition + 1]; + } + s[aftercursorenter1 + cursorposition - beforcursorenter -1] = cursor; } - else { - vec[n][m] = s[sum]; - break; + else{ + for(int newcursorposition = cursorposition;newcursorposition < (aftercursorenter2); newcursorposition++){ + s[newcursorposition] = s[newcursorposition + 1]; + } + s[aftercursorenter2] = cursor; + } + + } + else{ + std::cout<<"enter the loop & aftercursorenter2 ==s.npos" <= (cursorposition - beforcursorenter)) { + std::cout<<"enter the loop if" <= cursorcolumn){ - cursorrow++; + 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); + } } - else if(vec[cursorrow+1].size() >=1){ - cursorrow++; - cursorcolumn = vec[cursorrow].size()-1; - } - std::cout<<"after" + std::to_string(cursorrow) + ' '+ std::to_string(cursorcolumn)< i; x--){ + s[x] = s[x-1]; + } + s[x] = '\n'; + } + } + std::cout<<"plus enter:" + s <= 0); + std::cout<<"cursorpositon:" + std::to_string(cursorposition)<= (cursorposition - beforcursorenter)) { + for(int newcursorposition = cursorposition;newcursorposition < (aftercursorenter1 + cursorposition -beforcursorenter -1);newcursorposition++){ + s[newcursorposition] = s[newcursorposition + 1]; + } + s[aftercursorenter1 + cursorposition - beforcursorenter -1] = cursor; + } + else{ + for(int newcursorposition = cursorposition;newcursorposition < (aftercursorenter2); newcursorposition++){ + s[newcursorposition] = s[newcursorposition + 1]; + } + s[aftercursorenter2] = cursor; + } + + } + else{ + std::cout<<"enter the loop & aftercursorenter2 ==s.npos" <= (cursorposition - beforcursorenter)) { + std::cout<<"enter the loop if" <