Skip to content

Commit

Permalink
beginning with tasks
Browse files Browse the repository at this point in the history
  • Loading branch information
Sarsoo committed Jan 27, 2025
1 parent 002df38 commit ed7879e
Show file tree
Hide file tree
Showing 7 changed files with 136 additions and 6 deletions.
8 changes: 5 additions & 3 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
valid/link.cpp
logging.cpp
config.cpp
image/img.cpp
print/print.cpp
task/task.cpp
# image/img.cpp
)

FetchContent_Declare(
Expand All @@ -19,7 +21,7 @@ FetchContent_Declare(
)
FetchContent_MakeAvailable(Boost)

find_package( OpenCV REQUIRED )
include_directories( ${OpenCV_INCLUDE_DIRS} )
#find_package( OpenCV REQUIRED )
#include_directories( ${OpenCV_INCLUDE_DIRS} )

target_link_libraries(kc PRIVATE Boost::program_options Boost::log Boost::date_time Boost::filesystem Boost::system Boost::thread Boost::log_setup Boost::chrono Boost::atomic ${OpenCV_LIBS})
6 changes: 5 additions & 1 deletion src/const.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,8 @@
static const std::string MD_LINK_REGEX = R"(\[.*?\]\(.*?\))";
static const std::string MD_MD_LINK_REGEX = R"(\[.*?\]\(.*?\.md(#.*?)*\))";
static const std::string MD_IMAGE_LINK_REGEX = R"(!\[.*?\]\(.*?\.png\))";
static const std::string MD_TAG_REGEX = R"((^|[[:blank:]])#{1}[^\s#.]+)";
static const std::string MD_TAG_REGEX = R"((^|[[:blank:]])#{1}[^\s#.]+)";

static const std::string TASK_REGEX = R"(.*\[(.)\] (.+) 📅 (.*))";
static const std::string TIGHT_TASK_REGEX = R"(.*\[(.)\] (.+) 📅 (.{10}))";
static const std::string UNCOMPLETED_TASK_REGEX = R"(.*\[(.)\] (.+) 📅 (.{10})(?! [✅❌].*))";
16 changes: 14 additions & 2 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@
#include "appcontext.hpp"
#include "fs/fs.hpp"
#include "parse/FileContextCache.hpp"
#include "print/print.hpp"
#include "valid/link.hpp"
#include "image/img.hpp"
//#include "image/img.hpp"

void run_validate(const kc::AppContext &app_context);
void run_img(const kc::AppContext &app_context);
void run_print(const kc::AppContext &app_context);


int main(int argc, const char *argv[]) {
Expand Down Expand Up @@ -45,6 +47,11 @@ int main(int argc, const char *argv[]) {
app_context.load_and_parse_cache();
run_img(app_context);
}
else if (command == "print")
{
app_context.load_and_parse_cache();
run_print(app_context);
}
}
else
{
Expand All @@ -65,5 +72,10 @@ void run_validate(const kc::AppContext &app_context)

void run_img(const kc::AppContext &app_context)
{
kc::image_proc(app_context.file_cache->get());
// kc::image_proc(app_context.file_cache->get());
}

void run_print(const kc::AppContext &app_context)
{
kc::print_file(app_context.file_cache->get());
}
28 changes: 28 additions & 0 deletions src/print/print.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#include "print.hpp"

#include <filesystem>
#include <iostream>

#include "../logging.hpp"

namespace fs = std::filesystem;

namespace kc {

void print_file(const std::vector<std::shared_ptr<kc::FileContext>> &contexts)
{
for (const auto &entry : contexts) {

std::regex link_regex(UNCOMPLETED_TASK_REGEX);
std::string file_content = entry->file_entry->get_content();
std::smatch link_match;
while(std::regex_search(file_content, link_match, link_regex)) {

std::cout << entry->file_entry->file_entry.path() << " (" << link_match[2] << ") : " << link_match[3] << std::endl;

file_content = link_match.suffix();
}
}
}

}
10 changes: 10 additions & 0 deletions src/print/print.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#pragma once

#include <vector>
#include "../parse/FileContext.hpp"

namespace kc {

void print_file(const std::vector<std::shared_ptr<kc::FileContext>> &contexts);

}
47 changes: 47 additions & 0 deletions src/task/task.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#include "task.hpp"

namespace kc {

constexpr TaskState get_task_state(char c){
switch(c){
case ' ':
return TaskState::NOT_STARTED;
case '/':
return TaskState::IN_PROGRESS;
case 'x':
return TaskState::COMPLETED;
case '-':
return TaskState::CANCELLED;
}

return TaskState::UNKNOWN;
}

constexpr char get_task_state(TaskState c){
switch(c){
case TaskState::NOT_STARTED:
return ' ';
case TaskState::IN_PROGRESS:
return '/';
case TaskState::COMPLETED:
return 'x';
case TaskState::CANCELLED:
return '-';
}

return '?';
}

Task::Task(const std::string &task_content, TaskState state, const std::string &due_date_str)
: task_content(task_content), state(state), due_date_str(due_date_str) {
}

Task::Task(const std::string &task_content, TaskState state)
: task_content(task_content), state(state) {
}

Task::Task(const std::string &task_content)
: task_content(task_content), state(NOT_STARTED) {
}

}
27 changes: 27 additions & 0 deletions src/task/task.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#pragma once
#include <string>

namespace kc {

enum TaskState {
NOT_STARTED, IN_PROGRESS, COMPLETED, CANCELLED, UNKNOWN
};

constexpr TaskState get_task_state(char c);
constexpr char get_task_state(TaskState c);

class Task {
public:

explicit Task(const std::string &task_content, TaskState state, const std::string &due_date_str);
explicit Task(const std::string &task_content, TaskState state);
explicit Task(const std::string &task_content);

private:

std::string task_content;
std::string due_date_str;
TaskState state;
};

}

0 comments on commit ed7879e

Please sign in to comment.