diff --git a/src/anki_search.cpp b/src/anki_search.cpp index 3cacb6b..37d510c 100644 --- a/src/anki_search.cpp +++ b/src/anki_search.cpp @@ -98,6 +98,9 @@ static constexpr std::string_view css_style = R"EOF( )EOF"; @@ -110,6 +113,7 @@ struct card_info int64_t type; std::string deck_name; NameToValMap fields; + uint64_t nid; }; auto split_anki_field_names(std::string_view const show_fields) -> std::vector @@ -189,7 +193,7 @@ auto make_ankiconnect_request(std::string_view const request_str) -> cpr::Respon ); } -auto make_info_request_str(std::vector const& cids) +auto make_info_request_str(std::vector const& cids) -> std::string { auto request = json::parse(R"EOF({ "action": "cardsInfo", @@ -232,6 +236,33 @@ auto fetch_media_dir_path() -> std::string return obj["result"]; } +auto make_get_note_tags_request_str(uint64_t const nid) -> std::string +{ + auto request = json::parse(R"EOF({ + "action": "getNoteTags", + "version": 6, + "params": { + "note": 1483959289817 + } + })EOF"); + request["params"]["note"] = nid; + return request.dump(); +} + +auto get_note_tags(uint64_t const nid) -> std::string +{ + auto const request_str = make_get_note_tags_request_str(nid); + cpr::Response const r = make_ankiconnect_request(request_str); + raise_if(r.status_code != cpr::status::HTTP_OK, "Couldn't connect to Anki."); + auto const obj = json::parse(r.text); + raise_if(not obj["error"].is_null(), "Error getting data from AnkiConnect."); + std::string html; + for (std::string const tag_name: obj["result"]) { + html += std::format(R"EOF({})EOF", tag_name, tag_name); + } + return html; +} + void print_table_header(search_params const& params) { // Print the first row (header) that contains tags, starting with Card ID. @@ -239,6 +270,7 @@ void print_table_header(search_params const& params) ajt::print("Card ID"); ajt::print("Deck name"); for (auto const& field: params.show_fields) { ajt::print("{}", field); } + ajt::print("Tags"); ajt::print("\n"); } @@ -257,7 +289,8 @@ auto card_json_to_obj(nlohmann::json const& card_json) -> card_info result.emplace(element.key(), element.value()["value"]); } return result; - }(), // + }(), + .nid = card_json["note"] // }; } @@ -292,6 +325,7 @@ void print_cards_info(search_params const& params) : "Not present") ); } + ajt::print("{}\n", get_note_tags(card.nid)); ajt::print("\n"); } ajt::print("\n"); diff --git a/src/echo.cpp b/src/echo.cpp index f8c3f81..fc9d13d 100644 --- a/src/echo.cpp +++ b/src/echo.cpp @@ -90,36 +90,3 @@ void stroke_order(std::span const args) ajt::print("{}\n", ex.what()); } } - -//Later just use stroke_order to print it -void print_css_hw(stroke_order_params const& params) -{ - static constexpr std::string_view css = R"EOF( - - )EOF"; - ajt::print(css, this_pid, params.font_size); -} - -void print_with_hw(stroke_order_params const& params) -{ - if (params.gd_word.length() <= params.max_len) { - ajt::print("
{}
\n", this_pid, params.gd_word); - print_css_hw(params); - } -} - -void handwritten(std::span const args) -{ - try { - print_with_hw(fill_args(args)); - } catch (gd::help_requested const& ex) { - ajt::print(help_text); - } catch (gd::runtime_error const& ex) { - ajt::print("{}\n", ex.what()); - } -} \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index 0a87896..be42093 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -85,7 +85,7 @@ auto take_action(std::span const args) -> void case "gd-strokeorder"_h: return stroke_order(rest); case "gd-handwritten"_h: - return handwritten(rest); + return stroke_order(rest); case "gd-massif"_h: return massif(rest); case "gd-images"_h: @@ -109,7 +109,7 @@ auto take_action(std::span const args) -> void case "strokeorder"_h: return stroke_order(rest); case "handwritten"_h: - return handwritten(rest); + return stroke_order(rest); case "massif"_h: return massif(rest); case "images"_h: @@ -144,12 +144,19 @@ auto main(/*int const argc, char const* const* const argv*/) -> int args_utf8.push_back(test_str); } + std::string_view font = "--font-family"; + std::string_view font_value = "armedlemon"; + + if(std::string(args_utf8[1]) == "handwritten" || base_name(args_utf8[0]) == "gd-handwritten" && argc > 2){ + args_utf8.push_back(font); + args_utf8.push_back(font_value); + } + for (const std::string& arg : args_utf8) args.push_back(arg); take_action(args); - return 0; } #endif //ifndef WIN32 @@ -157,7 +164,21 @@ auto main(/*int const argc, char const* const* const argv*/) -> int #ifndef WIN32 //General Main auto main(int const argc, char const* const* const argv) -> int { - take_action(std::vector{ argv, std::next(argv, argc) }); - return 0; + std::vector args{}; + for(int i{0}; i < argc; i++) + args.push_back(argv[i]); + + //Automatically change font for handwritten + std::string_view font = "--font-family"; + std::string_view font_value = "armedlemon"; + if(std::string(argv[1]) == "handwritten" || base_name(argv[0]) == "gd-handwritten" && argc > 2){ + args.push_back(font); + args.push_back(font_value); + } + + take_action(args); + + //Original code + //take_action(std::vector{ argv, std::next(argv, argc) }); } #endif //General Main