Skip to content

Commit

Permalink
Merge pull request #1 from AOSXAP/main
Browse files Browse the repository at this point in the history
better version
  • Loading branch information
AOSXAP authored Aug 26, 2024
2 parents ec4c2ca + 0f7cc3e commit 38bb1a0
Show file tree
Hide file tree
Showing 12 changed files with 2,954 additions and 1,953 deletions.
4 changes: 2 additions & 2 deletions binding.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
"targets": [
{
"target_name": "reqless",
"cflags!": [ "-fno-exceptions" ],
"cflags_cc!": [ "-fno-exceptions", "-lssl", "-lcrypto" ],
"cflags!": [ "-fno-exceptions", "-g" ],
"cflags_cc!": [ "-fno-exceptions", "-lssl", "-lcrypto", "-g" ],
"sources": [ "reqless.cc" ],
"include_dirs": [
"<!@(node -p \"require('node-addon-api').include\")"
Expand Down
1 change: 0 additions & 1 deletion build.sh

This file was deleted.

22 changes: 11 additions & 11 deletions core/build.sh
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
if [ "$1" == "" ]; then
if [ "$OSTYPE" == "win32" ] || [ "$OSTYPE" == "msys" ]; then
g++ core.cpp -o core.exe -I C:/OpenSSL/include -L C:/OpenSSL/lib -lssl -lcrypto -lws2_32 -lgdi32 && ./core.exe
else
g++ core.cpp -o core -lssl -lcrypto && ./core
fi
if [ "$OSTYPE" == "win32" ] || [ "$OSTYPE" == "msys" ]; then
g++ -g core.cpp -o core.exe -I C:/OpenSSL/include -L C:/OpenSSL/lib -lssl -lcrypto -lws2_32 -lgdi32 && ./core.exe
else
g++ -g core.cpp -o core -lssl -lcrypto && ./core
fi
elif [ "$1" == "code" ]; then
if [ "$2" == "original" ]; then
git ls-files | grep -v -E "package.json|package-lock.json|node/build|.gitignore" | xargs wc -l
else
git ls-files | xargs wc -l
fi
fi
if [ "$2" == "original" ]; then
git ls-files | grep -v -E "package.json|package-lock.json|node/build|.gitignore" | xargs wc -l
else
git ls-files | xargs wc -l
fi
fi
118 changes: 53 additions & 65 deletions core/colors.h
Original file line number Diff line number Diff line change
@@ -1,70 +1,58 @@
#pragma once

#include <ostream>
#include <iostream>
#include <unordered_map>
#include <ostream>
#include <sstream>
#include <unordered_map>

namespace Color
{
std::unordered_map<std::string, int> ColorMapLinux
({
{"red" , 31},
{"blue" , 34},
{"green" , 32},
{"original", 39}
});
std::unordered_map<std::string, int> ColorMapWin
({
{"red" , 12},
{"blue" , 9},
{"green" , 10},
{"original", 14}
});

#if defined(_WIN32)
void CPRINT(std::string color , std::string print)
{
int color_code;

std::unordered_map<std::string,int>::iterator itr = ColorMapWin.find(color);

if(itr == ColorMapWin.end()) color_code = 14;
else color_code = itr->second;

HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleTextAttribute(hConsole, color_code);
cout << print << endl;
SetConsoleTextAttribute(hConsole, 7);
}
#else
std::string reset = "\033[0;39m\033[0m\n\n";

template <class T>
void PREPSTREAMS
(
std::stringstream &s, std::stringstream &b , std::stringstream &e,
int color_code , T print
)
{
b << s.rdbuf() << ";" << color_code << "m" << print;
e << s.rdbuf() << "m"; b << e.rdbuf();
}

template <class T>
void CPRINT(std::string color , T print)
{
int color_code;

std::unordered_map<std::string,int>::iterator itr = ColorMapLinux.find(color);

if(itr == ColorMapLinux.end()) color_code = 39;
else color_code = itr->second;

std::stringstream ss("\033[0") , begin , end;
PREPSTREAMS(ss , begin , end , color_code , print);

std::cout << begin.rdbuf() << reset;
}
#endif
}
namespace Color {
std::unordered_map<std::string, int>
ColorMapLinux({{"red", 31}, {"blue", 34}, {"green", 32}, {"original", 39}});
std::unordered_map<std::string, int>
ColorMapWin({{"red", 12}, {"blue", 9}, {"green", 10}, {"original", 14}});

#if defined(_WIN32)
void CPRINT(std::string color, std::string print) {
int color_code;

std::unordered_map<std::string, int>::iterator itr = ColorMapWin.find(color);

if (itr == ColorMapWin.end())
color_code = 14;
else
color_code = itr->second;

HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleTextAttribute(hConsole, color_code);
cout << print << endl;
SetConsoleTextAttribute(hConsole, 7);
}
#else
std::string reset = "\033[0;39m\033[0m\n\n";

template <class T>
void PREPSTREAMS(std::stringstream &s, std::stringstream &b,
std::stringstream &e, int color_code, T print) {
b << s.rdbuf() << ";" << color_code << "m" << print;
e << s.rdbuf() << "m";
b << e.rdbuf();
}

template <class T> void CPRINT(std::string color, T print) {
int color_code;

std::unordered_map<std::string, int>::iterator itr =
ColorMapLinux.find(color);

if (itr == ColorMapLinux.end())
color_code = 39;
else
color_code = itr->second;

std::stringstream ss("\033[0"), begin, end;
PREPSTREAMS(ss, begin, end, color_code, print);

std::cout << begin.rdbuf() << reset;
}
#endif
} // namespace Color
Loading

0 comments on commit 38bb1a0

Please sign in to comment.