aboutsummaryrefslogtreecommitdiff
path: root/src/tui
diff options
context:
space:
mode:
authorRichard Qin <richard.qin.x@gmail.com>2026-04-11 04:12:56 +0800
committerRichard Qin <richard.qin.x@gmail.com>2026-04-11 04:12:56 +0800
commit5efb7400b96fa112c38009b18e2a48620f328148 (patch)
tree85f8065b8bb2aa03e940a71cb1fbf511d571a812 /src/tui
parent617b10ded3722a8c2d615fbee5dd256f5f3c6a7f (diff)
downloadrwebbrowser-5efb7400b96fa112c38009b18e2a48620f328148.tar.gz
rwebbrowser-5efb7400b96fa112c38009b18e2a48620f328148.tar.xz
feat: implement interactive TUI with scrolling and add OpenSSL dependency support
Diffstat (limited to 'src/tui')
-rw-r--r--src/tui/terminal.cc62
1 files changed, 62 insertions, 0 deletions
diff --git a/src/tui/terminal.cc b/src/tui/terminal.cc
new file mode 100644
index 0000000..8fdb585
--- /dev/null
+++ b/src/tui/terminal.cc
@@ -0,0 +1,62 @@
+/*
+ * 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/>.
+ */
+
+#include "ricochet/tui/terminal.hh"
+#include <cstdlib>
+#include <iostream>
+#include <unistd.h>
+
+namespace ricochet::tui {
+
+Terminal::Terminal() {
+ // get terminal attributes
+ tcgetattr(STDIN_FILENO, &original_termios_);
+
+ struct termios raw = original_termios_;
+
+ // close echo, close canonical mode
+ // close terminal signals (ISIG disable Ctrl+C and Ctrl+Z, let the program handle it)
+ raw.c_lflag &= ~(ECHO | ICANON | ISIG);
+
+ // close software flow control (Ctrl+S, Ctrl+Q)
+ raw.c_iflag &= ~(IXON | ICRNL);
+
+ // apply new terminal attributes
+ tcsetattr(STDIN_FILENO, TCSAFLUSH, &raw);
+}
+
+Terminal::~Terminal() {
+ // RAII: restore terminal attributes when program exits
+ tcsetattr(STDIN_FILENO, TCSAFLUSH, &original_termios_);
+}
+
+char Terminal::read_key() const { // NOLINT(readability-convert-member-functions-to-static)
+ char c = '\0';
+ // read 1 byte
+ if (read(STDIN_FILENO, &c, 1) == -1) {
+ return '\0';
+ }
+ return c;
+}
+
+void Terminal::clear_screen() const { // NOLINT(readability-convert-member-functions-to-static)
+ // ANSI escape codes: \x1b[2J clear screen, \x1b[H move cursor to (1,1)
+ std::cout << "\x1b[2J\x1b[H";
+}
+
+} // namespace ricochet::tui \ No newline at end of file