From 10c3746a6df45dd154955a9e91e662260f36363f Mon Sep 17 00:00:00 2001 From: Richard Qin Date: Tue, 14 Apr 2026 14:38:42 +0800 Subject: refactor: adjust code structure --- include/ricochet/core/form_handler.hh | 38 +++++++++++++++++++++++ include/ricochet/core/link_hints.hh | 27 +++++++++++++++++ include/ricochet/core/local_data.hh | 32 +++++++++++++++++++ include/ricochet/core/page_loader.hh | 32 +++++++++++++++++++ include/ricochet/core/page_processor.hh | 32 +++++++++++++++++++ include/ricochet/core/search_handler.hh | 23 ++++++++++++++ include/ricochet/core/types.hh | 54 +++++++++++++++++++++++++++++++++ include/ricochet/core/ui_input.hh | 29 ++++++++++++++++++ include/ricochet/core/ui_view.hh | 37 ++++++++++++++++++++++ include/ricochet/core/utils.hh | 32 +++++++++++++++++++ 10 files changed, 336 insertions(+) create mode 100644 include/ricochet/core/form_handler.hh create mode 100644 include/ricochet/core/link_hints.hh create mode 100644 include/ricochet/core/local_data.hh create mode 100644 include/ricochet/core/page_loader.hh create mode 100644 include/ricochet/core/page_processor.hh create mode 100644 include/ricochet/core/search_handler.hh create mode 100644 include/ricochet/core/types.hh create mode 100644 include/ricochet/core/ui_input.hh create mode 100644 include/ricochet/core/ui_view.hh create mode 100644 include/ricochet/core/utils.hh (limited to 'include/ricochet/core') diff --git a/include/ricochet/core/form_handler.hh b/include/ricochet/core/form_handler.hh new file mode 100644 index 0000000..5abf148 --- /dev/null +++ b/include/ricochet/core/form_handler.hh @@ -0,0 +1,38 @@ +/* + * Ricochet - A minimalist CLI web browser for fast, distraction-free navigation. + * Copyright (C) 2026 Richard Qin + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + */ + +#pragma once + +#include "ricochet/core/types.hh" +#include "ricochet/render/renderer.hh" +#include "ricochet/tui/terminal.hh" +#include +#include +#include + +namespace ricochet::core { + +InputAction submit_form( const render::InputField& target_input, + const std::vector& inputs, + const std::string& current_url, + std::vector& history, + std::size_t& history_idx ); + +void update_input_value( PageData& page_data, std::size_t index, const std::string& query ); +void update_single_line_ui( std::string& line, const std::string& marker, const render::InputField& in ); +void update_toggle_ui( PageData& page_data ); + +InputAction handle_form_input( const tui::Terminal& terminal, + PageData& page_data, + const std::string& current_url, + std::vector& history, + std::size_t& history_idx ); + +} // namespace ricochet::core diff --git a/include/ricochet/core/link_hints.hh b/include/ricochet/core/link_hints.hh new file mode 100644 index 0000000..5da4846 --- /dev/null +++ b/include/ricochet/core/link_hints.hh @@ -0,0 +1,27 @@ +/* + * Ricochet - A minimalist CLI web browser for fast, distraction-free navigation. + * Copyright (C) 2026 Richard Qin + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + */ + +#pragma once + +#include "ricochet/core/types.hh" +#include "ricochet/tui/terminal.hh" +#include + +namespace ricochet::core { + +std::string index_to_hint( std::size_t index ); +void toggle_link_hints( PageData& page_data, bool show ); +void handle_follow_link( const tui::Terminal& terminal, + PageData& page_data, + std::string& current_url, + std::size_t& scroll_y, + bool& navigate ); + +} // namespace ricochet::core diff --git a/include/ricochet/core/local_data.hh b/include/ricochet/core/local_data.hh new file mode 100644 index 0000000..ca07846 --- /dev/null +++ b/include/ricochet/core/local_data.hh @@ -0,0 +1,32 @@ +/* + * Ricochet - A minimalist CLI web browser for fast, distraction-free navigation. + * Copyright (C) 2026 Richard Qin + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#pragma once + +#include + +namespace ricochet::core { + +std::string get_config_path( const std::string& filename ); +void save_bookmark( const std::string& title, const std::string& url ); +std::string generate_bookmarks_html(); +void append_to_history( const std::string& url, const std::string& title ); +std::string generate_history_html(); +std::string generate_help_html(); + +} // namespace ricochet::core diff --git a/include/ricochet/core/page_loader.hh b/include/ricochet/core/page_loader.hh new file mode 100644 index 0000000..11131e2 --- /dev/null +++ b/include/ricochet/core/page_loader.hh @@ -0,0 +1,32 @@ +/* + * Ricochet - A minimalist CLI web browser for fast, distraction-free navigation. + * Copyright (C) 2026 Richard Qin + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#pragma once + +#include "ricochet/core/types.hh" +// #include "ricochet/net/http_client.hh" +// #include "ricochet/parser/dom_tree.hh" +// #include + +namespace ricochet::core { + +// std::string extract_title( const parser::DomNode& root_node ); +// PageData process_binary_download( const HttpRequest& req, const net::HttpResponse& resp ); +PageData load_page( const HttpRequest& req ); + +} // namespace ricochet::core diff --git a/include/ricochet/core/page_processor.hh b/include/ricochet/core/page_processor.hh new file mode 100644 index 0000000..8f40d3a --- /dev/null +++ b/include/ricochet/core/page_processor.hh @@ -0,0 +1,32 @@ +/* + * Ricochet - A minimalist CLI web browser for fast, distraction-free navigation. + * Copyright (C) 2026 Richard Qin + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#pragma once + +#include "ricochet/core/types.hh" +#include "ricochet/net/http_client.hh" +#include "ricochet/parser/dom_tree.hh" +#include + +namespace ricochet::core { + +std::string extract_title( const parser::DomNode& root_node ); + +PageData process_binary_download( const HttpRequest& req, const net::HttpResponse& resp ); + +} // namespace ricochet::core diff --git a/include/ricochet/core/search_handler.hh b/include/ricochet/core/search_handler.hh new file mode 100644 index 0000000..7053be8 --- /dev/null +++ b/include/ricochet/core/search_handler.hh @@ -0,0 +1,23 @@ +/* + * Ricochet - A minimalist CLI web browser for fast, distraction-free navigation. + * Copyright (C) 2026 Richard Qin + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + */ + +#pragma once + +#include "ricochet/core/types.hh" +#include +#include + +namespace ricochet::core { + +void find_search_matches( PageData& page_data, const std::string& query ); +void apply_search_highlight( PageData& page_data, const std::string& query ); +void execute_search( PageData& page_data, const std::string& query, std::size_t& scroll_y, bool next_match ); + +} // namespace ricochet::core diff --git a/include/ricochet/core/types.hh b/include/ricochet/core/types.hh new file mode 100644 index 0000000..bd7e819 --- /dev/null +++ b/include/ricochet/core/types.hh @@ -0,0 +1,54 @@ +/* + * Ricochet - A minimalist CLI web browser for fast, distraction-free navigation. + * Copyright (C) 2026 Richard Qin + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#pragma once + +#include "ricochet/render/renderer.hh" +#include +#include +#include + +namespace ricochet::core { + +struct PageData +{ + std::vector lines; + std::vector links; + std::vector inputs; + std::string title; + std::vector original_lines {}; + std::string last_search {}; + std::size_t current_match_idx { 0 }; + std::vector match_lines {}; +}; + +struct HttpRequest +{ + std::string url {}; + std::string method = "GET"; + std::string body {}; +}; + +enum class InputAction : std::uint8_t +{ + None, + Quit, + Navigate +}; + +} // namespace ricochet::core diff --git a/include/ricochet/core/ui_input.hh b/include/ricochet/core/ui_input.hh new file mode 100644 index 0000000..bf71685 --- /dev/null +++ b/include/ricochet/core/ui_input.hh @@ -0,0 +1,29 @@ +/* + * Ricochet - A minimalist CLI web browser for fast, distraction-free navigation. + * Copyright (C) 2026 Richard Qin + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#pragma once + +#include "ricochet/tui/terminal.hh" +#include + +namespace ricochet::core { + +std::string get_url_input( const tui::Terminal& terminal ); +std::string get_terminal_input( const tui::Terminal& terminal, const std::string& prompt ); + +} // namespace ricochet::core diff --git a/include/ricochet/core/ui_view.hh b/include/ricochet/core/ui_view.hh new file mode 100644 index 0000000..d9a55fa --- /dev/null +++ b/include/ricochet/core/ui_view.hh @@ -0,0 +1,37 @@ +/* + * Ricochet - A minimalist CLI web browser for fast, distraction-free navigation. + * Copyright (C) 2026 Richard Qin + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#pragma once + +#include "ricochet/tui/terminal.hh" + +#include +#include +#include + +namespace ricochet::core { + +std::string build_footer( std::string_view url, std::size_t width ); + +void draw_view( const tui::Terminal& terminal, + const std::vector& lines, + std::size_t scroll_y, + std::string_view url, + std::string_view title ); + +} // namespace ricochet::core diff --git a/include/ricochet/core/utils.hh b/include/ricochet/core/utils.hh new file mode 100644 index 0000000..d9f58dd --- /dev/null +++ b/include/ricochet/core/utils.hh @@ -0,0 +1,32 @@ +/* + * Ricochet - A minimalist CLI web browser for fast, distraction-free navigation. + * Copyright (C) 2026 Richard Qin + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#pragma once + +#include +#include +#include + +namespace ricochet::core { + +std::vector split_into_lines( const std::string& text ); +std::string normalize_url( const std::string& target, const std::string& current_url ); +std::string strip_ddg_tracker( std::string target ); +std::vector wrap_lines( const std::vector& original_lines, std::size_t wrap_width ); + +} // namespace ricochet::core -- cgit v1.2.3