mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 10:38:11 +00:00
find: Print hyperlinks when standard output is attached to a terminal
This commit is contained in:
parent
446200d6f3
commit
71ddc33fbf
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(expr PRIVATE LibRegex)
|
||||||
target_link_libraries(fdtdump PRIVATE LibDeviceTree)
|
target_link_libraries(fdtdump PRIVATE LibDeviceTree)
|
||||||
target_link_libraries(file PRIVATE LibGfx LibIPC LibArchive LibCompress LibAudio)
|
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(functrace PRIVATE LibDebug LibX86)
|
||||||
target_link_libraries(glsl-compiler PRIVATE LibGLSL)
|
target_link_libraries(glsl-compiler PRIVATE LibGLSL)
|
||||||
target_link_libraries(gml-format PRIVATE LibGUI)
|
target_link_libraries(gml-format PRIVATE LibGUI)
|
||||||
|
|
|
@ -10,9 +10,11 @@
|
||||||
#include <AK/NonnullOwnPtr.h>
|
#include <AK/NonnullOwnPtr.h>
|
||||||
#include <AK/OwnPtr.h>
|
#include <AK/OwnPtr.h>
|
||||||
#include <AK/Time.h>
|
#include <AK/Time.h>
|
||||||
|
#include <AK/URL.h>
|
||||||
#include <AK/Vector.h>
|
#include <AK/Vector.h>
|
||||||
#include <LibCore/DirIterator.h>
|
#include <LibCore/DirIterator.h>
|
||||||
#include <LibCore/System.h>
|
#include <LibCore/System.h>
|
||||||
|
#include <LibFileSystem/FileSystem.h>
|
||||||
#include <LibMain/Main.h>
|
#include <LibMain/Main.h>
|
||||||
#include <LibRegex/Regex.h>
|
#include <LibRegex/Regex.h>
|
||||||
#include <dirent.h>
|
#include <dirent.h>
|
||||||
|
@ -30,6 +32,7 @@
|
||||||
bool g_follow_symlinks = false;
|
bool g_follow_symlinks = false;
|
||||||
bool g_there_was_an_error = false;
|
bool g_there_was_an_error = false;
|
||||||
bool g_have_seen_action_command = false;
|
bool g_have_seen_action_command = false;
|
||||||
|
bool g_print_hyperlinks = false;
|
||||||
|
|
||||||
template<typename... Parameters>
|
template<typename... Parameters>
|
||||||
[[noreturn]] static void fatal_error(CheckedFormatString<Parameters...>&& fmtstr, Parameters const&... parameters)
|
[[noreturn]] static void fatal_error(CheckedFormatString<Parameters...>&& fmtstr, Parameters const&... parameters)
|
||||||
|
@ -409,7 +412,20 @@ public:
|
||||||
private:
|
private:
|
||||||
virtual bool evaluate(FileData& file_data) const override
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -739,6 +755,8 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
g_print_hyperlinks = TRY(Core::System::isatty(STDOUT_FILENO));
|
||||||
|
|
||||||
if (!command)
|
if (!command)
|
||||||
command = make<PrintCommand>();
|
command = make<PrintCommand>();
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue