Move debug stuff out of normal code

This commit is contained in:
Wroclaw 2022-05-25 22:01:22 +02:00
parent 6087d88015
commit 3a930d082a
4 changed files with 60 additions and 27 deletions

28
src/debug.cpp Normal file
View file

@ -0,0 +1,28 @@
#ifdef DEBUG
#ifndef __DEBUG_CPP
#define __DEBUG_CPP
/**
* @brief Prints value of pressed key in top left corner.
* Additionally it can get offet to see more presses.
*
* @param _flags keypress flags.
* @param _key char that we got.
*/
void debugKey(cursor::key _key) {
static unsigned short offset = 0;
cursor::savePosition();
cursor::setPosition(1, 1);
// std::cout << " "; // clear debug corner :^)
cursor::setPosition(offset++ * 4 + 1, 1);
std::cout << "\033[31;1m";
// if control flag set
if (_key.special != 0)
std::cout << "^";
std::cout << int(_key.code);
std::cout << "\033[0m";
cursor::restorePosition();
}
#endif
#endif

View file

@ -3,31 +3,10 @@
#include "calculator.cpp"
#include "commands.cpp"
#include "cursor.cpp"
#include "debug.cpp"
#include "getch.h"
#include "terminal.cpp"
/**
* @brief Prints value of pressed key in top left corner.
* Additionally it can get offet to see more presses.
*
* @param _flags keypress flags.
* @param _key char that we got.
* @param offset how much column do you want to spare?
*/
void debugKey(cursor::key _key, short& offset) {
cursor::savePosition();
cursor::setPosition(1, 1);
// std::cout << " "; // clear debug corner :^)
cursor::setPosition(offset++ * 4 + 1, 1);
std::cout << "\033[31;1m";
// if control flag set
if (_key.special != 0)
std::cout << "^";
std::cout << int(_key.code);
std::cout << "\033[0m";
cursor::restorePosition();
}
/**
* @brief Prints entered keys to the console.
*
@ -116,7 +95,6 @@ int main() {
std::setlocale(LC_ALL, "");
std::cout << "type :q to exit, type :h for help\n";
short debugOffset = 0; //debug
bool exit = false; //should we exit?
terminal::state keys;
while (!exit) {
@ -139,7 +117,9 @@ int main() {
terminal::key_right(keys);
break;
default:
// debugKey(input, debugOffset);
#ifdef DEBUG
debugKey(input);
#endif
break;
}
continue;
@ -176,7 +156,9 @@ int main() {
exit |= commands::loop();
break;
default:
// debugKey(input, debugOffset);
#ifdef DEBUG
debugKey(input);
#endif
break;
};
}