mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-12-02 12:30:31 +00:00
find: Print hyperlinks when standard output is attached to a terminal
This commit is contained in:
parent
446200d6f3
commit
71ddc33fbf
Notes:
sideshowbarker
2024-07-17 06:35:16 +09:00
Author: https://github.com/tcl3 Commit: https://github.com/SerenityOS/serenity/commit/71ddc33fbf Pull-request: https://github.com/SerenityOS/serenity/pull/20976 Reviewed-by: https://github.com/ADKaster ✅
2 changed files with 20 additions and 2 deletions
|
@ -92,7 +92,7 @@ target_link_libraries(disasm PRIVATE LibX86)
|
|||
target_link_libraries(expr PRIVATE LibRegex)
|
||||
target_link_libraries(fdtdump PRIVATE LibDeviceTree)
|
||||
target_link_libraries(file PRIVATE LibGfx LibIPC LibArchive LibCompress LibAudio)
|
||||
target_link_libraries(find PRIVATE LibRegex)
|
||||
target_link_libraries(find PRIVATE LibFileSystem LibRegex)
|
||||
target_link_libraries(functrace PRIVATE LibDebug LibX86)
|
||||
target_link_libraries(glsl-compiler PRIVATE LibGLSL)
|
||||
target_link_libraries(gml-format PRIVATE LibGUI)
|
||||
|
|
|
@ -10,9 +10,11 @@
|
|||
#include <AK/NonnullOwnPtr.h>
|
||||
#include <AK/OwnPtr.h>
|
||||
#include <AK/Time.h>
|
||||
#include <AK/URL.h>
|
||||
#include <AK/Vector.h>
|
||||
#include <LibCore/DirIterator.h>
|
||||
#include <LibCore/System.h>
|
||||
#include <LibFileSystem/FileSystem.h>
|
||||
#include <LibMain/Main.h>
|
||||
#include <LibRegex/Regex.h>
|
||||
#include <dirent.h>
|
||||
|
@ -30,6 +32,7 @@
|
|||
bool g_follow_symlinks = false;
|
||||
bool g_there_was_an_error = false;
|
||||
bool g_have_seen_action_command = false;
|
||||
bool g_print_hyperlinks = false;
|
||||
|
||||
template<typename... Parameters>
|
||||
[[noreturn]] static void fatal_error(CheckedFormatString<Parameters...>&& fmtstr, Parameters const&... parameters)
|
||||
|
@ -409,7 +412,20 @@ public:
|
|||
private:
|
||||
virtual bool evaluate(FileData& file_data) const override
|
||||
{
|
||||
out("{}{}", file_data.full_path, m_terminator);
|
||||
auto printed = false;
|
||||
if (g_print_hyperlinks) {
|
||||
auto full_path_or_error = FileSystem::real_path(file_data.full_path.string());
|
||||
if (!full_path_or_error.is_error()) {
|
||||
auto fullpath = full_path_or_error.release_value();
|
||||
auto url = URL::create_with_file_scheme(fullpath.to_deprecated_string());
|
||||
out("\033]8;;{}\033\\{}{}\033]8;;\033\\", url.serialize(), file_data.full_path, m_terminator);
|
||||
printed = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (!printed)
|
||||
out("{}{}", file_data.full_path, m_terminator);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -739,6 +755,8 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
|||
}
|
||||
}
|
||||
|
||||
g_print_hyperlinks = TRY(Core::System::isatty(STDOUT_FILENO));
|
||||
|
||||
if (!command)
|
||||
command = make<PrintCommand>();
|
||||
|
||||
|
|
Loading…
Reference in a new issue