Skip to content

Commit

Permalink
added colors
Browse files Browse the repository at this point in the history
  • Loading branch information
DeaSTL committed Nov 1, 2023
1 parent fab6de1 commit 2c71bef
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 11 deletions.
8 changes: 8 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,17 @@ FetchContent_Declare(
GIT_REPOSITORY "https://github.com/curl/curl.git"
GIT_TAG "curl-8_3_0"
)
FetchContent_Declare(
termcolor
GIT_REPOSITORY "https://github.com/ikalnytskyi/termcolor.git"
GIT_TAG "v2.1.0"
)

FetchContent_MakeAvailable(nlohmann_json)
FetchContent_MakeAvailable(cxxopts)
FetchContent_MakeAvailable(tomlplusplus)
FetchContent_MakeAvailable(curl)
FetchContent_MakeAvailable(termcolor)



Expand Down Expand Up @@ -99,6 +105,8 @@ target_link_libraries(${PROJECT_NAME} curl)
target_link_libraries(${PROJECT_NAME} cxxopts)
target_link_libraries(${PROJECT_NAME} nlohmann_json)
target_link_libraries(${PROJECT_NAME} tomlplusplus::tomlplusplus)
target_link_libraries(${PROJECT_NAME} termcolor::termcolor)

set(SOURCE_DIR src)
set(BUILD_DIR build)
set_target_properties(cmaker PROPERTIES RUNTIME_OUTPUT_DIRECTORY build)
Expand Down
12 changes: 6 additions & 6 deletions install_manifest.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@
/usr/local/bin/curl-config
/usr/local/lib/pkgconfig/libcurl.pc
/usr/local/include/curl/multi.h
/usr/local/include/curl/stdcheaders.h
/usr/local/include/curl/curlver.h
/usr/local/include/curl/urlapi.h
/usr/local/include/curl/typecheck-gcc.h
/usr/local/include/curl/options.h
/usr/local/include/curl/curl.h
/usr/local/include/curl/urlapi.h
/usr/local/include/curl/header.h
/usr/local/include/curl/websockets.h
/usr/local/include/curl/mprintf.h
/usr/local/include/curl/curlver.h
/usr/local/include/curl/system.h
/usr/local/include/curl/typecheck-gcc.h
/usr/local/include/curl/easy.h
/usr/local/include/curl/stdcheaders.h
/usr/local/include/curl/curl.h
/usr/local/include/curl/mprintf.h
/usr/local/lib/cmake/CURL/CURLTargets.cmake
/usr/local/lib/cmake/CURL/CURLTargets-release.cmake
/usr/local/lib/cmake/CURL/CURLConfigVersion.cmake
Expand Down
1 change: 1 addition & 0 deletions src/Command/Command.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ namespace Command {
std::string url;
std::vector<std::string> versions;
std::string target_link;
std::string description;
int score;
} packageResult;

Expand Down
5 changes: 3 additions & 2 deletions src/Command/CommandAdd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <string>
#include "../Utils/General.hpp"
#include <cmath>
#include <termcolor/termcolor.hpp>

namespace Command {
using nlohmann::json;
Expand Down Expand Up @@ -91,14 +92,14 @@ namespace Command {
std::string version = "";

for(size_t i = 0; i < versions.size(); i++){
std::cout << "[" << i << "]" << versions[i] << std::endl;
std::cout << "[" << termcolor::green << i << termcolor::white << "]" << versions[i] << std::endl;
if (versions[i] == "master" || versions[i] == "main" || versions[i] == "stable"){
version = versions[i];
}
}


std::cout << "Select a version to install [" + version + "] : ";
std::cout << "Select a version to install [" << termcolor::green << version << termcolor::white << "] : ";
std::string versionInput;
std::cin >> versionInput;

Expand Down
25 changes: 22 additions & 3 deletions src/Command/SearchPackage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
#include <curl/easy.h>
#include <nlohmann/json.hpp>
#include "../Utils/General.hpp"
#include "termcolor/termcolor.hpp"
#include <termcolor/termcolor.hpp>



Expand Down Expand Up @@ -40,20 +42,33 @@ namespace Command {
delete[] curr;
return result;
}
int compareDescription(packageResult& package, std::string& query){
int score = 0;
std::vector<std::string> queryTokens = Utils::split(query, ' ');
for(std::string token: queryTokens){
if(package.description.find(token) != std::string::npos){
score += 1;
}
}
return score;
}
std::vector<packageResult> calculatePackageScores(std::vector<std::string> queryTokens){
std::vector<packageResult> results;
json rawIndex = fetchIndex();
int lengthDiffAbs = 0;
for(std::string query: queryTokens){
for(json package: rawIndex){
//TODO: add description that can be searched
results.push_back({
results.push_back(packageResult{
.name = package["name"],
.url = package["git"],
.versions = package["versions"],
.target_link = package.contains("target_link")
? package["target_link"]
: package["name"],
.description = package.contains("description")
? package["description"]
: "",
.score = 0
});
//if it is an exact match
Expand All @@ -68,6 +83,10 @@ namespace Command {
results.back().score += 10;
}

if(!results.back().description.empty() && results.back().score < 20){
results.back().score += compareDescription(results.back(), query);
}

lengthDiffAbs = std::abs((int)results.back().name.length() - (int)query.length());
if(results.back().score > 20){
results.back().score -= lengthDiffAbs;
Expand Down Expand Up @@ -99,12 +118,12 @@ namespace Command {
std::vector<packageResult> results = calculatePackageScores(queryTokens);


std::cout << "Results:" << std::endl;
std::cout << "Results: " << results.size() << std::endl;
for(int i = results.size();i > -1; i--){
if(results[i].score > 10){
//Adjusting the indexes for the normies
std::cout << "[" << i << "]" << "[s:" << results[i].score << "] " << results[i].name << " - (" << results[i].url << ")" << std::endl;
std::cout << "[" << termcolor::green << i << termcolor::white << "]" << "[s:" << results[i].score << "] " << results[i].name << " - (" << termcolor::bright_blue << results[i].url << termcolor::white << ")" << std::endl;
std::cout << " " << termcolor::cyan << results[i].description << termcolor::white << std::endl;
}
}

Expand Down

0 comments on commit 2c71bef

Please sign in to comment.