terminal/main/main.cpp

143 lines
5.3 KiB
C++

#include "../src/Terminal.hpp"
#include "internal.hpp"
#include "vkvm.hpp"
#include <iostream>
#include <unistd.h>
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)){
terminal.shiftpressed();
}
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)){
int status = terminal.getstatus();
char ch;
if(status == 0){
ch = keycode - vkvm::KeyCode::A + 'a';
}
else{
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 + ' ';
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 + ' ';
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 + ' ';
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){
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;
vkvm::setText(terminal.getString());
vkvm::callEvent(vkvm::EventType::RenderText);
}
if(vkvm::KeyCode::Arrow_Right == keycode){
terminal.moveright();
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);
}
});
vkvm::registerEvent(vkvm::KeyUp, [&terminal]() {
vkvm::KeyCode keycode = vkvm::getLastPressedKey();
if(((vkvm::KeyCode::ShiftLeft) == keycode) ||((vkvm::KeyCode::ShiftRight) == keycode)){
terminal.shiftup();
}
// char ch = keycode - (vkvm::KeyCode::A & 0xfff) + 'A';
// std::cout << ch << std::endl;
// terminal.setString(ch);
// vkvm::setText(terminal.getString());
// std::cout<< vkvm::getText()<< std::endl;
// vkvm::callEvent(vkvm::EventType::RenderText);
});
while(1){
sleep(0.1);
}
}