aboutsummaryrefslogtreecommitdiff
path: root/include/ricochet/core
diff options
context:
space:
mode:
authorRichard Qin <richard.qin.x@gmail.com>2026-04-14 14:38:42 +0800
committerRichard Qin <richard.qin.x@gmail.com>2026-04-14 14:38:42 +0800
commit10c3746a6df45dd154955a9e91e662260f36363f (patch)
tree0c9c879439baf659d875ec1438154ca9ea71faf1 /include/ricochet/core
parentd4f78be6f231b5289eb1c658d1f67006b7d884dd (diff)
downloadrwebbrowser-10c3746a6df45dd154955a9e91e662260f36363f.tar.gz
rwebbrowser-10c3746a6df45dd154955a9e91e662260f36363f.tar.xz
refactor: adjust code structure
Diffstat (limited to 'include/ricochet/core')
-rw-r--r--include/ricochet/core/form_handler.hh38
-rw-r--r--include/ricochet/core/link_hints.hh27
-rw-r--r--include/ricochet/core/local_data.hh32
-rw-r--r--include/ricochet/core/page_loader.hh32
-rw-r--r--include/ricochet/core/page_processor.hh32
-rw-r--r--include/ricochet/core/search_handler.hh23
-rw-r--r--include/ricochet/core/types.hh54
-rw-r--r--include/ricochet/core/ui_input.hh29
-rw-r--r--include/ricochet/core/ui_view.hh37
-rw-r--r--include/ricochet/core/utils.hh32
10 files changed, 336 insertions, 0 deletions
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 <cstddef>
+#include <string>
+#include <vector>
+
+namespace ricochet::core {
+
+InputAction submit_form( const render::InputField& target_input,
+ const std::vector<render::InputField>& inputs,
+ const std::string& current_url,
+ std::vector<HttpRequest>& 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<HttpRequest>& 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 <string>
+
+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 <https://www.gnu.org/licenses/>.
+ */
+
+#pragma once
+
+#include <string>
+
+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 <https://www.gnu.org/licenses/>.
+ */
+
+#pragma once
+
+#include "ricochet/core/types.hh"
+// #include "ricochet/net/http_client.hh"
+// #include "ricochet/parser/dom_tree.hh"
+// #include <string>
+
+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 <https://www.gnu.org/licenses/>.
+ */
+
+#pragma once
+
+#include "ricochet/core/types.hh"
+#include "ricochet/net/http_client.hh"
+#include "ricochet/parser/dom_tree.hh"
+#include <string>
+
+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 <cstddef>
+#include <string>
+
+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 <https://www.gnu.org/licenses/>.
+ */
+
+#pragma once
+
+#include "ricochet/render/renderer.hh"
+#include <cstdint>
+#include <string>
+#include <vector>
+
+namespace ricochet::core {
+
+struct PageData
+{
+ std::vector<std::string> lines;
+ std::vector<std::string> links;
+ std::vector<render::InputField> inputs;
+ std::string title;
+ std::vector<std::string> original_lines {};
+ std::string last_search {};
+ std::size_t current_match_idx { 0 };
+ std::vector<std::size_t> 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 <https://www.gnu.org/licenses/>.
+ */
+
+#pragma once
+
+#include "ricochet/tui/terminal.hh"
+#include <string>
+
+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 <https://www.gnu.org/licenses/>.
+ */
+
+#pragma once
+
+#include "ricochet/tui/terminal.hh"
+
+#include <string>
+#include <string_view>
+#include <vector>
+
+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<std::string>& 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 <https://www.gnu.org/licenses/>.
+ */
+
+#pragma once
+
+#include <cstddef>
+#include <string>
+#include <vector>
+
+namespace ricochet::core {
+
+std::vector<std::string> 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<std::string> wrap_lines( const std::vector<std::string>& original_lines, std::size_t wrap_width );
+
+} // namespace ricochet::core