From c8e0dd9e47ec5688dc5e86c473a2ba856bf1cfe3 Mon Sep 17 00:00:00 2001 From: Witold Filipczyk Date: Sun, 30 Apr 2023 20:14:33 +0200 Subject: [PATCH] [remote] Now addBookmark takes two parameters URL and title. Refs #227 title must be passed without quotes. Example: elinks --remote 'addBookmark(https://www.example.com/forum, Forum Example)' Implementation note: uri->post was reused and is title here. --- doc/remote.txt | 2 +- src/config/cmdline.c | 8 ++++++-- src/session/session.cpp | 13 +++++++++++-- 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/doc/remote.txt b/doc/remote.txt index d22732ea1..e89321dbf 100644 --- a/doc/remote.txt +++ b/doc/remote.txt @@ -74,7 +74,7 @@ xfeDoCommand(openBrowser) Opens an ELinks instance in a new window. \ `-------------------------------`---------------------------------------------- Command Description ------------------------------------------------------------------------------- -addBookmark(URL) Bookmarks the passed URL. +addBookmark(URL, title) Bookmarks the passed URL and set title. infoBox(text) Show text in a message box. reload() Reload the document in the current tab. search(string) Search for the string in the current tab diff --git a/src/config/cmdline.c b/src/config/cmdline.c index a5808ff8a..3adce9cc2 100644 --- a/src/config/cmdline.c +++ b/src/config/cmdline.c @@ -405,7 +405,11 @@ remote_cmd(struct option *o, char ***argv, int *argc) case REMOTE_METHOD_ADDBOOKMARK: if (remote_argc < 1) break; - remote_url = stracpy(remote_argv[0]); + if (remote_argc == 2) { + remote_url = straconcat(remote_argv[0], POST_CHAR_S, remote_argv[1], NULL); + } else { + remote_url = stracpy(remote_argv[0]); + } remote_session_flags = SES_REMOTE_ADD_BOOKMARK; break; @@ -960,7 +964,7 @@ union option_info cmdline_options_info[] = { "\topenURL(URL) : open URL in current tab\n" "\topenURL(URL, new-tab) : open URL in new tab\n" "\topenURL(URL, new-window) : open URL in new window\n" - "\taddBookmark(URL) : bookmark URL\n" + "\taddBookmark(URL, title) : bookmark URL with title\n" "\tinfoBox(text) : show text in a message box\n" "\treload() : reload the document in the current tab\n" "\tsearch(string) : search in the current tab\n" diff --git a/src/session/session.cpp b/src/session/session.cpp index da06dcc9a..20cf5b04b 100644 --- a/src/session/session.cpp +++ b/src/session/session.cpp @@ -1144,9 +1144,18 @@ init_remote_session(struct session *ses, remote_session_flags_T *remote_ptr, * then have a function that reversibly converts them * to IRIs for display in a given encoding. */ uri_cp = get_cp_index("System"); - add_bookmark_cp(NULL, 1, uri_cp, struri(uri), struri(uri)); -#endif + if (uri->post) { + char *title = stracpy(uri->post); + char *url = get_uri_string(uri, URI_ORIGINAL); + + add_bookmark_cp(NULL, 1, uri_cp, title, url); + mem_free_if(url); + mem_free_if(title); + } else { + add_bookmark_cp(NULL, 1, uri_cp, struri(uri), struri(uri)); + } +#endif } else if (remote & SES_REMOTE_INFO_BOX) { char *text;