PHANTOM
🇮🇳 IN
aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/IO/control.c9
-rw-r--r--src/uicmd.cc13
-rw-r--r--src/uicmd.hh3
-rw-r--r--test/dilloc/Makefile.am3
-rwxr-xr-xtest/dilloc/cmd-title.sh19
5 files changed, 43 insertions, 4 deletions
diff --git a/src/IO/control.c b/src/IO/control.c
index b9b871ae..47962a5e 100644
--- a/src/IO/control.c
+++ b/src/IO/control.c
@@ -1,7 +1,7 @@
/*
* File: control.c
*
- * Copyright (C) 2025 Rodrigo Arias Mallo <rodarima@gmail.com>
+ * Copyright (C) 2025-2026 Rodrigo Arias Mallo <rodarima@gmail.com>
*
* 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
@@ -217,6 +217,7 @@ static void Control_req_prepare_reply(struct control_req *req)
dStr_sprintfa(r, " ready Exits with 0 if finished loading, 1 otherwise\n");
dStr_sprintfa(r, " open URL Open the given URL in the current tab\n");
dStr_sprintfa(r, " url Print the url in the current tab\n");
+ dStr_sprintfa(r, " title Print the title of page in the current tab\n");
dStr_sprintfa(r, " status [MSG] Set the status bar to MSG\n");
dStr_sprintfa(r, " dump Print the content of the current tab\n");
dStr_sprintfa(r, " hdump Print the HTTP headers of the current tab\n");
@@ -241,6 +242,12 @@ static void Control_req_prepare_reply(struct control_req *req)
dStr_sprintfa(r, "0\n");
} else if (strcmp(cmd, "url") == 0) {
dStr_sprintfa(r, "0\n%s\n", a_UIcmd_get_location_text(bw));
+ } else if (strcmp(cmd, "title") == 0) {
+ const char *title = a_UIcmd_get_page_title(bw);
+ if (title)
+ dStr_sprintfa(r, "0\n%s\n", title);
+ else
+ dStr_sprintfa(r, "1\n");
} else if (!strcmp(cmd, "status") || !strncmp(cmd, "status ", 7)) {
if (cmd[6] == ' ')
a_UIcmd_set_msg(bw, "%s", cmd + 7);
diff --git a/src/uicmd.cc b/src/uicmd.cc
index 71a9652e..36f12aa9 100644
--- a/src/uicmd.cc
+++ b/src/uicmd.cc
@@ -2,7 +2,7 @@
* File: uicmd.cc
*
* Copyright (C) 2005-2011 Jorge Arellano Cid <jcid@dillo.org>
- * Copyright (C) 2024-2025 Rodrigo Arias Mallo <rodarima@gmail.com>
+ * Copyright (C) 2024-2026 Rodrigo Arias Mallo <rodarima@gmail.com>
*
* 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
@@ -1615,6 +1615,17 @@ void a_UIcmd_set_page_title(BrowserWindow *bw, const char *label)
}
/*
+ * Get page title based on the current location URL, NULL if empty.
+ */
+const char *a_UIcmd_get_page_title(BrowserWindow *bw)
+{
+ DilloUrl *url = a_Url_new(a_UIcmd_get_location_text(bw), NULL);
+ const char *title = a_History_get_title_by_url(url, 0);
+ a_Url_free(url);
+ return title;
+}
+
+/*
* Set a printf-like status string on the bottom of the dillo window.
* Beware: The safe way to set an arbitrary string is
* a_UIcmd_set_msg(bw, "%s", str)
diff --git a/src/uicmd.hh b/src/uicmd.hh
index 86fcce87..2f279da8 100644
--- a/src/uicmd.hh
+++ b/src/uicmd.hh
@@ -2,7 +2,7 @@
* File: uicmd.cc
*
* Copyright (C) 2005-2011 Jorge Arellano Cid <jcid@dillo.org>
- * Copyright (C) 2024-2025 Rodrigo Arias Mallo <rodarima@gmail.com>
+ * Copyright (C) 2024-2026 Rodrigo Arias Mallo <rodarima@gmail.com>
*
* 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
@@ -99,6 +99,7 @@ void a_UIcmd_set_page_prog(BrowserWindow *bw, size_t nbytes, int cmd);
void a_UIcmd_set_img_prog(BrowserWindow *bw, int n_img, int t_img, int cmd);
void a_UIcmd_set_bug_prog(BrowserWindow *bw, int n_bug);
void a_UIcmd_set_page_title(BrowserWindow *bw, const char *label);
+const char *a_UIcmd_get_page_title(BrowserWindow *bw);
void a_UIcmd_set_msg(BrowserWindow *bw, const char *format, ...);
void a_UIcmd_set_buttons_sens(BrowserWindow *bw);
diff --git a/test/dilloc/Makefile.am b/test/dilloc/Makefile.am
index 019d0709..9ad38213 100644
--- a/test/dilloc/Makefile.am
+++ b/test/dilloc/Makefile.am
@@ -9,7 +9,8 @@ LOG_COMPILER = $(srcdir)/driver.sh
TESTS = \
cmd-load.sh \
cmd-load-multi.sh \
- cmd-load-deadlock.sh
+ cmd-load-deadlock.sh \
+ cmd-title.sh
EXTRA_DIST = \
$(TESTS) \
diff --git a/test/dilloc/cmd-title.sh b/test/dilloc/cmd-title.sh
new file mode 100755
index 00000000..e71cc27b
--- /dev/null
+++ b/test/dilloc/cmd-title.sh
@@ -0,0 +1,19 @@
+#!/bin/bash
+#
+# Copyright (C) 2026 Rodrigo Arias Mallo <rodarima@gmail.com>
+#
+# 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.
+
+set -eux
+
+i="$SRCDIR/test.html"
+o="$WORKDIR/output.html"
+
+$DILLOC open "file://$(readlink -f $i)"
+$DILLOC wait
+$DILLOC title > "$o"
+
+echo "Testing dilloc load command" | diff -up - "$o"