From 3a930d082aab9cce87aac154c0b18eda199b1853 Mon Sep 17 00:00:00 2001 From: Wroclaw Date: Wed, 25 May 2022 22:01:22 +0200 Subject: [PATCH] Move debug stuff out of normal code --- .vscode/launch.json | 2 +- .vscode/tasks.json | 25 ++++++++++++++++++++++++- src/debug.cpp | 28 ++++++++++++++++++++++++++++ src/main.cpp | 32 +++++++------------------------- 4 files changed, 60 insertions(+), 27 deletions(-) create mode 100644 src/debug.cpp diff --git a/.vscode/launch.json b/.vscode/launch.json index 9401465..e772a64 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -20,7 +20,7 @@ "ignoreFailures": true } ], - "preLaunchTask": "Build c++ project" + "preLaunchTask": "Build Debug" } ] } \ No newline at end of file diff --git a/.vscode/tasks.json b/.vscode/tasks.json index 893e657..bf9911e 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -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", diff --git a/src/debug.cpp b/src/debug.cpp new file mode 100644 index 0000000..ec56767 --- /dev/null +++ b/src/debug.cpp @@ -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 \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index ca17c19..c0bc19b 100644 --- a/src/main.cpp +++ b/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,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; }; }