Move debug stuff out of normal code
This commit is contained in:
parent
6087d88015
commit
2b4cc1bd06
4 changed files with 64 additions and 27 deletions
2
.vscode/launch.json
vendored
2
.vscode/launch.json
vendored
|
@ -20,7 +20,7 @@
|
|||
"ignoreFailures": true
|
||||
}
|
||||
],
|
||||
"preLaunchTask": "Build c++ project"
|
||||
"preLaunchTask": "Build Debug"
|
||||
}
|
||||
]
|
||||
}
|
25
.vscode/tasks.json
vendored
25
.vscode/tasks.json
vendored
|
@ -2,7 +2,30 @@
|
|||
"tasks": [
|
||||
{
|
||||
"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++",
|
||||
"args": [
|
||||
"-fdiagnostics-color=always",
|
||||
|
|
28
src/debug.cpp
Normal file
28
src/debug.cpp
Normal 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.
|
||||
* @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();
|
||||
}
|
||||
|
||||
#endif
|
||||
#endif
|
36
src/main.cpp
36
src/main.cpp
|
@ -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,10 @@ int main() {
|
|||
std::setlocale(LC_ALL, "");
|
||||
std::cout << "type :q to exit, type :h for help\n";
|
||||
|
||||
short debugOffset = 0; //debug
|
||||
#ifdef DEBUG
|
||||
short debugOffset = 0;
|
||||
#endif
|
||||
|
||||
bool exit = false; //should we exit?
|
||||
terminal::state keys;
|
||||
while (!exit) {
|
||||
|
@ -139,7 +121,9 @@ int main() {
|
|||
terminal::key_right(keys);
|
||||
break;
|
||||
default:
|
||||
// debugKey(input, debugOffset);
|
||||
#ifdef DEBUG
|
||||
debugKey(input, debugOffset);
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
continue;
|
||||
|
@ -176,7 +160,9 @@ int main() {
|
|||
exit |= commands::loop();
|
||||
break;
|
||||
default:
|
||||
// debugKey(input, debugOffset);
|
||||
#ifdef DEBUG
|
||||
debugKey(input, debugOffset);
|
||||
#endif
|
||||
break;
|
||||
};
|
||||
}
|
||||
|
|
Reference in a new issue