terminal/main/main.cpp

143 lines
5.3 KiB
C++
Raw Normal View History

2020-01-08 19:19:26 +01:00
#include "../src/Terminal.hpp"
#include "internal.hpp"
2019-12-02 14:27:11 +01:00
#include "vkvm.hpp"
#include <iostream>
#include <unistd.h>
int main() {
2019-12-02 14:27:11 +01:00
vkvm::initialize(0);
2019-12-12 11:59:07 +01:00
Terminal terminal = Terminal();
2019-12-18 13:26:59 +01:00
terminal.init();
std::cout << terminal.getString() << std::endl;
2019-12-12 11:59:07 +01:00
vkvm::registerEvent(vkvm::KeyDown, [&terminal]() {
vkvm::KeyCode keycode = vkvm::getLastPressedKey();
std::cout << keycode << std::endl;
2019-12-18 13:26:59 +01:00
if((vkvm::KeyCode::ShiftLeft == keycode) ||(vkvm::KeyCode::ShiftRight == keycode)){
2019-12-12 11:59:07 +01:00
terminal.shiftpressed();
}
2019-12-18 13:26:59 +01:00
if((vkvm::KeyCode::Zero <= keycode) && (keycode <=vkvm::Nine)){
char ch = keycode - vkvm::KeyCode::Zero + '0';
2019-12-12 11:59:07 +01:00
std::cout << ch << std::endl;
terminal.setString(ch);
vkvm::setText(terminal.getString());
2019-12-18 13:26:59 +01:00
std::cout << terminal.getString() << std::endl;
2019-12-12 11:59:07 +01:00
std::cout<< vkvm::getText()<< std::endl;
vkvm::callEvent(vkvm::EventType::RenderText);
}
2019-12-18 13:26:59 +01:00
if((vkvm::KeyCode::A <= keycode) && (keycode <= vkvm::KeyCode::Z)){
2019-12-12 11:59:07 +01:00
int status = terminal.getstatus();
char ch;
if(status == 0){
2019-12-18 13:26:59 +01:00
ch = keycode - vkvm::KeyCode::A + 'a';
2019-12-12 11:59:07 +01:00
}
else{
2019-12-18 13:26:59 +01:00
ch = keycode - vkvm::KeyCode::A + 'A';
2019-12-12 11:59:07 +01:00
}
std::cout << ch << std::endl;
terminal.setString(ch);
vkvm::setText(terminal.getString());
2019-12-18 13:26:59 +01:00
std::cout << terminal.getString() << std::endl;
2019-12-12 11:59:07 +01:00
std::cout<< vkvm::getText()<< std::endl;
vkvm::callEvent(vkvm::EventType::RenderText);
}
2019-12-18 13:26:59 +01:00
if(vkvm::KeyCode::Space == keycode){
char ch = keycode - vkvm::KeyCode::Space + ' ';
2019-12-12 11:59:07 +01:00
std::cout << ch << std::endl;
terminal.setString(ch);
vkvm::setText(terminal.getString());
2019-12-18 13:26:59 +01:00
std::cout << terminal.getString() << std::endl;
2019-12-12 11:59:07 +01:00
std::cout<< vkvm::getText()<< std::endl;
vkvm::callEvent(vkvm::EventType::RenderText);
}
2019-12-18 13:26:59 +01:00
if(vkvm::KeyCode::Backspace == keycode){
char ch = keycode - vkvm::KeyCode::Backspace + ' ';
2019-12-12 11:59:07 +01:00
std::cout << ch << std::endl;
terminal.subString();
vkvm::setText(terminal.getString());
2019-12-18 13:26:59 +01:00
std::cout << terminal.getString() << std::endl;
2019-12-12 11:59:07 +01:00
std::cout<< vkvm::getText()<< std::endl;
vkvm::callEvent(vkvm::EventType::RenderText);
}
2019-12-18 13:26:59 +01:00
if(vkvm::KeyCode::Tab == keycode){
char ch = keycode - vkvm::KeyCode::Tab + ' ';
2019-12-12 11:59:07 +01:00
for(int i = 0; i < 3; i++) {
std::cout << ch << std::endl;
terminal.setString(ch);
}
vkvm::setText(terminal.getString());
2019-12-18 13:26:59 +01:00
std::cout << terminal.getString() << std::endl;
2019-12-12 11:59:07 +01:00
std::cout<< vkvm::getText()<< std::endl;
vkvm::callEvent(vkvm::EventType::RenderText);
}
2019-12-18 13:26:59 +01:00
if(vkvm::KeyCode::Enter == keycode){
2019-12-12 11:59:07 +01:00
char ch = '\n';
std::cout << ch << std::endl;
terminal.setString(ch);
vkvm::setText(terminal.getString());
2019-12-18 13:26:59 +01:00
std::cout << terminal.getString() << std::endl;
2019-12-12 11:59:07 +01:00
std::cout<< vkvm::getText()<< std::endl;
vkvm::callEvent(vkvm::EventType::RenderText);
}
2019-12-18 13:26:59 +01:00
if(vkvm::KeyCode::Arrow_Left == keycode){
terminal.moveleft();
std::cout << terminal.getString() << std::endl;
vkvm::setText(terminal.getString());
vkvm::callEvent(vkvm::EventType::RenderText);
2019-12-18 13:26:59 +01:00
}
if(vkvm::KeyCode::Arrow_Right == keycode){
terminal.moveright();
std::cout << terminal.getString() << std::endl;
vkvm::setText(terminal.getString());
vkvm::callEvent(vkvm::EventType::RenderText);
2019-12-18 13:26:59 +01:00
}
2019-12-20 16:13:24 +01:00
if(vkvm::KeyCode::Arrow_Down == keycode){
terminal.movedown();
std::cout << terminal.getString() << std::endl;
vkvm::setText(terminal.getString());
vkvm::callEvent(vkvm::EventType::RenderText);
}
2020-01-06 15:35:22 +01:00
if(vkvm::KeyCode::Arrow_Up == keycode){
terminal.moveup();
std::cout << terminal.getString() << std::endl;
vkvm::setText(terminal.getString());
vkvm::callEvent(vkvm::EventType::RenderText);
}
2019-12-18 13:26:59 +01:00
2019-12-12 11:59:07 +01:00
});
vkvm::registerEvent(vkvm::KeyUp, [&terminal]() {
vkvm::KeyCode keycode = vkvm::getLastPressedKey();
2019-12-18 14:05:03 +01:00
if(((vkvm::KeyCode::ShiftLeft) == keycode) ||((vkvm::KeyCode::ShiftRight) == keycode)){
2019-12-12 11:59:07 +01:00
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);
2019-12-02 14:46:30 +01:00
});
2019-12-12 11:59:07 +01:00
while(1){
sleep(0.1);
2019-12-02 14:27:11 +01:00
}
}