2020-01-18 05:38:21 -03:00
|
|
|
/*
|
2020-01-24 10:45:29 -03:00
|
|
|
* Copyright (c) 2019-2020, Sergey Bugaev <bugaevc@serenityos.org>
|
2021-04-23 12:19:17 -03:00
|
|
|
* Copyright (c) 2021, Andreas Kling <kling@serenityos.org>
|
Help: Add support for launching with a section and page, like man
I found it strange that `man` and `Help` did not accept the same command
line arguments since they are so similar. So... now they do. :^)
This means you can now open for example the `tar` man page in Help with
`Help tar`, or `Help 1 tar` if you want to disambiguate between pages in
different sections.
If the result is not found, it falls back to the previous behavior,
treating the input as a search query.
Initially I had this written as two optional positional arguments, but
when told to parse `[optional int] [optional string]`, and then given a
string input, ArgsParser forwards it to the [optional int], which then
fails to parse. Ideally it would pass it to the second, [optional
string] arg instead, but that looks like a fairly big change to make to
ArgsParser's internals, and risk breaking things. Maybe this ugly hack
will be an incentive to fix it. :^)
2021-12-19 12:35:21 -03:00
|
|
|
* Copyright (c) 2021, Sam Atkins <atkinssj@serenityos.org>
|
2022-07-12 15:23:28 -03:00
|
|
|
* Copyright (c) 2022, kleines Filmröllchen <filmroellchen@serenityos.org>
|
2020-01-18 05:38:21 -03:00
|
|
|
*
|
2021-04-22 05:24:48 -03:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-01-18 05:38:21 -03:00
|
|
|
*/
|
|
|
|
|
|
2022-02-28 13:05:35 -03:00
|
|
|
#include "MainWidget.h"
|
2022-04-20 16:35:15 -03:00
|
|
|
#include <AK/URL.h>
|
2020-07-22 12:34:27 -03:00
|
|
|
#include <LibCore/ArgsParser.h>
|
2021-11-23 12:03:01 -03:00
|
|
|
#include <LibCore/System.h>
|
2020-02-06 16:33:02 -03:00
|
|
|
#include <LibGUI/Application.h>
|
2022-02-28 13:05:35 -03:00
|
|
|
#include <LibGUI/Icon.h>
|
2020-02-06 16:33:02 -03:00
|
|
|
#include <LibGUI/Window.h>
|
2021-11-23 12:03:01 -03:00
|
|
|
#include <LibMain/Main.h>
|
2022-02-28 13:05:35 -03:00
|
|
|
|
|
|
|
|
using namespace Help;
|
2019-09-20 18:47:31 -03:00
|
|
|
|
2021-11-23 12:03:01 -03:00
|
|
|
ErrorOr<int> serenity_main(Main::Arguments arguments)
|
2019-09-20 18:47:31 -03:00
|
|
|
{
|
2022-10-03 10:32:18 -03:00
|
|
|
TRY(Core::System::pledge("stdio recvfd sendfd rpath unix"));
|
2023-05-05 01:24:53 -03:00
|
|
|
auto app = TRY(GUI::Application::create(arguments));
|
2020-01-11 22:23:55 -03:00
|
|
|
|
2021-11-23 12:03:01 -03:00
|
|
|
TRY(Core::System::unveil("/res", "r"));
|
2022-06-23 20:06:24 -03:00
|
|
|
// We specifically don't want to load this path from a library, as that can be hijacked with LD_PRELOAD.
|
2021-11-23 12:03:01 -03:00
|
|
|
TRY(Core::System::unveil("/usr/share/man", "r"));
|
2022-09-06 03:04:06 -03:00
|
|
|
TRY(Core::System::unveil("/tmp/session/%sid/portal/filesystemaccess", "rw"));
|
|
|
|
|
TRY(Core::System::unveil("/tmp/session/%sid/portal/launch", "rw"));
|
|
|
|
|
TRY(Core::System::unveil("/tmp/session/%sid/portal/webcontent", "rw"));
|
2021-11-23 12:03:01 -03:00
|
|
|
TRY(Core::System::unveil(nullptr, nullptr));
|
2020-01-21 18:09:12 -03:00
|
|
|
|
2022-07-12 15:23:28 -03:00
|
|
|
DeprecatedString first_query_parameter;
|
|
|
|
|
DeprecatedString second_query_parameter;
|
2020-07-22 12:34:27 -03:00
|
|
|
|
|
|
|
|
Core::ArgsParser args_parser;
|
2022-07-12 15:23:28 -03:00
|
|
|
// The actual "page query" parsing happens when we set the main widget's start page.
|
|
|
|
|
args_parser.add_positional_argument(
|
|
|
|
|
first_query_parameter,
|
|
|
|
|
"Section of the man page",
|
|
|
|
|
"section",
|
|
|
|
|
Core::ArgsParser::Required::No);
|
|
|
|
|
args_parser.add_positional_argument(
|
|
|
|
|
second_query_parameter,
|
|
|
|
|
"Help page to open. Either an absolute path to the markdown file, or a search query",
|
|
|
|
|
"page",
|
|
|
|
|
Core::ArgsParser::Required::No);
|
2021-11-23 12:03:01 -03:00
|
|
|
args_parser.parse(arguments);
|
2022-07-12 15:23:28 -03:00
|
|
|
Vector<StringView, 2> query_parameters;
|
|
|
|
|
if (!first_query_parameter.is_empty())
|
|
|
|
|
query_parameters.append(first_query_parameter);
|
|
|
|
|
if (!second_query_parameter.is_empty())
|
|
|
|
|
query_parameters.append(second_query_parameter);
|
2020-07-22 12:34:27 -03:00
|
|
|
|
2022-07-11 14:32:29 -03:00
|
|
|
auto app_icon = GUI::Icon::default_icon("app-help"sv);
|
2020-07-07 08:04:06 -03:00
|
|
|
|
2023-09-16 08:51:33 -03:00
|
|
|
auto window = GUI::Window::construct();
|
2020-07-07 08:04:06 -03:00
|
|
|
window->set_icon(app_icon.bitmap_for_size(16));
|
2019-09-20 18:47:31 -03:00
|
|
|
window->set_title("Help");
|
2020-07-31 19:12:11 -03:00
|
|
|
window->resize(570, 500);
|
2019-09-20 18:47:31 -03:00
|
|
|
|
2023-09-18 21:13:48 -03:00
|
|
|
auto main_widget = TRY(MainWidget::try_create());
|
|
|
|
|
window->set_main_widget(main_widget);
|
|
|
|
|
|
2022-02-28 13:05:35 -03:00
|
|
|
TRY(main_widget->initialize_fallibles(window));
|
2022-07-12 15:23:28 -03:00
|
|
|
TRY(main_widget->set_start_page(query_parameters));
|
2021-04-23 12:19:17 -03:00
|
|
|
|
2019-09-20 18:47:31 -03:00
|
|
|
window->show();
|
|
|
|
|
|
2020-07-04 09:05:19 -03:00
|
|
|
return app->exec();
|
2019-09-20 18:47:31 -03:00
|
|
|
}
|