Merge remote-tracking branch 'origin/dev' into dev
# Conflicts: # CMakeLists.txt # main/main.cpp
This commit is contained in:
commit
06bd6013a5
@ -9,84 +9,104 @@ int main() {
|
||||
vkvm::initialize(0);
|
||||
|
||||
Terminal terminal = Terminal();
|
||||
terminal.init();
|
||||
std::cout << terminal.getString() << std::endl;
|
||||
|
||||
vkvm::registerEvent(vkvm::KeyDown, [&terminal]() {
|
||||
vkvm::KeyCode keycode = vkvm::getLastPressedKey();
|
||||
std::cout << keycode << std::endl;
|
||||
|
||||
if(((vkvm::KeyCode::ShiftLeft) == keycode) ||((vkvm::KeyCode::ShiftRight) == keycode)){
|
||||
if((vkvm::KeyCode::ShiftLeft == keycode) ||(vkvm::KeyCode::ShiftRight == keycode)){
|
||||
terminal.shiftpressed();
|
||||
}
|
||||
|
||||
if(((vkvm::KeyCode::Zero) <= keycode) && (keycode <= (vkvm::Nine))){
|
||||
char ch = keycode - (vkvm::KeyCode::Zero) + '0';
|
||||
if((vkvm::KeyCode::Zero <= keycode) && (keycode <=vkvm::Nine)){
|
||||
char ch = keycode - vkvm::KeyCode::Zero + '0';
|
||||
std::cout << ch << std::endl;
|
||||
terminal.setString(ch);
|
||||
vkvm::setText(terminal.getString());
|
||||
std::cout << terminal.getString() << std::endl;
|
||||
std::cout<< vkvm::getText()<< std::endl;
|
||||
vkvm::callEvent(vkvm::EventType::RenderText);
|
||||
}
|
||||
|
||||
if(((vkvm::KeyCode::A) <= keycode) && (keycode <= (vkvm::KeyCode::Z))){
|
||||
if((vkvm::KeyCode::A <= keycode) && (keycode <= vkvm::KeyCode::Z)){
|
||||
int status = terminal.getstatus();
|
||||
char ch;
|
||||
if(status == 0){
|
||||
ch = keycode - (vkvm::KeyCode::A) + 'a';
|
||||
ch = keycode - vkvm::KeyCode::A + 'a';
|
||||
}
|
||||
else{
|
||||
ch = keycode - (vkvm::KeyCode::A) + 'A';
|
||||
ch = keycode - vkvm::KeyCode::A + 'A';
|
||||
}
|
||||
std::cout << ch << std::endl;
|
||||
terminal.setString(ch);
|
||||
vkvm::setText(terminal.getString());
|
||||
std::cout << terminal.getString() << std::endl;
|
||||
std::cout<< vkvm::getText()<< std::endl;
|
||||
vkvm::callEvent(vkvm::EventType::RenderText);
|
||||
}
|
||||
|
||||
if((vkvm::KeyCode::Space) == keycode){
|
||||
char ch = keycode - (vkvm::KeyCode::Space) + ' ';
|
||||
if(vkvm::KeyCode::Space == keycode){
|
||||
char ch = keycode - vkvm::KeyCode::Space + ' ';
|
||||
std::cout << ch << std::endl;
|
||||
terminal.setString(ch);
|
||||
vkvm::setText(terminal.getString());
|
||||
std::cout << terminal.getString() << std::endl;
|
||||
std::cout<< vkvm::getText()<< std::endl;
|
||||
vkvm::callEvent(vkvm::EventType::RenderText);
|
||||
}
|
||||
|
||||
if((vkvm::KeyCode::Backspace) == keycode){
|
||||
char ch = keycode - (vkvm::KeyCode::Backspace) + ' ';
|
||||
if(vkvm::KeyCode::Backspace == keycode){
|
||||
char ch = keycode - vkvm::KeyCode::Backspace + ' ';
|
||||
std::cout << ch << std::endl;
|
||||
terminal.subString();
|
||||
vkvm::setText(terminal.getString());
|
||||
std::cout << terminal.getString() << std::endl;
|
||||
std::cout<< vkvm::getText()<< std::endl;
|
||||
vkvm::callEvent(vkvm::EventType::RenderText);
|
||||
}
|
||||
|
||||
if((vkvm::KeyCode::Tab) == keycode){
|
||||
char ch = keycode - (vkvm::KeyCode::Tab) + ' ';
|
||||
if(vkvm::KeyCode::Tab == keycode){
|
||||
char ch = keycode - vkvm::KeyCode::Tab + ' ';
|
||||
for(int i = 0; i < 3; i++) {
|
||||
std::cout << ch << std::endl;
|
||||
terminal.setString(ch);
|
||||
}
|
||||
vkvm::setText(terminal.getString());
|
||||
std::cout << terminal.getString() << std::endl;
|
||||
std::cout<< vkvm::getText()<< std::endl;
|
||||
vkvm::callEvent(vkvm::EventType::RenderText);
|
||||
}
|
||||
|
||||
if((vkvm::KeyCode::Enter) == keycode){
|
||||
if(vkvm::KeyCode::Enter == keycode){
|
||||
char ch = '\n';
|
||||
std::cout << ch << std::endl;
|
||||
terminal.setString(ch);
|
||||
vkvm::setText(terminal.getString());
|
||||
std::cout << terminal.getString() << std::endl;
|
||||
std::cout<< vkvm::getText()<< std::endl;
|
||||
vkvm::callEvent(vkvm::EventType::RenderText);
|
||||
}
|
||||
|
||||
if(vkvm::KeyCode::Arrow_Left == keycode){
|
||||
terminal.moveleft();
|
||||
std::cout << terminal.getString() << std::endl;
|
||||
}
|
||||
|
||||
if(vkvm::KeyCode::Arrow_Right == keycode){
|
||||
terminal.moveright();
|
||||
std::cout << terminal.getString() << std::endl;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
});
|
||||
|
||||
vkvm::registerEvent(vkvm::KeyUp, [&terminal]() {
|
||||
vkvm::KeyCode keycode = vkvm::getLastPressedKey();
|
||||
if(((vkvm::KeyCode::ShiftLeft) == keycode) ||((vkvm::KeyCode::ShiftRight) == keycode)){
|
||||
if(((vkvm::KeyCode::ShiftLeft & 0xfff) == keycode) ||((vkvm::KeyCode::ShiftRight & 0xfff) == keycode)){
|
||||
terminal.shiftup();
|
||||
}
|
||||
// char ch = keycode - (vkvm::KeyCode::A & 0xfff) + 'A';
|
||||
|
@ -1,6 +1,7 @@
|
||||
//
|
||||
// Created by yukun on 29.11.19.
|
||||
//
|
||||
#include <iostream>
|
||||
#include "vkvm.hpp"
|
||||
#include "Terminal.h"
|
||||
|
||||
@ -8,12 +9,41 @@ std::string Terminal::getString() {
|
||||
return s;
|
||||
}
|
||||
|
||||
void Terminal::init(){
|
||||
s = s + cursor;
|
||||
}
|
||||
|
||||
void Terminal::setString(char c) {
|
||||
s = s + c;
|
||||
// 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;
|
||||
std::cout << "else1 " + s << std::endl;
|
||||
s[s.length()-2] = c;
|
||||
std::cout << "else2 " + s << std::endl;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
void Terminal::subString(){
|
||||
s = s.substr(0, s.length() - 1);
|
||||
// if(s.length() > 1)
|
||||
// s.erase(s.end() - 1);
|
||||
// s.erase(s.end() - 1);
|
||||
// s = s + cursor;
|
||||
int i = s.find(cursor);
|
||||
s.erase(i-1, 1);
|
||||
|
||||
}
|
||||
|
||||
void Terminal::shiftpressed() {
|
||||
@ -30,3 +60,28 @@ int Terminal::getstatus() {
|
||||
return status;
|
||||
}
|
||||
|
||||
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() {
|
||||
|
||||
}
|
||||
|
||||
void Terminal::moveup() {
|
||||
|
||||
}
|
||||
|
@ -9,15 +9,20 @@
|
||||
|
||||
class Terminal {
|
||||
public:
|
||||
void init();
|
||||
std::string getString();
|
||||
void setString(char c);
|
||||
void subString();
|
||||
void shiftpressed();
|
||||
void shiftup();
|
||||
int getstatus();
|
||||
|
||||
void moveleft();
|
||||
void moveright();
|
||||
void moveup();
|
||||
void movedown();
|
||||
private:
|
||||
std::string s="";
|
||||
int status = 0;
|
||||
char cursor = -127;
|
||||
};
|
||||
#endif //TERMINAL_TERMINAL_H
|
||||
|
Loading…
Reference in New Issue
Block a user