From 6257befb797caeae2f3b110b5318fe5ac0a7218b Mon Sep 17 00:00:00 2001 From: yukun Date: Mon, 6 Jan 2020 15:35:22 +0100 Subject: [PATCH] move down --- main/main.cpp | 12 +-- src/Terminal.cpp | 224 ++++++++++++++++++++++++----------------------- 2 files changed, 122 insertions(+), 114 deletions(-) diff --git a/main/main.cpp b/main/main.cpp index be09017..016d5f9 100644 --- a/main/main.cpp +++ b/main/main.cpp @@ -110,12 +110,12 @@ int main() { 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); -// } + 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 4ff6866..b3e4e42 100644 --- a/src/Terminal.cpp +++ b/src/Terminal.cpp @@ -158,13 +158,13 @@ void Terminal::movedown() { int cursorposition = s.find(cursor); int aftercursorenter1 = s.find('\n',cursorposition); int beforcursorenter = cursorposition - 1; - do { + while (beforcursorenter >= 0){ if (s[beforcursorenter] != '\n') { beforcursorenter--; } else { break; } - } while (beforcursorenter >= 0); + } std::cout<<"cursorpositon:" + std::to_string(cursorposition)<= (cursorposition - beforcursorenter)) { std::cout<<"enter the loop if" < i; x--){ -// s[x] = s[x-1]; -// } -// s[x] = '\n'; -// } -// } -// std::cout<<"plus enter:" + s <= 0); -// std::cout<<"cursorpositon:" + std::to_string(cursorposition)<= 0); -// -// -// std::cout<<"aftercursorenter2:" + std::to_string(aftercursorenter2)<= (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" < i; x--){ + s[x] = s[x-1]; + } + s[x] = '\n'; + count = 0; + } + } + std::cout<<"plus enter:" + s <= 0){ + if (s[beforecursorenter1] != '\n') { + beforecursorenter1--; + } else { + break; + } + } + + std::cout<<"cursorpositon:" + std::to_string(cursorposition)<= 0){ + if (s[beforecursorenter2] != '\n') { + beforecursorenter2--; + } else { + break; + } + } + + + std::cout<<"beforecursorenter2:" + std::to_string(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" <= (cursorposition - beforecursorenter1)) { + std::cout<<"enter the loop if" < (cursorposition -beforecursorenter1 -1); newcursorposition--){ + s[newcursorposition] = s[newcursorposition - 1]; + std::cout<<"forcursorpositon:" + std::to_string(cursorposition)< (beforecursorenter1); newcursorposition--){ + s[newcursorposition] = s[newcursorposition - 1]; + } + std::cout<<"new cursorposition" + std::to_string(beforecursorenter1) <