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

2
.vscode/launch.json vendored
View file

@ -20,7 +20,7 @@
"ignoreFailures": true "ignoreFailures": true
} }
], ],
"preLaunchTask": "Build c++ project" "preLaunchTask": "Build Debug"
} }
] ]
} }

25
.vscode/tasks.json vendored
View file

@ -2,7 +2,30 @@
"tasks": [ "tasks": [
{ {
"type": "cppbuild", "type": "cppbuild",
"label": "Build c++ project", "label": "Build Debug",
"command": "c++",
"args": [
"-fdiagnostics-color=always",
"-g",
"${workspaceFolder}\\src\\main.cpp",
"-o",
"${workspaceFolder}\\build\\build.exe",
"-DDEBUG"
],
"options": {
"cwd": "${workspaceFolder}\\build\\"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": false
},
},
{
"type": "cppbuild",
"label": "Build \"Release\"",
"command": "c++", "command": "c++",
"args": [ "args": [
"-fdiagnostics-color=always", "-fdiagnostics-color=always",

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 "calculator.cpp"
#include "commands.cpp" #include "commands.cpp"
#include "cursor.cpp" #include "cursor.cpp"
#include "debug.cpp"
#include "getch.h" #include "getch.h"
#include "terminal.cpp" #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. * @brief Prints entered keys to the console.
* *
@ -116,7 +95,6 @@ int main() {
std::setlocale(LC_ALL, ""); std::setlocale(LC_ALL, "");
std::cout << "type :q to exit, type :h for help\n"; std::cout << "type :q to exit, type :h for help\n";
short debugOffset = 0; //debug
bool exit = false; //should we exit? bool exit = false; //should we exit?
terminal::state keys; terminal::state keys;
while (!exit) { while (!exit) {
@ -139,7 +117,9 @@ int main() {
terminal::key_right(keys); terminal::key_right(keys);
break; break;
default: default:
// debugKey(input, debugOffset); #ifdef DEBUG
debugKey(input);
#endif
break; break;
} }
continue; continue;
@ -176,7 +156,9 @@ int main() {
exit |= commands::loop(); exit |= commands::loop();
break; break;
default: default:
// debugKey(input, debugOffset); #ifdef DEBUG
debugKey(input);
#endif
break; break;
}; };
} }