Coverage Report

Created: 2025-09-05 06:52

/src/serenity/Userland/Libraries/LibShell/URLHighlight.cpp
Line
Count
Source (jump to first uncovered line)
1
/*
2
 * Copyright (c) 2020-2022, the SerenityOS developers.
3
 *
4
 * SPDX-License-Identifier: BSD-2-Clause
5
 */
6
7
#include <AK/Format.h>
8
#include <LibShell/Highlight.h>
9
#include <LibURL/URL.h>
10
#include <unistd.h>
11
12
namespace Shell {
13
14
void Shell::print_path(StringView path)
15
0
{
16
0
    if (!m_is_interactive || !isatty(STDOUT_FILENO)) {
17
0
        out("{}", path);
18
0
        return;
19
0
    }
20
0
    auto url = URL::create_with_file_scheme(path, {}, hostname);
21
0
    out("\033]8;;{}\033\\{}\033]8;;\033\\", url.serialize(), path);
22
0
}
23
24
Optional<Line::Style> highlight_runnable(Shell& shell, Shell::RunnablePath& runnable)
25
0
{
26
0
    Line::Style bold = { Line::Style::Bold };
27
0
    VERIFY(runnable.kind == Shell::RunnablePath::Kind::Executable || runnable.kind == Shell::RunnablePath::Kind::Alias);
28
0
    auto name = shell.help_path_for({}, runnable);
29
0
    if (name.has_value()) {
30
0
        auto url = URL::create_with_help_scheme(name.release_value(), shell.hostname);
31
0
        return bold.unified_with(Line::Style::Hyperlink(url.to_byte_string()));
32
0
    }
33
0
    return {};
34
0
}
35
36
ErrorOr<void> highlight_filesystem_path(StringView path, Line::Editor& editor, Shell& shell, size_t start_offset, size_t end_offset)
37
0
{
38
0
    auto realpath = shell.resolve_path(path);
39
0
    return highlight_filesystem_path_without_resolving(path, editor, shell, start_offset, end_offset);
40
0
}
41
42
ErrorOr<void> highlight_filesystem_path_without_resolving(StringView realpath, Line::Editor& editor, Shell& shell, size_t start_offset, size_t end_offset)
43
0
{
44
0
    auto url = URL::create_with_file_scheme(realpath);
45
0
    url.set_host(TRY(String::from_byte_string(shell.hostname)));
46
0
    editor.stylize({ start_offset, end_offset }, { Line::Style::Hyperlink(url.to_byte_string()) });
47
0
    return {};
48
0
}
49
50
}